akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define isFile 0
#define NAME "taskA"
#define scan 1
using namespace std;

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<ull> vull;
typedef vector<pii> vpii;

#define mp make_pair
#define pb push_back
#define fr first
#define sc second

#define ins insert
#define all(v) v.begin(), v.end()
#define rep(i,a,n) for (int i=a;i<n;i++)
#define bit(n, i) (n >> i) & 1
#define bpc(x) __builtin_popcountll(x)
#define rev(a) reverse(all(a))
#define skip continue
#define read(a) for(auto &i : a) cin >> i
#define print(a) for(auto i : a) cout << i << ' '
#define unique(a) sort(all(a));    a.resize(unique(all(a)) - a.begin())

//                D  R  U   L
const int dx[] = {1, 0, -1, 0, 1, 1, -1, -1};
const int dy[] = {0, 1, 0, -1, 1, -1, 1, -1};
const int day[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

void faster() {
    if (isFile) {
        freopen(NAME".in", "r", stdin);
        freopen(NAME".out", "w", stdout);
    }
    if (scan) {
        ios_base::sync_with_stdio(false);
        cin.tie(0);
        cout.tie(0);
    }
}

const ll  INF = 1e18;
const int inf = 2e9;
const int MOD = 1e9 + 7;
//const int MOD = 998244353;
const ld  PI = acos(-1);
const ld  EPS = 3E-16;
const int ALPHA = 26;
const int N = (int)3e2 + 5;
const int M = 123;

void solve() {
    ll n, m;
    cin >> n >> m;
    cout << (n * (n - 1)) / 2 + (m * (m - 1)) / 2 << endl;
}

int main() {
    faster();
    int t = 1;
//    cin >> t;
    while(t--) {
        solve();
    }
    return 0;
}


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

struct Y{
  string n; int b,e;
  Y(void){}
  Y(string a,int x,int y):n(a),b(x),e(y){}
  bool operator<(const Y a)const{return b<a.b;}
};

int main(){
  int n,q,i;
  int a,b,y;
  string name;
  Y e[1010];

  while(cin >> n >> q, n+q){
    for(i=0;i<n;i++){
      cin >> name >> a >> b;
      e[i] = Y(name,b-a+1,b);
    }
    sort(e,e+n);
    for(i=0;i<q;i++){
      cin >> y;
      int l=-1,r=n;
      while(r-l>1){
	int m = (l+r)/2;
	if(e[m].e>=y)r = m;
	else l = m;
      }

      if(r==n || e[r].b>y)cout << "Unknown\n";
      else cout << e[r].n << " " << y-e[r].b+1 << endl;
    }
  }
}

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

bool flg = false;

int main() {
  int C[3][3],C1[3][3],C2[3][3],C3[3][3],C4[3][3],C5[2][3];
  for (int i = 0; i<3; i++) for (int j = 0; j<3; j++) cin >> C[i][j];
  for (int i = 0; i<3; i++) for (int j = 0; j<3; j++) C1[i][j] = C[i][(j+1)%3]-C[i][j];
  for (int i = 0; i<3; i++) for (int j = 0; j<3; j++) C2[i][j] = C[(i+1)%3][j]-C[i][j];
  for (int i = 0; i<3; i++) for (int j = 0; j<3; j++) C3[i][j] = C1[(i+1)%3][j]-C1[i][j];
  for (int i = 0; i<3; i++) for (int j = 0; j<3; j++) C4[i][j] = C2[i][(j+1)%3]-C2[i][j];

  
  for (int i = 0; i<2; i++) for (int j = 0; j<2; j++) if(C3[i][j] != 0 && flg ==false) {
    cout << "No\n";
    flg = true;
  }
  for (int i = 0; i<2; i++) for (int j = 0; j<2; j++) if(C4[i][j] != 0 && flg ==false) {
    cout << "No\n";
    flg = true;
  }

  if(flg == false) cout << "Yes\n";
}

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

int main(void){
    // Your code here!
   long n,a,b;
   cin >> n >> a >> b;

   long c = a+b;
   long count;
   
   count = (n/c)*a+min(n%c,a);
 
   
   cout << count << endl;
   
   
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include<iostream>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<string>
#include<stdbool.h>
#include<math.h>
#include<sstream>
#include<math.h>
#include<vector>
#include<functional>
#include<queue>
#include<utility>
#include<bitset>
#include<time.h>
typedef long long ll;
#define N (1000000000+7)
#define INF 1e16
using namespace std;
typedef pair<int, int> P;

ll dp[55][2];

int main(void) {
	int n;
	ll k;
	cin >> n >> k;
	vector<ll> a(n);
	for (int i = 0; i < n; ++i) cin >> a[i];
	for (int i = 0;i < 50;i++) {
		for (int j = 0;j < 2;j++) {
			dp[i][j] = -1;
		}
	}
	dp[0][0] = 0;
	for (int d = 0; d < 50; ++d) {
		ll mask = (ll)1 << (50 - d - 1);

		int num = 0;
		for (int i = 0; i < n; ++i) if (a[i] & mask) ++num;

		ll cost0 = mask * num;
		ll cost1 = mask * (n - num);


		if (dp[d][1] != -1) {
			dp[d + 1][1] = max(dp[d + 1][1], dp[d][1] + max(cost0, cost1));
		}

		if (dp[d][0] != -1) {
			if (k & mask) {
				dp[d + 1][1] = max(dp[d + 1][1], dp[d][0] + cost0);
			}
		}

		if (dp[d][0] != -1) {
			if (k & mask) dp[d + 1][0] = max(dp[d + 1][0], dp[d][0] + cost1);
			else dp[d + 1][0] = max(dp[d + 1][0], dp[d][0] + cost0);
		}
	}
	cout << max(dp[50][0], dp[50][1]) << endl;
	return 0;
}

Measured memory_bytes: 1024
N, M = map(int, input().split())
E = [None]*M
for i in range(M):
    a, b, c = map(int, input().split())
    E[i] = (a-1, b-1, c)
d = [-float("inf") for _ in range(N)]
d[0] = 0

for i in range(N):
    for (f, t, c) in E:
        if d[f] != -float("inf") and d[t] < d[f] + c:
            d[t] = d[f] + c
            if i == N-1 and t == N-1:
                print("inf")
                exit()

print(d[-1])

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

const int MOD =1000000007;

signed main() {
int n,k,r,s,p;
cin>>n>>k>>r>>s>>p;
string t;
cin>>t;
int c[t.size()];
for(int i=0;i<n;i++){
    if(i>=k&&t[i]==t[i-k])c[i]=c[i-k]+1;
    else c[i]=2;
}
int ans=0;
for(int i=0;i<k;i++){
    for(int j=0;i+j*k<n;j++){
        if(i+(j+1)*k>=n||c[i+(j+1)*k]==2){
            if(t[i+j*k]=='r')ans+=p*(c[i+j*k]/2);
            else{
                if(t[i+j*k]=='s')ans+=r*(c[i+j*k]/2);
                else{
                    if(t[i+j*k]=='p')ans+=s*(c[i+j*k]/2);
                }
            }
        }
    }
   // cerr<<ans<<endl;
}
cout<<ans;

}


Measured memory_bytes: 1280
import java.util.Scanner;


public class Main {
	
	public static void main(String[] args){
		
		Scanner sc = new Scanner(System.in);
		
		while(true){
			
			int n = sc.nextInt();
			
			String[] line = new String[n];
			sc.nextLine();
			
			for(int i = 0; i < n; i++){
				line[i] = sc.nextLine();
			}
			
			for(int i = 0; i < n; i++){
				String[] linespl = line[i].split(" ");
				int calcsum = 0;
				for(int j = 0; j < linespl.length; j++){
					int soeji = 1;
					for(int k = 0; k < linespl[j].length(); k++){
						if(linespl[j].charAt(k) == 'm' || linespl[j].charAt(k) == 'c' || linespl[j].charAt(k) == 'x' || linespl[j].charAt(k) == 'i'){
							calcsum = calcsum + calc(soeji, linespl[j].charAt(k));
							soeji = 1;
						}else{
							soeji = new Integer(linespl[j].charAt(k) - '0');
						}
					}
					
				}	
				int up;
				while(true){
					if(calcsum >= 1000){
						up = calcsum/1000;
						if(up == 1){
							System.out.print("m");
						}else{
							System.out.print(up + "m");
						}
						calcsum = calcsum%1000;
					}else if(calcsum >= 100){
						up = calcsum/100;
						if(up == 1){
							System.out.print("c");
						}else{
							System.out.print(up + "c");
						}
						calcsum = calcsum%100;
					}else if(calcsum >= 10){
						up = calcsum/10;
						if(up == 1){
							System.out.print("x");
						}else{
							System.out.print(up + "x");
						}
						calcsum = calcsum%10;
					}else{
						if(calcsum == 1){
							System.out.println("i");
						}else{
							System.out.println(calcsum + "i");
						}
						break;	
					}
					
					if(calcsum == 0){
						System.out.println("");
						break;
					}
				}

				
			}
			break;
			
		}
		
	}

	private static int calc(int soeji, char charAt) {
		
		if(charAt == 'm'){
			return 1000 * soeji;
		}else if(charAt == 'c'){
			return 100 * soeji;
		}else if(charAt == 'x'){
			return 10 * soeji;
		}else if(charAt == 'i'){
			return soeji;
		}
		return 0;
	}

}

Measured memory_bytes: 13000
#include <bits/stdc++.h>
using namespace std;
const int maxn = 100000 + 10;
int sg[maxn];
vector<int> E[maxn];
void dfs(int x, int fa)
{
	for(auto v : E[x])
		if(v != fa)
		{
			dfs(v, x);
			sg[x] ^= (sg[v] + 1);
		} 
}
int main()
{
	int n;
	scanf("%d", &n);
	for(int i = 1; i < n; ++i)
	{
		int u, v;
		scanf("%d%d", &u, &v);
		E[u].push_back(v);
		E[v].push_back(u);
	}
	dfs(1, 0);
	puts(sg[1] ? "Alice" : "Bob");
	return 0;
}

Measured memory_bytes: 17264
#include <iostream>
#include <sstream>
#include <stack>
#include <iomanip>
#include <numeric>
#include <string>
#include <cstring>
#include <algorithm>
#include <functional>
#include <cstdlib>
#include <cassert>
#include <map>
#include <set>
#include <vector>
#include <utility>
#include <queue>
#include <cmath>

#define BEGIN(x) x.begin()
#define END(x) x.end()
#define ALL(x) BEGIN(x), END(x)
#define PAIR make_pair
#define VEC(type) vector<type >
#define endl '\n'
#define FIR first
#define SEC second
#define PB push_back
#define SZ(x) ((int)x.size())

#define FOR(i, A, B) for(auto i = (A);i != (B); i++)
#define FORD(i, A, B) for(auto i = (A);i != (B); i--)

#define READRANGE(begin, end) FOR(it, begin, end) cin >> *it
#define READVEC(V) READRANGE(BEGIN(V), END(V))

using namespace std;

typedef long long lint;
typedef pair<int, int> Pii;
typedef pair<int, lint> Pil;
typedef pair<lint, lint> Pll;
typedef pair<lint, int> Pli;

template<class U, class V>
istream& operator >>(istream& in, pair<U, V>& pr) {
    return in >> pr.first >> pr.second;
}

template<class U, class V>
ostream& operator <<(ostream& out, pair<U, V>& p) {
    return out << p.first << " " << p.second;
}

template<class T>
ostream& operator <<(ostream& out, vector<T> vec) {
    for (T& e : vec)
        out << e << " ";
    return out << endl;
}

// ---- BEGIN LIBRARY CODE ----
// ---- END LIBRARY CODE ----
void io_init()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
};

const int MOD7 = int(1e9) + 7;

int factorial(int n)
{
    int ret = 1;
    FOR(i, 1, n + 1)
        ret = (int)(ret * 1LL * i % MOD7);
    return ret;
};

void solveSingleCase(int caseNo)
{
    int N, M;
    cin >> N >> M;
    int a = factorial(N), b = factorial(M);
    if (N == M - 1 || N == M + 1) {
        cout << (a * 1LL * b % MOD7) << endl;
    } else if (N == M) {
        cout << (2 * a * 1LL * b % MOD7) << endl;
    }
    else 
        cout << 0 << endl;
};

int main(int argc, char **argv)
{
    io_init();

    // Actual program code starts here.
    int T = 1;
    // cin >> T;
    FOR(tcase, 1, T + 1) {
        solveSingleCase(tcase);
    }
    return 0;
};


Measured memory_bytes: 256
#include <string>
#include <vector>
#include <iostream>

using namespace std;

bool compare(string S1, string S2)
{
	if (S1.size() != S2.size()) { return S1.size() > S2.size(); }

	return S1 > S2;
}

int main()
{
	int H, W; char c[70];

	while (true)
	{
		scanf("%d", &W);
		scanf("%d", &H);

		if (H == 0 && W == 0) { break; }

		vector<string> R;

		for (int i = 0; i < H; i++)
		{
			scanf("%s", c);

			R.push_back(c);
		}

		vector<vector<string> > dp(H, vector<string>(W, ""));

		for (int i = 0; i < H; i++)
		{
			for (int j = 0; j < W; j++)
			{
				if (isdigit(R[i][j]))
				{
					if (R[i][j] != '0')
					{
						dp[i][j] = R[i][j];
					}

					if (i != 0)
					{
						if (R[i][j] != '0')
						{
							if (compare(dp[i - 1][j] + R[i][j], dp[i][j]))
							{
								dp[i][j] = dp[i - 1][j] + R[i][j];
							}
						}
						else
						{
							if (compare(dp[i - 1][j] + R[i][j], dp[i][j]) && dp[i - 1][j] != "")
							{
								dp[i][j] = dp[i - 1][j] + R[i][j];
							}
						}
					}

					if (j != 0)
					{
						if (R[i][j] != '0')
						{
							if (compare(dp[i][j - 1] + R[i][j], dp[i][j]))
							{
								dp[i][j] = dp[i][j - 1] + R[i][j];
							}
						}
						else
						{
							if (compare(dp[i][j - 1] + R[i][j], dp[i][j]) && dp[i][j - 1] != "")
							{
								dp[i][j] = dp[i][j - 1] + R[i][j];
							}
						}
					}
				}
			}
		}

		string ret = "";

		for (int i = 0; i < H; i++)
		{
			for (int j = 0; j < W; j++)
			{
				if (compare(dp[i][j], ret))
				{
					ret = dp[i][j];
				}
			}
		}

		printf("%s\n", ret.c_str());
	}

	return 0;
}

Measured memory_bytes: 3244
#include<stdio.h>

int main(){
int h,w,i,j;

while(1){
scanf("%d %d",&h,&w);
if(h==0&&w==0)break;
for(i=0;i<h;i++){

if(i==0 || i==h-1){
for(j=0;j<w;j++){
printf("#");
}
}else{
for(j=0;j<w;j++){
if(j==0 || j==w-1){printf("#");}
else{printf(".");}
}
}

printf("\n");
}
printf("\n");
}


return 0;
}

Measured memory_bytes: 572
use std::io;
use std::io::{Read, BufReader};
use std::cmp;

fn next_token<R: Read>(reader: &mut R) -> Vec<u8> {
    let mut buf: [u8; 1] = [0];
    let mut read_chars = false;
    let mut ret: Vec<u8> = vec![];

    loop {
        if reader.read(&mut buf).unwrap() == 0 {
            break;
        } else {
            if buf[0] == '\r' as u8 || buf[0] == '\n' as u8 || buf[0] == ' ' as u8 {
                if read_chars {
                    break;
                }
            } else {
                read_chars = true;
                ret.push(buf[0]);
            }
        }
    };
    ret
}
fn next_i64<R: Read>(reader: &mut R) -> i64 {
    let token = next_token(reader);
    let mut ret: i64 = 0;
    let mut sgn = false;

    for c in token {
        if '0' as u8 <= c && c <= '9' as u8 {
            ret = ret * 10 + (c - ('0' as u8)) as i64;
        } else if '-' as u8 == c {
            sgn = true;
        }
    };
    ret * if sgn { -1 } else { 1 }
}
fn next_i32<R: Read>(reader: &mut R) -> i32 {
    next_i64(reader) as i32
}
fn main() {
    let buf = &mut BufReader::new(io::stdin());

    let n = next_i32(buf);
    let mut cnt = [1001001001; 26];
    for _ in 0..n {
        let st = next_token(buf);
        let mut mcnt = [0; 26];
        for c in st {
            mcnt[(c - 'a' as u8) as usize] += 1;
        }
        for i in 0..26 {
            cnt[i] = cmp::min(cnt[i], mcnt[i]);
        }
    }
    let mut ans = "".to_string();
    for i in 0..26 {
        for _ in 0..cnt[i] {
            ans.push((i + 'a' as usize) as u8 as char);
        }
    }
    println!("{}", ans);
}


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

const int mod = 1000000007;
const int inf = 1000000000;
const int size = 100000;

vector<bool> prime(size + 1, true);
vector<int> p(size + 1, 0);

int main() {
    prime[0] = prime[1] = false;
    for (int i = 2; i * i <= size; i++) {
        if (prime[i]) {
            for (int j = i * i; j <= size; j += i) {
                prime[j] = false;
            }
        }
    }
    for (int i = 1; i <= size; i++) {
        p[i] = p[i - 1] + (prime[i] and prime[(i + 1) / 2]);
    }

    int q;
    scanf("%d", &q);
    int l, r;
    for (int i = 0; i < q; i++) {
        scanf("%d %d", &l, &r);
        printf("%d\n", p[r] - p[l - 1]);
    }

    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define bit(n) (1<<(n))
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1;} return 0;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1;} return 0;}
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 const INF = 1001001001;

vector<pii> List[90005];

int main()
{
    int H,W,D;
    cin >> H >> W >> D;
    vvi a(H,vi(W));
    vector<pii> data(H*W);
    rep(h,H) rep(w,W) {
        cin >> a[h][w];
        a[h][w]--;
        data[a[h][w]] = pii(h,w);
    }
    rep(i,H*W) List[i%D].emplace_back(data[i]);//List[x]:= 余りxである整数の場所が小さい順に並ぶ

    vvi d(D);
    vvi sd(D);
    rep(i,D) {
        if(List[i].empty()) continue;
        int n = List[i].size() - 1;
        d[i].resize(n);
        sd[i].resize(n+1);
        rep(j,n) {
            int uh = List[i][j].first; int uw = List[i][j].second;
            int vh = List[i][j+1].first; int vw = List[i][j+1].second;
            d[i][j] = abs(uh-vh) + abs(uw-vw);
            sd[i][j+1] = sd[i][j] + d[i][j];
        }
    }

    int Q;
    cin >> Q;
    rep(q,Q) {
        int L,R;
        cin >> L >> R;
        L--; R--;
        cout << sd[R%D][R/D] - sd[L%D][L/D] << endl;
    }
    return 0;
}

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

int main(){
    int N;
    cin >> N;
    int T[N];
    for(int i = 0; i < N; i++) cin >> T[i];

    int E = 0;
    for (int i = 0; i < N - 1; i++)
    {
        for (int j = i + 1; j < N; j++)
        {
            E += T[i] * T[j];
        }
        
    }
    cout << E << "\n";
    return 0;
}

Measured memory_bytes: 256
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


N,X=map(int,input().split())
x_list=list(map(int,input().split()))
x_list.append(X)
x_list.sort()
y_list=[]
for i in range(N):
    y_list.append(x_list[i+1]-x_list[i])
z_list=list(set(y_list))
if len(z_list)==1:
    print(z_list[0])

else:
    for i in range(len(z_list)-1):
        z_list[i+1]=gcd(z_list[i],z_list[i+1])
    print(z_list[-1])


Measured memory_bytes: 14480
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

class Program
{
    static void Main(string[] args)
    {
        new Program().Solve();
    }

    void Solve()
    {
        Scanner cin = new Scanner();
        int N = cin.NextInt();
        int[] V = cin.ArrayInt(N);
        int[] C = cin.ArrayInt(N);
        int pattern = N * N;
        int ans = 0;        
        for (int i = 0; i < N; ++i)
        {
            if (V[i] - C[i] > 0)
            {
                ans += V[i] - C[i];
            }
        }

        Console.WriteLine(ans);
    }
}


class Scanner
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner()
    {
        s = new string[0];
        i = 0;
    }

    public string Next()
    {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return Next();
        i = 0;
        return s[i++];
    }

    public int NextInt()
    {
        return int.Parse(Next());
    }
    public int[] ArrayInt(int N, int add = 0)
    {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = NextInt() + add;
        }
        return Array;
    }

    public long NextLong()
    {
        return long.Parse(Next());
    }

    public long[] ArrayLong(int N, long add = 0)
    {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = NextLong() + add;
        }
        return Array;
    }

    public double NextDouble()
    {
        return double.Parse(Next());
    }


    public double[] ArrayDouble(int N, double add = 0)
    {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = NextDouble() + add;
        }
        return Array;
    }
}

Measured memory_bytes: 13140
# -*- codinf: utf-8 -*-
N = input()
hon = [2, 4, 5, 7, 9]
pon = [0, 1, 6, 8]
bon = [3]
if int(N[-1]) in hon:
  print("hon")
elif int(N[-1]) in pon:
  print("pon")
elif int(N[-1]) in bon:
  print("bon")

Measured memory_bytes: 61800
#include <bits/stdc++.h>
using namespace std;
using lli = int_fast64_t;
using ulli = uint_fast64_t;
#define debug(x) cerr << #x << " : " << x << endl
#define debugv(x) cerr << #x << " : {";for(auto value_of_x:x){ cerr << value_of_x << ", ";}cerr << endl
#define debugst(x) auto xt = x;cerr << #x << " : {";for(int i=0;i<x.size();i++){ cerr << xt.top() << ", ";xt.pop();}cerr << endl
#define debugvp(x) cerr << #x << " : {";for(auto value_of_x:x){ cerr << value_of_x.first << " : " << value_of_x.second << ", ";}cerr << endl

const lli MOD = 1000000007;
const lli LIMIT = 1000000000000000000 * 5;
const int tenfive = 100000;

int main() {
	int N, D;
	cin >> N >> D;
	vector<vector<int>> v(N, vector<int>(D));
	for (int i = 0;i < N; i++) {
		for (int j = 0; j < D; j++) {
			cin >> v[i][j];
		}
	}
	int ans = 0;
	for (int i = 0; i < N; i++) {
		for (int j = i + 1; j < N; j++) {
			int sum = 0;
			for (int k = 0; k < D; k++) {
				sum += abs(v[i][k] - v[j][k]) * abs(v[i][k] - v[j][k]);
			}
			for (int k = 1; k * k <= sum; k++) {
				if (k * k == sum) {
					ans++;
				}
			}
		}
	}
	cout << ans << endl;
 	return 0;
}


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

using i32 = std::int_fast32_t;
using i64 = std::int_fast64_t;
template <typename T> constexpr T inf = numeric_limits<T>::has_infinity ? numeric_limits<T>::infinity() : numeric_limits<T>::max() / 4;

#define REP(i, stop) FOR(i, 0, stop)
#define FOR(i, start, stop) for (int i = start, i##_len = stop; i < i##_len; ++i)
#define RREP(i, n) for (int i = n; i-- > 0;)
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define COMP(key) [](const auto& a, const auto& b) { return a.key < b.key; }

template<typename T, typename U> istream& operator>>(istream& is, pair<T, U>& a) { return is >> a.first >> a.second; }
template<typename T> istream& operator>>(istream& is, vector<T>& a) { for (T& x : a) is >> x; return is; }

void LOG(const int& x) { cerr << x << "\n"; }
template<typename T> void LOG(const vector<T>& a) { for (const T& x : a) cerr << x << " "; cerr << "\n"; }
template<typename T, std::size_t S> void LOG(const T (&a)[S]) { REP(i, S) cerr << a[i] << " "; cerr << "\n"; }
template<typename T, std::size_t S, std::size_t R> void LOG(const T (&a)[S][R]) { REP(i, S) { REP(j, R) cerr << a[i][j] << " "; cerr << "\n"; } }

i64 ceil(i64 a, i64 b) { return (a - 1) / b + 1; }
i64 gcd(i64 a, i64 b) { while (b != 0) { i64 t = b; b = a % b; a = t; } return a; }
i64 lcm(i64 a, i64 b) { return a / gcd(a, b) * b; }
i64 gcd(const vector<i64>& v) { return accumulate(ALL(v), 1LL, static_cast<i64(*)(i64, i64)>(gcd)); }
i64 lcm(const vector<i64>& v) { return v.empty() ? 0LL : accumulate(v.begin() + 1, v.end(), v[0], static_cast<i64(*)(i64, i64)>(lcm)); }
i64 pow(i64 x, i64 y, i64 z) { i64 a = 1; while (y > 0) { if (y & 1) a = a * x % z; x = x * x % z; y /= 2; } return a; }
i64 inv(i64 x, i64 m) { return pow(x, m - 2, m); }

struct InitCpp { InitCpp() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(10); } } initCpp;

const i64 INF = inf<i64>;
using P = pair<i64, i64>;
signed main() {
  i64 N;
  cin >> N;
  vector<i64> A(N);
  i64 X[20][20];
  i64 Y[20][20];
  i64 T[20][20];
  REP(i, N) {
    cin >> A[i];
    REP(j, N) {
      T[i][j] = 2;
    }
    REP(j, A[i]) {
      cin >> X[i][j] >> Y[i][j];
      X[i][j] -= 1;
      T[i][X[i][j]] = Y[i][j];
    }
  }
  i64 ans = 0;
  REP(s, 1 << N) {
    i64 cnt = 0;
    REP(i, N) {
      if ((s >> i) & 1) {
        cnt += 1;
        REP(j, A[i]) {
          i64 a = (s >> X[i][j]) & 1;
          i64 b = Y[i][j];
          if (a != b) {
            goto fail;
          }
        }
      }
    }
    ans = max(ans, cnt);
    fail:;
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
n = int(input())
s = list(input())

dic = {}
for i in range(26):
    dic[chr(i+97)] = []

for i in range(n):
    dic[s[i]].append(i)

for i in range(26):
    dic[chr(i+97)].append(float('inf'))

from bisect import bisect_left
q = int(input())
for i in range(q):
    x, y, z = input().split()
    if x == '1':
        y = int(y) - 1
        p = bisect_left(dic[s[y]], y)
        dic[s[y]].pop(p)
        dic[z].insert(bisect_left(dic[z], y), y)
        s[y] = z
    else:
        res = 0
        y, z = int(y) - 1, int(z) - 1
        for i in range(26):
            p = dic[chr(i+97)][bisect_left(dic[chr(i+97)], y)]
            if p <= z:
                res += 1
        print(res)

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

int main() {
    long long N, K;
    cin >> N >> K;
    if(K & 1) {
        long long q = N / K;
        cout << q * q * q << endl;
    } else {
        long long q = N / (K >> 1);
        long long r1 = q / 2, r2 = (q + 1) / 2; 
        cout << r1 * r1 * r1 + r2 * r2 * r2 << endl;
    }
}

Measured memory_bytes: 256
//#include <bits/stdc++.h>
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <stdio.h>
#include <queue>
#include <deque>
#include <set>
#include <stack>
#include <time.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;

#define fi first
#define se second
#define mp make_pair
 
const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll INF = 1ll << 60;
const double PI = 2 * asin(1);

void yes() {printf("yes\n");}
void no() {printf("no\n");}
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}

int H, N, A[int(1e3 + 5)], B[int(1e3 + 5)];
int DP[int(1e3 + 5)][int(2e4 + 5)];

int main(){
  scanf("%d%d", &H, &N);
  for (int i = 1; i <= N; i++) scanf("%d%d", A + i, B + i);

  for (int j = 1; j < 2e4 + 5; j++) DP[0][j] = 1e9;

  for (int i = 1; i <= N; i++){
    for (int j = 0; j < 2e4 + 5; j++){
      DP[i][j] = DP[i - 1][j];
    }
    for (int j = 0; j + A[i] < 2e4 + 5; j++){
      DP[i][j + A[i]] = min(DP[i][j + A[i]], DP[i - 1][j] + B[i]); 
    }
    for (int j = 0; j + A[i] < 2e4 + 5; j++){
      DP[i][j + A[i]] = min(DP[i][j + A[i]], DP[i][j] + B[i]);
    }
    
    for (int j = 2e4 + 3; j >= 0; j--){
      DP[i][j] = min(DP[i][j], DP[i][j + 1]);
    }
  }

  cout << DP[N][H] << endl;
  
  return 0;
}


Measured memory_bytes: 78464
#include <iostream>/*{{{*/
#include <bits/stdc++.h>
#define REP(i, x) for(int i = 0; i < (int)(x); i++)
#define REPS(i,x) for(int i = 1; i <= (int)(x); i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREPS(i,x) for(int i=((int)(x));i>0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define RFOR(i, m, n) for(int i = m;i >= n;i--)
#define ALL(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define FILL(x,y) memset(x,y,sizeof(x))
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define PB(a) push_back(a)
#define debug(x) cerr << __LINE__ << ": " << #x << " -> " << x << '\n'
#define INF 999999999
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};/*}}}*/

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

  string s;
  cin >> s;

  set<int> w;
  FOR(i, 0, s.size()){
    if (w.count(s[i]) == 0){
      w.insert(s[i]);
    }
    else{
      cout << "no" << endl;
      return 0;
    }
  }
  cout << "yes" << endl;
  // cout << (w.size()==1)?"yes":"no"; << endl;
  //

  return 0;
}


Measured memory_bytes: 256
H, W = map(int, input().split())

if (H * W) % 3 == 0:
    ans = 0
else:
    ans = H*W
    for _ in range(2):
        for h in range(H//3, H//3 + 2):
            for w in range(W//2, W//2 + 2):
                M = max(h * W, (H-h)*w, (H-h)*(W-w))
                m = min(h * W, (H-h)*w, (H-h)*(W-w))
                ans = min(ans, M-m)
            
            for h2 in range((H-h)//2, (H-h)//2 + 2):
                M = max(h*W, h2*W, (H-h-h2)*W)
                m = min(h*W, h2*W, (H-h-h2)*W)
                ans = min(ans, M-m)
                
        H, W = W, H
        

print(ans)


Measured memory_bytes: 3064
//Created by: Aditya Singh
//Bleed Blue
#include <bits/stdc++.h>

using namespace std;

#pragma GCC optimize("Ofast")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,avx,avx2")
#define int long long int
#define ld long double
#define F first
#define S second
#define P pair<int,int>
#define unm unordered_map<int,int>
#define pb emplace_back
#define nt _int128
#define PI 3.1415926535897932384626433
#define inf 1e18

const int N = 100005;

vector<int> gr[N];
int deg[N], dis[N];
bool vis[N];

void dfs(int node)
{
    vis[node] = 1;
    for (auto x : gr[node])
    {
        dis[x] = max(dis[x], 1 + dis[node]);
        deg[x]--;
        if (deg[x] == 0)
            dfs(x);
    }
}

int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    // int t;cin>>t;while(t--)
    {
        int i, j, k, n, m, ans = 0, cnt = 0, sum = 0;
        cin >> n >> m;
        for (i = 1; i <= m; i++)
        {
            int x, y;
            cin >> x >> y;
            gr[x].pb(y);
            deg[y]++;
        }
        for (i = 1; i <= n; i++)
        {
            if (!vis[i] && deg[i] == 0)
                dfs(i);
        }
        for (i = 1; i <= n; i++)
            ans = max(ans, dis[i]);
        cout << ans;
    }
    return 0;
}

Measured memory_bytes: 15364
<?php

$sum = 0;
$total = 0;
$cnt = 0;
while (($line = trim(fgets(STDIN))) !== '') {
    sscanf($line, '%d,%d', $n, $m);
    $sum += $n * $m;
    $total += $m;
    $cnt++;
}

printf("%d\n%d\n", $sum, round($total / $cnt));

Measured memory_bytes: 6580
#include <cstring>
#include <map>
#include <unordered_map>
#include <string>
#include <list>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <cstdio>
#include <iostream>
#include <set>
#include <unordered_set>
using namespace std;

#define MAX(a,b) (a>b?a:b)
#define MIN(a,b) (a<b?a:b)
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef pair<int, int> pii;

int gi() {
    int a;
    scanf("%d", &a);
    return a;
}

ll gli() {
    ll a;
    scanf("%lld", &a);
    return a;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    char c[4];
    scanf("%s", c);
    printf("%c\n", c[0]+1);

    return 0;
}


Measured memory_bytes: 256
#include<iostream>

int main(){
    int a,b,c;
    std::string s;

    std::cin >> a >> s >> b;
    if(s == "+"){
        c = a + b;
    }else if(s == "-"){
        c = a - b;
    }else{
        return -1;
    }

    std::cout << c << std::endl;
    return 0;
}

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

using namespace std;

int main() {

	// freopen("input.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);

	string s;
	cin >> s;
	s[5] = ' ';
	s[13] = ' ';
	cout << s << '\n';
	return 0;
}

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

using namespace std;
typedef long long ll;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
#define all(a) (a).begin(), (a).end()
#define all2(a, b) (a).begin(), (a).begin() + (b)
#define debug(vari) cerr << #vari << " = " << (vari) << endl;

int main()
{
    int n, x;
    cin >> n >> x;
    vector<int> a(n);
    rep(i, n) cin >> a[i];

    sort(all(a));

    int ans = 0;
    rep(i, n - 1)
    {
        if (x >= a[i])
        {
            ans++;
            x -= a[i];
        }
        else
        {
            break;
        }
    }

    if (x == a[n - 1])
    {
        ans++;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;(i)<(n);i++)
typedef long long ll;
using namespace std;
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 f(int x){
    int res = 0;
    while(x%2==0){
        res++;
        x/=2;
    }
    return res;
}
int main (){
    int n,m; cin >> n >> m;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    rep(i,n) a[i]/=2;
    int t = f(a[0]);
    rep(i,n){
        if(f(a[i])!=t){
            cout << 0 << endl;
            return 0;
        }
        a[i] >>= t;
    }
    m >>= t;
    ll LCM = 1;
    rep(i,n){
        LCM = lcm(LCM,a[i]);
        if(LCM>m){
            cout << 0 << endl;
            return 0;
        }
    }m/=LCM;
    cout << (m+1)/2 << endl;
}



Measured memory_bytes: 640
//#include <bits/stdc++.h>
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <queue>
#include <deque>
#include <set>
#include <stack>
#include <time.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;

const ll nmax = 1e9 + 7;
const ll Mod = 998244353;
const double PI = 2 * asin(1);

int main(){
  int A, B, C, D, E, F;
  cin >> A >> B >> C >> D >> E >> F;

  vector <bool> water(31), sugar(3001);
  water[0] = true;

  for (int i = 0; i < 31; i++){
    if (water[i] == true) {
      if (i + A < 31) water[i + A] = true;
      if (i + B < 31) water[i + B] = true;
    }
  }
  
  sugar[0] = true;
  for (int i = 0; i < 3001; i++){
    if (sugar[i] == true){
      if (i + C < 3001) sugar[i + C] = true;
      if (i + D < 3001) sugar[i + D] = true;
    }
  }

  vector <double> Water, Sugar;
  for (int i = 1; i < 31; i++){
    if (water[i] == true) Water.push_back(i * 100);
  }

  for (int i = 0; i < 3001; i++){
    if (sugar[i] == true) Sugar.push_back(i);
  }


  double Max_rate = -1;
  double Water_ans = 0, Sugar_ans = 0;

  for (int i = 0; i < Water.size(); i++){
    for (int j = 0; j < Sugar.size(); j++){
      if (Water[i] + Sugar[j] > F) break;

      if (Water[i] / 100 * E < Sugar[j]) break;
      double now = Sugar[j] / (Water[i] + Sugar[j]);
      if (Max_rate < now){
        Max_rate = now;
        Water_ans = Water[i];
        Sugar_ans = Sugar[j];
      }
    }
  }

  cout << Water_ans + Sugar_ans << " " << Sugar_ans << endl;
  
  return 0;
}


Measured memory_bytes: 256
S = input()[::-1]
W = ['dream','dreamer','erase','eraser']
i = 0
while i < len(S):
    for w in W:
        if S[i:i+len(w)] == w[::-1]:
            i += len(w)
            break
    else:
        print('NO')
        exit()
print('YES')

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

int main() {
  long long n,sum=0, mod=2019;
  string a;
  cin>>n;
  vector<string> st(n);
  rep(i,n){
    cin>>st[i];
  }
  sort(st.begin(), st.end());
  for(int i=0; i<n-1; i++){
    if(st[i]==st[i+1])
      sum++;
  }
    
  cout<<n-sum<<endl;
  
  
  
  
}

Measured memory_bytes: 9536
#!/usr/bin/python3

from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]


def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W

def main():
    A, B, C = map(int, input().split())
    K = int(input())

    m = max(A, B, C)
    d = m
    for i in range(K):
        d *= 2
    print(A + B + C - m + d)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3956
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

#define fo(i,n)         for(int i=0;i<n;i++)
#define Fo(i,k,n)       for(int i=k;i<n;i++) 
#define endl            "\n"
#define ff              first
#define ss              second
#define int             long long
#define pb              push_back
#define mp              make_pair
#define vec(x)          vector<x>
#define matrix(x)       vector<vector<x>>
#define mem(a,b)        memset(a, b, sizeof a)
#define vii             vector<pair<int,int>>
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define MOD             998244353
#define deb(x)          cerr <<#x<<" = "<<x<<"\n"
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
#define all(v)          v.begin(),v.end()
#define rep(i,a,b)      for (int i = a; i<b; ++i)
#define len(s)          s.length()
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());
 
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
 
 
int power(int a,int b,int m=mod)
{int ans=1;while(b>0){if(b&1)ans=(ans*a)%m;a=(a*a)%m;b>>=1;}
return ans;}

void angshuGod()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
}

const int N = 1e5+1;
const double pi = acos(-1);

void solve(){    

    int n;
    cin>>n;

    vi v(n);
    int mx = -1;
    mii m;
    set<int>s;
    fo(i,n){
    	cin>>v[i];
    	mx = max(mx,v[i]);
    	m[v[i]]++;
    	s.insert(v[i]);
    }
    int dp[mx+1];
    mem(dp,true);

    for(int x : s){
    	for(int i = 2*x;i<=mx;i+=x){
    		dp[i] = false;
    	}
    }
    int cnt = 0;
    for(int x : s){
    	if(dp[x] && m[x]==1) cnt++;
    }
    cout<<cnt;
}

 
int32_t main()
{
    angshuGod();

    int t;

    t = 1;
    //cin>>t;

    while(t--){
        solve();
    }
    
    return 0;
}

Measured memory_bytes: 34544
#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = int(a); i < int(b); i++)
#define rer(i, a, b) for(int i = int(a) - 1; i >= int(b); i--)
#define sz(v) (int)(v).size()
#define pb push_back
#define sc second
#define fr first
#define sor(v) sort(v.begin(),v.end())
#define rev(s) reverse(s.begin(),s.end())
#define lb(vec,a) lower_bound(vec.begin(),vec.end(),a)
#define ub(vec,a) upper_bound(vec.begin(),vec.end(),a)
#define uniq(vec) vec.erase(unique(vec.begin(),vec.end()),vec.end())
using namespace std;
typedef long long int ll;
typedef pair <int, int> P;

const ll MOD=1000000007;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll A,B,K;
    cin>>A>>B>>K;
    rep(i,0,K){
        if(!(i%2)){
            A/=2;
            B+=A;
        }
        else{
            B/=2;
            A+=B;
        }
    }
    cout <<A<< " " <<B <<"\n";
}

Measured memory_bytes: 256
local str = io.read()
local y, m, d = str:match("(%d+)/(%d+)/(%d+)")
y,m,d=tonumber(y),tonumber(m),tonumber(d)
if(y < 2019) then print("Heisei")
elseif(2019 < y) then print("TBD")
else
  if(m <= 4) then print("Heisei")
  else print("TBD") end
end


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

int a,b,o,ab,n;
char x[5];

int main(){
	a=b=o=ab=0;
	while(scanf("%d,%s",&n,x)!=EOF){
		if(strcmp(x, "A")==0) a++;
		if(strcmp(x, "B")==0) b++;
		if(strcmp(x, "O")==0) o++;
		if(strcmp(x,"AB")==0)ab++;
	}
	printf("%d\n%d\n%d\n%d\n",a,b,ab,o);
	
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 1;
int n,m,mn[N];
int main(){
	//freopen("readin.txt","r",stdin);
	scanf("%d%d",&n,&m);
	for(int i = 0;i < n;i++)mn[i] = 1e9;
	for(int i = 0,a,b;i < m;i++){
		scanf("%d%d",&a,&b);
		mn[a - 1] = min(mn[a - 1],b - 1);
	}
	int cur = 1e9,ans = 0;
	for(int i = 0;i < n;i++){
		if(cur == i){
			ans++;
			cur = 1e9;
		}
		cur = min(cur,mn[i]);
	}
	printf("%d\n",ans);
}  

Measured memory_bytes: 640
x, y, a, b, c = map(int, input().split()) 
z = min(c, x+y)
p = sorted(list(map(int, input().split())))[a - x:]
q = sorted(list(map(int, input().split())))[b - y:]
r = sorted(list(map(int, input().split())))[c - z:]

s = sorted(p + q + r)[z:]

print(sum(s))

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

int main () {
  int N, count = 30;
  cin >> N;
  
  for (int i = 0; i < N; i++) {
    int A, x;
    cin >> A;
    
    for (int j = 0; j < 30; j++) {
      if (A % 2 == 0) 
        A /= 2;
      
      else {
        x = j;
        break;      
      }
    }
    
    if (x < count) 
      count = x;
  }
  
  cout << count << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<stdio.h>
using namespace std;
#define ll  long long
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define pii pair<int,int>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>



int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n,k;
cin>>n>>k;
string s;
cin>>s;
int a[n];
for(int i=0;i<n;i++){
    if(s[i]=='L')
        a[i]=-1;
    else a[i]=1;
}

int i=0;
int ans=0;
int u=0;
while(i<n){
    int j=i+1;
    while(j<n && a[j]==a[j-1])
        j++;

    ans+=(j-i-1);


    u++;
    i=j;
}
if(2*k>=u)
    ans=n-1;
else
     ans+=2*k;
cout<<ans<<endl;



}













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

int main() {
  long long N, M, K;
  cin >> N >> M >> K;
  vector<long long> A(N), B(M);
  vector<long long> d_A(N+1), d_B(M+1);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
    d_A[i+1] += d_A[i] + A[i];
  }
  for (int i = 0; i < M; i++) {
    cin >> B[i];
    d_B[i+1] += d_B[i] + B[i];
  }
  
  long long max_count = 0;
  long long book_count = 0;
  long long time_count = 0;
  long long a_book_count = 0;
  long long a_time_count = 0;
  
  long long i = 0, j = M;
  for (; i<=N; i++) {
    for (; j>=0; j--) {
      if (d_A[i] + d_B[j] > K) {
        continue;
      } else {
        max_count = max(max_count, i+j);
        break;
      }
    }
  }
  cout << max_count << endl;
  return 0;
}

Measured memory_bytes: 9588
#include<bits/stdc++.h>
#define ll long long
#define mx 200005
#define mod 1000000007
#define mxm 999999999999
using namespace std;

ll dp[mx];
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
    ll a[mx],i,n,k,j;
    cin>>n>>k;
    for(i=1;i<n+1;i++)
    cin>>a[i];
    dp[1]=0;
    /*dp[2]=abs(a[2]-a[1]);
    for(i=3;i<n+1;i++)
    dp[i]=min(dp[i-2]+abs(a[i]-a[i-2]),dp[i-1]+abs(a[i]-a[i-1]));*/
    for(i=2;i<n+1;i++)
    {
        ll mnm=mxm;
        for(j=i-1;j>0&&j>i-k-1;j--)
        {
            mnm=min(mnm,dp[j]+abs(a[i]-a[j]));
        }
        dp[i]=mnm;
    }
    cout<<dp[n];
	return 0;
}

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

using namespace std;
using ll = long long;
#define int ll
using PII = pair<int, int>;
template <typename T> using V = vector<T>;
template <typename T> using VV = vector<V<T>>;
template <typename T> using VVV = vector<VV<T>>;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define PB push_back

const ll INF = (1LL<<60);
const int MOD = 1000000007;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template <typename T> bool IN(T a, T b, T x) { return a<=x&&x<b; }
template<typename T> T ceil(T a, T b) { return a/b + !!(a%b); }
template<class S,class T>
ostream &operator <<(ostream& out,const pair<S,T>& a){
  out<<'('<<a.first<<','<<a.second<<')';
  return out;
}
template<class T>
ostream &operator <<(ostream& out,const vector<T>& a){
  out<<'[';
  REP(i, a.size()) {out<<a[i];if(i!=a.size()-1)out<<',';}
  out<<']';
  return out;
}

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

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

  int n, q;
  cin >> n >> q;

  int st = 0;
  REP(i, q) {
    int type, k;
    cin >> type >> k; k--;
    if(type == 0) {
      cout << ((st+k) % n) + 1 << endl;
    } else {
      st = (st+k+1) % n;
    }
  } 
  
  return 0;
}



Measured memory_bytes: 3204
/// sultanov      

#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
     
#define x first
#define y second
#define pb push_back
#define sz(x) (int) x.size()

using namespace std;
using namespace __gnu_pbds;
                                                          
template<typename T> 
using ordered_set = tree<T, null_type,   
less<T>, rb_tree_tag,
tree_order_statistics_node_update>;

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

const int N = 2e2;
const int MOD = 1e9 + 7;
const int INF32 = 1e9 + 1e2;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    ll a, b;
    cin >> a >> b;
    if (a <= 0 && b >= 0)
        cout << "Zero", exit(0);
    int n = 0;
    if (a < 0) 
        n += (b < 0 ? b + 1 : 0) - a;
    cout << (n & 1 ? "Negative" : "Positive");
    return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;

using ll = long long;

int main() {
    ll N, A, B;
    cin >> N >> A >> B;
    vector<ll> X(N);
    rep(i, N) cin >> X[i];
    ll ans = 0;
    rep(i, N - 1) {
        ans += min(A * (X[i + 1] - X[i]), B);
    }
    cout << ans << endl;
}

Measured memory_bytes: 1024
import java.io.PrintWriter;
import java.util.*;

public class Main {

    private static Scanner in = new Scanner(System.in);
    private static PrintWriter out = new PrintWriter(System.out);

    public static void main(String[] args) {
        solve();
        out.flush();
    }

    private static void solve() {
        int n = in.nextInt();
        int[] h = new int[n];
        for (int i=0; i < n; i++)
            h[i] = in.nextInt();

        int[] dp = new int[n];
        dp[1] = Math.abs(h[1] - h[0]);
        for (int i=2; i < n; i++)
            dp[i] = Math.min(dp[i-2] + Math.abs(h[i] - h[i-2]), dp[i-1] + Math.abs(h[i] - h[i-1]));

        out.println(dp[n-1]);
    }

}


Measured memory_bytes: 50452
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int INF = 1LL<<60;
const int MOD = (int)1e9 + 7;

signed main() {
    int n;
    cin >> n;
    vector<pair<int, int> > v;
    for (int i = 0; i < n; i++) {
        int a;
        cin >> a;
        v.emplace_back(make_pair(a, i + 1));
    }
    sort(v.begin(), v.end());
    for(auto&& p: v) {
        cout << p.second << " ";
    }
    cout << "\n";
}

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

using namespace std;

int cval[3];

int dp[30003][4];

int main(){

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

    cin >> cval[0] >> cval[1] >>  cval[2]; 
    int m;
    cin >> m ;
    dp[0][0] = 0;
    for(int i = 1 ; i <= 3 ; ++i){
        dp[0][i] = 1;
    }
    
    for(int i = 1; i <= m ; ++i ){
        for(int j = 1; j <= 3 ; ++j){
            if (i >= cval[j-1])
                dp[i][j] =  dp[i - cval[j-1]][j] + dp[i][j-1];
            else 
                dp[i][j] = dp[i][j-1];
        }
    }

  /*   cout << "printing dp "<< "\n";

    for(int i = 0; i <= m ; ++i){
        for(int j = 0; j <= 3; ++j){
            cout << dp[i][j] << " ";
        }
        cout << "\n";
    }
    
 */
   
    cout << dp[m][3] << "\n";
    
  
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<set>
#include<algorithm>

int main() {
	std::set<size_t> v;
	for (size_t i{ 0 }; i < 3; i++) {
		size_t t;
		std::cin >> t;
		v.emplace(t);
	}
	//std::unique(std::begin(v),std::end(v) );
	
	std::cout << v.size() << "\n";
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
 
const double EPS = 1e-10;
const ll INF = 100000000;
const ll MOD = 1000000007;

int a[100000];
int b[100000];

int main() {
    int n;
    cin >> n;
    rep(i,n) cin >> a[i];
    sort(a,a+n);
    if (n%2 == 0) {
        b[0] = a[n/2];
        b[n-1] = a[n/2-1];
        int j = 0;
        for (int i = 1; i < n-1; i += 2) {
            b[i] = a[j];
            b[i+1] = a[n-1-j];
            j++;
        }
    } else {
        bool f = false;
        b[0] = a[n/2];
        if (a[n/2+1]-a[n/2] > a[n/2]-a[n/2-1]) {
            f = true;
        }
        int j = 0;
        for (int i = 1; i < n; i += 2) {
            if (!f) {
                b[i] = a[j];
                b[i+1] = a[n-1-j];
            } else {
                b[i] = a[n-1-j];
                b[i+1] = a[j];
            }
            j++;
        }
    }
    ll ans = 0;
    for (int i = 0; i < n-1; i++) ans += abs(b[i]-b[i+1]);
    cout << ans << endl;
}



Measured memory_bytes: 1024