akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <iostream>
#include <cmath>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <queue>
#include <utility>
#include <vector>
#include <set>
#include <memory.h>
#include <iomanip>
#include <bitset>
#include <list>
#include <stack>
#include <deque>
#include <numeric>

using namespace std;

#define mod 1000000007

int main()
{
	int n;
	cin >> n;
	int a[101];
	for(int i = 0; i < n; i++){
		cin >> a[i];
	}
	sort(a, a + n);
	cout << a[n - 1] - a[0] << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }

void _main() {
  string s;
  cin >> s;

  deque<char> deq;
  fore(i, s) {
    if (i == 'B' && !deq.empty()) deq.pop_back();
    if (i == 'B') continue;
    else deq.push_back(i);
  }

  fore (i, deq) {
    cout << i;
  }
  cout << "\n";
}

Measured memory_bytes: 256
def main():
    S = input()
    T = input()

    # K個ずれたところ始めてマッチするかどうか
    def match(k):
        ans = True
        for i in range(len(T)):
            if S[k+i] != T[i] and S[k+i] != '?':
                ans = False
            # print(i, S[k+i], T[i], ans)
        return ans

    def construct(k):
        s = list(S)
        for i in range(len(T)):
            s[k+i] = T[i]
        return "".join(s)


    back = None
    for i in range(len(S) - len(T) + 1):
        if match(i):
            back = i

    if back is None:
        print('UNRESTORABLE')
    else:
        s = construct(back)
        s = s.replace('?', 'a')
        print(s)

if __name__ == "__main__":
    main()

Measured memory_bytes: 3064
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#include<cmath>


#define REP(i,n) for (int i = 0; (i) < (n); ++ (i))
#define FOR(i,n) for (int i = 1; (i) <= (n); ++ (i))
#define dump(x)  cout << #x << " = " << (x) << endl;
#define pb push_back
#define int long long
//#define lint long long

const int INF = 1e18;
const int MOD = 1e9+7;
//const lint LINF = 1e18;
const double eps = 0.000000001;//もとの値の10^(-16)まで

using namespace std;

//typedef pair<int, int> P;
//priority_queue< P, vector<P>, greater<P> > q;//ダイクストラの時、greaterで小さい順

vector<int> edge[300000];
int wa[300000];

int ans[300000];
int pa[300000];

void dfs(int now, int npo){
  ans[now] = npo + wa[now];
  REP(i,edge[now].size()){
    int nex = edge[now][i];
    if(nex == pa[now]) continue;
    pa[nex] = now;
    dfs(nex,ans[now]);
  }
}


signed main(){
  int n;
  cin >> n;
  int q;
  cin >> q;
  REP(i,n-1){
    int a1,b1;
    cin >> a1 >> b1;
    edge[a1].pb(b1);
    edge[b1].pb(a1);
  }
  REP(i,q){
    int p1,x1;
    cin >> p1 >> x1;
    wa[p1] += x1;
  }
  dfs(1,0);
  REP(i,n-1){
    cout << ans[i+1] << " ";
  }
  cout << ans[n] << endl;

  return 0;
}


Measured memory_bytes: 31616
def solve(a,k):
    dp=[0]*(k+1)
    for i in range(k+1):
        for j in a:
            if i>=j and not dp[i-j]:
                dp[i]=1
    return 'First' if dp[-1] else 'Second'
if __name__=='__main__':
    n,k=map(int,input().split())
    a=list(map(int,input().split()))
    print(solve(a,k))

Measured memory_bytes: 73824
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>

#define NUMBER 100

int main(void)
{
	int x[NUMBER];
	int i;
	int n;

	do {
		scanf("%d", &n);
	} while (n < 1 || n > 100);
	for (i = 0; i < n; i++) {
		scanf("%d",&x[i]);
	}
	for (i = 0; i < (n - 1); i++) {
		printf("%d ", x[(n - 1) - i]);
	}
	printf("%d\n",x[0]);

	
	
	
	
	
	
	
	
	
	
	return 0;
}

Measured memory_bytes: 2752
using namespace std;
#include <bits/stdc++.h>
#define rep(i, s) for (int i = 0; i < s; ++i)
#define repr(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define all(v) (v.begin(), v.end())
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define VEC(a, n) vector<int>a(n)
#define PQ(a) priority_queue<int>a
#define PQmin(a) priority_queue< int, :vector<int>, greater<int> >a
#define PAIR pair<int, int>
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
#define EPS (1e-7)
#define INF (1e10)
#define PI (acos(-1))
const ll mod = 1000000007;
 
int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N;
  string S;
  cin>>N>>S;
  int ans=0;
  FOR(i,1,N){
    int cnt=0;
    for(char s='a';s<='z';s++){
      bool left =false,right=false;
      rep(j,i){
        if(S[j]==s)
          left=true;
      }
      FOR(j,i,N){
        if(S[j]==s)
          right=true;
      }
      if(right&&left)
        cnt++;
    } 
    ans=max(cnt,ans);
  }
  cout<<ans<<endl;
    
    
}
  



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MAXN 100100
const ll inf = (ll)1e10;
const ll MOD = (ll)1e9+7;
ll dp[22][1 << 22];
bool chk ( int pos, int mask ) {
	return mask & (1 << pos);
}
int on ( int pos, int mask ) {
	return mask | (1<<pos);
}
int n, done;
int adj[21][21];
ll solve(ll pos , ll mask){
    
    if (pos == n){
        if (mask == done - 1) {
            return 1;
        } else return 0;
    }
    if(dp[pos][mask] != -1) return dp[pos][mask];
    dp[pos][mask] = 0;
    for(int j = 0 ; j < n; j++){
        if (adj[pos][j] && !(mask & (1<<j) ) ) dp[pos][mask] = (dp[pos][mask] + solve ( pos+1, mask|(1<<j) ) ) %MOD;
    }
    return dp[pos][mask];
}
int main()
{
	#ifdef __APPLE__
	//freopen("in.txt","r",stdin);
	//freopen("out.txt","w",stdout);
	#endif
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin >> n;
	for ( int i = 0; i < n; i++ ) {
		for ( int j = 0; j < n; j++ ) {
			cin >> adj[i][j];
		}
	}
	done = (1<<n);
	memset(dp,-1,sizeof(dp));
	cout << solve(0,0) << endl;
	return 0;
}


Measured memory_bytes: 721152
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
#include<complex>
using namespace std;

//#define int long long
typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = mod * mod;
typedef pair<int, int>P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef pair<ll, ll> LP;
typedef double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-6;
const ld pi = acos(-1.0);
typedef vector<vector<ll>> mat;
typedef vector<int> vec;

void solve() {
	int n, d, x; cin >> n >> d >>x;
	vector<int> a(n);
	rep(i, n)cin >> a[i];
	int ans = x;
	rep(i, n) {
		for (int j = 1; j <= d; j += a[i])ans++;
	}
	cout << ans << endl;
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(6);
	//init();
	solve();
	stop
		return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;

class Program
{
    static string InputPattern = "InputX";

    static List<string> GetInputList()
    {
        var WillReturn = new List<string>();

        if (InputPattern == "Input1") {
            WillReturn.Add("aatt");
            //5
        }
        else if (InputPattern == "Input2") {
            WillReturn.Add("xxxxxxxxxx");
            //1
        }
        else if (InputPattern == "Input3") {
            WillReturn.Add("abracadabra");
            //44
        }
        else {
            string wkStr;
            while ((wkStr = Console.ReadLine()) != null) WillReturn.Add(wkStr);
        }
        return WillReturn;
    }

    static void Main()
    {
        List<string> InputList = GetInputList();
        string A = InputList[0];

        long Answer = 1 + Derive_nC2(A.Length);
        foreach (var Each in A.ToCharArray().GroupBy(X => X)) {
            if (Each.Count() <= 1) continue;
            Answer -= Derive_nC2(Each.Count());
        }
        Console.WriteLine(Answer);
    }

    //nC2を返す
    static long Derive_nC2(long pN)
    {
        return pN * (pN - 1) / 2;
    }
}


Measured memory_bytes: 15712
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for (int i = 0; i < n; ++i)
#define REP(i,k,n) for (int i = k; i <= n; ++i)
#define REPR(i,k,n) for (int i = k; i >= n; --i)
#define pb push_back
#define F first
#define S second
#define I insert
#define mp make_pair
#define sz(a) (int)((a).size())
#define all(a) (a).begin(), (a).end()
#define debug1(a) cout<<" a : "<<a<<"\n"
#define debug2(a,b) cout<<" a : "<<a<<" b : "<<b<<"\n"
#define debug3(a,b,c) cout<<" a : "<<a<<" b : "<<b<<" c : "<<c<<"\n"
#define debug4(a,b,c,d) cout<<" a : "<<a<<" b : "<<b<<" c : "<<c<<" d : "<<d<<"\n"
// #define M 421412341324321
#define MOD 998244353 

signed main()
{
	ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
	
	int a,b;
	cin>>a>>b;
	cout<<max(a+b, max(a-b,a*b));

	return 0;
}


Measured memory_bytes: 256
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char) 
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn min<T: std::cmp::PartialOrd>(a: T, b: T) -> T {
    if a < b {
        return a;
    } else {
        return b;
    }
}

fn main() {
    let n: usize = read();
    let hi: Vec<i32> = (0..n).map(|_| read()).collect();

    let mut dp = vec![std::i32::MAX; n];
    dp[0] = 0;

    for i in 1..n {
        dp[i] = min(dp[i], dp[i-1] + (hi[i-1] - hi[i]).abs());
        if i > 1 {
            dp[i] = min(dp[i], dp[i-2] + (hi[i-2] - hi[i]).abs());
        }
    }

    println!("{}", dp[n-1]);
}


Measured memory_bytes: 4352
from collections import Counter

n = int(input())
v = [int(x) for x in input().split()]

odd = sorted(Counter(v[0:n:2]).items(), reverse=True, key=lambda x: x[1])
even = sorted(Counter(v[1:n+1:2]).items(), reverse=True, key=lambda x: x[1])

if odd[0][0] != even[0][0]:
    res = n - odd[0][1] - even[0][1]
elif len(odd) == 1:
    res = odd[0][1]
else:
    if odd[0][1] == even[0][1]:
        if odd[1][1] >= even[1][1]:
            res = n - odd[1][1] - even[0][1]
        else:
            res = n - odd[0][1] - even[1][1]
    elif odd[0][1] > even[0][1]:
        res = n - odd[0][1] - even[1][1]
    else:
        res = n - odd[1][1] - even[0][1]

print(res)


Measured memory_bytes: 20692
#include <iostream>
#include <iomanip>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <utility>
#include <string>
#include <cmath>
#include <cstdlib>
#include <cstring>

using namespace std;

typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;

const double PI=3.14159265358979323846;

#define MAX(x, y) ((x) < (y) ? (y) : (x))
#define MIN(x, y) ((x) > (y) ? (y) : (x))

#define rep(i, N) for(int i = 0; i < N; ++i)

#define CEIL(x, y) (((x) + (y) - 1) / (y))
#define MOD 1000000007ULL

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

    int N;
    cin >> N;

    char c;
    char prevc = 'A';
    int ans = 0;
    rep (i, N)
    {
        cin >> c;
        if (prevc != c) ++ans;
        prevc = c;
    }

    cout << ans << "\n";
    return 0;
}



Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
    unsigned long long n , a=1, b=0 ;


    cin>>n;

    for(long long d=2;d*d<=n;d++)
    {
        if(n%d==0) a=d;
    }

    b=n/a;

    cout<<a-1+b-1;


        return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  int N;
  cin >> N;
  string S[N];
  int ans = 1;
  for (int i = 0; i < N; i++) {
    cin >> S[i];
  }
  sort(S,S+N);
  for (int i = 0; i < N - 1; i++) {
    if (S[i] != S[i + 1]) {
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 9884
//#pragma comment(linker, "/stack:200000000") //  (UNCOMMENT WHEN HAVING LOTS OF RECURSIONS)
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC optimize("unroll-loops")  // $ (UNCOMMENT WHEN TRYING TO BRUTEFORCE WITH A LOT OF LOOPS)\

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

#define fast_cin ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int long long
#define pb push_back
#define all(con) (con).begin(), (con).end()
#define fi first
#define se second
#define rep(i,a,b) for(int i=a;i<b;++i)
#define fre(i,a,b) for(int i=a;i<=b;i++)
#define rpe(i,a,b) for(i=a-1;i>=b;i--)
#define rp(i,n) rep(i,0,n)
#define fr(i,n) fre(i,1,n)
#define ff(i,a,b) for(int i=a;i<=b;i++)

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;

template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
// order_of_key (val): returns the no. of values less than val
// find_by_order (k): returns the iterator to kth largest element.(0-based)

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

#define TRACE
#ifndef ONLINE_JUDGE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
	cerr << name << " : " << arg1 << endl;}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
	const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<"  ";__f(comma+1, args...);}
#else
#define trace(...)
#endif

template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){
	return o<<"("<<p.fs<<","<<p.sc<<")";
}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){
	o<<"{";
	for(const T& v:vc) o<<v<<",";
	o<<"}";
	return o;
}

int modpow(int x, int n, int m) {
	x %= m;
	int res = 1;
	while(n > 0) {
		if(n & 1)
		res = res * x % m;
		x = x * x % m;
		n >>= 1;
	}
	return res;
}

const long long inf = 2e18 ;
const int mod = 1e9+7 ;
// const int mod = 998244353 ;

const int N = 1e5 + 10 ;

void solve() {
	int n,m;
	cin>>n>>m;
	if(n==m) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
}

signed main() {
        fast_cin;
	srand(chrono::high_resolution_clock::now().time_since_epoch().count());
        #ifndef ONLINE_JUDGE
        // freopen("input.txt", "r", stdin);
        // freopen("output.txt", "w", stdout);
    	#endif

	int tests=1;
	// cin>>tests;
	while(tests--) {
		solve();
	}

return 0 ;
}



Measured memory_bytes: 256
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<stack>
#include<queue>
#include<algorithm>
#include<vector>
#include<math.h>
#include<bitset>
#include<iomanip>
using namespace std;

typedef stack<int> IntStack;
typedef queue<int> IntQueue;

const double pi = 3.141592653589793;

/*ここまでテンプレ*//*ここまでテンプレ*//*ここまでテンプレ*//*ここまでテンプレ*/

int card[4][13]; //0S 1H 2C 3D

int main()
{	
	int n;
	char c;
	int cn, m;

	cin >> n;

	char mark[5] = "SHCD";

	for (int i = 0; i < n; i++)
	{
		cin >> c >> m;

		if (c == 'S') cn = 0;
		else if (c == 'H') cn = 1;
		else if (c == 'C') cn = 2;
		else if (c == 'D') cn = 3;

		card[cn][m-1] = 1;
	}

	for (int i = 0;i < 4;i++)
	{
		for (int j = 0; j < 13; j++)
		{
			if (card[i][j] == 0)
				cout << mark[i] << " " << j + 1 << endl;
		}
	}

	return 0;
}



Measured memory_bytes: 3084
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();
		int[] a = new int[N];
		int[] rev = new int[N+1];
		for(int i=0; i<N; i++) {
			a[i] = sc.nextInt();
			rev[a[i]] = i;
		}
		
		long ans = 0;
		
		TreeSet<Integer> sorted = new TreeSet<>();
		sorted.add(-1);
		sorted.add(N);
		
		for(int i=1; i<=N; i++) {
			int l = sorted.lower(rev[i]);
			int r = sorted.higher(rev[i]);
			ans += (long)i*(rev[i]-l)*(r-rev[i]);
			sorted.add(rev[i]);
		}
		
		System.out.println(ans);
		sc.close();
	}
}


Measured memory_bytes: 58836
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <numeric>
using namespace std;

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

  // p = 1
  double dist1 = 0;
  double dist2 = 0;
  double dist3 = 0;
  double dist_max = 0;
  for (int i = 0; i < n; i++) {
    int k_term = abs(x[i] - y[i]);
    dist1 += k_term;
    dist2 += pow(k_term, 2);
    dist3 += pow(k_term, 3);
    dist_max = max(dist_max, (double)k_term);
  }
  printf("%.6lf\n", dist1);
  printf("%.6lf\n", sqrt(dist2));
  printf("%.6lf\n", cbrt(dist3));
  printf("%.6lf\n", dist_max);
  return 0;
}



Measured memory_bytes: 3388
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>
#include <fstream>
#include <bitset>
#include <time.h>
#include <tuple>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef complex<double> Point;

#define PI acos(-1.0)
#define EPS 1e-10
const ll INF = (1LL << 60) - 1;
const ll MOD = 1e9 + 7;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,N) for(int i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
#define EQV(a,b) ( EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()) )
#define fi first
#define se second
#define N_SIZE (1LL << 20)
#define NIL -1
#define MAX_N 100100 * 3

string a, b, c;

int main() {
	cin >> a >> b >> c;

	if (a[a.size() - 1] == b[0] && b[b.size() - 1] == c[0]) {
		cout << "YES" << endl;
	}
	else cout << "NO" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i, n) for (long long i = 0, max_i = (n); i < max_i; i++)
template <class T>
ostream& operator<<(ostream& s, vector<T>& d) {
    REP(i, d.size()) s << d[i] << (i == d.size() - 1 ? "" : " ");
    return s;
}
using Int = long long;

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

    int n, d;
    cin >> n >> d;
    vector<int> acc;
    int curt = 0, curf = 1, ans = 0;
    while (n--) {
        int t, f;
        cin >> t >> f;
        int yuuyo = t - curt;
        int idou = abs(f - curf);
        if (yuuyo < idou) {
            cout << -1 << endl;
            return 0;
        }
        int modoru = (curf - 1) + (f - 1);
        if (yuuyo >= modoru) {
            int touchaku = curt + (curf - 1);
            for (int a : acc) {
                ans += touchaku - a;
            }
            acc.clear();
        }
        acc.push_back(t);
        if (acc.size() > d) {
            cout << -1 << endl;
            return 0;
        }
        curt = t;
        curf = f;
    }
    if (acc.size()) {
        int touchaku = curt + (curf - 1);
        for (int a : acc) {
            ans += touchaku - a;
        }
    }
    cout << ans << endl;
}



Measured memory_bytes: 3848
import bisect
from collections import defaultdict
s = input()
t = input()

D = defaultdict(list)
for i, c in enumerate(s, start=1):
    D[c].append(i)

times = 0
cs = 0
for c in t:
    if c not in D.keys():
        print(-1)
        exit()
    else:
        i = bisect.bisect_left(D[c], cs+1)
        if i == len(D[c]):
            times += 1
            cs = D[c][0]
        else:
            cs = D[c][i]
print(times*len(s)+cs)


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


int main(void){
    // Your code here!
    int  a,b,c,d,e;
    int k;
    cin >> a >> b >> c >> d >> e >> k;
    if(abs(a - e) > k){
        cout << ":(" << endl;
    }else{
        cout << "Yay!" << endl;
    }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define p push
#define ll long long 
#define mod 1000000007
#define mk make_pair

int main()
{
   ios_base::sync_with_stdio(false);
   cin.tie(NULL);
   int n,d,a,x,h;
   cin>>n>>d>>a;
   vector<pair<int,int>> v;
   for(int i=0;i<n;i++)
   {
       cin>>x>>h;
       v.pb(mk(x,h));
   }
   sort(v.begin(),v.end());
   int pfx[n]={0};
   ll ans=0;
   for(int i=0;i<n;i++)
   {
       if(i>0)
       pfx[i]+=pfx[i-1];
       if((v[i].second-pfx[i]*a)>0)
       {
           int t=v[i].second-pfx[i]*a;
           x=t/a;
           if(t%a!=0)
           {
               x++;
           }
           pfx[i]+=x;ans+=x;int u=v[i].first+2*d;u++;//cout<<i<<" "<<x<<endl;
           auto it=upper_bound(v.begin(),v.end(),mk(u,0));
           if(it!=v.end())
           {
               int y=it-v.begin();
               pfx[y]-=x;
           }
          }
       
   }cout<<ans;
   return 0; 
}


Measured memory_bytes: 2672
import collections
n = int(input())
nums = list(map(int,input().split()))
a = []
b = []
for i in range(n):
    if i%2 == 0:
        b.append(nums[i])
    else:
        a.append(nums[i])
acol = collections.Counter(a)
bcol = collections.Counter(b)
amost = acol.most_common()[0][1]
bmost = bcol.most_common()[0][1]
if acol.most_common()[0][0] != bcol.most_common()[0][0]:    
    f = amost + bmost
    print(n-f)
elif len(acol.most_common()) != 1 and len(bcol.most_common()) != 1:
    if acol.most_common()[0][1] + bcol.most_common()[1][1] > acol.most_common()[1][1] + bcol.most_common()[0][1]:
        print(n-(acol.most_common()[0][1] + bcol.most_common()[1][1]))
    else:
        print(n-(acol.most_common()[1][1] + bcol.most_common()[0][1]))
elif len(acol.most_common()) == 1 and len(bcol.most_common()) != 1:
    print(n-(acol.most_common()[0][1]+bcol.most_common()[1][1]))
elif len(bcol.most_common()) == 1 and len(acol.most_common()) != 1:
    print(n-(acol.most_common()[1][1]+bcol.most_common()[0][1]))
else:
    print(n//2)

Measured memory_bytes: 20576
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<functional>
#include<map>
#include<cstdlib>
#include<complex>
#include<numeric>
#include<set>
#include<deque>

using namespace std;
using Int = long long;
Int INF = 1LL << 60;
const Int MOD = 1000000000 + 7;

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	Int H, W;
	cin >> H >> W;

	if (H % 3 == 0 || W % 3 == 0) {
		cout << 0 << "\n";
		return 0;
	}

	Int ans = INF;
	Int Smin, Smax;
	Int w1, w2, h1, h2;

	//H切り捨て
	w1 = W / 2;
	w2 = W - w1;
	h1 = H / 3;
	h2 = H - h1;
	if (h1>0 && h2>0) {
		Smin = min(w1 * h2, W * h1);
		Smax = max(w2 * h2, W * h1);
		ans = min(ans, Smax - Smin);
	}

	//H切り上げ
	w1 = W / 2;
	w2 = W - w1;
	h1 = (H + 2) / 3;
	h2 = H - h1;
	if (h1>0 && h2>0) {
	Smin = min(w1 * h2, W * h1);
	Smax = max(w2 * h2, W * h1);
	ans = min(ans, Smax - Smin);
    }

	//W切り捨て
	w1 = W / 3;
	w2 = W - w1;
	h1 = H  / 2;
	h2 = H - h1;
	if (w1>0 && w2>0) {
		Smin = min(w2 * h1, w1 * H);
		Smax = max(w2 * h2, w1 * H);
		ans = min(ans, Smax - Smin);
	}

	//W切り上げ
	w1 = (W + 2) / 3;
	w2 = W - w1;
	h1 = H / 2;
	h2 = H - h1;
	if (w1>0 && w2>0) {
		Smin = min(w2 * h1, w1 * H);
		Smax = max(w2 * h2, w1 * H);
		ans = min(ans, Smax - Smin);
	}

	//W三分割（切り捨て）
	w1 = W / 3;
	w2 = W - 2 * w1;
	if (w1 > 0 && w2 > 0) {
		Smin = min(w1 * H, w2 * H);
		Smax = max(w1 * H, w2 * H);
		ans = min(ans, Smax - Smin);
	}

	//W三分割（切りあげ）
	w1 = (W+2) / 3;
	w2 = W - 2 * w1;
	if (w1 > 0 && w2 > 0) {
		Smin = min(w1 * H, w2 * H);
		Smax = max(w1 * H, w2 * H);
		ans = min(ans, Smax - Smin);
	}

	//H三分割（切り捨て）
	h1 = H / 3;
	h2 = H - 2 * h1;
	if (h1 > 0 && h2 > 0) {
		Smin = min(h1 * W, h2 * W);
		Smax = max(h1 * W, h2 * W);
		ans = min(ans, Smax - Smin);
	}

	//H三分割（切り上げ）
	h1 = (H+2) / 3;
	h2 = H - 2 * h1;
	if (h1 > 0 && h2 > 0) {
		Smin = min(h1 * W, h2 * W);
		Smax = max(h1 * W, h2 * W);
		ans = min(ans, Smax - Smin);
	}

	cout << ans << "\n";

}

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

int main() {
  char c;cin>>c;
  if (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u' ) {
  cout << "vowel" << endl;}
  else {cout << "consonant" << endl;}
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long LL;
#define SORT(c) sort((c).begin(),(c).end())

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

using namespace std;
struct Unionfind {
  vector<int> size;
  vector<int> par;
  
  Unionfind( int n ) :  size(n, 1), par(n) {
    iota( par.begin() , par.end() , 0 );
  }
  
  int find( int x ) {
    if ( par[x] == x ) return x;
    return par[x] = find( par[x] );
  }
  
  bool unite( int x , int y ) {
    x = find(x);
    y = find(y);
    if ( x == y ) return false;
    
    if ( size[y] < size[x] ) swap( x , y );
    
    par[x] = y;
    size[y] += size[x];
    
    return true;
  }
  
  bool same( int x , int y ) {
    return find(x) == find(y);
  }
};

int main() {
  int n, q;
  cin >> n >> q;
  Unionfind uf(n);
  int x, y;
  REP(i,q) {
    cin >> x >> y;
    uf.unite(x-1, y-1);
  }
  set<int> sum,ci;
  REP(i,n){
    if(uf.find(i)==i) sum.insert(i);
    else ci.insert(uf.find(i));
  }
  cout << abs(int(sum.size())-2*int(ci.size())) << endl;
  return 0;
}

Measured memory_bytes: 3176
#include<stdio.h>
#include<stdlib.h>

int desc(const void *a, const void *b) {
  return *(int *)b - *(int *)a;
}

int main(){
  int k,n,l[100],i,ans=0;
  scanf("%d%d",&n,&k);
  for(i=0;i<n;i++){
    scanf("%d",&l[i]);
  }
  qsort(l,n,sizeof(int),desc);
  for(i=0;i<k;i++){
    ans+=l[i];
  }
  printf("%d\n",ans);
  return 0;
}

Measured memory_bytes: 256
<?php
fscanf(STDIN, '%d', $n);
$ans = 0;
for ($i  = 0; $i < $n; $i++) {
    fscanf(STDIN, '%f %s', $x, $u);
    $ans += ($u === 'JPY') ? $x : $x * 380000;
}
echo $ans . PHP_EOL;

Measured memory_bytes: 4728
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int N, K;

int main(void) {

	cin >> N >> K;

	int num = ((N - 1)*(N - 2)) / 2;

	if (K > num) { cout << -1 << endl; return 0; }

	//cout << "num= " << num << endl;

	int M = N - 1 + num - K;

	cout << M << endl;

	for (int i = 1; i <= N - 1; i++) {
		cout << i << " " << N << endl;
	}

	int count = 0;

	for (int i = 1; i <= N - 1; i++) {
		for (int j = i + 1; j <= N - 1; j++) {
			if (count + N - 1 >= M) { continue; }
			cout << i << " " << j << endl;
			count++;
		}
	}

	return 0;
}

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

int main(){
	int n,a,b,c,x,x2;
	while(1){
		cin>>n>>a>>b>>c>>x;	if(n==0)break;

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

		int pos=0;
		while(1){
			//printf("x=%d, y[%d]=%d\n",x,pos,y[pos]);
			if(x==y[pos]){
				pos++;
			}

			if(pos>=n)break;

			x=(a*x +b)%c;
			ans++;
			if(ans>10000){
				ans=-1;
				break;
			}


		}
		cout<<ans<<endl;
	}

	return 0;
}



Measured memory_bytes: 3080
N, K = map(int, input().split())
P = list(map(int, input().split()))
P_kitaiti = []

ans = 0
for p in P:
    P_kitaiti.append((1+p)*p/2/p)

for left in range(0, N-K+1):
    if left ==0:
        ans = sum(P_kitaiti[left:left+K])
        now = sum(P_kitaiti[left:left+K])
    else:
        # print(left, left-1, left+K-1)
        now -= P_kitaiti[left-1]
        now += P_kitaiti[left+K-1]
        ans = max(ans, now)
print(ans)

Measured memory_bytes: 77448
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define mod 1000000007
#define pb push_back
#define pii pair<ll,ll>
#define pi pair<int ,int> 
#define REP(i,a,n) for(int i=a;i<n;i++)
#define rep(i,a,n) for(int i=a;i>=n;i-- )
int main() {

int n,m,k;
cin>>n>>m>>k;
int  count=1;
int A[n][m];
REP(i,0,n)
{
    REP(j,0,m)
    {
        A[i][j]=0;
    }
}
 REP(i,0,n)
 {
     REP(j,0,m)
     {
         char c;
         cin>>c;
         if(c=='#')
         {
             A[i][j]=count++;
         }
     }
 }
 

 REP(i,1,n)
 {
     REP(j,0,m)
     {
         if(A[i-1][j]!=0 && A[i][j]==0)
         {
             A[i][j]=A[i-1][j];
         }
     }
 }
  rep(i,n-2,0)
 {
     REP(j,0,m)
     {
         if(A[i+1][j]!=0&& A[i][j]==0)
         {
             A[i][j]=A[i+1][j];
         }
     }
 }
  REP(i,1,m)
 {
     REP(j,0,n)
     {
         if(A[j][i-1]!=0&& A[j][i]==0)
         {
             A[j][i]=A[j][i-1];
         }
     }
 }
  rep(i,m-2,0)
 {
     REP(j,0,n)
     {
         if(A[j][i+1]!=0&& A[j][i]==0)
         {
             A[j][i]=A[j][i+1];
         }
     }
 }
 
  REP(i,0,n)
{
    REP(j,0,m)
    {
        cout<<A[i][j]<<" ";
    }
    cout<<endl;
}
	return 0;
}

Measured memory_bytes: 1152
/*Be patient && calm!
All our dreams can come true, if we have the courage to pursue them.
The secret of getting ahead is getting started.
It is hard to beat a person who never gives up.
First, solve the problem. Then, write the code.
Fix the cause, not the symptom.
Simplicity is the soul of efficiency.
Make it work, make it right, make it fast.*/
// #include<bits\stdc++.h>
#include<iostream>
#include<vector>
#include<cmath>
#include<map>
#include<set>
#include<algorithm>
#include<sstream>
using namespace std;
#define mod 1000000007
#define N 100005
#define ll long long
#define ull unsigned long long
#define loop1(i, j, k, step) for (int i = j; i < k; i += step)
#define loop(i, j, k) for (int i = j; i < k; i++)
#define rloop1(i, j, k, step) for (int i = j; i >= k; i -= step)
#define rloop(i, j, k) for (int i = j; i >= k; i--)
#define rep(i, k) for (int i = (0); i < (k); i++)
#define rrep(i, k) for (int i = k - 1; i >= 0; i--)
#define forall(it, l) for (auto it = l.begin(); it != l.end(); it++)
#define mp make_pair
#define pb push_back
#define F first
#define S second
#define sz(x) (int)(x).size()
#define lin "\n"
#define Max (int)INT_MAX
#define Min (int)INT_MIN
#define MEM(a, b) memset(a, (b), sizeof(a))
#define fast_io ios_base::sync_with_stdio(0), cin.tie(NULL), cout.tie(0)
#define PI 2 * acos(0.0)
typedef vector<int> vi;
typedef pair<int, int> pi;
typedef vector<ll> vl;
typedef pair<ll, ll> pll;
// bool sortinrev(const pair<int, int> &a,
//                const pair<int, int> &b)
// {
//     return (a.first > b.first);
// }
// bool spOrder(const pair<int, int> &a,
//              const pair<int, int> &b)
// {
//     if (a.first == b.first)
//         return a.second < b.second;
//     return a.first > b.first;
//  }





void solve()
{
    string s;
    cin>>s;
    ll ans = 0;
    bool ok=true;
    if(s[0]=='R'&&s[0]==s[1]&&s[1]==s[2])
        cout << 3 << lin;
    else if((s[0]=='R'&&s[0]==s[1])||(s[1]=='R'&&s[1]==s[2]))
        cout << 2 << lin;
    else if(s[0]=='R'||s[1]=='R'||s[2]=='R')
        cout << 1 << lin;
        else
    cout << 0 << lin;
}





int main()
{
    // auto start = clock();
    fast_io;
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    int t = 1;
    // cin >> t;
    // int c = 1;
    while (t--)
    {
        // cout << "Case " << c << ":"
        // << lin;
        solve();
        // if(t)
        // {
        //     cout << lin;
        // }
        // c++;
    }
    // auto stop = clock();
    // cerr << "time taken:" << double(stop - start) / double(CLOCKS_PER_SEC) << " s" << endl;
    return 0;
}

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

int main() {
    string S; cin >> S;
    if (S[S.size() - 1] == 's') {
        cout << S << "es" << endl;
    }
    else cout << S << "s" << endl;
}

Measured memory_bytes: 3624
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
using namespace std;

int main(){
	//データの読み込み
	int a;	//整数
	string s;	//文字列
	cin >> a;
	cin >> s;

	if (a >= 3200){
		printf("%s\n", s.c_str());
	} else {
		printf("red\n");
	}

	return 0;
}


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

int len(int n) {
    int count = 0;
    while (n) {
        count++;
        n /= 10;
    }
    return count;
}

int power(int n) {
    int p = 1;
    for (int i = 0; i < n; i++) {
        p *= 10;
    }
    return p;
}

int main() {
    int q;
    cin >> q;
    while (q--) {
        int n;
        cin >> n;
        int count = 0;
        while (len(n) > 1 && count < LIMIT) {
            int next = 0;
            for (int i = 1; i < len(n); i++) {
                int res = power(len(n) - i);
                int a = n / res;
                int b = n % res;
                next = max(next, a * b);
            }
            n = next;
            count++;
        }
        if (count == LIMIT) cout << -1 << endl;
        else cout << count << endl;
    }
    return 0;
}

Measured memory_bytes: 3092
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <numeric>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <cassert>
#include <cstdarg>
#include <sys/time.h>
#include <fstream>
//#include "cout.h"

using namespace std;

#define SZ(x) ((int)x.size())
#define MSET(x,a) memset(x, a, (int)sizeof(x))
#define PB push_back
#define VI vector < int >
#define PII pair < int, int >
#define LL long long
#define FOR(i,a,b) for (LL i = (a); i < (b); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(), (v).end()
#define FIT(it,v) for (__typeof((v).begin()) it = (v).begin(); it != (v).end(); it++)
#define OUT(A) cout << #A << " = "<< (A) << endl
#define OUT2(A, B) cout << "(" << #A << ", " << #B << ") = (" << (A) << ", "<< (B) << ")" << endl
template<class T> void chmin(T &t, T f) { if (t > f) t = f; }
template<class T> void chmax(T &t, T f) { if (t < f) t = f; }

#define present(c, e) ((c).find((e)) != (c).end())
#define cpresent(c, e) (find(ALL(c), (e)) != (c).end())


void solve() {
  LL l, r;
  cin >> l >> r;
  if (r-l >= 2019) {
    cout << 0 << endl;
    return;
  }
  LL res = 2018;
  l = l%2019;
  r = r%2019;
  if(l > r) r = r+2019;
  FOR(i, l, r) FOR(j, i+1, r+1) {
    chmin(res, i*j%2019);
  }
  cout << res << endl;
}

int main() {
	solve();
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <complex>
#include <cstring>
using namespace std;

using ll = long long;
using P = pair<int, int>;
constexpr int INF = 1001001001;
// constexpr int mod = 1000000007;
constexpr int mod = 998244353;

template<class T>
inline bool chmax(T& x, T y){
    if(x < y){
        x = y;
        return true;
    }
    return false;
}
template<class T>
inline bool chmin(T& x, T y){
    if(x > y){
        x = y;
        return true;
    }
    return false;
}

ll dp[200005][5][2];

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

    int L;
    cin >> L;
    vector<int> A(L);
    for(int i = 0; i < L; ++i)  cin >> A[i];
    constexpr ll inf = 1e+17;
    for(int i = 0; i <= L; ++i){
        for(int j = 0; j < 5; ++j){
            for(int k = 0; k < 2; ++k){
                dp[i][j][k] = inf;
            }
        }
    }
    dp[0][0][0] = dp[0][1][1] = 0;
    auto update = [&](int i, int j, int k) -> void {
        if(dp[i][j][k] == inf)  return;
        if(j == 0){
            if(k){
                chmin(dp[i + 1][0][1], dp[i][0][1] + ((A[i] >= 2) ? (A[i] & 1) : (2 - A[i])));
                chmin(dp[i + 1][1][1], dp[i][0][1] + ((A[i] >= 2) ? (A[i] & 1) : (2 - A[i])));
            }
            else{
                chmin(dp[i + 1][0][0], dp[i][0][0] + A[i]);
                chmin(dp[i + 1][0][1], dp[i][0][0] + ((A[i] >= 2) ? (A[i] & 1) : (2 - A[i])));
                chmin(dp[i + 1][1][1], dp[i][0][0] + (A[i] & 1));
            }
        }
        else if(j == 4){
            if(k){
                chmin(dp[i + 1][4][1], dp[i][4][1] + ((A[i] >= 2) ? (A[i] & 1) : (2 - A[i])));
                chmin(dp[i + 1][4][0], dp[i][4][1] + A[i]);
            }
            else{
                chmin(dp[i + 1][4][0], dp[i][4][0] + A[i]);
            }
        }
        else if(j == 1){
            chmin(dp[i + 1][2][1], dp[i][1][1] + (~A[i] & 1));
            chmin(dp[i + 1][3][1], dp[i][1][1] + (~A[i] & 1));
            chmin(dp[i + 1][4][1], dp[i][1][1] + ((A[i] >= 2) ? (A[i] & 1) : (2 - A[i])));
            chmin(dp[i + 1][4][0], dp[i][1][1] + A[i]);
        }
        else if(j == 3){
            chmin(dp[i + 1][4][1], dp[i][3][1] + ((A[i] >= 2) ? (A[i] & 1) : (2 - A[i])));
            chmin(dp[i + 1][4][0], dp[i][3][1] + A[i]);
        }
        else{
            chmin(dp[i + 1][2][1], dp[i][2][1] + (~A[i] & 1));
            chmin(dp[i + 1][3][1], dp[i][2][1] + (~A[i] & 1));
        }
    };
    for(int i = 0; i < L; ++i){
        for(int j = 0; j < 5; ++j){
            for(int k = 0; k < 2; ++k){
                update(i, j, k);
            }
        }
    }
    cout << min({dp[L][1][1], dp[L][3][1], dp[L][4][0], dp[L][4][1]}) << endl;
}

Measured memory_bytes: 19580
#include <bits/stdc++.h>
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define rep(i,n) for (int i = (0); i < (n); ++i)
#define rng(x) (x).begin(),(x).end()
#define rrng(x) (x).rbegin(),(x).rend()
#define show(x) cout << #x << " = " << (x) << endl;
#define show2(x,y) cout << #x << " = " << (x) << ", " << #y << " = " << (y) << endl;
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define uni(x) x.erase(unique(rng(x)),x.end())
#define SP << " " <<
#define int long long
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using pii = pair<int, int>;
using tiii = tuple<int, int, int>;
const int mod = 1000000007;
const double EPS = 1e-9;
const int INF = 1<<30;
const ll INFLL = 1LL<<60;
//cout << fixed << setprecision(10);

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

signed main () {
  int n;
  cin >> n;
  vll a(n);
  rep(i,n) cin >> a[i];
  
  vector<ll> csum(a.size()+1);
  rep(i,a.size()) {
    csum[i+1] = csum[i] + a[i];
  }
  ll ans = INFLL;
  for (int i = 1; i <= n-1; ++i) {
    ll x = csum[i] - csum[0];
    ll y = csum[n] - csum[i];
    ans = min(ans, abs(x-y));
  }

  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3328
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include<numeric>
#include<cmath>
#include<map>
#include<iomanip>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using P = pair<int,int>;
using pll = pair<ll,ll>;
using vvii = vector<vector<int> >;
using vvll =  vector<vector<ll> >;

const ll inf = 1LL << 60;

int main(){
    cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	//cout << fixed << setprecision(15);
    int N; cin >> N;
    vector<int> L(N);
    REP(i,N){
        cin >> L[i];
    }
    int ans = 0;
    sort(ALL(L));
    /*REP(i,N){
        cout << L[i] << endl;
    }*/
    for(int i = 0;i < N - 2; i++){
        for(int j = i + 1; j < N - 1; j++){
            for(int k = j + 1; k < N; k++){
                if((L[i] != L[j] && L[j] != L[k]) && (L[i] + L[j] > L[k])){
                    ans++;
                    //cout << L[i] << " " << L[j] << " " << L[k] << endl;
                } 
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3608
"""
import random
import functools
import copy
import bisect
import array
import re
import collections
import heapq
import fractions
import itertools
import string
import math
from operator import itemgetter as ig
from bisect import bisect_left, bisect_right, insort_left, insort_right
from itertools import permutations, combinations, product, accumulate, groupby
from heapq import heappush, heappop
from collections import deque, defaultdict, Counter
import sys
sys.setrecursionlimit(10 ** 7)
# import numpy as np

inf = 10 ** 20
INF = float("INF")
mod = 10 ** 9 + 7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = dd + [(-1, 1), (1, 1), (1, -1), (-1, -1)]
ddn9 = ddn + [(0, 0)]
'''for dx, dy in dd:
        nx = j + dx; ny = i + dy
            if 0 <= nx < w and 0 <= ny < h:'''
"""
from collections import defaultdict
import sys
sys.setrecursionlimit(10 ** 7)


def wi(): return list(map(int, sys.stdin.readline().split()))
# WideIntPoint


def wip(): return [int(x) - 1 for x in sys.stdin.readline().split()]


def ws(): return sys.stdin.readline().split()


def si(): return int(sys.stdin.readline())  # SingleInt


def ss(): return input()


def hi(n): return [si() for _ in range(n)]


def hs(n): return [ss() for _ in range(n)]  # HeightString


def s_list(): return list(input())


def mi(n): return [wi() for _ in range(n)]  # MatrixInt


def mip(n): return [wip() for _ in range(n)]


def ms(n): return [ws() for _ in range(n)]


def num_grid(n): return [[int(i) for i in sys.stdin.readline().split()[
    0]] for _ in range(n)]  # NumberGrid


def grid(n): return [s_list() for _ in range(n)]


def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

# a/b の切り上げ


def round_up(a, b):
    """ a/b の切り上げ """
    c = (a + b - 1) / b
    return c


def lcm(a, b):
    """a,bの最小公倍数"""
    return a * b // gcd(a, b)


def main():
    s = input()
    q = int(input())
    Q = []
    cnt = 0
    head = []
    tail = []
    for _ in range(q):
        Q.append(list(map(str, input().split())))
    # print(Q)
    for i in range(q):
        if Q[i][0] == '1':
            cnt += 1
            head, tail = tail, head

        else:
            if Q[i][1] == '1':
                head.append(Q[i][2])
            else:
                tail.append(Q[i][2])
    print("".join(head[::-1]) + (s[::-1] if cnt %
                                 2 == 1 else s) + "".join(tail))


if __name__ == '__main__':
    main()


Measured memory_bytes: 117848
#include <iostream>
#include <algorithm>
#include <vector>
#define REP(i, n) for(int i=0;i<N;++i)

typedef long long ll;
using namespace std;

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

ll gcd(ll x, ll y) {
    while(y>0) {
        ll tmp = y;
        y = x % y;
        x = tmp;
    }
    return x;
}

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

    int N;
    cin >> N;
    //ll* A = (ll *)calloc(N, sizeof(ll));
    vector<int> A(N);
    for(int i=0;i<N;++i)cin >> A[i];

    vector<int> left(N+1, 0), right(N+1, 0);
    REP(i,N){ left[i+1] = gcd(left[i], A[i]); }
    for(int i=N-1;i>=0;--i){ right[i] = gcd(right[i+1], A[i]); }

    ll res = 0;
    REP(i,N){
        int l = left[i];
        int r = right[i+1];
        chmax(res, gcd(l, r));
    }
    cout << res << "\n";

    return 0;
}

Measured memory_bytes: 1408
import sys
import numpy as np
input = sys.stdin.readline

def main():
    N, M = map(int, input().split())
    INF = int(1e10)
    dp = [INF] * (1 << N)
    dp[0] = 0
    bits = set()
    bits.add(0)
    for i in range(M):
        a, b = map(int, input().split())
        c = list(map(int, input().split()))
        key = 0
        for t in c:
            key += 1 << (t - 1)
        add_bits = set()
        for bit in bits:
            tmp = bit | key
            if dp[bit] + a < dp[tmp]:
                dp[tmp] = dp[bit] + a
                add_bits.add(tmp)
        bits |= add_bits
    
    if dp[(1 << N) - 1] == INF:
        print(-1)
    else:
        print(dp[(1 << N) - 1])

if __name__ == "__main__":
    main()

Measured memory_bytes: 14672
n,m=map(int,input().split())
l={}
p=2

while m>=p*p:
    if m%p==0:
        if not p in l.keys():
            l[p]=0
        l[p]+=1
        m//=p
    else:
        p+=1
if not m in l.keys():
    l[m]=0
l[m] += 1

ans=1
for p,q in l.items():
    if p==1:
        continue
    for i in range(q):
        ans*=n+i
    for i in range(q):
        ans//=i+1

print(ans%1000000007)

Measured memory_bytes: 3064
#include<cstdio>
const int MaxN=200010;
int N;
struct edge{int to;edge*next;}E[MaxN*2],*ne,*fir[MaxN];
void link(int u,int v){*ne=(edge){v,fir[u]};fir[u]=ne++;}
char mx1[MaxN],mn0[MaxN];
int dfs(int i,int f=0){
	int a=0,b=0;
	for(edge*e=fir[i];e;e=e->next)if(e->to!=f){
		int x=dfs(e->to,i);
		b|=a&x;a|=x;
	}
	b=mx1[b];a>>=b;
	return(a>>mn0[a]|1)<<mn0[a]+b;
}
int main(){
	while(scanf("%d",&N)==1){
		ne=E;
		for(int i=1;i<=N;i++)fir[i]=0;
		for(int i=1,u,v;i<N;i++)scanf("%d%d",&u,&v),link(u,v),link(v,u);
		for(int i=1;i<=N;i++){
			mx1[i]=mx1[i/2]+1;
			mn0[i]=i%2?mn0[i/2]+1:0;
		}
		int ans=mx1[dfs(1)]-1;
		printf("%d\n",ans);
	}
}

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

using namespace std;

int gcd(int x, int y){
	if(y == 0){
		return x;
	}
	return gcd(y, x % y);
}

int main(){
	int n, x;
	scanf("%d%d", &n, &x);
	int which[n + 1];
	which[0] = x;
	for(int i = 1; i <= n; i++){
		int num;
		scanf("%d", &num);
		which[i] = num;
	}
	sort(which, which + n + 1);
	int g = which[1] - which[0];
	for(int i = 1; i <= n; i++){
		g = gcd(which[i] - which[i - 1], g);
	}
	g = max(g, 1);
	printf("%d", g);
	return 0;
}

Measured memory_bytes: 640
import java.util.*;
public class Main {
	public static void main(String[] args){		
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		sc.close();
		
		if (a%b == 0) {
			System.out.println(0);
		} else {
			System.out.println(1);
		}
	}
}


Measured memory_bytes: 21716
N, K = [int(_) for _ in input().split()]
AB = [[int(_) for _ in input().split()] for i in range(N - 1)]

from collections import defaultdict

v = defaultdict(set)

for a, b in AB:
    v[a].add(b)
    v[b].add(a)

M = 10**9+7

import sys
sys.setrecursionlimit(100001)

result = 1

def check(n, b, p):
    global result
    result = result * max(K - b - p, 0) % M
    #print("check:", n, r[n])
    np = min(p + 1, 2)
    for b, x in enumerate(v[n]):
        v[x].remove(n)
        check(x, b, np)

check(1, 0, 0)

print(result)


Measured memory_bytes: 197888