akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define F first
#define S second
#define REP(i, a, b, c) for(int i = a; i <= b; i+=c)
#define pb push_back
//#define int long long int
#define MOD 1000000007
using namespace std;

/*class Graph {

  map<int, list<pair<int, int> > > l;

public:
  void addEdge(int x, int y, int cost) {
    l[x].pb(make_pair(y, cost));
    l[y].pb(make_pair(x, cost));
  }

  int dfs_helper(int n, int node, map<int, int> &vis, map<int, int> &count, int &ans) {
    //cout << node << " " ;
    vis[node] = 1;
    count[node] = 1;
    for (auto m : l[node]) {
      if (!vis[m.F]) {
        vis[m.F] = 1;
        count[node] += dfs_helper(m.F, vis, count, ans);
        ans += 2 * min(count[node], n - count[node]) * m.S.S;
      }
    }
    return count[node];
  }

  void dfs() {
    map<int, int> vis;
    map<int, int> count;
    int ans = 0;
    dfs_helper(0, vis, count, ans);
    cout << ans << endl;
  }

};*/
string res = "";
int dp[3005][3005];
void solve(string s, string t)
{
  memset(dp, 0, sizeof(dp));
  for (int i = 1; i <= s.size(); i++)
  {
    for (int j = 1; j <= t.size(); j++)
    {
      if (s[i - 1] == t[j - 1])
        dp[i][j] = 1 + dp[i - 1][j - 1];
      else
        dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);

    }
  }

  int i = s.size();
  int j = t.size();
  while (i > 0 and j > 0)
  {
    if (s[i - 1] == t[j - 1]){
      res = s[i - 1] + res;
      i--;
      j--;
    }
    else if (dp[i - 1][j] > dp[i][j - 1])
      i--;
    else
      j--;
  }
}
int32_t main()
{
  ios :: sync_with_stdio(false); cin.tie(0);
  int t2 = 1;
  //cin >> t;
  for (int i9 = 1; i9 <= t2; i9++)
  {
    /* Graph G;
     int n, x, y, cost;
     cin >> n;
     while (n--) {
       cin >> x >> y >> cost;
       G.addEdge(x, y, cost);
     }
     G.dfs();*/
    //freopen("ouputnew.txt", "w", stdout);
    //flclose(stdout);
    string s, t;
    cin >> s >> t;
    solve(s, t);
    cout << res << endl;
  }
}



Measured memory_bytes: 38976
#include<cstdio>
#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<functional>
#define rep(i,a,b) for(int (i)=(a);(i)<(b);(i)++)
#define MaxCards 1000
using namespace std;
int	b,r,V;
int blue[MaxCards],red[MaxCards];
vector<int> G[MaxCards];
int match[MaxCards]; 
bool used[MaxCards];



void add_edge(int u, int v) {
    G[u].push_back(v);
    G[v].push_back(u);
}

// 増加パスをDFSで探す
bool dfs(int v) {
    used[v] = true;
    for(int i=0;i<G[v].size();i++) {
        int u = G[v][i], w = match[u];
        if (w < 0 || !used[w] && dfs(w)) {
            match[v] = u;
            match[u] = v;
            return true;
        }
    }
    return false;
}

int bipartite_matching() {
    int res = 0;
    memset(match, -1, sizeof(match));
    for(int v = 0; v < V; v++) {
        if (match[v] < 0) {
            memset(used, 0, sizeof(used));
            if (dfs(v)) {
                res++;
            }
        }
    }
    return res;
}
int gcd(int n1,int n2){
	if(n1%n2==0) return n2;
	return gcd(n2,n1%n2);
}
int main(){

	while(true){
		memset(blue,0,sizeof(blue));
		memset(red,0,sizeof(red));
		for(int i=0;i<MaxCards;i++){
			G[i].clear();
		}
		cin>>b>>r;
		V=b+r;
		if(b==0)
			break;
		int idx=0;
		for(int i=0;i<b;i++){
			cin >> blue[i];
		}
		for(int i=0;i<r;i++){
			cin >> red[i];
		}
		for(int i=0;i<b;i++){
			for(int j=0;j<r;j++){
				if(blue[i]>red[j]){
					if(gcd(blue[i],red[j])!=1){
						add_edge(i,b+j);
					}
				}
				else if(gcd(red[j],blue[i])!=1){
					add_edge(i,b+j);
				}		
			}
		}
		cout << bipartite_matching() << endl;
	}
	return 0;
}

Measured memory_bytes: 3380
N = int(input())
place = []
for _ in range(N):
    place.append(tuple(map(int, input().split())))

length = 0
for i in range(N):
    for j in range(i):
        length += ((place[i][0] - place[j][0]) ** 2 + (place[i][1] - place[j][1]) ** 2) ** (1 / 2)

print(length * 2 / N)


Measured memory_bytes: 3060
import java.util.Scanner;

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

		String s = sc.next();

		sc.close();

		int N = s.length();

		long[][] dp = new long[N][13];
		int[] pow10mod13 = { 1, 10, 9, 12, 3, 4 };

		int m = pow10mod13[(N - 1) % 6];
		if (s.charAt(0) == '?') {
			for (int p = 0; p <= 9; p++) {
				dp[0][p * m % 13] = 1;
			}
		} else {
			int p = Character.getNumericValue(s.charAt(0));
			dp[0][p * m % 13] = 1;
		}

		for (int i = 1; i < N; i++) {
			m = pow10mod13[(N - i - 1) % 6];
			if (s.charAt(i) == '?') {
				for (int p = 0; p <= 9; p++) {
					int q = p * m % 13;
					for (int j = 0; j <= 12; j++) {
//						System.out.println("i:" + i + "j:" + j + "dp[i-1][j]" + dp[i-1][j]);
						dp[i][(j + q) % 13] += dp[i - 1][j];
						if(dp[i][(j + q) % 13] >= MOD) dp[i][(j + q) % 13] -= MOD;
//						System.out.println("dp[i][(j+q)%13]:" + dp[i][(j+q)%13]);
					}
				}

			} else {
				int p = Character.getNumericValue(s.charAt(i));
				int q = p * m % 13; //i番目の数字によりq余りが増える
				for (int j = 0; j <= 12; j++) {
//					System.out.println("i:" + i);
//					System.out.println("j:" + i);
					dp[i][(j + q) % 13] = dp[i - 1][j];
				}
			}

		}

		System.out.println(dp[N - 1][5]);
//		for (int j = 0; j <= N - 1; j++) {
//			System.out.println("j:" + j);
//			for (int i = 0; i <= 12; i++) {
//				System.out.print(dp[j][i] + " ");
//			}
//			System.out.println();
//		}

	}

}


Measured memory_bytes: 38268
#include <bits/stdc++.h>
#define debug(x) cerr << #x << ": " << x << '\n';
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = (int)1e9;
const int MOD = (int)1e9 + 7;

int main(void){
	int N, M;
	cin >> N >> M;
	int l = 0, r = N;
	for(int i = 0; i < M; i++){
		int L, R;
		cin >> L >> R;
		l = max(l, L);
		r = min(r, R);
	}

	int res = (l<=r ? r-l+1 : 0);
	cout << res << '\n';

	return 0;
}

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

#define REP(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) REP(i,0,n)
#define INF (1<<30)
#define INFLL (1LL<<62LL)

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

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

int main() {
  ios_base::sync_with_stdio(false); cin.tie(0);
  int N, M;
  vector<vector<int>> A;
  vector<bool> can_use;

  cin >> N >> M;

  A.assign(N, vector<int>(M));
  can_use.resize(M);

  rep(i, N) rep(j, M) {
    cin >> A[i][j];
    A[i][j]--;
  }

  fill(can_use.begin(), can_use.end(), true);

  int ans = INF;
  rep(i, M) {
    map<int, int> cnt;
    rep(j, N) rep(k, M) {
      if (!can_use[A[j][k]])
        continue;
      cnt[A[j][k]]++;
      break;
    }

    int maxi = 0, maxi_match = 0;
    rep(j, M) {
      if (cnt[j] <= maxi) continue;
      maxi = cnt[j];
      maxi_match = j;
    }

    ans = min(maxi, ans);
    can_use[maxi_match] = false;
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 640
import sys
input = sys.stdin.readline

N = int(input())

import math
BASE = math.ceil(math.sqrt(N))

X0=0
Y0=0

rest = BASE**2 - N

X1= BASE
Y2= BASE - rest//BASE

rest = X1*Y2 - N

if rest == 0:
    X2 = 0
    Y1 = 0

else:
    X2 = rest
    Y1 = 1

print(X0,Y0,X1,Y1,X2,Y2)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i,cc,n) for(int i=cc;i<=n;++i)
#define drep(i,cc,n) for(int i=cc;i>=n;--i)
#define sz(s) (int)(s.size())
#define vecprint(v) rep(i,0,v.size()-1)cout << v[i] << " ";cout << endl;
#define mod 1000000007
using namespace std;

int main(){

  int n,ans;
 
  cin >> n;
  int a[n];
  int max=0,smax=-1;
  rep(i,0,n-1){
    cin >> a[i];
    if(max <= a[i]){
      smax = max;
      max = a[i];
    }else if(smax < a[i]){
      smax = a[i];
    }
  }
  
  rep(i,0,n-1){
    if(a[i] == max)cout << smax << endl;
    else   cout << max << endl;
  }

    return 0;
}

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

const ll maxs = 1e6+5;
const ll lmaxs = 20;
ll mod = 1e9+7;
ll oo = 1e9;

#define pb push_back
#define mp make_pair
#define ff first
#define ss second

char a[maxs];

int main(){
    //freopen("input00.txt","r",stdin);
    ll T = 1;
    //cin>>T;
    while(T--){
        string s;
        cin>>s;
        ll st = maxs/2;
        ll ed = st;
        for(ll i=0;i<s.size();i++){
            a[ed++] = s[i];
        }
        ed--;
        ll q;
        cin>>q;
        while(q--){
            ll ty;
            cin>>ty;
            if( ty == 1 ){
                swap(st,ed);
            }
            else{
                char ch;
                cin>>ty>>ch;
                if(ty==1){
                    if(st <= ed){
                        --st;
                        a[st] = ch;
                    }
                    else{
                        st++;
                        a[st] = ch;
                    }
                }
                else{
                    if(st <= ed){
                        ed++;
                        a[ed] = ch;
                    }
                    else{
                        ed--;
                        a[ed] = ch;
                    }
                }
            }
        }     
        // cout << st << " " << a[st] << endl;
        // cout << ed << " " << a[ed] << endl;
        if(st <= ed){
            for(ll i = st ; i <= ed ; i++)
               cout << a[i];
        }    
        else{
                for(ll i = st ; i >= ed ; i--)
               cout << a[i];
        }
        

    }
    return 0;
}

Measured memory_bytes: 1024
fun main(args: Array<String>) {
    val n= readLine()!!.toInt()
    val a = readLine()!!.split(" ").map{ it.toLong() }
            .groupBy{ it }
            .mapValues { it.value.size }
            .toList()
            .fold(0L){ acc, pair ->
                val number=pair.first
                val count = pair.second.toLong()
                return@fold acc + if(count<number) count else count-number
            }
            .let { println(it) }

}

Measured memory_bytes: 82340
n = int(input())
l = []
for i in range(n):
	l.append(int(input()))
maxnum = max(l)
maxidx = l.index(maxnum)

for i,e in enumerate(l):
	if i == maxidx:
		lwomax = l[:]
		lwomax.pop(maxidx)
		print(max(lwomax))
	else:
		print(maxnum)


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

int main()
{
	int N, M, p;
	cin >> N >> M >> p;

	int d[10001];
	d[0] = p;

	for (int i = 1; i < M + 1; i++)
		cin >> d[i];

	sort(d, d + M + 1);

	int c_min = N - 1;

	for (int i = 0; i < M + 1; i++) {
		int q = d[i];
		int r1 = d[(i - 1 + M + 1) % (M + 1)];
		int r2 = d[(i + 1) % (M + 1)];

		int c1 = ((p - q + N) % N) * 2 + (r1 - p + N) % N;
		int c2 = ((q - p + N) % N) * 2 + (p - r2 + N) % N;

		c_min = min(c_min, min(c1, c2));
	}
	cout << c_min * 100 << endl;
	return 0;
}

Measured memory_bytes: 3168
#include "bits/stdc++.h"
using namespace std;
#define F first
#define S second
#define s(x) #x<<" "<<x<<" | "<<
#define f(i,j,k) for(int i = j;i<=k;i++)
#define fr(i,j,k) for(int i = j;i>=k;i--)
#define ll long long
#define all(A)  A.begin(),A.end()  
#define FIO ios_base::sync_with_stdio(false);cin.tie(NULL);  
#define endl "\n"
const int MSIZE = 1e5+5;;
const int MOD = 1e9+7;
 

int arr[105];

int main(){
 
    FIO
    int x, n; cin>>x>>n;
    memset(arr,0,sizeof(arr));
    f(i,1,n) {
        int y; cin>>y;
        arr[y] = 1;
    }
    int ans1, ans2;
    f(i,x,100+x) 
        if(i>100 or !arr[i] )     {ans1 = i; break;}
    fr(i,x,x-100)
        if(i<1 or !arr[i] )     {ans2 = i; break;}
    if(ans1-x<x-ans2) cout<<ans1<<endl;
    else cout<<ans2<<endl;
 
} 

Measured memory_bytes: 3608
/*
 * c.cc: 
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>

using namespace std;

/* constant */

/* typedef */

/* global variables */

int cs[26];

/* subroutines */

/* main */

int main() {
  for (;;) {
    string s;
    getline(cin, s);
    if (cin.eof()) break;

    for (int i = 0; i < s.size(); i++) {
      if (s[i] >= 'A' && s[i] <= 'Z') cs[s[i] - 'A']++;
      else if (s[i] >= 'a' && s[i] <= 'z') cs[s[i] - 'a']++;
    }
  }

  for (int i = 0; i < 26; i++)
    printf("%c : %d\n", 'a' + i, cs[i]);

  return 0;
}

Measured memory_bytes: 1188
#include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
using namespace std;
typedef long long ll;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define all(v) v.begin(), v.end()
#define REP(i, x, n) for(int i = x; i < n; i++)
#define INF 2e9
signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int m;
    string s;
    cin>>s;
    s[3]='8';
    cout<<s<<'\n';
    return(0);
}

Measured memory_bytes: 256
def main():
    N, K = map(int, input().split())
    masterArray = []
    for i in range(K):
        _ = input()
        haveNumber = list(map(int, input().split()))
        masterArray.extend(haveNumber)
    result = set(masterArray)
    print(N - len(result))


if __name__ == "__main__":
    # execute only if run as a script
    main()


Measured memory_bytes: 9176
#include<iostream>
#include<stdio.h>
//#include <bits/stdc++.h>
#include<vector>
#include<float.h>
#include<iomanip>
#include<algorithm>
#include<string>
#include<cstring>
#include<math.h>
#include<cmath>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include <cassert>
#include <cmath>
#include<cstdint>

#define INF 1e9
#define rep(i,n)for(int i=0;(i)<(int)(n);i++)
#define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)
#define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
#define vec(type,n) vector<type>(n)
#define vvec(m,n) vector<vector<int>> (int(m),vector<int>(n))
#define ALL(a)  (a).begin(),(a).end()

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using P = pair<int,int>;

vector<int>bitSearch(int bit,int n){
    vector<int>S;
    rep(i,n)if(bit&(1<<i))S.push_back(i);
    return S;
}



int main(){
    int n;cin>>n;
    if(n==7 || n==5 || n==3)cout<<"YES";
    else cout<<"NO";
}



Measured memory_bytes: 256
import java.util.Scanner;
public class Main{
	public static void main(String[] args) {
		int a,b=0,W,H;
		Scanner br = new Scanner(System.in);
		while(true){
			H=br.nextInt();
			W=br.nextInt();
			if(H==0 && W==0){
				break;
			}else{
				for(a=1;a<=H;a++){
					if(a%2==1){
						for(b=1;b<=W;b++){
							if(b%2==1){
								System.out.print("#");
								}else{
									System.out.print(".");
									}
							}
					}else{
						for(b=1;b<=W;b++){
							if(b%2==1){
								System.out.print(".");
							}else{
								System.out.print("#");
							}
						}
					}
					System.out.println();
				}
			System.out.println();
			}
		}
	}
}

Measured memory_bytes: 34852
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)
var c int64 = 1000000007

func main() {
	scanInit()

	n := nextInt()
	if n == 1 {
		fmt.Println(1)
		return
	}

	m := map[int]int{}

	for i := 2; i <= n; i++ {
		ifac := getFactor(i)
		//fmt.Println(ifac) //! DBG
		for f, e := range ifac {
			m[f] += e
		}
	}

	var ans int64 = 1
	for _, e := range m {
		ans *= int64(e) + 1
		ans %= c
	}

	fmt.Println(ans)

}

// 素因数分解列挙Map作成
func getFactor(a int) (m map[int]int) {
	m = map[int]int{}
	for k := 2; a != 1; k++ {
		for ; a%k == 0; a /= k {
			m[k]++
		}
	}
	return m
}

// ---- readfunc
func scanInit() {
	const cap = 200 * 1024 // default=64*1024
	var buf = make([]byte, cap)
	sc.Buffer(buf, cap)
	sc.Split(bufio.ScanWords)
	return
}
func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}
func nextStr() string {
	sc.Scan()
	return sc.Text()
}


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

using i32 = int32_t;
using i64 = int64_t;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    i32 n, m;
    cin >> n >> m;
    cout << (n * (n - 1) / 2) + (m * (m - 1) / 2)  << endl;
    return 0;
}


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

int main()
{
    int i, cnt = 0;
    vector<int> v;
    string s;

    cin >> s;
    v.push_back(0);

    for (i = 0; i < s.size(); i++)
    {
        if (s[i] == 'A' || s[i] == 'G' || s[i] == 'T' || s[i] == 'C')
            cnt++;
        else
        {
            v.push_back(cnt);
            cnt = 0;
        }
    }
    v.push_back(cnt);
    cout << *max_element(v.begin(), v.end()) << endl;
}

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

int main() {
  long long t1, t2, a1, a2, b1, b2;
  cin >> t1 >> t2 >> a1 >> a2 >> b1 >> b2;

  // make a1 > b1
  if (a1 < b1) {
    swap(a1, b1);
    swap(a2, b2);
  }

  auto d1 = (a1 - b1) * t1; // d1 > 0
  auto d2 = (a2 - b2) * t2;

  if (d1 + d2 == 0) {
    cout << "infinity";
    return 0;
  }
  if (d1 + d2 > 0) {
    cout << 0;
    return 0;
  }

  if (-d1 % (d1 + d2) == 0) {
    auto n = -d1 / (d1 + d2);
    cout << (2 * n);
    return 0;
  }

  auto n = -d1 / (d1 + d2);
  cout << (2 * n + 1);
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <cmath>
#include <bitset>
#include <iomanip>
#include <stack>
#include <list>
#include <map>
#include <unordered_map>
#include <chrono>
#include <numeric>
using namespace std;
using ll = long long;
const ll INF = (ll)1e18+1;
const ll DIV = 1000000007;
//#define TEST
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
#ifdef TEST
    chrono::system_clock::time_point start, end;
    start = chrono::system_clock::now();
#endif
    long N, i;
    cin >> N >> i;
    cout << N-i+1 << endl;
#ifdef TEST
    end = chrono::system_clock::now();
    cerr << static_cast<double>(chrono::duration_cast<chrono::microseconds>(end - start).count() / 1000.0) << "[ms]" << endl;
#endif
    return 0;
}

Measured memory_bytes: 3548
def F(n, b):
    res = 0
    while n:
        n, m = divmod(n, b)
        res += m
    return res


N = int(input())
S = int(input())
if S > N:
    print(-1)
    exit()
if S == N:
    print(N + 1)
    exit()


inf = 10**18
ans = inf
d = 0
while True:
    d += 1
    lower = N // d
    upper = N // (d + 1) + 1
    if lower == upper:
        break
    FL = F(N, lower)
    FU = F(N, upper)
    if FL <= S <= FU:
        if (FU - S) % d == 0:
            pos = (FU - S)//d
            ans = min(ans, upper + pos)

for b in range(2, upper + 1):
    if F(N, b) == S:
        ans = min(ans, b)

if ans >= inf:
    print(-1)
else:
    print(ans)

Measured memory_bytes: 9252
use input::*;
use std::cmp::*;
use std::io::*;
use std::num::*;
use std::str::*;

mod input {
    use super::*;
    pub fn read<T: FromStr>() -> T {
        stdin()
            .bytes()
            .map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>()
            .parse::<T>()
            .ok()
            .unwrap()
    }
    pub fn string() -> String {
        read()
    }
    pub fn int() -> i64 {
        read()
    }
    pub fn char() -> char {
        read::<String>().pop().unwrap()
    }
    pub fn vecchar() -> Vec<char> {
        string().chars().collect()
    }
    pub fn vecint(n: i64) -> Vec<i64> {
        let mut vec = Vec::new();
        for i in 0..n {
            vec.push(int())
        }
        vec
    }
}
fn main() {
    let (n, m) = (int(), int());
    let a = vecint(m);
    let sum = a.iter().sum::<i64>() as i64;
    println!("{}", if n < sum { -1i64 } else { n - sum })
}


Measured memory_bytes: 2168
import sys
input = sys.stdin.readline


def main():
    N = int(input())
    A = [int(x) for x in input().split()]

    r = 0
    b = A[0]
    ans = 0
    for l in range(N):
        while r + 1 < N and A[r + 1] & b == 0:
            r += 1
            b |= A[r]
        ans += r - l + 1
        b = b ^ A[l]

    print(ans)




if __name__ == '__main__':
    main()



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

typedef struct
{
  double x, y;
}Point; 

void koch(int, Point, Point);

int main()
{
	Point a, b;
	int n;

	a.x = 0;
	a.y = 0;
	b.x = 100;
	b.y = 0;
	
	scanf("%d",&n);

	printf("%.8f %.8f\n", a.x, a.y);
	koch(n, a, b);
	printf("%.8f %.8f\n", b.x, b.y);
	
	return 0;
}

void koch(int n, Point a, Point b)
{
	Point s, t, u;
	double rad = 60 * M_PI / 180;
	
	if(n == 0)return;
	
	s.x = (2 * a.x + 1 * b.x) / 3;
	s.y = (2 * a.y + 1 * b.y) / 3;
	t.x = (1 * a.x + 2 * b.x) / 3;
	t.y = (1 * a.y + 2 * b.y) / 3;
	u.x = (t.x - s.x) * cos(rad) - (t.y - s.y) * sin(rad) + s.x;
	u.y = (t.x - s.x) * sin(rad) + (t.y - s.y) * cos(rad) + s.y;
	
	koch(n-1, a, s);
	printf("%.8f %.8f\n", s.x, s.y);
	
	koch(n-1, s, u);
	printf("%.8f %.8f\n", u.x, u.y);
	
	koch(n-1, u, t);
	printf("%.8f %.8f\n", t.x, t.y);
	
	koch(n-1, t, b);
}



Measured memory_bytes: 2120
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vs = vector<string>;
using msi = map<string, int>;
using mii = map<int, int>;
using psi = pair<string, int>;
using pii = pair<int, int>;
using vlai = valarray<int>;
#define rep(i,n) for(int i=0;i<n;i++)
#define range(i,s,n) for(int i=s;i<n;i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define fs first
#define sc second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define INF 1e9
#define EPS 1e-9
#define MOD (1e9+7)

int main() {
	int a,b;
	cin >> a >> b;
	if ((a > b || (a == 1 && b == 13))&&a!=13)cout << "Alice" << endl;
	else if (a < b || (a == 13 && b == 1))cout << "Bob" << endl;
	else cout << "Draw" << endl;
}


Measured memory_bytes: 256
N, K = input().split(" ")

price = input().split(" ")
list1 = []

for j in price:
    list1.append(int(j))

list1 = list1[:int(N)]
list1.sort()

list2 = list1[:int(K)]

summ = 0
for i in list2[:int(K)]:
    summ += int(i)

print(summ)


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

// #undef DEBUG  // Uncomment this line to forcefully disable debug print.
#if DEBUG
template <typename T>
void debug(T value) {
  std::cerr << value;
}
template <typename T, typename... Ts>
void debug(T value, Ts... args) {
  std::cerr << value << ", ";
  debug(args...);
}
#define dbg(...)                              \
  do {                                        \
    cerr << #__VA_ARGS__ << ": ";             \
    debug(__VA_ARGS__);                       \
    cerr << " (L" << __LINE__ << ")" << endl; \
  } while (0)
#else
#define dbg(...)
#endif

void read_from_cin() {}
template <typename T, typename... Ts>
void read_from_cin(T& value, Ts&... args) {
  std::cin >> value;
  read_from_cin(args...);
}
#define in(type, ...) \
  type __VA_ARGS__;   \
  read_from_cin(__VA_ARGS__);

template <typename T>
void write_to_cout(const T& value) {
  std::cout << value << std::endl;
}
template <typename T, typename... Ts>
void write_to_cout(const T& value, const Ts&... args) {
  std::cout << value << ' ';
  write_to_cout(args...);
}
#define out(...) write_to_cout(__VA_ARGS__);

#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)

using ll = long long;

using namespace std;

int main() {
  in(int, n);
  vector<pair<ll, ll>> v(n);
  rep(i, n) cin >> v[i].second >> v[i].first;
  sort(all(v));
  int t = 0;
  rep(i, n) {
    t += v[i].second;
    if (t > v[i].first) {
      out("No");
      return 0;
    }
  }
  out("Yes");
}


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

int main(void) {
    string s;
    int sum;
    while (cin >> s) {
        if (s == "0") return 0;
        sum = 0;
        for (int i = 0; i < s.size(); i++) {
            sum += s[i] - '0';
        }
        cout << sum << endl;
    }
}


Measured memory_bytes: 3196
attrs = Array.new
while line = $stdin.gets
    attrs << line.chomp.split.map{|v| v.to_i }
end

N = attrs.shift[0]
B = attrs.shift

if N == 2 then
  puts B[0] * 2
else
  result = B[0] + B[-1]
  for i in 1..(N - 2) do
    result += B[i] if B[i] < B[i - 1]
    result += B[i - 1] if B[i] >= B[i - 1]
  end
  puts result 
end

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

int main(int argc, char const *argv[])
{
	int n;
	cin>>n;
	long long x,y,u[n],v[n];
	for (int i = 0; i < n; ++i)
	{
		cin>>x>>y;
		u[i]=x+y;
		v[i]=x-y;
	}
	long long r=((u[0]%2LL)+2LL)%2LL;
	for (int i = 1; i < n; ++i)
	{
		if (r!=((u[i]%2LL)+2LL)%2LL)
		{
			cout<<"-1\n";
			return 0;
		}
	}
	int m=31;
	if (r==0)
	{
		m=32;
	}
	cout<<m<<endl;
	long long d[m];
	d[0]=1LL;
	for (int i = 1; i < m; ++i)
	{
		if (i==1&&r==0)
		{
			d[1]=1LL;
			++i;
		}
		d[i]=d[i-1]*2LL;
	}
	reverse(d,d+m);
	cout<<d[0];
	for (int i = 1; i < m; ++i)
	{
		cout<<" "<<d[i];
	}
	cout<<endl;
	for (int i = 0; i < n; ++i)
	{
		char w[m];
		long long nu=0LL,nv=0LL;
		for (int j = 0; j < m; ++j)
		{
			if (nu>u[i])
			{
				if (nv>v[i])
				{
					w[j]='L';
					nu-=d[j];
					nv-=d[j];
				}
				else
				{
					w[j]='D';
					nu-=d[j];
					nv+=d[j];
				}
			}
			else
			{
				if (nv>v[i])
				{
					w[j]='U';
					nu+=d[j];
					nv-=d[j];
				}
				else
				{
					w[j]='R';
					nu+=d[j];
					nv+=d[j];
				}
			}
		}
		for (int j = 0; j < m; ++j)
		{
			cout<<w[j];
		}
		cout<<endl;
	}
	return 0;
}


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

typedef long long ll;

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

    int ans = 0;
    string s;
    cin >> s;
    int size = s.size();
    if(size%2==0){
        for(int i=0;i<size/2;i++){
            if(s[i]!=s[size-i-1]) ans++;
        }
        cout << ans << endl;
    }else{
        for(int i=0;i<=size/2-1;i++){
            if(s[i]!=s[size-i-1]) ans++;
        }
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main () {
  int m[100], f[100], r[100];
  int i;
  for (i=0; i<100; i++) {
    scanf("%d %d %d", &m[i], &f[i], &r[i]);
    if (m[i]==-1 && f[i]==-1 && r[i]==-1) {
      break;
    }
  }

  for (i=0; i<100; i++) {
    if (m[i]==-1 && f[i]==-1 && r[i]==-1) {
      break;
    }
      if (f[i]==-1 || m[i]==-1) {
      printf("F\n");
    }
    else if (m[i]+f[i]>=80) {
    printf("A\n");
    }
    else if (m[i]+f[i]>=65 && m[i]+f[i]<80) {
      printf("B\n");
    }
    else if (m[i]+f[i]>=50 && m[i]+f[i]<65) {
      printf("C\n");
    }
    else if (m[i]+f[i]>=30 && m[i]+f[i]<50 && r[i]<50) {
      printf("D\n");
    }
    else if (m[i]+f[i]>=30 && m[i]+f[i]<50 && r[i]>=50) {
      printf("C\n");
    }
    else if (m[i]+f[i]<30) {
      printf("F\n");
    }
  }

  return 0;
}

Measured memory_bytes: 584
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */

#include <iostream>
#include <fstream>

#include <bits/stdc++.h>
#define rep(i,n) for (int i= 0;i<(n);++i)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

class ATherefore {
public:
	void solve(std::istream& cin, std::ostream& cout) {
	    int n;
	    cin >>n;

	    if(n%10==3){
	        cout<< "bon"<<endl;
	    }
	    else if(n%10==0||n%10==1||n%10==6||n%10==8){
	        cout<<"pon"<<endl;
	    }
	    else{
	        cout<<"hon"<<endl;
	    }


	}
};


int main() {
	ATherefore solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 3600
#include<bits/stdc++.h>
#define fora(i,a,b) for(int i=a,Wub=b;i<Wub;++i)
#define ford(i,a,b) for(int i=a,Wub=b;i>=Wub;--i)
#define SPEEDIO ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define MAX 1000000
#define MOD 1073741824
using namespace std;
typedef long long ll;

int main(){
    string a, b, c;
    cin >> a >> b >> c;
    cout<< (char)(a[0] - 32) << (char)(b[0] - 32) << (char)(c[0] - 32) <<"\n";
    return 0;
}


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

string intersection(string tree1, string tree2);
string tunion(string tree1, string tree2);
int camma_pos(string tree);


int camma_pos(string tree){
	int i, camma_p;
	int braket = 0;
	for(i = 0; i < tree.size(); i++){
		if(tree[i] == '('){
			braket++;
		}else if(tree[i] == ')'){
			braket--;
		}
		if((tree[i] == ',') && (braket == 1)){
			camma_p = i;
		}
	} 
	return camma_p;
}

string intersection(string tree1, string tree2){
	int i;
	int braket = 0;
	int camma_p1, camma_p2;
	string tree1_l, tree1_r;
	string tree2_l, tree2_r;
	string left, right;
	if(tree1.size() == 0 || tree2.size() == 0){
		return "";
	}
	camma_p1 = camma_pos(tree1);
	camma_p2 = camma_pos(tree2);
	tree1_l = tree1.substr(1,camma_p1-1);
	tree1_r = tree1.substr(camma_p1+1, tree1.size() - camma_p1 - 2);
	tree2_l = tree2.substr(1,camma_p2-1);
	tree2_r = tree2.substr(camma_p2+1, tree2.size() - camma_p2 - 2);
	left = intersection(tree1_l, tree2_l);
	right = intersection(tree1_r, tree2_r);
	return "(" + left + "," + right + ")";
}

string tunion(string tree1, string tree2){
	int i;
	int braket = 0;
	int camma_p1, camma_p2;
	string tree1_l, tree1_r;
	string tree2_l, tree2_r;
	string left, right;
	if(tree1.size() == 0){
		return tree2;
	}
	if(tree2.size() == 0){
		return tree1;
	}
	camma_p1 = camma_pos(tree1);
	camma_p2 = camma_pos(tree2);
	tree1_l = tree1.substr(1,camma_p1-1);
	tree1_r = tree1.substr(camma_p1+1, tree1.size() - camma_p1 - 2);
	tree2_l = tree2.substr(1,camma_p2-1);
	tree2_r = tree2.substr(camma_p2+1, tree2.size() - camma_p2 - 2);
	left = tunion(tree1_l, tree2_l);
	right = tunion(tree1_r, tree2_r);
	return "(" + left + "," + right + ")";
}

int main(){
	char ui;
	string tree1, tree2, treeans;
	while(cin >> ui >> tree1 >> tree2){
		if(ui == 'i'){
			treeans = intersection(tree1, tree2);
		}else{
 			treeans = tunion(tree1, tree2);
		}
		cout << treeans << endl;
	}
}

Measured memory_bytes: 1208
#include<iostream>
#include<algorithm>
using namespace std;
int n;
long X,x[2<<17];
long ans=9e18;
long calc(int k)
{
	long now=(n+k)*X;
	for(int i=0;i<n;i++)
	{
		now+=x[n-i-1]*(i/k==0?5:i/k*2+3);
	}
	return now;
}
main()
{
	cin>>n>>X;
	for(int i=0;i<n;i++)cin>>x[i];
	int L=1,R=n+1;
	ans=min(calc(1),calc(n));
	while(R-L>2)
	{
		int k1=(L*2+R)/3;
		int k2=(L+R*2)/3;
		long now1=calc(k1);
		long now2=calc(k2);
		ans=min(ans,min(now1,now2));
		if(now1<now2)R=k2;
		else L=k1;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 1792
/********** BiSmIlLaHiR rAhMaNiR rAhIm ***********\
*$*$*$*$*$*$*$*$*$*$*$*$*$*$*$*$*$*$*$*$*$*$*$*$*$*
*$*                                             *$*
*$*    ||||||||  ||||||||  ||||||||  ||||||||   *$*
*$*    ||    ||  ||           ||     ||         *$*
*$*    ||||||||  ||||||||     ||     ||||||     *$*
*$*    ||    ||        ||     ||     ||         *$*
*$*    ||    ||  ||||||||  ||||||||  ||         *$*
*$*                                             *$*
*$*$*$*$*$*$*$*$*$*$*$*$*$*$*$*$*$*$*$*$*$*$*$*$*$*
\*************** DIIT(17th batch) ****************/

#include<bits/stdc++.h>
#define ll long long int
#define ul unsigned long long int
#define pf printf
#define sf scanf
#define endl "\n"
#define pb push_back
#define makep make_pair
#define MOD 1000000007
#define PI acos(-1.0)
#define PII pair<string , ll> 
#define SIZE 1000005
#define fio() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
using namespace std;
ll fx[]={1,0,-1,0,-1,-1,1,1};
ll fy[]={0,1,0,-1,-1,1,-1,1};

int main()
{
    /*#ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif*/
    fio();
    ll q,t,f,cnt=0,i;
    string s,s1,str1,str2;
    cin>>s>>q;
    while(q--)
    {
        cin>>t;
        if(t==1)
        {
            cnt++;
        }
        else
        {
            cin>>f>>s1;
            if(f==1){
                if(cnt%2==0){
                    str1=str1+s1;
                }
                else{
                    str2=s1+str2;
                }
            }
            else{
                if(cnt%2==0){
                    str2=s1+str2;
                }
                else{
                    str1=str1+s1;
                }
            }
        }
        //cout<<str1<<" "<<str2<<endl;
    }
    if(cnt%2==1){
        //s=str2+s+str1;
        reverse(s.begin(),s.end());
        //reverse(str1.begin(),str1.end());
        //reverse(str2.begin(),str2.end());
        s=str2+s+str1;
    }
    else
    {
        reverse(str1.begin(),str1.end());
        reverse(str2.begin(),str2.end());
        s=str1+s+str2;
    }
    cout<<s<<endl;
    return 0;
}
// ! () &

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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N, K;
  cin >> N >> K;
  double res = 0.0;
  for (int i = 1; i <= N; i++) {
    int x = i;
    double p = 1.0 / N;
    while (x < K) {
      p /= 2;
      x *= 2;
    }
    res += p;
  }
  cout << setprecision(10) << res << '\n';
  return 0;
}


Measured memory_bytes: 256
n = int(input())
keta = len(str(n))

# keta=n
ttl=0
if len(str(n)) % 2 != 0:
    ttl+=(n - 10**(keta - 1)+1)
    
# keta<n
for i in [i for i in range(keta) if i % 2 != 0]:
    ttl+=(10**(i-1) * 9)

print(ttl)

Measured memory_bytes: 3060
import bisect
N = int(input())
L = list(map(int, input().split()))
L.sort()
ans = 0
for i in range(N-2):
    for j in range(i+1, N-1):
        id = bisect.bisect_left(L, L[i] + L[j])
        ans += id - j - 1

print(ans)


Measured memory_bytes: 3188
#include <stdio.h>
#include <stdlib.h>
#include <string.h>


struct node{
  int key;
  struct node *left;
  struct node *right;
  struct node *parent;
};

typedef struct node *NodePointer;

void insert(int);
void delete(int);
void change(NodePointer, NodePointer);
NodePointer Treemin(NodePointer);
NodePointer Search(NodePointer, int);
void Preorder(NodePointer);
void Inorder(NodePointer);

NodePointer root = NULL; 


int main () {
  int n = 0, i, x = 0;
  char str[7];


  scanf("%d",&n);

  for(i = 0 ; i < n ; i++) {
    scanf("%s",str);
    if(strcmp(str,"insert") == 0) {
      scanf("%d",&x);
      insert(x);
    }
    else if(strcmp(str,"print") == 0) {
      Inorder(root);
      printf("\n");
      Preorder(root);
      printf("\n");
    }
    else if(strcmp(str,"find") == 0) {
      scanf("%d",&x);
      if(Search(root, x) != NULL) printf("yes\n");
      else printf("no\n");
    }

    else {
      scanf("%d",&x);
      delete(x);
    }
  }
  

  return 0;
}


NodePointer Search(NodePointer p, int x) {
  if(p == NULL) return NULL;
  else if(p->key == x) return p;
  else if(p->key > x) return Search(p->left, x);
  else return Search(p->right, x);
}



void insert(int z) {
  NodePointer p, x = root, y = NULL;
  
  p = (NodePointer)malloc(sizeof(struct node));

  p->key = z;
  p->left = NULL;
  p->right = NULL;
  
  while(x != NULL) {
  
    y = x;
    
    if(z < x->key) x = x->left;
    else x = x->right; 
  }
  
  p->parent = y; 
  
  if(y == NULL) root = p;
  else if(p->key < y->key) y->left = p;
  else y->right = p; 


}



void delete(int x) {
  NodePointer p, y,z;

  p = Search(root, x);

  if(p != NULL) {
    if(p->left == NULL) { //右の子のみ、また子がない
      change(p, p->right);
    }
    else if(p->right == NULL) { //左の子のみ
      change(p, p->left);
    }
    else {  //子が二人
      y = Treemin(p->right);
      if(y->parent != p) {
	change(y, y->right);
	y->right = p->right;
	p->right->parent = y;
      }
      change(p,y);
      y->left = p->left;
      p->left->parent = y;
    }
  }
  
}


void change(NodePointer p, NodePointer n) {
  if(p->parent == NULL) root = n;
  else if(p == p->parent->left) p->parent->left = n;
  else p->parent->right = n;
  if(n != NULL) n->parent = p->parent;
}


NodePointer Treemin(NodePointer p) {
  if(p->left == NULL) return p;
  else return Treemin(p->left);
}







void Preorder(NodePointer cur) {

  if(cur != NULL) {
    printf(" %d",cur->key);
    Preorder(cur->left);
    Preorder(cur->right);
  }
  
}


void Inorder(NodePointer cur) {

  if(cur != NULL) {
    Inorder(cur->left);
    printf(" %d",cur->key);
    Inorder(cur->right);
  }
}



Measured memory_bytes: 20452
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mp make_pair
#define fi first
#define se second
const int maxn=20;
const int maxm=2<<16;
const int maxe=maxn*2;
const ll mod=1e9+7;
const int inf=0x3f3f3f3f;
ll n,m,k;


int main(){
    scanf("%lld%lld",&n,&m);
    if(n==1&&m==1){
        printf("1\n");
    }
    else if(n==1){
        printf("%d\n",m-2);
    }
    else if(m==1){
        printf("%d\n",n-2);
    }
    else{
        printf("%lld\n",(n-2)*(m-2));
    }
    return 0;
}


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

namespace Finding_Missing_Cards
{
    class Program
    {
        static void Main(string[] args)
        {
            int cardNum = int.Parse(Console.ReadLine());

            List<string> cards = new List<string>();

            for (int i = 1; i <= 13; ++i)
            {
                cards.Add("S " + i);
            }
            for (int i = 1; i <= 13; ++i)
            {
                cards.Add("H " + i);
            }
            for (int i = 1; i <= 13; ++i)
            {
                cards.Add("C " + i);
            }
            for (int i = 1; i <= 13; ++i)
            {
                cards.Add("D " + i);
            }

            for (int i = 0; i < cardNum; ++i)
            {
                cards.Remove(Console.ReadLine());
            }

            foreach (string item in cards)
            {
                Console.WriteLine(item);
            }
        }
    }
}



Measured memory_bytes: 17844
import java.io.*;
import java.util.*;

class Main{

	static void dfs(int src,Map<Integer,LinkedList<Integer>> map,boolean vis[]){
		if(vis[src]) return;

		vis[src] = true;

		for(int i : map.get(src)){
			dfs(i,map,vis);
		}
	}

    public static void main(String args[])throws IOException{
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

    String s[] = br.readLine().split(" ");

    int n = Integer.parseInt(s[0]);
    int m = Integer.parseInt(s[1]);

    Map<Integer,LinkedList<Integer>> map = new HashMap<>();

    for(int i=1;i<=n;i++) map.put(i,new LinkedList<>());

    while(m-->0){
    	s = br.readLine().split(" ");
    	
    	int u = Integer.parseInt(s[0]);
    	int v = Integer.parseInt(s[1]); 

    	map.get(u).add(v);
    	map.get(v).add(u);
    }

    boolean vis[] = new boolean[n+1];

    int count=-1;

    for(int i=1;i<=n;i++){
    	if(vis[i]) continue;
    	dfs(i,map,vis);
    	count++;
    }


    System.out.println(count);
  }
}

Measured memory_bytes: 78412
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pl;


int main(){
  string s,t;
  cin>>s>>t;

  int ans=0;
  for(int i=0;i<3;i++){
    if(s[i]==t[i])
    ans++;
  }
  cout<<ans<<endl;

}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(700000)

def s_in():
    return input()

def n_in():
    return int(input())

def l_in():
    return list(map(int, input().split()))

n,s=l_in()
A=l_in()


dp = [[0]*(s+1) for _ in range(n+1)]

dp[0][0]=1


mod = 998244353

for i in range(1,n+1):
    for w in range(0,s+1):
        dp[i][w] = dp[i-1][w]*2
        a = A[i-1]
        if w >= a:
            dp[i][w] += dp[i-1][w-a]

        dp[i][w] =         dp[i][w]%mod


print(dp[n][s])


Measured memory_bytes: 132576
#include <iostream>
#include <cstdio>

using namespace std;

long long n, m;
long long a[100005];
long long b[100005];
long long cp[100005];
long long d[100005];
long long ans[100005];

long long fnd(long long p)
{
    if(cp[p] == p) return p;
    else return cp[p] = fnd(cp[p]);
}

int main()
{
    //freopen("input.txt", "r", stdin);
    scanf("%lld%lld", &n, &m);
    for(long long i = 0; i < m; i++)
    {
        scanf("%lld%lld", &a[i], &b[i]);
    }
    for(long long i = 1; i <= n; i++) cp[i] = i, d[i] = 1;
    ans[m] = n * (n - 1) / 2;
    for(long long i = m - 1; i >= 0; i--)
    {
        ans[i] = ans[i + 1];
        if(fnd(a[i]) != fnd(b[i]))
        {
            ans[i] -= d[fnd(a[i])] * d[fnd(b[i])];
            d[fnd(b[i])] += d[fnd(a[i])];
            cp[fnd(a[i])] = fnd(b[i]);
        }
    }
    for(long long i = 1; i <= m; i++) printf("%lld\n", ans[i]);
    return 0;
}


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

int main(){
    int n,hyaku,ju,ichi;

    // ページ数
    cin >> n;

    hyaku = n/100;
    ju = (n-hyaku*100)/10;
    ichi = n-hyaku*100-ju*10;
    if((hyaku==7)||(ju==7)||(ichi==7)){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}

Measured memory_bytes: 3580
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int a,b;
	cin>>a>>b;
	if (a>=1 && a<=9)
	{
		if (b>=1 && b<=9)
		{
			cout<<a*b<<endl;
		}
		else
		{
			cout<<-1<<endl;
		}
	}
	else
	{
		cout<<-1<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
//  Created by conan1024hao in 2019.
//  Copyright © 2019 conan1024hao. All rights reserved.
//  専用ライブラリです、自由にコピーして構いません。
//  感谢看我的代码！Wechat:conan1024hao Twitter/QQ:810396815
#pragma GCC optimize ("O3")
#include <iostream>
#include <iomanip>
#include <istream>
#include <ostream>
#include <sstream>
#include <iterator>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <utility>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <ctime>
#include <cctype>
#include <cstdlib>
#define IINF 10e8
#define INF 10e16
#define MOD 1000000007
#define mod 1000000007
#define rep(i, a, n) for (ll i = a; i < (ll)(n); i++)
#define Endl endl
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define mmax(x,y)(x>y?x:y)
#define mmin(x,y)(x<y?x:y)
#define chmax(x,y) x=mmax(x,y)
#define chmin(x,y) x=mmin(x,y)
#define all(x) (x).begin(),(x).end()
#define siz(x) (ll)(x).size()
#define PI acos(-1.0)
using namespace std;
//using Int=int_fast64_t;
typedef long long int ll;
typedef pair<ll,ll>Pll;
typedef pair<int,int>Pin;
long long GCD(long long a, long long b) { return b ? GCD(b, a%b) : a; }
long long LCM(long long a, long long b)  {return a/GCD(a,b)*b;}
int dx[8]={-1,0,1,0,1,1,-1,-1};
int dy[8]={0,-1,0,1,1,-1,1,-1};
char dir[4]={'u','l','d','r'};
ll cmp1(pair<ll,string>a,pair<ll,string> b){
        if(a.fi!=b.fi)
        return a.fi<b.fi;
        else
        return a.se<b.se;
}
//--------------------------------------------------------------------------

//---------------------------------------------------------------------------
int main(){//問題をちゃんと見ろ!!!!!!!!!!!!!!!!!      llか??????????        memset()!!!!!!!!!!!!       ペナを減らせ!!!!!!!!!!!!!
    cin.tie(0);
    ios::sync_with_stdio(false);
    //-------------------------------
    int h,w;cin>>h>>w;
    char c[200][100];
    for(int i=0;i<h;i++)
        for(int j=0;j<w;j++)
            cin>>c[i][j];
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            cout<<c[i][j];
        }
        cout<<endl;
        for(int j=0;j<w;j++){
            cout<<c[i][j];
        }
        cout<<endl;
    }
    //-------------------------------
    return 0;
}
//---------------------------------------------------------------------------









Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    string S; cin >> S;
    if (S.size() == 3) {
        swap(S[0], S[2]);
    }
    cout << S << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const ll INF = 100000000;
#define rep1(i, n) for (ll i=0; i<(n); i++) 
#define rep2(i, k, n) for (ll i=k; i<(n); i++)


int main() {
    ll n;
    cin >> n;
    vector<ll> a(n, 0);
    map<ll,ll> l,r;
    rep1(i, n){
        cin >> a[i];
        l[i+a[i]]++;
        r[i-a[i]]++;
    }
    ll ans = 0;
    ll size = l.size();
    for (auto p : l){
        ll key = p.first;
        ll val = p.second;
        if (r.count(key)) ans += l[key]*r[key];
        l.erase(key);
    }
    cout << ans << endl;
}

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

using namespace std;
using ll = long long;

struct edge{
    int to, from, cost;
    edge(){};
    edge(int t, int f, int c) : to(t), from(f), cost(c){};
};

const ll INFTY = 1e50;

int main(){
    int N,M; cin >> N >> M;
    int a,b,c;
    vector<edge> es(M);
    for(int i=0;i<M;i++){
        cin >> a >> b >> c;
        a--; b--;
        es[i] = edge(b,a,-c);
    }

    bool neg_loop = false;
    vector<ll> dist(N, INFTY);
    dist[0] = 0;
    for(int i=0;i<2*N;i++){
        for(int j=0;j<M;j++){
            edge e = es[j];
            if(dist[e.from] != INFTY && dist[e.to] > dist[e.from] + e.cost){
                dist[e.to] = dist[e.from] + e.cost;
                if(i >= N-1 && e.to == N-1){
                    neg_loop = true;
                }
            }
        }
    }

    if(neg_loop){
        cout << "inf" << endl;
    }else{
        cout << -dist[N-1] << endl;
    }
    return 0;

}

Measured memory_bytes: 384
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
  let mut s = String::new();
  std::io::stdin().read_line(&mut s).ok();
  s.trim().split_whitespace()
    .map(|e| e.parse().ok().unwrap()).collect()
}

fn main() {
  let abc: Vec<i32> = read_vec();

  let ans = if abc[0] <= abc[2] && abc[2] <= abc[1] {
    "Yes"
  } else {
    "No"
  };

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


Measured memory_bytes: 4352
#include <algorithm>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits.h>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <string>
#include <string.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<=n;i++)
#define eps LDBL_EPSILON
#define moder 1000000007
#define int long long
#define ll long long
#define double long double
#define INF LLONG_MAX
#define P pair<int,int>
#define prique priority_queue
using namespace std;
int n, k, a[100010], b[50];
int c[50][2];
signed main() {
	cin >> n >> k;
	rep(i, n) {
		cin >> a[i];
		rep(j, 45) {
			if ((a[i] >> j) & (ll)1)b[j]++;
		}
	}
	rep(i, 46) {
		c[i][0] = -INF;
	}
	for (int i = 45; i >= 0; i--) {
		if (k < ((ll)1 << i)) {
			c[i][1] = c[i + 1][1] + ((ll)1 << i) * b[i];
			continue;
		}
		if (b[i] >= n - b[i]) {
			if ((k >> i) & (ll)1) {
				c[i][0] = max(c[i + 1][0], c[i + 1][1]) + ((ll)1 << i) * b[i];
			}
			else {
				c[i][1] = c[i + 1][1] + ((ll)1 << i) * b[i];
				c[i][0] = c[i + 1][0] + ((ll)1 << i) * b[i];
			}
		}
		else {
			if ((k >> i) & (ll)1) {
				c[i][1] = c[i + 1][1] + ((ll)1 << i) * (n - b[i]);
				c[i][0] = c[i + 1][1] + ((ll)1 << i) * b[i];
			}
			else c[i][1] = c[i + 1][1] + ((ll)1 << i) * b[i];
			c[i][0] = max(c[i][0], c[i + 1][0] + ((ll)1 << i) * (n - b[i]));
		}
		c[i][1] = max(c[i][1], c[i][0]);
	}
	cout << max(c[0][0], c[0][1]) << endl;
	return 0;
}

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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef unsigned long long ull;

#define PI 3.1416
#define INF 1000000001
#define SQ(a) (a)*(a)
#define MAX 1000001


int main(){

    ios:: sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    // code here
    string str,line;

    while(getline(cin,str)){
        if(str.empty())
            break;
        line+=str;
    }

    for(char j='a';j<='z';j++){
            int cnt=0;
        for(int i=0;i<line.length();i++){
            if(line[i]==j || line[i]==j-32)
                cnt++;
        }

        cout<<j<<" : "<<cnt<<"\n";
    }
}




Measured memory_bytes: 3208