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


#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define MOD 1000000007
#define pii pair<int,int>
#define ll long long
#define el '\n'

using namespace std;

struct xyz{
    ll a;
    ll x,y,z;
    bool operator<(const xyz& rhs) const{
        if (a!=rhs.a)
            return a<rhs.a;
        if (x!=rhs.x) 
            return x<rhs.x;
        if (y!=rhs.y)
            return y<rhs.y;
        return z<rhs.z;
    }
    bool operator==(const xyz& rhs) const{
        return (a==rhs.a && x==rhs.x && y==rhs.y && z==rhs.z);
    }
};


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

    ll x,y,z,k;
    cin >> x >> y >> z >> k;

    ll arx[x+1],ary[y+1],arz[z+1];
    for (ll i=1;i<=x;i++){
        cin >> arx[i];
    }
    for (ll i=1;i<=y;i++){
        cin >> ary[i];
    }
    for (ll i=1;i<=z;i++){
        cin >> arz[i];
    }

    sort(arx+1,arx+x+1);
    sort(ary+1,ary+y+1);
    sort(arz+1,arz+z+1);

    priority_queue<xyz>pq;
    xyz tm;
    tm.a=arx[x]+ary[y]+arz[z];
    tm.x=x;
    tm.y=y;
    tm.z=z;
    pq.push(tm);
    vector <ll> ans;
    int cnt=0;
    xyz bef;
    bef.x=-1;

    while (cnt<k){
        if (bef==pq.top()){
            pq.pop();
            continue;
        }
        ans.pb(pq.top().a);
        bef=pq.top();

        ll tx=pq.top().x,ty=pq.top().y,tz=pq.top().z;
        pq.pop();
        if (tx>1){
            tm.a=arx[tx-1]+ary[ty]+arz[tz];
            tm.x=tx-1;
            tm.y=ty;
            tm.z=tz;
            pq.push(tm);
        }
        if (ty>1){
            tm.a=arx[tx]+ary[ty-1]+arz[tz];
            tm.x=tx;
            tm.y=ty-1;
            tm.z=tz;
            pq.push(tm);
        }
        if (tz>1){
            tm.a=arx[tx]+ary[ty]+arz[tz-1];
            tm.x=tx;
            tm.y=ty;
            tm.z=tz-1;
            pq.push(tm);
        }
        cnt++;
    }

    for (ll i=0;i<k;i++) cout << ans[i] << el;

    return 0;
}

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

using namespace std;

int main(void) {
  string s;
  cin >> s;
  int size = s.size();

  string ans;
  if (s.at(size - 1) != 's') {
    ans = s + "s";
  } else {
    ans = s + "es";
  }

  cout << ans << endl;
}

Measured memory_bytes: 3632
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Main {
	static class FastReader
	{
		BufferedReader br;
		StringTokenizer st;

		public FastReader()
		{
			br = new BufferedReader(new
					InputStreamReader(System.in));
		}

		String next()
		{
			while (st == null || !st.hasMoreElements())
			{
				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());
		}

		String nextLine()
		{
			String str = "";
			try
			{
				str = br.readLine();
			}
			catch (IOException e)
			{
				e.printStackTrace();
			}
			return str;
		}
	}
	public static String A, B; 
	public static int[][] memo; 
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		FastReader sc = new FastReader();
		A = sc.next(); B = sc.next(); 
		memo = new int[A.length()+1][B.length()+1]; 

		for (int i=0; i<=A.length(); i++) {
			Arrays.fill(memo[i], -1);
		}
		longest(A.length(), B.length());
//		System.out.println(memo[A.length()][B.length()]);
		int index = memo[A.length()][B.length()]; 
		int temp = index; 

		char[] lcs = new char[index]; 
		int i = A.length(), j = B.length(); 
		while (i > 0 && j > 0) { 
			if (A.charAt(i-1) == B.charAt(j-1)) { 
				lcs[index-1] = A.charAt(i-1);  
				i--;  
				j--;  
				index--;      
			} 

			else if (memo[i-1][j] > memo[i][j-1]) {
				i--; 
			}
			else {
				j--; 
			}
		} 
		String ans = "";
		for (int k=0; k<lcs.length; k++) {
			ans += lcs[k]; 
		}
		System.out.println(ans.length()==0 ? " " : ans);
	}

	//	public static void backtrack(int index1, int index2) {
	//		if (index1==0 || index2==0) {
	//			return; 
	//		}
	//		if (memo[index1][index2]==memo[index1-1][index2]) {
	//			backtrack(index1-1, index2); 
	//		}
	//		else if (memo[index1][index2]==memo[index1][index2-1]) {
	//			backtrack(index1, index2-1); 
	//		}
	//		else {
	//			System.out.print(A.charAt(index1));
	//			backtrack(index1-1, index2-1); 
	//		}
	//	}
	public static int longest(int index1, int index2) {
		if (memo[index1][index2]!=-1) {
			return memo[index1][index2]; 
		}
		else if (index1==0 || index2==0) {
			return memo[index1][index2]= 0; 

		}
		else if (A.charAt(index1-1)==B.charAt(index2-1)) {
			return memo[index1][index2] = 1+ longest(index1-1, index2-1); 
		}
		else {
			return memo[index1][index2] = Math.max(longest(index1-1, index2), longest(index1, index2-1));
		}
	}

}

Measured memory_bytes: 97876
class Unionfindtree:
    def __init__(self, number):
        self.par = [i for i in range(number)]
        self.rank = [0] * (number)

    def find(self, x):  # 親を探す
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    def union(self, x, y):  # x,yを繋げる
        px = self.find(x)
        py = self.find(y)
        if px == py:
            return
        if self.rank[px] < self.rank[py]:
            self.par[px] = py
        else:
            self.par[py] = px
        if self.rank[px] == self.rank[py]:
            self.rank[px] += 1

    def connect(self, x, y):  # 親が同じかみる
        return self.find(x) == self.find(y)


N, M, K = map(int, input().split())
C = [int(i) for i in input().split()]
table = []
t = K
for i in range(N):
    if C[i]==0:
        t+=1
        C[i]=t
for i in range(M):
    s, u, c = map(int, input().split())
    a, b = C[s - 1], C[u - 1]
    table.append((c, a, b))

tree = Unionfindtree(t+1)
table.sort()
ct = K - 1
ans = 0
for c, a, b in table:
    if not tree.connect(a, b) and ct > 0:
        tree.union(a, b)
        ans += c
        ct -= 1
if ct > 0:
    print(-1)
else:
    print(ans)



Measured memory_bytes: 111340
A, V = map(int, input().split())
B, W = map(int, input().split())
T = int(input())

if A < B:
  a = A + T * V
  b = B + T * W
  
else:
  b = A - T * V
  a = B - T * W
  
if b <= a:
  ans = 'YES'
else:
  ans = 'NO'
  
print(ans)

Measured memory_bytes: 9212
#!/usr/bin/env python3
def gcd(a, b):
    if a > b:
        a, b = b, a
    if a == 0:
        return b
    return gcd(b % a, a)


n, k = map(int, input().split())
a = list(map(int, input().split()))
max_a = max(a)
a_gcd = a[0]
for x in a:
    a_gcd = gcd(a_gcd, x)
if k <= max_a and k % a_gcd == 0:
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")


"""
どれだけ小さい差を作れるかがポイント
maxの値からそれを引くことでいろんな値を作ることができる
もし差が1を作れればmax 以下の値全て作れる
N この最大公約数が最小の差になる
"""


Measured memory_bytes: 19916
#include<stdio.h>

int main()
{
  int i,j,N,col,max;
  int flag[8]={0};
  j=0;
  col=0;
  scanf("%d",&N);
  int a[N];
  for(i = 0;i<N;i++){
    scanf("%d",&a[i]);
  }
  for(i = 0;i < N;i++){
    if(1<=a[i] && a[i] <= 399){
      flag[0] =1;
    }else if(a[i] <= 799){
      flag[1] =1;
    }else if(a[i] <= 1199){
      flag[2] =1;
    }else if(a[i] <= 1599){
     flag[3] =1;
    }else if(a[i] <= 1999){
      flag[4] =1; 
    }else if(a[i] <= 2399){
      flag[5] =1;
    }else if(a[i] <= 2799){
     flag[6] =1;    
    }else if(a[i] <= 3199){
      flag[7] =1;
    }else{
      j++;
    }
  }
    for(i=0;i<8;i++){
    	col+=flag[i];
    }
  max = col+j;
  if(col == 0){ 
    col=1;
    max = j;
  }
  printf("%d %d\n",col,max);
  return 0;
}

Measured memory_bytes: 128
N = int(input())
SP = []
for i in range(N):
    s, p = input().split()
    p = int(p)
    SP.append((s, p, i))
SP.sort(key = lambda k:k[1], reverse = True)
SP.sort(key = lambda k:k[0])
for j in SP:
    print(j[2] + 1)


Measured memory_bytes: 3060
import java.util.*;

class Main {
    public static void main(String[] args) throws java.lang.Exception {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        String ret = "red";
        if (a >= 3200) {
            ret = sc.next();
        }
        System.out.println(ret);
        sc.close();
    }
}


Measured memory_bytes: 21716
if __name__ == '__main__':
    N = int(input())
    S = input()

    old = S[1:].count('E')
    ans = old

    for i in range(1, N):
        if S[i-1] == 'W' and S[i] == 'W':
            new = old + 1
        elif S[i-1] == 'E' and S[i] == 'E':
            new = old - 1
        else:
            new = old

        ans = min(ans, new)
        old = new

    print(ans)


Measured memory_bytes: 3700
#include <stdio.h>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <iostream>
#include <math.h>
#include <bitset>
#include <iomanip>
#include <queue>
#include <cstring>
using namespace std;

int main() {
	int N,ans=0; cin >> N;
	for (int i = 1; i <= N; i++) {
		int x = i,z=0;
		while (x) { x /= 10; z++; }
		if (z % 2 == 1)ans++;
	}

	cout << ans << endl;
}





Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
#include <cstring>
#include <deque>
#include <iomanip>
#include <limits>
#include <fstream>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define MOD1 1000000007

int main() {
  int N, s = 0;
  cin >> N;

  rep(i, N) {
    int a;
    cin >> a;
    if (a % 2 == 1) s++;
  }

  cout << (s % 2 == 0 ? "YES" : "NO") << endl;

}


Measured memory_bytes: 256
def main():
    N, K = map(int, input().split())

    cnt = 0
    for b in range(1, N + 1):
        d, m = divmod(N, b)
        cnt += max(b - K, 0) * d + max(m - K + 1, 0)
    if not K:
        cnt -= N
    print(cnt)

main()


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;

int N, x;
int a[2010];

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  cin >> N >> x;
  for (int i = 0; i < N; i++) {
    cin >> a[i];
  }  
  int b[2010];
  fill_n((int*)b, 2010, 1 << 30);
  ll ans = 1LL << 60;
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) {
      b[j] = min(b[j], a[(i - j + N) % N]);
    }
    ll sum = (ll)i * x;
    for (int j = 0; j < N; j++) {
      sum += b[j];
    }
    ans = min(ans, sum);
  }
  cout << ans << endl;

  return 0;
}

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

int a, b, c;

int main() {
  cin >> a >> b >> c;
  bool flag = false;
  for (int i=a; i<=a*b; i+=a) {
    if (i % b == c) {
      cout << "YES" << endl;
      flag = true;
      break;
    }
  }
  if (!flag) cout << "NO" << endl;
  return 0;
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"log"
	"math"
	"os"
	"strconv"
	"strings"
)

func main() {
	scanner := makeWordScanner()
	n := eGetInt(scanner)
	min := 2*100000 + 1
	count := 0
	for i := 0; i < n; i++ {
		p := eGetInt(scanner)
		if p < min {
			count++
			min = p
		}
	}
	fmt.Println(count)
}

////////////////////////////////////////////////////////////////////////////////
// ライブラリ
////////////////////////////////////////////////////////////////////////////////
func makeScanner(maxByte int) *bufio.Scanner {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Buffer(make([]uint8, 0, 8192), maxByte)
	return scanner
}
func makeCharScanner() *bufio.Scanner {
	scanner := makeScanner(8192)
	scanner.Split(bufio.ScanRunes)
	return scanner
}
func makeWordScanner() *bufio.Scanner {
	scanner := makeScanner(8192)
	scanner.Split(bufio.ScanWords)
	return scanner
}
func eGetLine(r *bufio.Scanner) string {
	if r.Scan() {
		return r.Text()
	}
	err := r.Err()
	if err != nil {
		log.Fatal(err)
	}
	// EOF
	return ""
}
func eGetInt(r *bufio.Scanner) int {
	line := eGetLine(r)
	return eAtoi(line)
}
func eGetInt64(r *bufio.Scanner) int64 {
	line := eGetLine(r)
	return eAtoInt64(line)
}
func eGetFields(r *bufio.Scanner) []string {
	line := eGetLine(r)
	return strings.Fields(line)
}
func eGetInts(r *bufio.Scanner) []int {
	fields := eGetFields(r)
	ints := make([]int, len(fields))
	for i := 0; i < len(ints); i++ {
		ints[i] = eAtoi(fields[i])
	}
	return ints
}
func eGetInt64s(r *bufio.Scanner) []int64 {
	fields := eGetFields(r)
	ints := make([]int64, len(fields))
	for i := 0; i < len(ints); i++ {
		ints[i] = eAtoInt64(fields[i])
	}
	return ints
}
func eGetChars(r *bufio.Scanner) []string {
	line := eGetLine(r)
	return strings.Split(line, "")
}
func eAtoi(s string) int {
	n, err := strconv.Atoi(s)
	if err != nil {
		log.Fatal(err)
	}
	return n
}
func eAtoInt64(s string) int64 {
	n, err := strconv.ParseInt(s, 10, 64)
	if err != nil {
		log.Fatal(err)
	}
	return n
}
func pow(a, n int) int {
	return int(math.Pow(float64(a), float64(n)))
}
func countBitOfOn(i, numbits int) int {
	count := 0
	var bit uint64
	for bit = 0; bit < uint64(numbits); bit++ {
		t := 1 << bit
		if i&t > 0 {
			count++
		}
	}
	return count
}


Measured memory_bytes: 2048
#include<stdio.h>

int Search(int A[], int n, int agari){
  int i = 0;
  A[n] = agari;
  while(A[i] != agari)i++;
  return i != n;
}

int main(){
  int i,n,A[10000 + 1],q,agari,sum = 0;

  scanf("%d", &n);
  for(i = 0; i < n; i++)scanf("%d",&A[i]);

  scanf("%d",&q);
  for(i = 0; i < q; i++){
    scanf("%d", &agari);
    if(Search(A, n, agari))sum++;
  }
  printf("%d\n",sum);

  return 0;
}



Measured memory_bytes: 2108
package main

import (
	"fmt"
	"math"
)

func main() {
	var x,a,b float64
	fmt.Scan(&x,&a,&b)


	if math.Abs(x-a) > math.Abs(x-b) {
		fmt.Println("B")
	} else {
		fmt.Println("A")
	}
}


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

int main()
{
    int n;
    cin >> n;
    vector<pair<int,int>> ba(n);
    rep(i,n) cin >> ba[i].second >> ba[i].first;
    
    sort(ba.begin(),ba.end());
    i64 t = 0;
    rep(i,n)
    {
        i64 a = ba[i].second;
        i64 b = ba[i].first;
        t += a;
        if(t>b)
        {
            cout << "No" << endl;
            return 0;
        }
    }

    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 1792
import java.util.*;

public class Main {
    public static void main(String args[]) {
        FastScanner cin = new FastScanner();
        int n = cin.nextInt();
        int k = cin.nextInt();
        int[] d = new int[10];
        Arrays.fill(d, 0);

        for (int i = 0; i < k; ++i) {
            int x = cin.nextInt();
            d[x] = 1;
        }

        int res = 999999999;

        for (int i = 1; i < 10; ++i) {
            if (d[i] == 1)
                continue;

            res = Math.min(res, solve(n, d, i));
        }

        System.out.println(res);
    }

    private static int solve(int n, int[] d, int s) {
        if (s >= n)
            return s;

        int res = 999999999;

        for (int i = 0; i < 10; ++i) {
            if (d[i] == 1)
                continue;

            res = Math.min(res, solve(n, d, s * 10 + i));
        }

        return res;
    }

    static class FastScanner {
        StringTokenizer tokenizer;
        Scanner scanner;

        FastScanner() {
            tokenizer = null;
            scanner = new Scanner(System.in);
        }

        int nextInt() {
            while (tokenizer == null || !tokenizer.hasMoreTokens())
                tokenizer = new StringTokenizer(scanner.nextLine());

            return Integer.parseInt(tokenizer.nextToken());
        }

        String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens())
                tokenizer = new StringTokenizer(scanner.nextLine());

            return tokenizer.nextToken();
        }
    }
}



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

const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define ALL(v) (v.begin(),v.end())
#define COUT(x) cout<<(x)<<endl

int main(){
    int n;
    cin >> n;
    int t0=0,x0=0,y0=0;
    for(int i=0;i<n;i++){
        int t,x,y;
        cin >> t >> x >> y;
        int dis = abs(x-x0)+abs(y-y0);
        int time = t-t0;
        if(time<dis){
            COUT("No");
            return 0;
        }
        else if(time>dis){
            if((time-dis)%2!=0){
                COUT("No");
                return 0;
            }
        }
        t0=t;x0=x;y0=y;
    }
    COUT("Yes");
    return 0;
} 


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define rep(i,n)for(int i=0;i<(int)(n);i++)
#define PI 3.141592653589793
//vector < vector<int>>a(0, vector<int>(0));二次元配列宣言


int main()
{
	int a, b, c, d;
	int ans = 0;
	cin >> a >> b >> c >> d;
	if (a <= b)
		ans += a;
	else
		ans += b;
	if (c <= d)
		ans += c;
	else
		ans += d;
	cout << ans << endl;
} 

Measured memory_bytes: 3564
#include <iostream>
#include <vector>
#define MAXN 200005
#define lson (idx << 1)
#define rson (idx << 1 | 1)

using namespace std;
typedef long long ll;

struct Node {
  int l, r, hi, lazy = 0;
};

struct SegTree {
  Node s[MAXN << 2];
  void calc(int idx) { s[idx].hi = max(s[lson].hi, s[rson].hi); }

  void pushdown(int idx) {
    if (s[idx].lazy) {
      for (int i = lson; i <= rson; ++i) {
        if (s[i].hi > s[idx].lazy) {
          s[i].hi = s[idx].lazy;
          s[i].lazy = s[idx].lazy;
        }
      }
    }
    s[idx].lazy = 0;
  }

  void build(int idx, int l, int r, vector<int> &a) {
    s[idx].l = l, s[idx].r = r;
    if (l == r) {
      s[idx].hi = a[l];
      return;
    }
    int mid = (l + r) >> 1;
    build(lson, l, mid, a);
    build(rson, mid + 1, r, a);
    calc(idx);
  }

  void update(int idx, int l, int r, int x) {
    if (s[idx].hi <= x)
      return;
    if (s[idx].l >= l && s[idx].r <= r) {
      s[idx].hi = x;
      s[idx].lazy = x;
      return;
    }
    pushdown(idx);
    int mid = (s[idx].l + s[idx].r) >> 1;
    if (l <= mid)
      update(lson, l, r, x);
    if (mid + 1 <= r)
      update(rson, l, r, x);
    calc(idx);
  }

  int query(int idx, int l, int r) {
    if (s[idx].l >= l && s[idx].r <= r)
      return s[idx].hi;
    pushdown(idx);
    int ans = 0;
    int mid = (s[idx].l + s[idx].r) >> 1;
    if (l <= mid)
      ans = max(ans, query(lson, l, r));
    if (mid + 1 <= r)
      ans = max(ans, query(rson, l, r));
    return ans;
  }
};

int main() {
  int n, q;
  cin >> n >> q;
  vector<int> col(n + 1, n), row(n + 1, n);
  col[n] = 1, row[n] = 1;
  SegTree C, R;
  C.build(1, 1, n, col);
  R.build(1, 1, n, row);
  ll ans = (ll)(n - 2) * (n - 2);
  for (int i = 0; i < q; ++i) {
    int t, x;
    cin >> t >> x;
    if (t == 1) {
      int hi = C.query(1, x, x);
      ans -= hi - 2;
      R.update(1, 1, hi, x);
      C.update(1, x, x, 1);
    } else {
      int hi = R.query(1, x, x);
      ans -= hi - 2;
      C.update(1, 1, hi, x);
      R.update(1, x, x, 1);
    }
  }
  cout << ans;
}

Measured memory_bytes: 29924
#include <iostream>
#include <vector>
#include <queue>
#include <string>
#include <algorithm>
typedef long long ll;
const int MOD = 1000000007;
#define PI 3.1415
using namespace std;

int main() {
	ll n, k;
	cin >> n >> k;
	//k=1 : 0~n
	//k=2 : 0+1~(n-1)+n
	//k=3 : 0+1+2~(n-2)+(n-1)+n
	//k=k : (k-1)*k/2~n*k-(k-1)*k/2 : n*k-k*(k-1)+1 : (n-k+1)*k+1
	ll ans = 0;
	for (ll i = k; i <= n + 1; i++) {
		ans += ((n - i + 1) * i + 1) % MOD;
		ans %= MOD;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3636
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	ll ans = 0, sum = 0;
	vector<ll> a(n);
	rep(i,n) cin >> a[i];
	int l = 0, r = 0;
	while(r < n){
		bool add_ok = true;
		rep(j,21){
			if((a[r]>>j & 1) && ((sum>>j) & 1)) add_ok = false;
		}
		if(add_ok){
			sum += a[r];
			++r;
			ans += r - l;
		}
		else{
			sum -= a[l];
			++l;
		}
	}
	cout << ans << endl;
	return 0;
}

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

int main(){
  string s; cin>>s;
  int i=0,j=s.size()-1,ans=0;
  while(i!=j){
    if(s[i]!=s[j]){
      if(s[i]=='x'){
        ans++; i++;
      }else if(s[j]=='x'){
        ans++; j--;
      }else{
        cout<<-1<<endl;
        return 0;
      }
    }else{
      i++;
      if(i==j) break;
      j--;
    }
  }
  cout<<ans<<endl;
}

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

#define REP(i,n) for(int i=0;i<(n);i++)
#define REAP(i,a,n) for(int i=(a);i<(n);i++)
#define YES cout<<"Yes"<<endl
#define NO cout<<"No"<<endl
#define fr first
#define sc second
#define pb push_back
#define All(v) v.begin(),v.end()
typedef long long ll;

bool check(string t,string sub){
    REP(i,t.size()){
        if(t[i]!=sub[i]&&sub[i]!='?')return false;
    }
    return true;
}

int main(){
    string s,t;
    cin >> s >> t;
    int slen=s.size();
    int tlen=t.size();
    if(slen<tlen){
        cout << "UNRESTORABLE" << endl;
        return 0;
    }
    for(int i=slen-tlen;i>=0;i--){
        string sub=s.substr(i,tlen);
        if(check(t,sub)){
            REP(j,tlen)s[i+j]=t[j];
            REP(j,slen){
                if(s[j]=='?')s[j]='a';
            }
            cout << s << endl;
            return 0;
        }
    }

    cout << "UNRESTORABLE" << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string> 
using namespace std;
 int main() {
	 
	 int a, b, c, d;

	 cin >> a >> b >> c >> d;

	 if ((a >= c && a - c <= d) || (a <= c && c - a <= d))
		 cout << "Yes" << endl;
	 else if (a >= b && b >= c && a - b <= d && b - c <= d)
		 cout << "Yes" << endl;
	 else if (c >= b && b >= a && c - b <= d && b - a <= d)
		 cout << "Yes" << endl;
	 else
		 cout << "No" << endl;

	 return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include <cstdlib>  
#include <math.h>
#include <cmath>
#include<cctype>
#include<string>
#include<set>
#include<iomanip>
#include <map>
#include<algorithm>
#include <functional>
#include<vector>
#include<climits>
#include<stack>
#include<queue>
#include <deque>
#include <climits>
#include <typeinfo>
#include <utility> 
#define all(x) (x).begin(),(x).end()
#define rep(i,m,n) for(int i = m;i < n;++i)
#define pb push_back
#define fore(i,a) for(auto &i:a)
#define rrep(i,m,n) for(int i = m;i >= n;--i)
#define INF INT_MAX/2
using namespace std;
using ll = long long;
using R = double;
using Data = pair<ll, vector<int>>;
const ll MOD = 1e9 + 7;
const ll inf = 1LL << 50;
struct edge { ll from; ll to; ll cost; };
typedef tuple<ll, ll, ll>T;
typedef pair<ll,ll>pll;

int main(){
	int n, m;
	cin >> n >> m;

	vector<int>v[15];
	vector<int>p(15);
	rep(i, 0, m) {
		int temp;
		cin >> temp;
		rep(j, 0, temp) {
			int t1;
			cin >> t1;
			v[i].pb(t1-1);
		}
	}
	
	rep(i, 0, m) {
		cin >> p[i];
	}


	int ans = 0;
	rep(i, 0, 1 << n) {
		int ok = 1;
		rep(j, 0, m) {
			int temp = 0;
			fore(x, v[j]) {
				if (i & (1 << x))temp++;
			}
			if (temp % 2 != p[j])ok = 0;
		}
		if (ok)ans++;
	}
	cout << ans << endl;

	return 0;
}

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

#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define SORT(v, n) sort(v, v+n)
#define pb(a) push_back(a)
#define eb(a) emplace_back(a)
#define vi vector<int>
#define ddvi vector<vector<int>>

using namespace std;
typedef long long ll;
typedef pair<int, int> P;

int main(){
	#define int ll
	cin.tie(0);
	ios::sync_with_stdio(false);
	// ここに処理を記述

	int L;
	cin >> L;

	double length = (double)L/3;

	cout << fixed << setprecision(12);
	// cout << length << "\n";
	cout << length * length * length << "\n";

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
//#include <map>
//#include <set>
//#include <list>
//#include <cmath>
//#include <ctime>
//#include <deque>
//#include <queue>
//#include <stack>
//#include <string>
//#include <bitset>
//#include <cstdio>
//#include <limits>
//#include <vector>
//#include <climits>
//#include <cstring>
//#include <cstdlib>
//#include <fstream>
//#include <numeric>
//#include <sstream>
//#include <iomanip>
//#include <iostream>
//#include <algorithm>
//#include <unordered_map>

using namespace std;

#define file freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);
#define PI 3.141592653589793238462643383279502884
#define MAX 1000100
#define mod 1000000007
#define EPS 1E-9
#define int long long
#define endl "\n"

int fix(int cur, int m)
{
    return ((cur%m) + m) % m;
}

int fast_power(int x, int y,int m)
{
    if (y == 0)
        return 1;
    int temp = fast_power(x, y / 2, m) ;
    temp = (temp*temp)% m;
    if (y % 2 != 0)
        temp = (temp*x)% m;
    return temp;

}
int n,m;
vector<vector<int>>adj;
bool vis[100010];
void DFS(int source)
{
    vis[source]=true;
    for(int i=0;i<adj[source].size();i++)
        if(!vis[adj[source][i]])
            DFS(adj[source][i]);
}

int32_t main()
{
    //freopen("C:/Users/Joe/Desktop/tests/in11.txt", "r", stdin);
    //freopen("C:/Users/Joe/Desktop/tests/out11.txt", "w", stdout);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    cin.tie(0);
    std::ios::sync_with_stdio(false);
    cout.tie(0);

    int t=1;
    //cin >> t;
    while(t--)
    {
        cin >> n >> m;
        adj.resize(n+1);
        for(int i=0;i<m;i++)
        {
            int a,b,c;
            cin >> a >> b >> c;
            adj[a].push_back(b);
            adj[b].push_back(a);
        }
        int comp=0;
        for(int i=1;i<=n;i++)
        {
            if(!vis[i])
            {
                DFS(i);
                comp++;
            }
        }
        cout << comp << endl;


    }
    return 0;
}


Measured memory_bytes: 8960
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cstring>
#include <queue>
#include <vector>
#include <functional>
#include <map>
#include <set>
#include <cmath>
#include <string>
#define SIZE 1002
#define INF 1000000005LL

using namespace std;
typedef long long int ll;
typedef pair <int,int> P;

int N,W,H;
int X1[SIZE],X2[SIZE],Y1[SIZE],Y2[SIZE];
bool fld[SIZE*6][SIZE*6];
int dx[]={1,0,-1,0};
int dy[]={0,-1,0,1};

int compress(int *x1,int *x2,int w){
	vector<int> xs;
	int t1,t2;
	for(int i=0;i<N;i++){
		for(int d=-1;d<=1;d++){
			t1=x1[i]+d,t2=x2[i]+d;
			if(0<=t1&&t1<w)xs.push_back(t1);
			if(0<=t2&&t2<w)xs.push_back(t2);
		}
	}
	sort(xs.begin(),xs.end());
	xs.erase(unique(xs.begin(),xs.end()),xs.end());
	for(int i=0;i<N;i++){
		x1[i]=find(xs.begin(),xs.end(),x1[i])-xs.begin();
		x2[i]=find(xs.begin(),xs.end(),x2[i])-xs.begin();
	}
	return xs.size();
}

bool imain()
{
	scanf("%d %d",&W,&H);
	if(W==0&&H==0)return false;
	scanf("%d",&N);
	for(int i=0;i<N;i++){
		scanf("%d %d %d %d",&X1[i],&Y1[i],&X2[i],&Y2[i]);
	}

	//圧縮
	W = compress(X1,X2,W);
	H = compress(Y1,Y2,H);


	for(int i=0;i<N;i++){
		for(int y=Y1[i];y<Y2[i];y++){
			for(int x=X1[i];x<X2[i];x++){
				fld[y][x] = true;
			}
		}
	}
	/* 確認用
	for(int y=0;y<H;y++){
		for(int x=0;x<W;x++){
			printf("%d ",(fld[y][x]?1:0));
		}
		printf("\n");
	}
	*/

	int ans=0;
	for(int y=0;y<H;y++){
		for(int x=0;x<W;x++){
			if(fld[y][x])continue;
			ans++;
			queue<P> que;
			que.push(make_pair(x,y));
			while(!que.empty()){
				int tx=que.front().first;
				int ty=que.front().second;
				int sx,sy;
				que.pop();
				for(int i=0;i<4;i++){
					sx=tx+dx[i],sy=ty+dy[i];
					if(sx<0||sx>=W||sy<0||sy>=H)continue;
					if(fld[sy][sx])continue;
					que.push(make_pair(sx,sy));
					fld[sy][sx]=true;
				}
			}
		}
	}
	for(int y=0;y<H;y++){
		for(int x=0;x<W;x++){
			fld[y][x]=false;
		}
	}
	printf("%d\n",ans);
	return true;
}

int main(){
	while(imain());
	return 0;
}



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

#define ALL(v) v.begin(), v.end()
#define V vector
#define P pair
#define ld long double
#define ll long long
#define mod 1000000007
#define IINF INT_MAX
#define INF 1LL << 30


int main() {
    int a, b; cin >> a >> b;
    if(a == 1 && b == 2) cout << 3 << endl;
    if(a == 1 && b == 3) cout << 2 << endl;
    if(a == 3 && b == 2) cout << 1 << endl;
    if(a == 2 && b == 1) cout << 3 << endl;
    if(a == 3 && b == 1) cout << 2 << endl;
    if(a == 2 && b == 3) cout << 1 << endl;

    return 0;
}


Measured memory_bytes: 3612
import qualified Data.Vector.Unboxed as U
import qualified Data.Vector as V
import qualified Data.ByteString.Char8 as C
import Data.List
import Control.Monad
import Data.Ord

r :: Int -> IO (U.Vector Int)
r n = U.unfoldrN n (C.readInt . C.dropWhile (==' ')) <$> C.getLine

r' :: IO [Int]
r'  =   unfoldr    (C.readInt . C.dropWhile (==' ')) <$> C.getLine



main :: IO ()
main = do
    k <- readLn
    [a,b] <- r'
    putStrLn $ if not $ null $ filter ((==0).(`mod`k)) [a..b] then "OK" else "NG"


Measured memory_bytes: 3892
/* ex6_2
  bonbonc */

#include<stdio.h>
#include<string.h>

int main(void){
	char str[101];/*文字列を格納する配列*/
	int length;/*文字列の長さ*/
	scanf("%s",str);/*文字列を受け取る*/
	length = (int)strlen(str);/*lengthに文字列の長さを格納する*/

	printf("%c",str[0]);/*先頭の文字を出力*/
	printf("%d",length-2)/*文字列の長さ-2を出力*/;
	printf("%c\n",str[length-1])/*最後の文字を出力して改行*/;
	return 0;
}



Measured memory_bytes: 128
#include <iostream>

int main()
{
	int n;
	int apple;
	std:: cin >> n;
	bool ok = 0;
	while (n != 0) {
		std::cin >> apple;
		if (apple % 2 == 1) {
			std::cout << "first";
			return 0;
		}
		n--;
	}
	std::cout << "second";
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <numeric>
#include "bits/stdc++.h"
using namespace std;

long long lcm(long long a, long long b) {
    long long tmp;
    long long ra;
    long long rb;
    ra = a;
    rb = b;
    if (a < b) {
        tmp = a;
        a = b;
        b = tmp;
    }

    long long r;
    r = a % b;
    while(r != 0) {
        a = b;
        b = r;
        r = a % b;
    }
    return (ra / b) * rb;
}




int main() {
    int N;
    cin >> N;
    long long T[101];
    for (int i = 0; i < N; i++) {
        cin >> T[i];
    }
    long long l = T[0];
    for (int i = 0; i < N - 1; i++) {
        l = lcm(l, T[i+1]);
    }
    cout << l << endl;
}


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

int main(){
    ll a, b, c, k;
    cin >> a >> b >> c >> k;
    if(abs(a-b) > 1e18) cout << "Unfair" << endl;
    else {
        if(k % 2) cout << b-a << endl;
        else cout << a-b << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#[macro_use]
mod input {

use std;
use std::io;

const SPLIT_DELIMITER: char = ' ';

#[macro_export]
#[allow(unused_macros)]
macro_rules! input {
    ( $($x:expr ),*) => {
        {
            let temp_str = input_line_str();
            let mut split_result_iter = temp_str.split_whitespace();
                $(
                let buf_split_result = split_result_iter.next();
                let buf_split_result = buf_split_result.unwrap();
                    ($x) = buf_split_result.parse().unwrap();
                )*
        }
    };
}

#[allow(dead_code)]
pub fn input_line_str() -> String {
    let mut s = String::new();
    io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}

#[allow(dead_code)]
pub fn p<T>(t: T)
where
    T: std::fmt::Display,
{
    println!("{}", t);
}

#[allow(dead_code)]
pub fn input_vector2d<T>(line: usize) -> Vec<Vec<T>>
where
    T: std::str::FromStr,
{
    let mut v: Vec<Vec<T>> = Vec::new();

    for _ in 0..line {
        let vec_line = input_vector();
        v.push(vec_line);
    }
    v
}

#[allow(dead_code)]
pub fn input_vector<T>() -> Vec<T>
where
    T: std::str::FromStr,
{
    let mut v: Vec<T> = Vec::new();

    let s = input_line_str();
    let split_result = s.split(SPLIT_DELIMITER);
    for z in split_result {
        let buf = match z.parse() {
            Ok(r) => r,
            Err(_) => panic!("Parse Error"),
        };
        v.push(buf);
    }
    v
}

#[allow(dead_code)]
pub fn str2vec(s: &str) -> Vec<char> {
    let mut v: Vec<char> = Vec::new();
    for c in s.chars() {
        v.push(c);
    }
    v
}
}

use input::*;

fn main() {
    let mut s = str2vec(&input_line_str());
    let a = str2vec(&"maerd");
    let b = str2vec(&"remaerd");
    let c = str2vec(&"esare");
    let d = str2vec(&"resare");
    s.reverse();

    let mut i = 0;
    while i < s.len() {
        if i + 5 <= s.len() && &a[..] == &s[i..i + 5] {
            i += 5;
        } else if i + 7 <= s.len() && &b[..] == &s[i..i + 7] {
            i += 7;
        } else if i + 5 <= s.len() && &c[..] == &s[i..i + 5] {
            i += 5;
        } else if i + 6 <= s.len() && &d[..] == &s[i..i + 6] {
            i += 6;
        } else {
            p("NO");
            return;
        }
    }
    p("YES");
}


Measured memory_bytes: 4352
#include<stdio.h>


int main(){
	
	char a,b;
	
	scanf("%c %c", &a,&b);
	
	if(a=='H'){
		if(b=='H'){
			printf("H\n");
		}
		else printf("D\n");
	}
	else if(a=='D'){
		if(b=='H'){
			printf("D\n");
		}
		else printf("H\n");
	}
	
	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
//#include<ext/pb_ds/assoc_container.hpp>
using namespace std;
//using namespace __gnu_pbds;
const int inf=0x3f3f3f3f;
const double eps=1e-6;
const int mod=1000000007;
typedef long long ll;
int modpow(int x,int y,int md){if(y==0)return 1;int ret=modpow(x,y>>1,md);ret=(ll)ret*ret%md;if(y&1)ret=(ll)ret*x%md;return ret;}
struct Num{
	string s="";
	bool operator<(Num b){
		return s.size()<b.s.size()||(s.size()==b.s.size()&&s<b.s);
	}
	bool operator>(Num b){
		return s.size()>b.s.size()||(s.size()==b.s.size()&&s>b.s);
	}
	Num add(int x){
		Num ret=*this;
		ret.s.push_back('0'+x);
		return ret;
	}
	Num operator=(int x){
		s=to_string(x);
		return *this;
	}
	Num operator=(Num b){
		s=b.s;
		return *this; 
	}
}dp[10010];
const int cost[]={100000,2,5,5,4,5,6,3,7,6};
int main(){
	int n,m;
	cin>>n>>m;
	vector<int>a(m);
	for(int i=0;i<m;i++)cin>>a[i];
	for(int i=0;i<=n;i++){
		if(i&&dp[i].s=="")continue;
		for(auto x:a){
			if(dp[i].add(x)>dp[i+cost[x]]){
				dp[i+cost[x]]=dp[i].add(x);
			}
		}
	}
	cout<<dp[n].s<<endl;
	return 0;
}

Measured memory_bytes: 43392
#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 = 5e5 + 1000,mod = 998244353;
int n,m,mx,mn;
ll ans,jc[N],jcinv[N],inv[N];
ll ksm(ll x,int y){ll res = 1; for(;y;y >>= 1,x = x * x % mod) if(y & 1) res = res * x % mod; return res;}
ll C(int x,int y){if(y < 0 || y > x) return 0; return jc[x] * jcinv[y] % mod * jcinv[x - y] % mod;}
int main()
{
	n = read(); m = read(); mx = max(m,n); mn = min(m,n);
	jc[0] = jc[1] = inv[0] = inv[1] = jcinv[0] = jcinv[1] = 1;
	for(int i = 2;i <= mx;i ++)
	{
		jc[i] = jc[i - 1] * i % mod;
		inv[i] = (mod - mod / i) * inv[mod % i] % mod;
		jcinv[i] = jcinv[i - 1] * inv[i] % mod;
	}
	for(int i = 0;i <= mn;i ++)
	{
		if(i & 1) ans = (ans + mod - C(n,i) * C(m,i) % mod * ksm(m + 1,n - i) % mod * ksm(n + 1,m - i) % mod * jc[i] % mod) % mod;
		else ans = (ans + C(n,i) * C(m,i) % mod * ksm(m + 1,n - i) % mod * ksm(n + 1,m - i) % mod * jc[i] % mod) % mod;
	}
	cout << ans << "\n";
	return 0;
}


Measured memory_bytes: 12032
#include<iostream>
#include <algorithm>
#include<string>
#include <bitset>
#include <vector>
#include <functional>
#include <climits>
#include <iomanip>
#include <utility>
#include <stack>
#include <queue>
#include <math.h>
#include <iomanip>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <numeric>
#include <stack>
#include <map> // pair
#include <cstdlib>  // abs() for integer
#include <cmath>    // abs() for float, and fabs()
typedef std::stack<int> IntStack;
typedef std::stack<char> charStack;

using namespace std;
using ll = long long;
typedef pair <ll, ll > pll;

int main()
{
	ll a = 0, b = 0, c = 0, d = 0, e = 0, f = 0, g = 0, h = 0, ans = 0;
	ll n, m, K;
	ll memo[1003][1003] = { {} };
	ll memox[1003] = {};
	ll memoy[1003] = {};
	ll x[1000006] = {};
	ll y[200005] = {};
	ll z[200005] = {};
	string s;
	string s1, s2;
	//IntStack yStack;
	//charStack Stack;
	//vector<pair<int, int> > pairs(a);
	cin >> a;
	 //10進数の桁数を取得
	ans = a / 11;
	a = a-ans*11;
	ans *= 2;
	if (a==0)
	{

	}
	else if (a<=6)
	{
		ans++;
	}
	else
	{
		ans += 2;
	}

	cout << ans << endl;


	////std::cout << std::fixed;
	//cout << std::setprecision(20) << << endl;
	//cout << d+1 << endl;
	//cout << "" << endl;

	return 0;
}
//char型の文字数字は、-'0'で数値に変換できる
//accumulate(x, x + a, 0);//int型までの配列の合計
//memcpy(x, visited, sizeof(ll)*n);
//void kansuu(ll num, ll visited[10]) {}
//kansuu(1, zz);
//cout << setprecision(15) << v << endl;
//cout << char(z - 'a');
//log10(i) + 1 //10進数の桁数を取得

//int temp;
//for (int i = 0; i < n - 1; i++) {
//	for (int j = n - 1; j > i; j--) {
//		if (w[j - 1] < w[j]) {  /* 前の要素の方が大きかったら */
//			temp = w[j];        /* 交換する */
//			w[j] = w[j - 1];
//			w[j - 1] = temp;
//		}
//	}
//}

//最小公倍数
//ll x = a * b;
//ll tmp;
///* 自然数 a > b を確認・入替 */
//if (a<b) {
//	tmp = a;
//	a = b;
//	b = tmp;
//}
///* ユークリッドの互除法 */
//ll r = a % b;
//while (r != 0) {
//	a = b;
//	b = r;
//	r = a % b;
//}
//a = x / b;//答え

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef vector< vector<int> > vvi;
typedef vector< vector<bool> > vvb;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef long long ll;

void dfs(const vvi &graphf, vb &found, int s, vi &connection){
    found[s]=true;
    connection.push_back(s);
    for(auto next:graphf[s]){
        if(found[next]) continue;
        dfs(graphf,found,next,connection);        
    }
    return;
}

int main(){
    int n,m;
    cin >> n >> m;
    //隣接リスト
    vvi graphf(n+1);
    for(int i=0;i<m;i++){
        int a,b;
        cin >> a >> b;
        graphf[a].push_back(b);
        graphf[b].push_back(a);
    }
    //連結成分
    vvi connection(n+1,vi());
    vi grouped(n+1,0);
    //連結成分を求める
    for(int i=1;i<=n;i++){
        if(grouped[i]!=0) continue;
        vb found(n+1,false);
        dfs(graphf,found,i,connection[i]);
        for(auto x:connection[i]){
            grouped[x]=i;
        }
    }

    /*
    for(int i=1;i<=n;i++){
        cout << i << " : "; 
        for(int x:connection[i]){
            cout << x << " ";
        }
        puts("");
    }
    */

    int ans=0;
    for(int i=1;i<=n;i++){
        int kani=connection[grouped[i]].size();
        ans=max(ans,kani);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 36072
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

constexpr int nil = -1;

class ILcs
{
public:
    using vvi = std::vector<std::vector<int>>;
    virtual int lcs() = 0;
    virtual int lcs(int i1, int i2) = 0;
};

class LcsLoop : public ILcs
{
public:

    LcsLoop(std::string str1, std::string str2)
        : str1 {" " + str1}
        , str2 {" " + str2}
        , dp {vvi(str1.size() + 1, std::vector<int>(str2.size() + 1))}
    {
        CalcLcs();
    }

    int lcs() override
    {
        return lcs(str1.size() - 1, str2.size() - 1);
    }

    int lcs(int i1, int i2) override
    {
        return dp[i1][i2];
    }

private:

    std::string str1;
    std::string str2;
    vvi         dp;
    
    void CalcLcs()
    {
        for (int i = 0; i < str1.size(); ++i)
            dp[i][0] = 0;
        for (int i = 0; i < str2.size(); ++i)
            dp[0][i] = 0;

        for (int i = 1; i < str1.size(); ++i)
        {
            for (int j = 1; j < str2.size(); ++j)
            {
                if (str1[i] == str2[j])
                    dp[i][j] = dp[i - 1][j - 1] + 1;
                else
                    dp[i][j] = std::max(dp[i][j - 1], dp[i - 1][j]);
            }
        }
    }
};

//class LcsReccursion : public ILcs
//{
//public:
//    LcsReccursion(const std::string& str1, const std::string& str2)
//        : str1 {str1}
//        , str2 {str2}
//        , dp {vvi(str1.size(), std::vector<int>(str2.size(), nil))}
//    {}
//
//    int lcs() override
//    {
//        return lcs(str1.size() - 1, str2.size() - 1);
//    }
//
//    int lcs(int i1, int i2) override
//    {
//        if (dp[i1][i2] != nil)
//            return dp[i1][i2];
//
//        if (i1 == 0 || i2 == 0)
//        {
//            if (i1 == 0 && i2 == 0) return dp[i1][i2] = (str1[i1] == str2[i2]);
//            else if (i1 == 0)       return dp[i1][i2] = std::max(lcs(i1, i2 - 1), (str1[i1] == str2[i2] ? 1 : 0));
//            else                    return dp[i1][i2] = std::max(lcs(i1 - 1, i2), (str1[i1] == str2[i2] ? 1 : 0));
//        }
//
//        dp[i1][i2] = std::max(lcs(i1 - 1, i2), lcs(i1, i2 - 1))
//            + (str1[i1] == str2[i2]);
//        return dp[i1][i2];
//    }
//
//private:
//
//    std::string str1;
//    std::string str2;
//    vvi         dp;
//};

void solve()
{
    using namespace std;

    int n;
    cin >> n;

    string s1, s2;

    for (int i = 0; i < n; ++i)
    {
        cin >> s1 >> s2;
        LcsLoop lcs {s1, s2};
        //LcsReccursion lcs {s1, s2};
        cout << lcs.lcs() << endl;
    }
}

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


Measured memory_bytes: 6880
def ii():return int(input())
def iim():return map(int,input().split())
def iil():return list(map(int,input().split()))

l,r,d = iim()
lf = l//d
lmod = l%d
rf = r//d

if lf == rf:
    print(1 if lmod == 0 else 0)
else:
    print(rf-lf if lmod !=0 else rf-lf+1)

Measured memory_bytes: 9120
#include <iostream>
#include <vector>
#include <array>
#include <set>
#include <cmath>
#include <string>
#include <sstream>
#include <queue> 
#include <list>
#include <stack>
#include <unordered_map>
#include <algorithm> 
#include <numeric>  
#include <functional>
#include <cassert>
#include <bitset>
#include <cctype>  
#include <iomanip> 
#include <limits>  
#include <regex>
// std::numeric_limits<int>::max(), min()
// std::setprecision(X)
// std::islower(), std::isupper(), std::tolower, std::toupper
// std::accumulate(m.begin(), m.end(), 0LL);
// std::sort(begin(),end()) // 0, 1, 2, 3 ,4 (default, less);
// std::priority_queue<int, vector<int>, less<int>> que; // 4, 3, 2, 1 (defualt, less) : 
// if ( std::regex_match(S, std::regex("(dream|dreamer|erase|eraser)*")) ) std::cout << "YES" << std::endl;
 
#define rep(i, n) for(int i = 0; i < (int)(n);    i++)
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()

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; }
typedef long long ll;

ll gcd ( ll a, ll b ) { if ( b == 0 ) return a; else return gcd ( b, a%b ); }
ll lcm ( ll a, ll b ) { return a * b / gcd(a, b); }

const int mod = 1e9+7;
struct mint {
  typedef long long ll;
  ll x;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};



int main (void) {
  std::cin.tie(0);  std::ios::sync_with_stdio(false);
  int X, Y; std::cin >> X >> Y;
  if ( (2*X-Y) < 0 || (2*X - Y) % 3 != 0 ) {
    std::cout << 0 << std::endl;
    return 0;
  }
  if ( (2*Y-X) < 0 || (2*Y - X) % 3 != 0 ) {
    std::cout << 0 << std::endl;
    return 0;
  }

  int a = (2*Y-X)/3;
  int b = (2*X-Y)/3;

  ll N = a+b;
  ll M = a;
  mint fac(1), ifac(1);
  for (int i = 0; i < M; i++){ fac *= N - i; }
  for (int i = 0; i < M; i++){ ifac *= i + 1; } 
  ll ans = (fac * ifac.inv()).x; 
  std::cout << ans << std::endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.*;

class Main {
	static Scanner sc = new Scanner(System.in);
	public static void main(String args[]) {
		
		int n = sc.nextInt();
		ArrayList<Integer> list = new ArrayList<>();
		for (int i=0; i<n; i++) {
			list.add(sc.nextInt());
		}
		
		for (int i=0; i<n; i++) {

			for (int j=0; j<=i; j++) {
				if (list.get(i) <= list.get(j)) {
					Collections.swap(list, i, j);
				}
			}

			for (int j=0; j<n; j++) {
				System.out.print((j==0?"":" ")+list.get(j));
			}
			System.out.println();
			
		}
		
	}
}


Measured memory_bytes: 32072
def solve():
    n,d = map(int, input().split())
    L = [[int(x) for x in input().split()] for _ in range(n)]
    count = 0
    for i in range(n):
        y = L[i]
        for z in L[i+1:]:
            total = 0
            for a,b in zip(y,z):
                total += (a-b)**2
            if total**0.5 == int(total**0.5):
                count += 1
    return count
    
if __name__ == '__main__':
    print(solve())

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define pb push_back
#define ff first;
#define ss second;
#define ii pair<int,int>
#define vi vector<int>
#define vii vector<ii>
#define lli long long int
#define INF 1000000000
#define endl '\n'
const double pi = 3.141592653589793238460;
typedef std::complex<double> Complex;
typedef std::valarray<Complex> CArray;
using namespace std;
	
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	string n;
	cin >> n;
	if(n=="ABC"){
		cout << "ARC" << endl;
	}
	else{
		cout << "ABC" << endl;
	}
	
	
	return 0;
}



Measured memory_bytes: 3620