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

#define mp(x, y) make_pair(x, y)
#define pb(x) push_back(x)


typedef long long ll;
typedef long double ld;

typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;

template <class T>
using pqueue = priority_queue<T>;
template <class T>
using rpqueue = priority_queue<T, vector<T>, greater<T> >;


int sint() { int x; scanf("%d", &x); return x; }
ll sll() { ll x; scanf("%lld", &x); return x; }
double sdb() { double x; scanf("%lf", &x); return x; }


int arr[200];
bool memo[101000];

int main() {
	memset(memo, false, sizeof(memo));
	int n, k;
	n = sint();
	k = sint();
	
	for(int i = 0; i < n; i++) {
		arr[i] = sint();
	}
	
	for(int i = 1; i <= k; i++) {
		bool check = false;
		for(int l = 0; l < n; l++) {
			if(i-arr[l] >= 0) {
				if(memo[i-arr[l]] == false) {
					check = true;
				}
			}
		}
		memo[i] = check;
	}
	
//	for(int i = 1; i <= k; i++) {
//		printf("%d %d\n", memo[i][0], memo[i][1]);
//	}
	
	if(memo[k]) {
		printf("First\n");
	} else {
		printf("Second\n");
	}
}

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

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		PrintWriter pw = new PrintWriter(System.out);
		
		int N = sc.nextInt();
		int[] x = new int[N];
		for(int i=0; i<N; i++)
			x[i] = sc.nextInt();
		int M = sc.nextInt();
		long K = sc.nextLong();
		int[] a = new int[M];
		for(int i=0; i<M; i++)
			a[i] = sc.nextInt()-1;
		
		int[] map = new int[N-1];
		for(int i=0; i<N-1; i++)
			map[i] = i;
		
		for(int i=0; i<M; i++) {
			int temp = map[a[i]-1];
			map[a[i]-1] = map[a[i]];
			map[a[i]] = temp;
		}
		
		int[] mapK = pow(map, K);
		
		long cur = x[0];
		for(int i=0; i<N; i++) {
			pw.println(cur);
			if(i<N-1)
				cur += x[mapK[i]+1]-x[mapK[i]];
		}
		
		sc.close();
		pw.close();
	}
	
	static int[] pow(int[] m, long K) {
		int[] ans = new int[m.length];
		for(int i=0; i<ans.length; i++)
			ans[i] = i;
		
		while(K>0) {
			if((K&1)!=0) {
				ans = mul(ans, m);
			}
			m = mul(m, m);
			
			K>>=1;
		}
		
		return ans;
	}
	
	static int[] mul(int[] a, int[] b) {
		int[] ans = new int[a.length];
		for(int i=0; i<ans.length; i++)
			ans[i] = a[b[i]];
		return ans;
	}
}


Measured memory_bytes: 79312
s = input()
t = input()

a = [0 for i in range(26)]
n = len(s)
dict = {}
for i in range(n):
	x = ord(t[i]) - ord("a")
	if s[i] not in dict:
		dict[s[i]] = t[i]
		a[x] += 1
	else:
		if dict[s[i]] != t[i]:
			print ("No")
			exit()

for i in range(26):
	if a[i] >= 2:
		print ("No")
		exit()
print ("Yes")

Measured memory_bytes: 3632
/*
[ ( ^ _ ^ ) ]
*/

import java.io.*;
import java.util.*;


public class Main {
    int INF = (int)1e9;
    long MOD = 1000000007;

    long max(long...x) {long rs = x[0]; for(long y: x) rs = Math.max(rs, y); return rs;}
    long min(long...x) {long rs = x[0]; for(long y: x) rs = Math.min(rs, y); return rs;}
    


    void solve(InputReader in, PrintWriter out) throws IOException {
        int n = in.nextInt();
        long[] a = new long[n];
        long[] p = new long[n];
        for(int i=0; i<n; i++) {
            a[i] = in.nextInt();
            if(i==0) p[i] = a[i];
            else p[i] = a[i] + p[i-1];
        }
        long[][] dp = new long[n][n];
        for(int i=n-2; i>=0; i--) {
            for(int j=i+1; j<n; j++) {
                dp[i][j] = Long.MAX_VALUE;
                for(int k=i; k<j; k++) {
                    // show("cut", i, k, j, dp[i][k], dp[k][j], p[j]-(i>0?p[i-1]:0));
                    dp[i][j] = min(dp[i][j], dp[i][k] + dp[k+1][j] + p[j]-(i>0?p[i-1]:0));
                }
            }
        }
        // for(long[] x: dp) show("", x);
        out.println(dp[0][n-1]);
    }
    

    public static void main(String[] args) throws IOException {
        if(args.length>0 && args[0].equalsIgnoreCase("d")) {
            DEBUG_FLAG = true;
        }
        InputReader in = new InputReader();
        PrintWriter out = new PrintWriter(System.out);
        int t = 1;//in.nextInt();
        long start = System.nanoTime();
        while(t-- >0) {
            new Main().solve(in, out);
        }
        long end = System.nanoTime();
        debug("\nTime: " + (end-start)/1e6 + " \n\n");
        out.close();
    }
    
    static boolean DEBUG_FLAG = false;
    static void debug(String s) {
        if(DEBUG_FLAG) System.out.print(s);
    }
    
    public static void show(Object... o) {
        System.out.println(Arrays.deepToString(o));
    }
    
    static class InputReader {
        static BufferedReader br;
        static StringTokenizer st;
    
        public InputReader() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }
        
        String next() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }
        
        int nextInt() {
            return Integer.parseInt(next());
        }
        
        long nextLong() {
            return Long.parseLong(next());
        }
        
        double nextDouble() {
            return Double.parseDouble(next());
        }
    }
}

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

int main() {
  int n, q;
  scanf("%d", &n);
  vector<int> s(n);
  for (int i=0;i<n;i++) scanf("%d", &s[i]);
  scanf("%d", &q);
  vector<int> t(q);
  for (int i=0;i<q;i++) scanf("%d", &t[i]);

  int cnt=0;
  for (int i=0;i<q;i++) {
    for (int j=0;j<n;j++) {
      if (s[j]==t[i]) {
        cnt++;
        break;
      }
    }
  }
  printf("%d\n", cnt);
  return 0;
}


Measured memory_bytes: 3244
import sys
sys.setrecursionlimit(10 ** 7)
 
input = sys.stdin.buffer.readline

class SegTree():
    # 1-indexed
    def __init__(self, N, function, basement):
        self.n = N
        self.K = (self.n-1).bit_length()
        self.f = function
        self.b = basement
        self.seg = [basement]*(2**(self.K+1)+1)

    def update(self, k, value):
        X = 2**self.K
        k += X
        self.seg[k] = value
        while k:
            k = k >> 1
            self.seg[k] = self.f(self.seg[k << 1], self.seg[(k << 1) | 1])

    def query(self, L, R):
        num = 2**self.K
        L += num
        R += num
        vL = self.b
        vR = self.b
        while L < R:
            if L & 1:
                vL = self.f(vL, self.seg[L])
                L += 1
            if R & 1:
                R -= 1
                vR = self.f(self.seg[R], vR)
            L >>= 1
            R >>= 1
        return self.f(vL, vR)

    def find_max_index(self, L, R, X):
        # [L,R)でX以下の物で最大indexを取得
        return self.fMi(L, R, X, 1, 0, 2**self.K)

    def find_min_index(self, L, R, X):
        # [L,R) でX以下の物で最小のindexを取得する
        return self.fmi(L, R, X, 1, 0, 2**self.K)

    def fMi(self, a, b, x, k, l, r):
        if self.seg[k] > x or r <= a or b <= l:
            return -1
        else:
            if k >= 2**self.K:
                return k-2**self.K
            else:
                vr = self.fMi(a, b, x, (k << 1) | 1, (l + r) // 2, r)
                if vr != -1:
                    return vr
                return self.fMi(a, b, x, k << 1, l, (l + r) // 2)

    def fmi(self, a, b, x, k, l, r):
        if self.seg[k] > x or r <= a or b <= l:
            return -1
        else:
            if k >= 2**self.K:
                return k-2**self.K
            else:
                vl = self.fmi(a, b, x, k << 1, l, (l+r)//2)
                if vl != -1:
                    return vl
                return self.fmi(a, b, x, k << 1 | 1, (l+r)//2, r)

def main():
    N = int(input())
    A = list(map(int, input().split()))
    seg = SegTree(N, min, N+1)
    B = [0]*N
    for i, v in enumerate(A):
        B[i] = (i, A[i])
    B.sort(key=lambda x: x[1])
    ans = 0
    for index, v in B:
        seg.update(index, 1)
        left = seg.find_max_index(0, index, 1)
        right = seg.find_min_index(index+1, N, 1)
        if right == -1:
            right = N
        ans += v*(index-left)*(right-index)
    print(ans)
if __name__=="__main__":
    main()


Measured memory_bytes: 113556
#include <bits/stdc++.h>
#include <iostream>
using namespace std;
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
typedef long long int ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;

struct work
{
    ll a;
    ll b;

    bool operator<(const work& right) const{
        return this->b < right.b;
    }
};

int main()
{
    ll n;
    cin >> n;
    vector<work> w(n);
    rep(i,0,n) cin >> w[i].a >> w[i].b;

    sort(w.begin(),w.end());

    bool possible(true);
    ll time(0);
    rep(i,0,n){
        time += w[i].a;
        if(time > w[i].b) possible = false;
    }

    if(possible) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 3456
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#define ll long long
using namespace std;
inline int read()
{
	int x = 0, f = 1; char ch = getchar();
	while(ch < '0' || ch > '9') {if(ch == '-') f = -1; ch = getchar();}
	while(ch >= '0' && ch <= '9') {x = (x << 3) + (x << 1) + (ch ^ 48); ch = getchar();}
	return x * f;
}
const int N = 50;
int n,a[N][N];
ll f[N][N][N],g[N][N][N];
int main()
{
	n = read(); n <<= 1;
	for(int i = 1;i <= n;i ++) for(int j = 1;j <= n;j ++) scanf("%1d",&a[i][j]);
	for(int i = 1;i < n;i ++) {f[i][i][i] = 1; for(int j = i + 1;j < n;j ++) g[i][i][j] = a[i][j];}
	for(int z = 3;z < n;z += 2)
		for(int i = 1,j;i <= n - z;i ++)
		{
			j = i + z - 1;
			for(int p = i;p < j;p ++)
				for(int q = j;q > p;q -= 2)
				{
					ll sum = 0;
					for(int k = q;k <= j;k ++) sum += g[i][p][k] * f[q][j][k];
					for(int k = p + 1;k < q;k ++) f[i][j][k] += sum * f[p + 1][q - 1][k];
				}
			for(int w = i;w <= j;w ++)
				for(int k = j + 1;k < n;k ++)
					g[i][j][k] += f[i][j][w] * a[k][w];
		}
	ll ans = 0;
	for(int i = 1;i < n;i ++) if(a[n][i]) ans += f[1][n - 1][i];
	cout << ans << "\n";
	return 0;
}


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

int main(){
  long n, k;
  long ans = 0, ans1 = 0, ans2 = 0;
  long x = 0;
  cin >> n >> k;
  
  if ( k % 2 == 0 ){
    for ( long i = 1; i <= n; i ++){
      if ( i % k == 0 ){
        ans1++;
      }else if ( i % ( k / 2 ) == 0 ){
        ans2++;
      }
    }
  }else if ( k % 2 == 1 ){
    for ( long i = 1; i <= n; i++ ){
      if ( i % k == 0 ){
        ans1++;
      }
    }
  }
  ans = ans1 * ans1 * ans1 + ans2 * ans2 * ans2;
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <vector>
#include <stdio.h>
#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <set>
#include <map>

#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define for_p(i, a, b) for(int i = a; i < b; i++)
#define for_m(i, a, b) for(int i = a - 1; i >= b; i--)

//a = s1.size();
//vector<string> s1;
//string s2 = accumulate( s1.begin(), s1.end(), string() );

using namespace std;

int main()
{
  string a;
  
  cin >> a;
  
  if(a == "A"){
    cout << "T" << endl;
  }else if(a == "T"){
    cout << "A" << endl;
  }else if(a == "C"){
    cout << "G" << endl;
  }else{
    cout << "C" << endl;
  }
  
}
  


Measured memory_bytes: 256
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
#define int long long
#define double long double
typedef vector<int> VI;
typedef pair<int, int> pii;
typedef vector<pii> VP;
typedef vector<string> VS;
typedef priority_queue<int> PQ;
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; }
#define fore(i,a) for(auto &i:a)
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
#define eps 0.000000000001
//priority_queue<int,vector<int>, greater<int> > q2;



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

	int A; cin >> A;
	double B; cin >> B;
	int C = A * B;
	cout << C << endl;
	return 0;
}



Measured memory_bytes: 3696
#include<stdio.h>

int main(void)

{

int a,b;

scanf("%d" "%d",&a,&b);

if(a<b)

{

printf("a < b\n");

}

else if(a>b)

{

printf("a > b\n");

}

else{

printf("a == b\n");

}

return 0;

}

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

long long a[2000000];
int main() {
  long long n;
  cin >> n;
  for(int i=1;i<n;i++){
    int s;
    cin >> s;
    a[s-1]++;
    
  }
  for(int i=0;i<n;i++){
    cout << a[i] << endl;
  }
    
}
  


Measured memory_bytes: 5064
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define rep1(i,n) for(int i=1; i<=(n); ++i)
#define repi(i,a,b) for(int i=a; i<=(b); ++i)
#define rrep(i,n) for(int i=(n-1); i>=0; --i)
#define ALL(obj) (obj).begin(), (obj).end()
#define RALL(obj) (obj).rbegin(), (obj).rend()
#define pb push_back
#define mp make_pair
#define to_s to_string
#define sz(v) (int)v.size()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )
#define pr(x) cout<<(x)<<'\n'
#define debug(x) cout << #x << ": " << (x) << '\n'
#define yes "Yes"
#define no "No"
using namespace std;
using ll = long long;
using Edge = pair<int,long long>;
using Graph = vector<vector<Edge>>;
typedef pair<int,int> P;
struct aaa{aaa(){ cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20);};}aaaaaaa;
int MOD = 1e9 + 7;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return (a*b)/gcd(a,b);}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

int main(){
    ll M; cin >> M;
    ll ans = 0;
    vector<ll> res;

    rep(i,M){
        ll d,c; cin >> d >> c;
        ans += c-1;
        ll tp = (c*d)%9;
        if(tp == 0 && d != 0) tp = 9;
        res.pb(tp);
        ans += (c*d-tp)/9;
    }
    ll test = 0;
    rep(i,sz(res)) test += res[i];
    if(test%9 == 0) test -= 9;
    ans += test/9 + sz(res) - 1;
    pr(ans);
    return 0;
}


Measured memory_bytes: 2420
import java.util.*;

public class Main {

    public static void main(String args[]) {

        // 入力
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        Integer[] d1 = new Integer[n];
        Integer[] d2 = new Integer[n];
        for (int i = 0; i < n; i++) {
            d1[i] = Integer.parseInt(sc.next());
            d2[i] = Integer.parseInt(sc.next());
        }
        sc.close();

        // 主処理
        boolean judge = false;
        int renzoku = 0;
        for (int i = 0; i < n; i++) {
            if (d1[i] == d2[i]) {
                renzoku++;
            } else {
                renzoku = 0;
            }
            if (renzoku == 3) {
                judge = true;
                break;
            }
        }
        String result = judge ? "Yes" : "No";

        // 出力
        System.out.println(result);
    }
}


Measured memory_bytes: 35684
#include<bits/stdc++.h>
using namespace std;
int n;
string str;
set<string>s;
int main()
{
	cin >> n;
	while (n--)
	{
		cin >> str;
		if (!s.count(str))
			s.insert(str);
	}
	cout << s.size() << endl;
	return 0;
}

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

typedef long long ll;
typedef unsigned long long ull;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define RFOR(i,a,b) for(int i=(b-1);i>=(a);--i)
#define REP(i,n)   FOR(i,0,n)
#define RREP(i,n)   RFOR(i,0,n)
#define SORT(s) sort(s.begin(), s.end())
#define P pair<int, int>
#define mp make_pair

const double INF = 1e+09;
const int MOD = 1e9+7;

using namespace std;

template <typename _Ty>
ostream& operator << (ostream& ostr, const vector<_Ty>& v) {if (v.empty()) {ostr << "{ }"; return ostr;}
    ostr << "{" << v.front(); for (auto itr = ++v.begin(); itr != v.end(); itr++) {ostr << ", " << *itr;}
    ostr << "}";
    return ostr;}

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; }

int gcd(int a, int b){
   if (a%b == 0) return(b);
   else return(gcd(b, a%b));}

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

vector<int> uniq(vector<int> vec){
  sort(vec.begin(), vec.end());
  vec.erase(unique(vec.begin(), vec.end()), vec.end());
  return vec;}

vector<ll> divisor(ll n) {
vector<ll> ret;
for(int64_t i = 1; i * i <= n; i++) {
  if(n % i == 0) {
    ret.push_back(i);
    if(i * i != n) ret.push_back(n / i);
  }
}
  sort(begin(ret), end(ret));
  return (ret);
}
void permu(int n){
  vector<int> perm(n);
  REP(i, n) perm[i] = i;
do{
  cout << perm  << endl;
}
while (next_permutation(perm.begin(), perm.end()));
return;}

vector<pair<ll, int>> prime_div(ll n){
  vector<pair<ll, int>> res;
  for (ll i=2; i*i <= n;i++){
    if (n%i == 0){
      int a = 0;
      while(n%i == 0){
        n /= i;
        a++;
      }
      pair<ll, int> tmp;
      tmp.first = i;
      tmp.second = a;
      res.push_back(tmp);
    }
  }
  if (n != 1){
    pair<ll, int> now;
    now.first = n;
    now.second = 1;
    res.push_back(now);}
  return res;
}


// printf("%.10f\n" , ans);
int main(void){
  ios::sync_with_stdio(false);
  int h, w;
  cin >> h >> w;
  // vector<string> maze(h);
  vector<string> maze(h);
  REP(i, h){
    cin >> maze[i];
  }
  int dx[8] = {-1, -1, -1, 0, 0, 1, 1, 1};
  int dy[8] = {-1, 0, 1, 1, -1, 1, 0, -1};
  REP(i, h){
    string ans = "";
    REP(j, w){
      if (maze[i][j] == '.'){
        int cnt = 0;
        REP(k, 8){
          int nx = i + dx[k];
          int ny = j + dy[k];
          if (0 <= nx and nx < h and 0 <= ny and ny < w and maze[nx][ny] == '#'){
            cnt++;
          }
        }
        string st = to_string(cnt);
        ans += st;
      }
      else{
        ans += "#";
      }
    }
    cout << ans << endl;
    }
  return 0;
}



Measured memory_bytes: 3724
n,q = map(int,input().split(" "))
#空のキューを用意
Q = []

# キューにプロセスと処理時間を追加
for i in range(n):
    process, time = input().split(" ")
    Q.append([process,int(time)])
    
total_time = 0
# キューが空になるまで繰り返す
while Q != []:
    # 先頭をdequeue
    p_t = Q.pop(0)
    # クオンタイム以下
    if p_t[1] <= q:
        total_time += p_t[1]
        print(p_t[0],total_time)
    # クオンタイムより大
    else: 
        total_time += q
        # 末尾にenqueue
        Q.append([p_t[0],p_t[1] - q])


Measured memory_bytes: 13020
#include <cstdio>
#include <vector>
using namespace std;

int main() {
	int n;
	vector<int> a;
	scanf("%d",&n);
	a.resize(n);
	for(int i=0;i<n;++i) {
		scanf("%d",&a[i]);
	}
	for(auto x=a.rbegin(); x!=(--a.rend()); ++x) {
		printf("%d ",*x);
	}
	printf("%d\n",a[0]);
	return 0;
}

Measured memory_bytes: 2756
//#include <bits/stdc++.h>
 
#include <iostream>
#include <algorithm>
 
#include <bitset>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <stack>
#include <queue>
#include <deque>
#include <cstring>
#include <string>
#include <utility>
#include <array>
#include <complex>
#include <valarray>
 
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <chrono>
#include <random>
#include <numeric>
 
 
using namespace std;
#define int long long
 
typedef long long ll;
typedef unsigned long long ull;
//typedef unsigned __int128 HASH;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef pair<ull, ull> pullull;
typedef pair<ll,int> plli;
typedef pair<double, int> pdbi;
typedef pair<int,pii> pipii;
typedef pair<ll,pll> plpll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<pii> vpii;
typedef vector<vector<int>> mat;
 
#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n);i>0;i--)
#define rrep2(i,a,b) for (int i=(a);i>b;i--)
#define pb push_back
#define fi first
#define se second
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
 
const ll hmod1 = 999999937;
const ll hmod2 = 1000000000 + 9;
const int INF = 1<<30;
const ll INFLL = 1LL<<62;
const double EPS = 1e-12;
const ll mod = 1000000000 + 7;
const int dx4[4] = {1, 0, -1, 0};
const int dy4[4] = {0, 1, 0, -1};
const int dx8[8] = {1, 1, 1, 0, 0, -1, -1, -1};
const int dy8[8] = {0, 1, -1, 1, -1, 0, 1, -1};
const double pi = 3.141592653589793;
 
#define addm(X, Y) (X) = ((X) + ((Y) % mod) + mod) % mod
#define inside(y, x, h, w) (0 <= (y) && (y) < (h) && 0 <= (x) && (x) < (w)) ? true : false

int n, c;
vector<vector<pii>> g(37), g2(37);
tuple<int, int, int> tp[100000 + 5];
int imos[200000 + 5];

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n >> c;
    rep(i, n) {
        int s, t, cc;
        cin >> s >> t >> cc;
        s *= 2;
        t *= 2;
        cc--;
        g[cc].push_back({s, t});
    }
    rep(i,c) {
        sort(all(g[i]));
    }
    rep(i, c) {
        int m = g[i].size();
        bool check[m] = {};
        rep(j, m) {
            if (check[j]) continue;
            check[j] = true;
            int s = g[i][j].fi;
            int now = j;
            while (now < m - 1) {
                if (g[i][now].se == g[i][now + 1].fi) {
                    now++;
                    check[now] = true;
                }
                else break;
            }
            g2[i].push_back({s, g[i][now].se});
        }
    }
    rep(i, c) {
        rep(j, g2[i].size()) {
            imos[g2[i][j].fi - 1]++;
            imos[g2[i][j].se]--;
        }
    }
    rep(i, 200000 + 4) {
        imos[i + 1] += imos[i];
    } 
    int ans = 0;
    rep(i, 200000 + 4) ans = max(ans, imos[i]);
    cout << ans << endl;
}



Measured memory_bytes: 5888
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric, std.container, std.range;

enum BS = [2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536, 131072, 262144, 524288, 1048576, 2097152, 4194304, 8388608, 16777216, 33554432, 67108864, 134217728, 268435456, 536870912, 1073741824, 2147483648];

void main()
{
    auto N = readln.chomp.to!int;
    long[] AS;
    int[long] CS;
    foreach (a; readln.split.to!(long[])) {
        AS ~= a;
        ++CS[a];
    }
    sort(AS);
    AS = AS.uniq.array;
    int r;
    foreach_reverse (a; AS) {
        while (CS[a] > 0) {
            foreach_reverse (b; BS) if (b-a in CS && CS[b-a] > 0) {
                if (a == b-a && CS[a] == 1) {
                    CS[a] = 0;
                    break;
                }
                ++r;
                --CS[a];
                --CS[b-a];
                goto next;
            }
            break;
            next:
        }
    }
    writeln(r);
}

Measured memory_bytes: 22764
#include<bits/stdc++.h>
#define int long long
#define f(i,n) for(int i=0;i<n;i++)
#define F first
#define S second
#define mod 1000000007
#define P pair<int,int>
using namespace std;
signed main(){
	int a,b,c,d,x=0,y=0,z=0;
	cin>>a>>b>>c;
	f(i,a){
		cin>>d;
		if(d<=b)x++;
		else if(d<=c)y++;
		else z++;
	}
	cout<<min({x,y,z})<<endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int x, y, z;

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

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

    cin >> x >> y >> z;
    cout << z << ' ' << x << ' ' << y << '\n';
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
using namespace std;

#ifdef LOCAL
	#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
	#define eprintf(...) 42
#endif

typedef long long ll;
typedef pair<int, int> pii;
#define mp make_pair

const ll MOD = 998244353;
ll add(ll x, ll y) {
	x += y;
	if (x >= MOD) return x - MOD;
	return x;
}
ll sub(ll x, ll y) {
	x -= y;
	if (x < 0) return x + MOD;
	return x;
}
ll mult(ll x, ll y) {
	return (x * y) % MOD;
}
ll bin_pow(ll x, ll p) {
	if (p == 0) return 1;
	if (p & 1) return mult(x, bin_pow(x, p - 1));
	return bin_pow(mult(x, x), p / 2);
}
ll Rev(ll x) {
	return bin_pow(x, MOD - 2);
}
ll W;

const int LOG = 20;
const int N = 1 << 20;
ll w[N];
int rev[N];

void initFFT() {
	for (ll x = 2;; x++) {
		ll y = x;
		for (int i = 1; i < LOG; i++)
			y = mult(y, y);
		if (y == MOD - 1) {
			W = x;
			break;
		}
	}
	w[0] = 1;
	for (int i = 1; i < N; i++)
		w[i] = mult(w[i - 1], W);
	rev[0] = 0;
	for (int mask = 1; mask < N; mask++) {
		int k = 0;
		while(((mask >> k) & 1) == 0) k++;
		rev[mask] = rev[mask ^ (1 << k)] ^ (1 << (LOG - 1 - k));
	}
}

ll F[2][N];
void FFT(ll *A) {
	for (int i = 0; i < N; i++)
		F[0][rev[i]] = A[i];
	int t = 0, nt = 1;
	for (int lvl = 0; lvl < LOG; lvl++) {
		int len = 1 << lvl;
		for (int st = 0; st < N; st += (len << 1))
			for (int i = 0; i < len; i++) {
				ll ad = mult(F[t][st + len + i], w[i << (LOG - 1 - lvl)]);
				F[nt][st + i] = add(F[t][st + i], ad);
				F[nt][st + len + i] = sub(F[t][st + i], ad);
			}
		swap(t, nt);
	}
	for (int i = 0; i < N; i++)
		A[i] = F[t][i];
}

ll f[N], rf[N];
ll a[N];

ll getC(int n, int k) {
	if (k < 0 || k > n) return 0;
	return mult(f[n], mult(rf[k], rf[n - k]));
}

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

	initFFT();

	f[0] = 1;
	for (int i = 1; i < N; i++)
		f[i] = mult(f[i - 1], i);
	rf[N - 1] = Rev(f[N - 1]);
	for (int i = N - 1; i > 0; i--)
		rf[i - 1] = mult(rf[i], i);

	for (int k = 0; k < N / 2; k++) {
		a[k] = mult(f[2 * k], mult(rf[k], rf[k]));
	}
	FFT(a);
	for (int i = 0; i < N; i++)
		a[i] = mult(a[i], a[i]);
	FFT(a);
	reverse(a + 1, a + N);
	ll rN = Rev(N);
	for (int i = 0; i < N; i++) {
		a[i] = mult(a[i], rN);
		a[i] = mult(a[i], mult(rf[2 * i], mult(f[i], f[i])));
		a[i] = sub(a[i], 1);
		a[i] = mult(a[i], (MOD + 1) / 2);
		a[i] += i;
	}

	int n, m;
	scanf("%d%d", &n, &m);
	if (n < m) swap(n, m);
	if (n == m) {
		printf("%lld\n", a[n]);
		return 0;
	}

	ll ans = 0;

	for (int k = 0; k <= m; k++) {
		int L = n - m + k - 1;
		ll p = getC(L + k, k);
		if (k > 0)
			p = sub(p, getC(L + k, k - 1));
		p = mult(p, getC(2 * (m - k), m - k));
		ans = add(ans, mult(p, add(L + 1, a[m - k])));
	}
	ans = mult(ans, mult(rf[n + m], mult(f[n], f[m])));
	printf("%lld\n", ans);

	return 0;
}


Measured memory_bytes: 53632
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <deque>
#include <queue>
#include <array>
#include <set>
#include <map>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <cassert>
#include <utility>
#include <functional>
#include <bitset>
#include <cstdint>

using namespace std;
using lli = long long int;
using i64 = int64_t;
template<class T, class U> void init_n(vector<T>& v, size_t n, U x) 
{ v = vector<T>(n, x); }
template<class T> void init_n(vector<T>& v, size_t n) { init_n(v, n, T()); }
template<class T> void read_n(vector<T>& v, size_t n, size_t o = 0) 
{ v = vector<T>(n+o); for (size_t i=o; i<n+o; ++i) cin >> v[i]; }
template<class T> void read_n(T a[], size_t n, size_t o = 0)
{ for (size_t i=o; i<n+o; ++i) cin >> a[i]; }
template<class T> T gabs(const T& x) { return max(x, -x); }
#define abs gabs

int main() {
  i64 x, y, z;
  cin >> x >> y >> z;
  cout << (x - z) / (y + z) << '\n';
  return 0;
}



Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){
  
  int H,W,sharp = 0;
  cin >> H >> W;
  char s;
  
  for (int i=0;i<H;i++){
   for(int j=0;j<W;j++){
	cin >> s;
    sharp += (int)(s=='#');
   }
  }
  
  cout << ((sharp == H + W - 1) ? "Possible" : "Impossible") << endl;
  
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define SPEED ios_base::sync_with_stdio(false); cin.tie(NULL);
#define FOR(i, a, b) for (ll i = a; i < b; ++i)
#define RFOR(i, b, a) for (ll i = b; i >= a; --i)
#define ALL(x) x.begin(), x.end()
#define DEBUG(args...) { string _s = #args; replace(ALL(_s), ' ', '\0');\
replace(ALL(_s), ',', ' ');\
stringstream _ss(_s); istream_iterator<string> _it(_ss); _debug(_it, args);}
#define endl "\n"
#define F first
#define S second
#define pb(x) push_back(x)a
#define mp(x, y) make_pair(x, y)

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>;

void _debug(istream_iterator<string>) {}
template<typename T, typename... Args>
void _debug(istream_iterator<string> it, T first, Args... args) {
    cerr << ">> " << *it << " : " << first << endl; _debug(++it, args...);
}
template <typename T1, typename T2>
inline ostream& operator << (ostream& out, const pair<T1, T2>& p) {
    return out << "(" << p.F << ", " << p.S << ")";
}
template<typename T>
inline ostream& operator << (ostream& out, const vector<T>& v) {
    if (v.empty()) return out << "[]";
    else { out << '['; for (auto& e : v) { out << e << ", "; } return out << "\b\b]"; }
}
template<typename T>
inline ostream& operator << (ostream& out, const set<T>& s) {
    if (s.empty()) return out << "{}";
    else { out << '{'; for (auto& e : s) { out << e << ", "; } return out << "\b\b}"; }
}
template<typename T>
inline ostream& operator << (ostream& out, const unordered_set<T>& s) {
    return out << set<T>(ALL(s));
}
template<typename T1, typename T2>
inline ostream& operator << (ostream& out, const map<T1, T2>& m) {
    if (m.empty()) return out << "{}";
    out << '{'; for (auto& p : m) { out << p << ", "; } return out << "\b\b}";
}
template<typename T1, typename T2>
inline ostream& operator << (ostream& out, const unordered_map<T1, T2>& m) {
    return out << map<T1, T2>(ALL(m));
}
template<typename T>
inline ostream& operator << (ostream& out, const ordered_set<T>& s) {
    return out << set<T>(ALL(s));
}

typedef long long ll;
typedef long double ld;
typedef vector<long long> vll;
typedef pair<ll, ll> pll;
typedef vector<pair<ll, ll>> vpll;
typedef unordered_map<ll, ll> STll;
/************************************** MAIN PROGRAM ********************************************/

int main()
{
  //  freopen("input.txt", "r", stdin);
    SPEED
    int n;
    cin >> n;
    vector<int> a(n);
    for (auto &e : a) {
        cin >> e;
    }
    map<int, int> mp;
    ll ans = 0;
    for (int i = n - 1; i >= 0; --i) {
        ans += mp[-(a[i] + i)];
        mp[a[i] - i]++;
    }
    cout << ans;
}
/************************************** END OF PROGRAM ******************************************/
/** Stuff you should look for:
 * int overflow, array bounds, over-counting
 * special cases (n=1?), set/unordered_set TLE, multi-set/set error
 * do something instead of nothing and stay organized
 */


Measured memory_bytes: 21028
#2019/10/03
X = int(open(0).read())
#print(X)
max_exp=1
exp=0
for i in range(1,X+1):
#     print("i", i)
    for j in range(2,X+1):
#         print("j", j)
        exp = i**j
        if exp > X:
            break
        if max_exp < exp:
            max_exp = exp
print(max_exp)

Measured memory_bytes: 2940
#include<stdio.h>
#include<algorithm>
#include<queue>
#include<vector>
#include<map>
#include<set>
using namespace std;
long long pow16[11];
int from[9];
int to[9];
long long cur;
void sw(int a,int b){
	int p=cur%pow16[a+1]/pow16[a];
	int q=cur%pow16[b+1]/pow16[b];
	cur-=pow16[a]*p;
	cur-=pow16[b]*q;
	cur+=pow16[b]*p;
	cur+=pow16[a]*q;
}
int main(){
	int a,b;
	pow16[0]=1;
	for(int i=1;i<11;i++)pow16[i]=pow16[i-1]*16;
	while(scanf("%d%d",&a,&b),a){
		for(int i=0;i<9;i++)scanf("%d",to+i);
		for(int i=0;i<9;i++)scanf("%d",from+i);
		long long S=0;
		for(int i=0;i<9;i++)S+=pow16[i]*from[i];
		long long T=0;
		for(int i=0;i<9;i++)T+=pow16[i]*to[i];
		priority_queue<pair<int,long long> > Q;
		map<long long,int> ijk;
		set<long long>v;
		Q.push(make_pair(0,S));
		int best=999999999;
		if(S==T){
			printf("0\n");continue;
		}
		while(Q.size()){
			int cost=-Q.top().first;
			cur=Q.top().second;
			Q.pop();
			if(best<=cost)continue;
			if(v.count(cur))continue;
			if(cur==T){
				break;
			}
			v.insert(cur);
			int at=0;
			for(int i=0;i<9;i++)if(cur%pow16[i+1]/pow16[i]==0)at=i;
		//	printf("%d %d\n",cost,at);
			sw(at,(at+1)%9);
			if((!ijk.count(cur)||ijk[cur]>cost+a)){
				ijk[cur]=cost+a;
				if(cur==T)best=min(best,cost+a);
				Q.push(make_pair(-cost-a,cur));
			}
			sw(at,(at+1)%9);sw(at,(at+8)%9);
			if((!ijk.count(cur)||ijk[cur]>cost+a)){
				ijk[cur]=cost+a;
				if(cur==T)best=min(best,cost+a);
				Q.push(make_pair(-cost-a,cur));
			}
			sw(at,(at+8)%9);sw(at,(at+3)%9);
			if((!ijk.count(cur)||ijk[cur]>cost+b)){
				ijk[cur]=cost+b;
				if(cur==T)best=min(best,cost+b);
				Q.push(make_pair(-cost-b,cur));
			}
			sw(at,(at+3)%9);sw(at,(at+6)%9);
			if((!ijk.count(cur)||ijk[cur]>cost+b)){
				ijk[cur]=cost+b;
				if(cur==T)best=min(best,cost+b);
				Q.push(make_pair(-cost-b,cur));
			}
		}
		printf("%d\n",best);
	}
}

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

using namespace std;

vector<int> nodes;

int get_root(int a){
  if(nodes[a] == a) return a;
  else return nodes[a] = get_root(nodes[a]);
}

void unite(int a, int b){
  int ra = get_root(a);
  int rb = get_root(b);
  nodes[ra] = rb;
}

int main(){
  int n,m;
  cin >> n >> m;
  nodes = vector<int>(n);
  vector<int> used(n, 0);
  for(int i = 0; i < n ; i++) nodes[i] = i;
  for(int j = 0; j < m ; j++){
    int a,b,c;
    cin >> a >> b >> c;
    a--; b--;
    unite(a, b);
  }
  int ans = 0;
  for(int i = 0; i < n ; i++){
    if(!used[get_root(i)]){
      ans++;
      used[get_root(i)] = 1;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 1536
#include<iostream>
#include<algorithm>
#include<map>
using namespace std;
int main(){
  int n;
  while(cin >> n , n){
    int ret = 0, RIPPO = 0;
    for(int i = 0 ; (RIPPO = i * i * i) <= n ; i++ ){
      int SANKAKU = 0;
      for(int j = 0 ; RIPPO + ( SANKAKU = j * ( j + 1 ) * ( j + 2 ) / 6 ) <= n ; j++ ){
	ret = max( ret, RIPPO + SANKAKU);
      }
    }
    cout << ret << endl;
  } 
}

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

using namespace std;

typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<bool> vb;
typedef vector<string> vst;
typedef pair<ll,ll> pll;
typedef vector<pll> vpll;


const ll mod=(1e+9)+7;
const ll inf=1e+16; 

#define rep(i,m,n) for(ll i=m;i<n;i++)
#define repr(i,m,n) for(ll i=m;i>=n;i--)

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

 ll w,h;
  cin >> w >> h;
 vpll e;
  rep(i,0,w) {
   ll p;
    cin >> p;
    e.push_back(make_pair(p,0));
  }
  rep(i,0,h) {
   ll q;
    cin >> q;
    e.push_back(make_pair(q,1));
  }
  
  sort(e.begin(),e.end());
  
  ll a=w+1,b=h+1,res=0;
  rep(i,0,e.size()){
   if(e[i].second==0) {
     res+=max(b,0ll)*e[i].first;
     a--;
   }
   else {
     res+=max(a,0ll)*e[i].first;
     b--;
   } 
    if(a==0&&b==0) break;
  }
  
  cout << res << endl;
  
}


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

int main() {
 long long A,B,N;
  cin >> A >> B >> N;
  long long t;
  if(B - 1 <= N){
  t = B - 1;}else{
  t = N;}
  cout << (A * t) / B + A * (t / B) << endl;
}

Measured memory_bytes: 3672
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> l_l;
//typedef pair<int , int> i_i;
typedef vector<ll> vel;
typedef vector<int> vei;
typedef vector<char> vec;
typedef vector<bool> veb;
typedef vector<string> ves;
typedef vector<vector<ll>> ve_vel;
typedef vector<vector<int>> ve_vei;
typedef vector<vector<char>> ve_vec;
typedef vector<vector<bool>> ve_veb;
typedef vector<vector<string>> ve_ves;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define rep2(i,n) for(int i=2;i<(int)(n);i++)
#define repk(i,k,n) for(int i=k;i<(int)(n);i++)
#define fs first
#define sc second
#define pub push_back
#define puf push_front
#define pob pop_back
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define maxel(a) *max_element(all(a))
#define minel(a) *min_element(all(a))
#define acc accumulate
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define mod (1000000007)
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 (a>b) { a=b; return 1; } return 0; }


//codefes2016FinalC

#define MAX_N 100000
int par[MAX_N+1]; //親
int ran[MAX_N+1]; //木の深さ

//n要素で初期化
void init(int n) {
    rep(i,n) {
		par[i] = i; ran[i] = 0;
	}
}

//木の根を求める
int root(int x){ return par[x]==x ? x : par[x]=root(par[x]); }

//x,yの属する集合の併合
void unite(int x, int y) {
	x = root(x); y = root(y);
	if(x == y) return ;

	if(ran[x] < ran[y]) par[x] = y;
	else {
		par[y] = x;
		if(ran[x] == ran[y]) ran[x]++;
	}
}

//x,yが同じ集合に属するか
bool same(int x, int y) { return root(x) == root(y); }


typedef pair<int , int> P;//<最短距離, 頂点番号>
#define MAX_V 100005
struct edge {int to; int cost; };
int V;//頂点数
vector<edge> G[MAX_V];
int d[MAX_V];//頂点sからの最短距離



void dijkstra(int s) {
    //greater<P>を指定し.fsを小さい順に取り出す
    priority_queue<P, vector<P>, greater<P> > que;
    fill(d, d+V, INF);
    d[s] = 0;
    que.push(P(0,s));

    while(!que.empty()) {
        P p = que.top(); que.pop();
        int v = p.sc;
        if(d[v] < p.fs) continue;
        rep(i,G[v].size()) {
            edge e = G[v][i];
            if(d[e.to] > d[v] + e.cost) {
                d[e.to] = d[v] + e.cost;
                que.push(P(d[e.to], e.to));
            }
        }
    } 
}



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

    cin >> V;
    init(V);
    rep(i,V-1) {
        int u, v; ll w; cin >> u >> v >> w;
        u--; v--;
        if(w % 2 == 0) w = 0;
        else w = 1;
        edge e = {v, w};
        G[u].pub(e);
        edge f = {u, w};
        G[v].pub(f);
    }
    dijkstra(0);
    rep1(i,V) {
        if(d[i] % 2 == 0) unite(0, i);
    }
    rep(i,V) {
        if(root(i) == 0) cout << 0 << endl;
        else cout << 1 << endl;
    }
    return 0;

}



Measured memory_bytes: 7680
/*
 * @Author: clorf 
 * @Date: 2020-08-31 20:27:12 
 * @Last Modified by: clorf
 * @Last Modified time: 2020-08-31 21:29:26
 */
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#include<ctime>
#define INF 1e9
using namespace std;
const int maxn=200010;
const double Pi=acos(-1.0);
template<class T>void read(T &x)
{
    x=0;int f=0;char ch=getchar();
    while(ch<'0'||ch>'9') {f|=(ch=='-');ch=getchar();}
    while(ch>='0'&&ch<='9'){x=(x<<1)+(x<<3)+(ch^48);ch=getchar();}
    x=f?-x:x;
    return;
}
int n,q,cnt;
int fa[maxn];
long long p[maxn],ans;
struct edge
{
    int x;
    int y;
    long long z;
}s[maxn],e[maxn<<1];
inline bool cmp(edge a,edge b)
{
    return a.z<b.z;
}
inline int sub(int x)
{
    return (x+1)%n;
}
int getfa(int x)
{
    if(fa[x]==x)
        return x;
    return fa[x]=getfa(fa[x]);
}
int main()
{
    memset(p,0x3f,sizeof(p));
    scanf("%d%d",&n,&q);
    for(int i=1;i<=q;i++)
    {
        scanf("%d%d%lld",&s[i].x,&s[i].y,&s[i].z);
        e[++cnt]=(edge){s[i].x,s[i].y,s[i].z};
        p[s[i].x]=min(p[s[i].x],s[i].z+1);
        p[s[i].y]=min(p[s[i].y],s[i].z+2);
    }
    int now=s[1].x,tot=2*n+1;
    long long sum=p[now];
    while(tot--)
    {
        if(sum<p[now])
            p[now]=sum;
        else
            sum=p[now];
        sum+=2;
        now=sub(now);
    }
    for(int i=0;i<n;i++)
        e[++cnt]=(edge){i,sub(i),p[i]};
    for(int i=0;i<=n;i++)
        fa[i]=i;
    sort(e+1,e+cnt+1,cmp);
    for(int i=1;i<=cnt;i++)
    {
        int x=getfa(e[i].x);
        int y=getfa(e[i].y);
        if(x!=y)
        {
            fa[x]=y;
            ans+=e[i].z;
        }
    }
    printf("%lld",ans);
    return 0;
}


Measured memory_bytes: 19684
//author-Abhijit Dey
//Welcome to my code. btw I hate coding 😉




#include <bits/stdc++.h>
using namespace std;
#define     ff first
#define     ss second
#define     pb push_back
#define     mp make_pair
#define     INF 1000000005
#define     MOD 1000000007
#define     ninf -1000000000
#define     all(c) c.begin(), c.end()
#define     tinput long long int t;cin>>t;
#define     mem(a,x) memset(a,x,sizeof a)
#define     for0(i,n) for(long long int i=0;i<n;i++)
#define     pi 3.141592653589793238462643383279502884
#define     fori(i,a,n) for(long long int i=a;i<n;i++)
#define     forxy(i,x,y) for(int i=x;i<=y;i++)
#define     rfor(i,n) for(long long int i=n-1;i>=0;i--)
#define     ainput for(int i=0; i<n; i++) cin>>a[i];
#define     fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);




typedef     long long int ll;
typedef     vector<long long int>vll;
typedef     vector<vector<int> >vvll;
typedef     pair<long long int,long long int>pr;
typedef     vector<pair<long long int,long long int> >vp;





inline long long  min2(long long  a, long long  b)  {return (a)<(b)?(a):(b);}
inline long long  max2(long long  a, long long  b)  {return (a)>(b)?(a):(b);}
inline long long  max3(long long  a, long long  b, long long  c)    {return (a)>(b)?((a)>(c)?(a):(c)):((b)>(c)?(b):(c));}
inline long long  min3(long long  a, long long  b, long long  c)    {return (a)<(b)?((a)<(c)?(a):(c)):((b)<(c)?(b):(c));}
using namespace std::chrono;
ll dx[4]={0,0,1,-1};
ll dy[4]={1,-1,0,0};
bool valid(ll x,ll y,ll n,ll m){if(x<0 or y<0)return false;else if(x>=n or y>=m)return false;else return true;}

void process()
{
    ll n;cin>>n;
    ll total=0,i;
    for(i=1;i<=1e6;i++)
    {
        total=((total*10)+7)%n;
        if(total==0){cout<<i<<endl;return;}
    }
    if(i>1e6)cout<<-1<<endl;
}
int main()
{
    fastio;
    //tinput;
    //while(t--)
        process();
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,n) for(int i=0;i<n;i++)
const ll MOD=1000000007;
const long double PI=3.14159265358979;
const ll MAX=0;

int main() {
  ll N;
  cin>>N;
  ll a[N];
  rep(i,N){
    cin>>a[i];
  }
  ll bit[31];
  rep(i,31){
    bit[i]=0;
  }
  for(int i=0;i<N;i++){
    ll a1=a[i],j=0;
    while(a1>0){
      if(a1%2==1){
        bit[j]++;
      }
      a1/=2;
      j++;
    }
  }
  ll key=0;
  rep(i,31){
    if(bit[30-i]%2==1){
      key+=1;
    }
    key*=2;
  }
  key/=2;
  rep(i,N){
    ll a1=a[i];
    ll ans=a1^key;
    cout<<ans<<" ";
  }
  //cout<<key;
}


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

int main() {
  int N, M;
  cin >> N >> M;
  vector<int> K(N);
  vector<vector<int>> A(N, vector<int>(M));
  for(int i = 0; i < N; i++) {
    cin >> K.at(i);
    for(int j = 0; j < K.at(i); j++) {
      cin >> A.at(i).at(j);
    }
  }
  int count,a = 0;
  for(int i = 1; i < M+1; i++) {
    count = 0;
    for(int j = 0; j < N; j++) {
      for(int k = 0; k < K.at(j); k++) {
        if(i == A.at(j).at(k)) {
          count++;
        }
      }
    }
    if(count == N) {
      a++;
    }
  }
  cout << a << endl;
}


Measured memory_bytes: 256
# include <iostream>
# include <sstream>
# include <cstdio>
# include <cstdlib>
# include <algorithm>
# include <string>
# include <cstring>
# include <cmath>
# include <stack>
# include <queue>
# include <vector>
# include <list>
# include <map>
# include <set>
# include <deque>
# include <iterator>
# include <functional>
# include <bitset>
# include <climits>
# include <ctime>
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define odd(x) ((x)%2)
typedef long long ll;
typedef long double ld;
const ll oo=2*1000*1000*1000;
const int _cnt=1000*1000;
const int _p=1000*1000*1000+7;
int o(int x) { return x%_p; }
int gcd(int a,int b) { return b?gcd(b,a%b):a; }
int lcm(int a,int b) { return a/gcd(a,b)*b; }
using namespace std;

void file_put(){
	freopen("filename.in","r",stdin);
	freopen("filename.out","w",stdout);
}

string st;
int n;

int main(){
	//file_put();
	
	cin>>st;
	n=st.length();
	st=' '+st;
	for (int i=n/2; i>=2; i--)
		if (st.substr(1,i-1)==st.substr(i,i-1))
			return 0*printf("%d\n",2*(i-1));
  
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(v) v.begin(),v.end()
#define len(x) (ll)(x).length()
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const int INF=1e9;
const ll INFS=1e18;
const int MOD=INF+7;
const int di[] = {-1,0,1,0};
const int dj[] = {0,-1,0,1};

int main(){
  int n;
  cin>>n;
  vector<int> cnt(4);
  rep(i,n){
    string s;
    cin>>s;
    if(s=="AC") cnt[0]++;
    if(s=="WA") cnt[1]++;
    if(s=="TLE") cnt[2]++;
    if(s=="RE") cnt[3]++;
  }
  cout<<"AC"<<" "<<'x'<<" "<<cnt[0]<<endl;
  cout<<"WA"<<" "<<'x'<<" "<<cnt[1]<<endl;
  cout<<"TLE"<<" "<<'x'<<" "<<cnt[2]<<endl;
  cout<<"RE"<<" "<<'x'<<" "<<cnt[3]<<endl;
}

Measured memory_bytes: 3584
program main
  implicit none
  
  integer :: i,j,k,s,l,c=0
  
  read(*,*)k,s
  do i = 0, k
    do j = 0, k
      l = s - i - j
      if ((0<=l) .and. (l<=k)) then
        c = c + 1
      end if
    end do
  end do
  write(*,*)c
end program main

Measured memory_bytes: 256
#include <stdio.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define max(p,q)((p)>(q)?(p):(q))
ll gcd(ll p,ll q){
	while(q){
		ll t=p%q;
		p=q;
		q=t;
	}
	return p;
}
int main(){
    ll n;
	scanf("%lld",&n);
    ll a[n+10],dp1[n+10],dp2[n+10],ans;
	rep(i,0,n)scanf("%lld",&a[i]);
	dp1[0]=0;
	dp2[0]=0;
	rep(i,1,n+1){
		dp1[i]=gcd(dp1[i-1],a[i-1]);
		dp2[i]=gcd(dp2[i-1],a[n-i]);
	}
	ans=max(dp1[n-1],dp2[n-1]);
	rep(i,1,n-1)ans=max(ans,gcd(dp1[i],dp2[n-1-i]));
	printf("%lld",ans);
}

Measured memory_bytes: 2560
N,M = map(int,input().split())

IDS = [list(map(int,input().split())) for i in range(M)]

L0,R0 = 0,10**6

for i in IDS:
    L0 = max(L0,i[0])
    R0 = min(R0,i[1])

print(max(0,R0-L0+1))

Measured memory_bytes: 27328
A, B = map(int, input().split())

X = A - 1
fX_bit = []
base = 2
for i in range(40):
    if i == 0:
        fX_bit.append(((X + 1) // 2) % 2)
    else:
        if X % base < (base // 2):
            fX_bit.append(0)
        else:
            fX_bit.append((X % base - (base // 2) + 1) % 2)
    #
    base <<= 1

fB_bit = []
base = 2
for i in range(40):
    if i == 0:
        fB_bit.append(((B + 1) // 2) % 2)
    else:
        if B % base < (base // 2):
            fB_bit.append(0)
        else:
            fB_bit.append((B % base - (base // 2) + 1) % 2)
    #
    base <<= 1

ans = 0
for fXi, fBi in zip(fX_bit[::-1], fB_bit[::-1]):
    ans <<= 1
    ans += (fXi ^ fBi)

print(ans)

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

#define ARC(i, a, b) for(int i = (a); i < (b); ++i)
#define RC(i, n) ARC(i, 0, n)
#define ARCH(i, a, b) for(int i = (a) - 1; i >= (b); --i)
#define RCH(i, n) ARCH(i, n, 0)

template<class T> T ant(const T &a, const T &b){ return a > b ? a : b; }
template<class T> T ont(const T &a, const T &b){ return a < b ? a : b; }
template<class T> T rng(const T &a, const T &b){ return a > b ? a - b : b - a; }
template<class T> T &anth(T &a, const T &b){ return a = ant(a, b); }
template<class T> T &onth(T &a, const T &b){ return a = ont(a, b); }

int n, q;
char s_[220000], *s = s_ + 10, t[220000], d[220000];

int main(){
	std::cin >> n >> q >> s;
	RC(i, q) std::cin >> t[i] >> d[i];
	int l = 0, r = n;
	RCH(i, q){
		if(d[i] == 'L'){
			if(s[l] == t[i]){
				++l;
			}
			if(s[r] == t[i]){
				++r;
			}
		}else{
			if(s[l - 1] == t[i]){
				--l;
			}
			if(s[r - 1] == t[i]){
				--r;
			}
		}
	}
	printf("%d\n", r - l);
	return 0;
}


Measured memory_bytes: 896
n = int(input())
num_list = [ int(input()) for i in range(n) ]
num_list.reverse()


ans = 0
t = 0
for i in range(n):
    t = max(t-1, 0)
    if num_list[i] != 0 and num_list[i] > t:
        ans += num_list[i]
        t = num_list[i]
    elif num_list[i] < t:
        ans = -1
        break

if t != 0:
    ans = -1
print(ans)

Measured memory_bytes: 57560