akhauriyash/Code-Regression huggingface dataset:
package main

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

var sc = bufio.NewScanner(os.Stdin)

func Scan() string {
	sc.Scan()
	return sc.Text()
}
func iScan() int {
	n, _ := strconv.Atoi(Scan())
	return n
}
func fScan() float64 {
	n, _ := strconv.ParseFloat(Scan(), 64)
	return n
}
func stringToInt(s string) int {
	n, _ := strconv.Atoi(s)
	return n
}
func SScan(n int) []string {
	a := make([]string, n)
	for i := 0; i < n; i++ {
		a[i] = Scan()
	}
	return a
}
func iSScan(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = iScan()
	}
	return a
}
func abs(x int) int {
	if x < 0 {
		x = -x
	}
	return x
}
func larger(a, b int) int {
	if a < b {
		return b
	} else {
		return a
	}
}
func smaller(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}
func max(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x < a[i] {
			x = a[i]
		}
	}
	return x
}
func min(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x > a[i] {
			x = a[i]
		}
	}
	return x
}
func sum(a []int) int {
	x := 0
	for _, v := range a {
		x += v
	}
	return x
}

var mod int = 1000000007

func main() {
	buf := make([]byte, 0)
	sc.Buffer(buf, mod)
	sc.Split(bufio.ScanWords)
	h, w := iScan(), iScan()
	a := make([][]int, h)
	b := make([][]int, h)
	for i := 0; i < h; i++ {
		a[i] = iSScan(w)
	}
	for i := 0; i < h; i++ {
		b[i] = iSScan(w)
	}
	dp := make([][][]bool, h)
	for i := 0; i < h; i++ {
		dp[i] = make([][]bool, w)
		for j := 0; j < w; j++ {
			dp[i][j] = make([]bool, (h+w-1)*80+1)
		}
	}
	dp[0][0][abs(a[0][0]-b[0][0])] = true
	for i := 0; i < h; i++ {
		for j := 0; j < w; j++ {
			d := abs(a[i][j] - b[i][j])
			for k := 0; k < (h+w-1)*80+1; k++ {
				p, q := abs(k-d), abs(k+d)
				if i > 0 {
					if dp[i-1][j][k] {
						dp[i][j][p] = dp[i-1][j][k]
						dp[i][j][q] = dp[i-1][j][k]
					}
				}
				if j > 0 {
					if dp[i][j-1][k] {
						dp[i][j][p] = dp[i][j-1][k] || dp[i][j][p]
						dp[i][j][q] = dp[i][j-1][k] || dp[i][j][q]
					}
				}
			}
		}
	}
	for i, v := range dp[h-1][w-1] {
		if v {
			fmt.Println(i)
			break
		}
	}
}


Measured memory_bytes: 65756
#include <iostream>
#include <algorithm> //sortの使用に必要
using namespace std;

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

    sort(a, a + N, greater<int>());
    int Alice = 0;
    int Bob = 0;
    for (int i=0; i<N; i++){
        if (i % 2 == 0) Alice += a[i];
        else Bob += a[i];
    }
    cout << Alice - Bob << endl;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

constexpr int64_t mod = 1000000007, N = 100001;

int64_t x[N], y[N];

int64_t mul(int64_t a, int64_t b) {return a * b % mod;}

int main()
{
    int64_t n, m, cans = 0, cc = 0;
    cin >> n >> m;
    for (int i = 0; i < n; ++i)
        cin >> x[i];
    for (int i = 0; i < m; ++i)
        cin >> y[i];
    for (int i = 1; i < m; ++i)
        cc += mul(y[i] - y[i - 1], mul(i, m - i));
    cc %= mod;
    for (int i = 1; i < n; ++i)
        cans += mul(cc, mul(x[i] - x[i - 1], mul(i, n - i)));
    cout << cans % mod;
    return 0;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
const int M=1e9+7,N=100005;
int vis[N],fail[N],dp[45][N][2],ne[N][11],n,X,Y,Z,cnt;
queue<int> Q;
void dfs(int x,int y,int flag){
	if (flag==3){
		vis[x]=1;
		return;
	}
	int now=flag==0?X:flag==1?Y:Z;
	for (int i=1;i<=10;i++)
		if (i+y>now)break;
		else {
			ne[x][i]=++cnt;
			if (i+y==now)dfs(cnt,0,flag+1);
			else dfs(cnt,i+y,flag);
		}
}
void build(){
	Q.push(0);
	while (!Q.empty()){
		int now=Q.front();Q.pop();
		for (int i=1;i<=10;i++)
			if (ne[now][i])Q.push(ne[now][i]),fail[ne[now][i]]=now==0?0:ne[fail[now]][i];
			else if (now)ne[now][i]=ne[fail[now]][i];
	}
}
int main(){
	scanf("%d%d%d%d",&n,&X,&Y,&Z);
	dfs(0,0,0);
	build();
	dp[0][0][0]=1;
	for (int i=1;i<=n;i++)
		for (int j=0;j<=cnt;j++)
			for (int k=1;k<=10;k++)
				for (int flag=0;flag<=1;flag++)
					(dp[i][ne[j][k]][flag|vis[ne[j][k]]]+=dp[i-1][j][flag])%=M;
	int ans=0;
	for (int i=0;i<=cnt;i++)(ans+=dp[n][i][1])%=M;
	printf("%d\n",ans);
}


Measured memory_bytes: 34816
#!/usr/bin/env python3
import sys
from collections.abc import Iterable
from math import *
from itertools import *
from collections import *
from functools import *
from operator import *
try:
    from math import gcd
except Exception:
    from fractions import gcd


def solve(N: int, S: "List[str]", P: "List[int]"):
    return [v for _, _, v in sorted([(s, -p, i + 1) for i , (s, p) in enumerate(zip(S, P))])]


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    S = [str()] * (N)  # type: "List[str]" 
    P = [int()] * (N)  # type: "List[int]" 
    for i in range(N):
        S[i] = next(tokens)
        P[i] = int(next(tokens))
    result = solve(N, S, P)
    if isinstance(result, Iterable) and not isinstance(result, str):
        result = '\n'.join([str(v) for v in result])
    print(result)

if __name__ == '__main__':
    main()


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

const long long MOD=1e9+7;

long long powerMOdulo(long long base,long long power){
   long long res=1;
   while(power){
      if(power&1)res=(res*base)%MOD;
      base=(base*base)%MOD;
      power>>=1;
   }
   return res;
}


int32_t main(){
   int n,k;cin>>n>>k;
   vector<long long> v(k+1);
   for(int i=k;i>=1;i--){
      long long i_can_divide=k/i;
      v[i]=powerMOdulo(i_can_divide,n);
      for(int j=i+i;j<=k;j+=i){
         v[i]=(v[i]-v[j])%MOD;
      }
   }
   long long sum=0;
   for(int i=1;i<=k;i++){
      sum=(sum+(i*v[i])%MOD)%MOD;
   }
   cout<<sum%MOD<<"\n";
   return 0;
}

Measured memory_bytes: 4044
A, B, C, K = map(int,input().split())
Ans = 0
if A < K:
  Ans = A
  K = K-A
  
  if B < K:
    K = K-B
    Ans = Ans - K
    print(Ans)
  else:
    print(Ans)
else:
  print(K)

Measured memory_bytes: 9180
import collections,sys
def I(): return int(sys.stdin.readline().rstrip())
def S(): return sys.stdin.readline().rstrip()
N = I()
S = [S() for _ in range(N)]
counter_S = collections.defaultdict(int)
for s in S:
    counter_S[s] += 1
for ans in ['AC','WA','TLE','RE']:
    print('{0} x {1}'.format(ans,counter_S[ans]))
print()


Measured memory_bytes: 16484
n = int(input())
s = input().rstrip()

i=0
j=n-1
c= 0

while i!=j:
  while s[j]!='R' and j>i:
    j-=1
    
  while s[i]=='R' and j>i:
    i+=1
 
  if i!=j:
    c+= 1
    i+= 1
    j-=1
  if i>=j:
    break
    
print(c)

Measured memory_bytes: 73340
#include <algorithm>
#include <iostream>
#include <string>

using namespace std;

int main() {
	string s, t;
	cin >> s >> t;
	sort(s.begin(), s.end());
	sort(t.begin(), t.end());
	reverse(t.begin(), t.end());
	if (t.compare(s) > 0) {
		cout << "Yes" << endl;
	} else {
		cout << "No" << endl;
	}
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>

#define int long long
#define MOD7 1000000007
#define MOD9 1000000009

#define rep(i, n) for (int i = 0; i < (n); i++)
#define itrep(i, a) for (auto i = (a).begin(); i != (a).end(); i++)
#define REP(i, a, n) for (int i = (a); i <= (n); i++)
#define all(a) (a).begin(), (a).end()
#define mp(a, b) make_pair((a), (b))

using namespace std;

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

template<class T> void inputVector(vector<T>& v, int n) {
    v.resize(n);
    for (int i = 0; i < v.size(); i++) cin >> v[i];
}

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

	int N;
	cin >> N;
	N *= 4;

	int ret = 0;
	if (N >= 8) {
		int tmp = N / 8;
		int va = A * 8;
		int vb = B * 4;
		int vc = C * 2;
		int vd = D;
		if (va <= min(vb, min(vc, vd))) {
			ret += va * tmp;
		} else if (vb <= min(vc, vd)) {
			ret += vb * tmp;
		} else if (vc <= vd) {
			ret += vc * tmp;
		} else {
			ret += vd * tmp;
		}

		N %= 8;
	}
	if (N >= 4) {
		int tmp = N / 4;
		int va = A * 4;
		int vb = B * 2;
		int vc = C;
		if (va <= min(vb, vc)) {
			ret += va * tmp;
		} else if (vb <= vc) {
			ret += vb * tmp;
		} else {
			ret += vc * tmp;
		}

		N %= 4;
	}
	if (N >= 2) {
		int tmp = N / 2;
		int va = A * 2;
		int vb = B;
		if (va <= vb) {
			ret += va * tmp;
		} else {
			ret += vb * tmp;
		}

		N %= 2;
	}
	if (N == 1) {
		ret += A;
	}

	cout << ret << endl;

    return 0;
}


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

const double PI=acos(-1.0);

int A,B,H,M;
void input()
{
    cin>>A>>B>>H>>M;
}

void solve()
{
    double deg=abs(60.0*H-11.0*M)/2.0;
    double ans=1.0*(A*A+B*B)-2.0*A*B*cos(deg/180*PI);
    cout<<fixed<<setprecision(10)<<sqrt(ans)<<endl;
}

int main()
{
    cin.tie();
    ios::sync_with_stdio(false);
    input();
    solve();
    return 0;
}

Measured memory_bytes: 4076
#include <cstdio>
#include <vector>
#include <algorithm>
#include <functional>
#include <map>
#include <set>
#include <string>
#include <iostream>
#include <cassert>
#include <cmath>
#include <deque>
using namespace std;

int main() {
        int n, k;
        scanf("%d%d", &n, &k);
        string s;
        cin >> s;
        if (k > 2 * n) k = 2 * n + (k % 2);
        deque<bool> que;
        for (int i = 0; i < n; i ++) {
                que.push_back(s[i] == 'A');
        }
        bool f = false;
        for (int i = 0; i < k; i ++) {
                if (que.front() ^ f) {
                        que.pop_front();
                        que.push_front(f);
                } else {
                        f = !f;
                        que.pop_front();
                        que.push_back(!f);
                }
        }
        string ans = "";
        for (int i = 0; i < n; i ++) {
                ans.push_back(que.front() ^ f ? 'A' : 'B');
                que.pop_front();
        }
        cout << ans << endl;
        return 0;
}



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

int main() {
  int n; cin >> n;
  unordered_set<int> s;
  for (int i=1; i<10; ++i) {
    for (int j=1; j<10; ++j) {
      s.insert(i*j);
    }
  }
  cout << (s.count(n) ? "Yes\n" : "No\n");
  return 0;
}


Measured memory_bytes: 256
N=int(input())
A=list(map(int,input().split()))
ans=[]
ANS=0
for i in range(N):
  ans.append(A[i]-i-1)
re_ans=sorted(ans)

if N%2==1:
  b=re_ans[N//2]
else:
  b=(re_ans[N//2]+re_ans[N//2-1])/2
for j in range(N):
  ANS+=abs(A[j]-b-j-1)
print(int(ANS))

Measured memory_bytes: 26184
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int Max = 1E5 + 10;
char S[Max];
int main()
{
    cin>>S;
    int N=strlen(S),sum=0;
    for(int i=1;i<N;i++)
    	if(S[i]!=S[i-1]) sum++;
    cout<<sum<<endl;
	return 0;
}


Measured memory_bytes: 384
#include<stdio.h>

int main() {
	int n;
	int result = 0;

	scanf("%d", &n);

	int b, c;
	int i_flag, j_flag, k_flag;
	for (int cor = 1; cor <= n; cor++)
	{
		result = 0;
		b = 0, c = 0;
		i_flag = 0, j_flag = 0, k_flag = 0;
		for (int i = 1; i_flag == 0; i++)
		{
			j_flag = 0;
			for (int j = 1; j_flag == 0; j++)
			{
				k_flag = 0;
				for (int k = 1; k_flag == 0; k++)
				{
					int cal = i * i + j * j + k * k + i * j + j * k + k * i;
					if (cal == cor) {
						if (i == j && j == k) {
							result += 1;
						}
						else if (i == j || i == k || j == k) {
							b++;
							if (b == 3) {
								result += 3;
								b = 0;
							}
						}
						else {
							c++;
							if (c == 6) {
								result += 6;
								c = 0;
							}
						}
					}
					else if (cal > cor) {
						k_flag = 1;
						if (k == 1) {
							j_flag = 1;
							if (j == 1) {
								i_flag = 1;
								printf("%d\n", result);
							}
						}
					}
				}
			}
		}
	}

	return 0;
}

Measured memory_bytes: 2052
#include<stdio.h>
#include<math.h>
#include<map>
using namespace std;
#define MAX 1000000000000;
int main()
{
	long long  n,result;
	scanf("%lld",&n);
	result = n - 1;
	for (long long i=2;i<sqrt(n)+1;i++) {
		if (n%i==0) {
			result = result > (i + (n / i) - 2) ? (i + (n / i) - 2) : result;
		}
	}
	printf("%lld\n",result); 
	return 0;
}


Measured memory_bytes: 128
n=gets.to_i
a=gets.chomp.split(" ").map(&:to_i)

def QuickSort(sort_target,list,left,right)
  i=left+1
  k=right
  while i<k
    i+=1 while sort_target[i]<sort_target[left] and i<right
    k-=1 while sort_target[k]>=sort_target[left] and k>left
    if i<k
      sort_target[i],sort_target[k]=sort_target[k],sort_target[i]
      list[i],list[k]=list[k],list[i]
    end
  end
  if sort_target[left]>sort_target[k]
    sort_target[left],sort_target[k]=sort_target[k],sort_target[left]
    list[left],list[k]=list[k],list[left]
  end
  QuickSort(sort_target,list,left,k-1) if left<k-1
  QuickSort(sort_target,list,k+1,right) if k+1<right
  return list
end
puts QuickSort(a,Array.new(n){|i| i+1},0,n-1).join(" ")


Measured memory_bytes: 13204
using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
using System.Text;
using static System.Console;
using static System.Math;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var nabcd = ReadDoubles();
            var a = Ceiling(nabcd[0] / nabcd[1]);
            var b = Ceiling(nabcd[0] / nabcd[3]);
            WriteLine(Min(a * nabcd[2], b * nabcd[4]));

        }

        private static string Read() { return ReadLine(); }
        private static string[] Reads() { return (Read().Split()); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
    }
}



Measured memory_bytes: 18040
import java.util.Scanner;
public class Main {
    public static int[] a;
    public static int n;
    public static void main (String[] args) {
	Scanner scan = new Scanner(System.in);
	n = Integer.parseInt(scan.nextLine());
	a = new int[n];
	String[] inputA = scan.nextLine().split(" ");
	for (int i = 0; i < n; i++) {
	    a[i] = Integer.parseInt(inputA[i]);
	}
	int q = Integer.parseInt(scan.nextLine());
	int[] m = new int[q];
	String[] inputB = scan.nextLine().split(" ");
	for (int i = 0; i < q; i++) {
	    m[i] = Integer.parseInt(inputB[i]);
	}
	for (int i = 0; i < q; i++) {
	    if (solve(0, m[i])) {
		System.out.println("yes");
	    } else {
		System.out.println("no");
	    }
	}
    }
    static boolean solve (int i, int m) {
	if (m == 0) {
	    return true;
	}
	if (i >= n) {
	    return false;
	}
	return solve(i+1, m) || solve(i+1, m-a[i]);
    }
}

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

using namespace std;
typedef long long ll;

int main()
{
	int n;
	cin >> n;
	ll ans = 1;
	vector<ll> a;
	a.resize(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		if (a[i] == 0) {
			cout << 0 << endl;
			return 0;
		}
	}
	for (int i = 0; i < n; i++) {
		if (a[i] > 1000000000000000000/ans) {
			cout << -1 << endl;
			return 0;
		}
		else {
			ans *= a[i];
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3584
/*  4_1
    Y_Aizaki    */

#include <stdio.h>
#include <math.h>

int main(void){
    double num_tree, sight;
    // 木の本数、監視範囲
    // 後のceil関数に合わせて、double型で宣言してある
    scanf("%lf%lf", &num_tree, &sight);

    int num_observer = ceil(num_tree / (2 * sight + 1));
    // 必要な監視員の数
    // 一人あたり、(2*sight+1)本の木を監視できる
    printf("%d\n", num_observer);

    return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<cstring>
#include<vector>
using namespace std;
int main()
{
    int a,b,c,d,i,j,k;
    cin>>a>>b;
    if(a<2)
        cout<<(b*(b-1))/2<<endl;
    else if(b<2)
        cout<<(a*(a-1))/2<<endl;
    else
    cout<<(a*(a-1))/2 + (b*(b-1))/2<<endl;
	return 0;
}


Measured memory_bytes: 256
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    return divisors

def main():
    X = int(input())
    while True:
        tmp = make_divisors(X)
        if len(tmp) == 2:
            break
        X += 1

    print(X)


if __name__ == "__main__":
    main()


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

// ----------- define --------------
#define int long long
#define vi vector<int>
#define ii pair<int,int>
#define fi first
#define sc second
#define stoi stoll
#define popcnt __builtin_popcount
#define getBit(x, k) ((x >> k) & 1)
#define all(x) (x).begin(),(x).end()
// ---------------------------------

void chmin(int &a, int b) {
  if (a > b) a = b;
}

struct bit {
  int n;
  vector<int> a;
  bit(int n): n(n) {
    a.resize(n + 1, n);
  }
  int rev(int i) {
    return i = n - i + 1;
  }
  void update(int i, int v) {
    i = rev(i);
    for (; i <= n; i += i & -i) {
      chmin(a[i], v);
    }
  }
  int get(int i) {
    i = rev(i);
    int v = n;
    for (; i; i -= i & -i) {
      chmin(v, a[i]);
    }
    return v;
  }
};

void Main() {
  int n, q;
  cin >> n >> q;
  bit row(n), col(n);
  int ans = (n - 2) * (n - 2);
  for (int i = 1; i <= q; i++) {
    int t, x;
    cin >> t >> x;
    if (t == 1) {
      int g = col.get(x);
      ans -= g - 2;
      row.update(g - 1, x);
    }
    else {
      int g = row.get(x);
      ans -= g - 2;
      col.update(g - 1, x);
    }
  }
  cout << ans << '\n';
}

signed main() {
#ifdef _DEBUG
  // freopen("in" , "r", stdin );
  cerr << "i love ------- <3 \n";
#endif
  cin.tie(0)->sync_with_stdio(0);
  int T = 1;
  // cin >> T;
  while (T--) Main();
}


Measured memory_bytes: 6344
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
    public static void main(String[] args)throws Exception {
        BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer tokenizer = new StringTokenizer(input.readLine());
        int a = Integer.parseInt(tokenizer.nextToken());
        int b = Integer.parseInt(tokenizer.nextToken());
        int [] city = new int[a + 1];

        for (int i = 0; i < b; i++) {
            tokenizer = new StringTokenizer(input.readLine());
            city[Integer.parseInt(tokenizer.nextToken())]++;
            city[Integer.parseInt(tokenizer.nextToken())]++;
        }
        StringBuilder output = new StringBuilder();
        for (int i = 1; i <= a; i++) {
            output.append(city[i]).append("\n");
        }
        System.out.print(output);
    }
}


Measured memory_bytes: 22740
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Console;
using static System.Math;

namespace AtTest.ABC_154
{
    class C
    {
        static void Main(string[] args)
        {
            var sw = new System.IO.StreamWriter(OpenStandardOutput()) { AutoFlush = false };
            SetOut(sw);

            Method(args);

            Out.Flush();
        }

        static void Method(string[] args)
        {
            int n = ReadInt();
            int[] array = ReadInts();
            var hashSet = new HashSet<int>();
            for(int i = 0; i < n; i++)
            {
                hashSet.Add(array[i]);
            }
            WriteLine(hashSet.Count == n ? "YES" : "NO");
        }

        private static string Read() { return ReadLine(); }
        private static char[] ReadChars() { return Array.ConvertAll(Read().Split(), a => a[0]); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
    }
}


Measured memory_bytes: 40372
N = int(input())
A = list(map(int, input().split()))
B = [1]*N
# 参照する数の少ない後ろからチェックしていく
for i, ai in enumerate(reversed(A)):
  count = 0
# N-iの倍数番号の和をカウントし2で割った余りがaiと一致しなければBのN-i番目を0に変更
  for j in range(N-i, N+1, N-i):
    count += B[j-1]
  if ai != count%2:
    B[N-1-i] = 0
# MはBの1の数、Bの要素が1のインデックスを取得してリスト化、展開
M = sum(B)
l = [i+1 for i, bi in enumerate(B) if bi == 1]
print(M)
print(*l)

Measured memory_bytes: 14132
import collections
N, K = map(int,input().split())
A_list = []
d_sum = 0
for i in range(K):
  d = int(input())
  d_sum += d
  A = list(map(int,input().split()))
  A_list.extend(A)

c = collections.Counter(A_list)

print(N-len(c))

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

int main() {
	string s; cin >> s;
	long long ans = 0, tmp;
	for (int bit = 0; bit < (1 << s.size() - 1); bit++) {
		tmp = s[0] - '0';
		for (int i = 0; i < s.size() - 1; i++) {
			if (bit & (1 << i)) {
				ans += tmp;
				tmp = 0;
			}
			tmp = tmp * 10 + s[i + 1] - '0';
		}
		ans += tmp;
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
# # coding: utf-8
# # Your code here!

# //解説
# #include <iostream>
# #define rep(i,n) for(int i=0;i<n;i++)
# using namespace std;
# int N,C,X;
# int D[33][33];
# int t[3][33];
# int main(void)
# {
#     scanf("%d%d",&N,&C);
#     rep(i,C)rep(j,C)scanf("%d",&D[i][j]);
#     rep(i,N)rep(j,N)scanf("%d",&X),t[(i+j)%3][X-1]++;
#     int res=1<<30;
#     rep(i,C)rep(j,C)if(i!=j)rep(k,C)if(i!=k&&j!=k)
#     {
#         int tt=0;
#         rep(l,C)tt+=D[l][i]*t[0][l];
#         rep(l,C)tt+=D[l][j]*t[1][l];
#         rep(l,C)tt+=D[l][k]*t[2][l];
#         if(tt<res)res=tt;
#     }
#     printf("%d\n",res);
# }


from collections import defaultdict
N,C=map(int,input().split())
D=defaultdict(int)
t=defaultdict(int)

for i in range(C):
    s=list(map(int,input().split()))
    for j in range(C):
        D[(i,j)]=s[j]
for i in range(N):
    s=list(map(int,input().split()))
    for j in range(N):
        t[((i+j)%3,s[j]-1)]+=1
ans=1<<30
for i in range(C):
    for j in range(C):
        for k in range(C):
            if i!=j!=k!=i:
                res=0
                for l in range(C):res+=D[(l,i)]*t[(0,l)]
                for l in range(C):res+=D[(l,j)]*t[(1,l)]
                for l in range(C):res+=D[(l,k)]*t[(2,l)]
                ans=min(ans,res)

                
print(ans)
                



Measured memory_bytes: 3956
#include<iostream>
#include<stdio.h>
#include<string>
#include <algorithm>
#include<cstring>
#include <math.h>
#include <iomanip>
using namespace std;


bool isPrime(int x)
{

  if(x == 2)
    return true;
  if (x < 2 or x % 2 == 0)
    return false;
  int i=3;
  while(i <= sqrt(x)){
    if(x%i==0)
      return false;
    i = i + 2;
  }
  return true;
}
  

int main()
{
  int n;
  cin>>n;
  int x;
  int ans=0;
  for(int i=0;i<n;i++){
    cin>>x;
    if(isPrime(x))
      ans++;
  }
  cout<<ans<<endl;
  return 0;
}



Measured memory_bytes: 3072
#include <bits/stdc++.h>
using namespace std;
// type alias
typedef long long LL;
typedef pair<int,int> II;
typedef tuple<int,int,int> III;
typedef vector<int> VI;
typedef vector<string> VS;
typedef unordered_map<int,int> MAPII;
typedef unordered_set<int> SETI;
template<class T> using VV=vector<vector<T>>;
// minmax
template<class T> inline T SMIN(T& a, const T b) { return a=(a>b)?b:a; }
template<class T> inline T SMAX(T& a, const T b) { return a=(a<b)?b:a; }
// repetition
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)
#define REPE(i,n)  for(int i=0;i<=(n);++i)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  for(int i=0;i<(n);++i)
#define FORR(x,arr) for(auto& x:arr)
#define SZ(a) int((a).size())
// collection
#define ALL(c) (c).begin(),(c).end()
// DP
#define MINUS(dp) memset(dp, -1, sizeof(dp))
#define ZERO(dp) memset(dp, 0, sizeof(dp))
// stdout
#define println(args...) fprintf(stdout, ##args),putchar('\n');
// debug cerr
template<class Iter> void __kumaerrc(Iter begin, Iter end) { for(; begin!=end; ++begin) { cerr<<*begin<<','; } cerr<<endl; }
void __kumaerr(istream_iterator<string> it) { (void)it; cerr<<endl; }
template<typename T, typename... Args> void __kumaerr(istream_iterator<string> it, T a, Args... args) { cerr<<*it<<"="<<a<<", ",__kumaerr(++it, args...); }
template<typename S, typename T> std::ostream& operator<<(std::ostream& _os, const std::pair<S,T>& _p) { return _os<<"{"<<_p.first<<','<<_p.second<<"}"; }
#define __KUMATRACE__ true
#ifdef __KUMATRACE__
#define dump(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); __kumaerr(_it, args); }
#define dumpc(ar) { cerr<<#ar<<": "; FORR(x,(ar)) { cerr << x << ','; } cerr << endl; }
#define dumpC(beg,end) { cerr<<"~"<<#end<<": "; __kumaerrc(beg,end); }
#else
#define dump(args...)
#define dumpc(ar)
#define dumpC(beg,end)
#endif

// $ cp-batch TAKOYAKIFESTIVAL2019 | diff TAKOYAKIFESTIVAL2019.out -
// $ g++ -std=c++14 -Wall -O2 -D_GLIBCXX_DEBUG -fsanitize=address TAKOYAKIFESTIVAL2019.cpp && ./a.out

/*
 
 10/19/2019
 
 5:04-
 
 */

const int MAX_N=1e6+1;
LL A[MAX_N];
int N;

void solve() {
  LL res=0;
  REP(j,N)REP(i,j) {
    res+=A[i]*A[j];
  }
  cout<<res<<endl;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout<<setprecision(12)<<fixed;
  
  cin>>N;
  REP(i,N) cin>>A[i];
  solve();
  
  return 0;
}


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

char S[100];
char T[100];
int main()
{
    scanf("%s%s", S, T);
    int s = strlen(S);
    int t = strlen(T);
    for (int i = s - t; i >= 0; i--)
    {
        bool flag = false;
        for (int j = 0; j < t; j++)
        {
            if (!(S[i + j] == '?' || S[i + j] == T[j]))
                flag = true;
        }
        if (!flag)
        {
            for (int j = 0; j < t; j++)
                S[i + j] = T[j];
            for (int i = 0; i < s; i++)
                if (S[i] == '?')
                    S[i] = 'a';
            printf("%s", S);
            return 0;
        }
    }
    printf("UNRESTORABLE");
}


Measured memory_bytes: 256
def max(a, b); a < b ? b : a; end
def min(a, b); a < b ? a : b; end

class Problem
  attr_accessor *(?a..?z).to_a.map(&:to_sym)

  def initialize
    @n,@d = gets.to_s.split.map{ |v| v.to_i }
    @p = Array.new(n){ gets.to_s.split.map{ |v| v.to_i } }
  end

  def solve
    dd = d * d
    ans = 0
    n.times do |i|
      x,y = @p[i]
      ans += 1 if dist2(y,x) <= dd
    end
    ans
  end

  def dist2(y, x)
    y ** 2 + x ** 2
  end

  def show(ans)
    puts ans
  end
end

Problem.new.instance_eval do
  show(solve)
end


Measured memory_bytes: 28176
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	cin>>n;
	int a=n%10;
	if(a==2||a==4||a==5||a==7||a==9)cout<<"hon";
	if(a==0||a==1||a==6||a==8)cout<<"pon";
	if(a==3)cout<<"bon";
	return 0;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define leading zero str.erase(0, min(str.find_first_not_of('0'), str.size()-1));
using namespace __gnu_pbds;
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
string text="abcdefghijklmnopqrstuvwxyz";
const int maxn=1e6+7;
//        .--------------.
//        | Try First One|
//        '--------------'
//                |     .--------------.
//                |     |              |
//                V     V              |
//              .--------------.       |
//              |      AC.     |<---.  |
//              '--------------'    |  |
//              (True)|  |(False)   |  |
//           .--------'  |          |  |
//           |           V          |  |
//           |  .--------------.    |  |
//           |  |   Try Again  |----'  |
//           |  '--------------'       |
//           |                         |
//           |  .--------------.       |
//           '->| Try Next One |-------'
//              '--------------'
ll bin_pow(ll a,ll b,ll m)
{
    ll res=1;
    a%=m;
    while(b>0)
    {
        if(b&1)
            res=res*a%m;
        b>>=1;
        a=a*a%m;
    }
    return res;
}
bool miller_rabin(ll d,ll n)
{
    ll a=2+rand()%(n-4);
    ll x=bin_pow(a,d,n);
    if(x==1 || x==n-1)
        return true;
    while(d!=n-1)
    {
        x=(x*x)%n;
        d*=2;
        if(x==1)
            return false;
        if(x==n-1)
            return true;
    }
    return false;
}
bool prime(ll n,ll k)
{
    if(n==1 || n==4)
        return false;
    if(n<=3)
        return true;
    ll d=n-1;
    while(d%2==0)
        d/=2;
    for(int i=0; i<k; i++)
    {
        if(!miller_rabin(d,n))
            return false;
    }
    return true;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n,k;
    cin>>n>>k;
    for(int a=0;a<=n;a++){
        for(int b=0;a+b<=n;b++){
            int c=n-a-b;
            int x=10000*a+5000*b+1000*c;
            if(x==k)return cout<<a<<" "<<b<<" "<<c<<endl,0;
        }
    }
    puts("-1 -1 -1");
}


Measured memory_bytes: 3656
#include<bits/stdc++.h> 
//#define <- プログラムの文字列を置換する
//typedef <- 新しい型に名前を付けるためのキーワード

using namespace std;

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

const long long MOD = 1e9 + 7;
const long long INF = 1e15;
const int INF_INT = 1e9;

template<class TYPE>
struct edge{
    TYPE to,cost; 
    edge(TYPE t,TYPE c){
        to = t;
        cost = c;
    }
};

int main(){
    vector<int> a(3);
    for(int i = 0; i < 3; i++) cin >> a[i];
    sort(a.begin(),a.end());
    int count = 0;
    int dis0 = a[2] - a[0];
    int dis1 = a[2] - a[1];
    if(dis0 % 2 == 0 && dis1 % 2 == 0){
        count += dis0 / 2 + dis1 / 2;
    }
    else if(dis0 % 2 == 1 && dis1 % 2 == 1){
        dis0--;dis1--;
        count++;
        count += dis0 / 2 + dis1 / 2;
    }
    else{
        int odd,even;
        if(dis0 % 2 == 0){
            even = dis0;
            odd = dis1;
        }
        else{
            even = dis1;
            odd = dis0;
        }
        count += 1 + even / 2 + (odd + 1) / 2;
    }
    cout << count << endl;
    return 0;
}


Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
#define N 3005
ll inf = 1e14;
int mod = 998244353;
char en = '\n';

ll abs1(ll x) {
  if (x < 0)
    return -x;
  return x;
}
ll power(ll x, ll n, ll mod) {
  ll res = 1;
  while (n) {
    if (n & 1)
      res = (res * x) % mod;
    x = (x * x) % mod;
    n >>= 1;
  }
  return res;
}
ll dp[N][N];
char a[N], b[N];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  memset(dp, 0, sizeof(dp));

  string a1, b1;
  cin >> a1 >> b1;

  ll n1 = a1.length(), n2 = b1.length();

  for (ll i = 1; i <= n1; i++) {
    a[i] = a1[i - 1];
  }
  for (ll i = 1; i <= n2; i++) {
    b[i] = b1[i - 1];
  }

  for (ll i = 1; i <= n1; i++) {
    for (ll j = 1; j <= n2; j++) {
      if (a[i] == b[j]) {
        dp[i][j] = 1 + dp[i - 1][j - 1];
      } else
        dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
    }
  }

  string res = "";

  ll i = n1, j = n2;
  while (i > 0 && j > 0) {
    if (a[i] == b[j]) {
      res = a[i] + res;
      i--;
      j--;
    } else if (dp[i][j] == dp[i - 1][j]) {
      i--;
    } else
      j--;
  }

  cout << res << en;

  return 0;
}


Measured memory_bytes: 70912
N = int(input())
A = [int(i) for i in input().split() if int(i) % 2 == 0]
t = 0
for x in A:
    if x % 3 != 0 and x % 5 != 0:
        t += 1
if t == 0:
    print('APPROVED')
else:
    print('DENIED')

Measured memory_bytes: 2940
n,k = map(int,input().split())
r,s,p = map(int,input().split())
t = input()

kaburi = list(t)
for i in range(n-k):
    if kaburi[i] == kaburi[i+k]:
        kaburi[i+k] = 'x'
result = 0
for i in range(n):
    if kaburi[i] == 'r':
        result += p
    elif kaburi[i] == 's':
        result += r
    elif kaburi[i] == 'p':
        result += s
    else:
        pass


print(result)

Measured memory_bytes: 10020
using System;
using System.Linq;

namespace _7_B
{
    class Program
    {
        static void Main(string[] args)
        {
            while (true)
            {
                int[] x = Console.ReadLine().Split().Select(int.Parse).ToArray();
                if (x[0] == 0 && x[1] == 0)
                {
                    break;
                }
                int a = 0;
                for (int i = 1; i <= x[0]; i++)
                {
                    for (int j = 1; j <= x[0]; j++)
                    {
                        for (int k = 1; k <= x[0]; k++)
                        {
                            if (i != j && j != k && k != i)
                            {
                                if (i + j + k == x[1])
                                {
                                    a++;
                                }
                            }
                        }
                    }
                }
                Console.WriteLine(a / 6);
            }
        }
    }
}

Measured memory_bytes: 9572
#include<stdio.h>

int main()
{
	int n,i,j,num[110],max,min;
    scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		scanf("%d",&(num[i]));
		if(i==0)
		{
			max=num[i];
			min=num[i];
		}
		else
		{
			if(max<num[i])max=num[i];
			if(min>num[i])min=num[i];
		}
	}
	printf("%d",max-min);
	
}



Measured memory_bytes: 128
n = int(input())
S = list(map(int, input().split()))
q = int(input())
T = list(map(int, input().split()))

def binarySearch(A, key):
    left = 0
    right = n

    while left < right:
        mid = (left + right) // 2
        if A[mid] == key:
            return 1

        elif key < A[mid]:
            right = mid
        else:
            left = mid+1
    return 0

C = 0
for i in T:
    C += binarySearch(S, i)
print(C)



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

int main() {
  int S, L, R;
  cin >> S;
  L = S/100;
  R = S%100;
  
  if ( L >= 1 && L <= 12 ) {
    if ( R >= 1 && R <= 12 ) {
      cout << "AMBIGUOUS" << endl;
    }
    else {
      cout << "MMYY" << endl;
    }
  }   
  
  else {
    if ( R >= 1 && R <= 12 ) {
      cout << "YYMM" << endl;
    }
    else {
      cout << "NA" << endl;
    }
    
  }
      
  
  
}


Measured memory_bytes: 256
IDENTIFICATION DIVISION.
       PROGRAM-ID. test1.
       ENVIRONMENT DIVISION.
       DATA DIVISION.
       WORKING-STORAGE SECTION.
       01 INP PIC X(2000).
       01 A-REC.
      	02 A-DATA OCCURS 200 .
      		03 A PIC 999999999 .
       01 temp1 PIC 9999.
       01 temp2 PIC 9999.
       01 temp3 PIC 99999.
       01 N PIC 999.
       01 REN PIC ZZZZ9.
       01 RE PIC 99999.
       01 MOD PIC 9.
       01 R PIC 999999999.
       01 S PIC 999.
       01 NOW PIC 9999.
       PROCEDURE DIVISION.
       MAIN.
      	MOVE 10000 TO RE.
      	ACCEPT N.
      	MOVE 1 TO NOW.
      	ADD 1 TO N.
      	ACCEPT INP.
      	PERFORM VARYING S FROM 1 BY 1 UNTIL S = N
      		PERFORM VARYING temp1 FROM NOW BY 1 
      			UNTIL INP(temp1:1)=SPACE
      		END-PERFORM
      		COMPUTE temp2 = temp1 - NOW
      		MOVE INP(NOW:temp2) TO A(S)
      		COMPUTE NOW = temp1 + 1
      	END-PERFORM.
      	PERFORM VARYING S FROM 1 BY 1 UNTIL S = N
      		COMPUTE R = A(S) / 2
      		COMPUTE MOD = A(S) - R*2
      		PERFORM VARYING temp3 FROM 0 BY 1 UNTIL MOD = 1
      			COMPUTE R = A(S) / 2
      			COMPUTE MOD = A(S) - R*2
      			COMPUTE A(S) = R
      		END-PERFORM
      		IF temp3 > 0 THEN
      			SUBTRACT 1 FROM temp3
      		END-IF
      		IF temp3 < RE THEN
      			MOVE temp3 TO RE
      		END-IF
      	END-PERFORM.
      	MOVE RE TO REN.
      	DISPLAY REN.
        STOP RUN.




Measured memory_bytes: 384
#include "iostream"
#include <algorithm>
#include <stdlib.h>
#include <cstring>
using namespace std;
using ll=long long;

int main(int argc, char const *argv[]) {
  int a,b,c;
  std::cin >> a >> b >> c;
  if(b-a==c-b) printf("YES");
  else printf("NO");
  return 0;
}


Measured memory_bytes: 256
N, M = map(int, input().split())
p = list(map(int, input().split()))

num = [0 for _ in range(N+1)]

class Unionfind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * (n+1)
        
    def find(self, x):
        if(self.parents[x] < 0):
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]
        
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        
        if(x == y):
            return
        
        if(self.parents[x] > self.parents[y]):
            x, y = y, x
            
        self.parents[x] += self.parents[y]
        self.parents[y] = x
    
    def size(self, x):
        return -self.parents[self.find(x)]
    
    def same(self, x, y):
        return self.find(x) == self.find(y)
    
    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]
    
    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]
    
    def group_count(self):
        return len(self.roots())
    
    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}
    
    def __str__(self):
        return '\n'.join('{}:{}'.format(r, self.members(r)) for r in self.roots())
    
    
uf = Unionfind(N+1)
        
for _ in range(M):
    x, y = map(int, input().split())
    uf.union(x, y)
ans = 0
for i in range(N):
    if(uf.find(i+1) == uf.find(p[i])):
        ans += 1
print(ans)

Measured memory_bytes: 13940
#include<stdio.h>
int Partition(int *,int,int);
int main()
{
  int i,n,q;
  int A[2000000];
 
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&A[i]);
  }
 
  q=Partition(A,0,n-1);
 
  for(i=0;i<q;i++){
    printf("%d ",A[i]);
  }
  printf("[%d] ",A[q]);
  for(i=q+1;i<n-1;i++){
    printf("%d ",A[i]);
  }
  printf("%d\n",A[i]);
  return 0;
}
 
int Partition(int *A,int p,int r)
{
  int x,i,j,temp;
  x=A[r];
  i=p-1;
  for(j=p;j<r;j++){
    if(A[j]<=x){
      i++; 
      temp=A[i];
      A[i]=A[j];
      A[j]=temp;
    }
  }
  temp=A[i+1];
  A[i+1]=A[r];
  A[r]=temp;
  return i+1;
}  


Measured memory_bytes: 2140
#include<iostream>
using namespace std;
int c[100001],a[100001],b[100001],ans1,ans2;
string s;
int main()
{
    cin>>s;
    int n=s.length();
    for(int i=0;i<n;i++)
    {
        c[i+1]=s[i]-48;
    }
    for(int i=1;i<=n;i++)
    {
        b[i]=i%2;
        a[i]=1^b[i];
    }
    for(int i=1;i<=n;i++)
    {
        if(c[i]!=a[i])ans1++;
        if(c[i]!=b[i])ans2++;
    }
    cout<<min(ans1,ans2);
    return 0;
}

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

int dp[2][(1<<24)];
string s[501];
int n,m;
bool a[501][501];
 
int main(){
  while(cin>>n>>m,n|m){
    for(int i=0;i<n;i++){
      cin>>s[i];
      for(int j=0;j<m;j++){
        a[i][j]=(s[i][j]=='1');
      }
    }
    if(n<=m){
      int ans=0;
      for(int i=0;i<(1<<n);i++){
        if(ans>=__builtin_popcount(i))continue;
        bool ok=1;
        for(int j=0;j<m;j++){
          int cont=0;
          for(int k=0;k<n;k++){
            if(a[k][j] && i&(1<<k))cont++;
          }
          if(cont&1){ok=0;break;}
        }
        if(ok)ans=max(ans,__builtin_popcount(i));
      }
      cout<<ans<<endl;
    }else{
      int list[501];
      fill(list,list+n,0);
      for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
          if(a[i][j]){
            list[i]=list[i]|(1<<j);
          }
        }
      }
      for(int i=0;i<2;i++)for(int j=0;j<(1<<m);j++)dp[i][j]=-1;
      dp[0][0]=0;
      for(int i=0;i<n;i++){
        for(int j=0;j<(1<<m);j++)dp[(i+1)&1][j]=-1;
        for(int j=0;j<(1<<m);j++){
          if(dp[i&1][j]==-1)continue;
          dp[(i+1)&1][j^list[i]]=max(dp[(i+1)&1][j^list[i]],dp[i&1][j]+1);
          dp[(i+1)&1][j]=max(dp[(i+1)&1][j],dp[i&1][j]);
        }
      }
      cout<<dp[n&1][0]<<endl;
    }
  }
}


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

int main(int argc, char *argv[]){
  int n, t;
  cin >> n >> t;
  string s[2][n];
  int time[2][n];
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 2; j++) {
      int a, b;
      scanf("%d:%d ", &a, &b);
      time[j][i] = 60*a + b;
      cin >> s[j][i];
    }
  }
  vector<int> id;
  for (int i = 1; i < n; i++) {
    if(time[0][i] - time[1][i - 1] >= t){
      id.push_back(i);
    }
  }
  std::cout << id.size() << std::endl;
  for (int i = 0; i < id.size(); i++) {
    std::cout << s[0][id[i]] << " " <<
      time[0][id[i]] - time[1][id[i] - 1] << std::endl;
  }
  return 0;
}

Measured memory_bytes: 1276
from itertools import combinations as c
n=int(input());l=[input() for _ in range(n)];m="MARCH";p=[0]*5;r=0
for s in l:
  for i in range(5):
    if s[0]==m[i]:p[i]+=1
for d in c(p,3):r+=d[0]*d[1]*d[2]
print(r)

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

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

    int n, k, s;
    cin >> n >> k >> s;

    vector<int> ans(n);
    for (int i = 0; i < n; i++) {
        if (i < k) {
            ans[i] = s;
        } else {
            ans[i] = (s + 1 > 1e9 ? s - 1 : s + 1);
        }
    }

    for (int i = 0; i < n; i++) {
        cout << ans[i] << ' ';
    }
}


Measured memory_bytes: 1664
# from pprint import pprint
# import math
# import collections

n = int(input())
# n, k = map(int, input().split(' '))
# a = list(map(int, input().split(' ')))
s = []
for i in range(n):
    s.append(int(input()))


# 全問正解の場合から低い順に引いていく
tensu = sum(s)

s2 = sorted(s)

tensu_ans = 0

if tensu % 10 == 0:
    if all([True if _s % 10 == 0 else False for _s in s]):
        tensu_ans = 0
    else:
        tensu_ans = tensu - min([_s for _s in s if _s % 10 != 0])
else:
    tensu_ans = tensu

print(tensu_ans)

Measured memory_bytes: 9124
#include <cstdio>
#include <cstring>
#include <algorithm>
#define repu(i,x,y) for (int i=x; i<=y; ++i)
using namespace std;

typedef long long LL;
const int p=924844033;
int n,k,f[2010],g[1010][2][2010],ans;

void dp(int m,bool fst,bool lst)
{
    memset(g,0,(m+5)*sizeof(g[0]));
    memcpy(g[0][!fst],f,sizeof(f));
    repu(i,0,m-1)
        repu(j,0,n)
            if (g[i][0][j] || g[i][1][j])
            {
                g[i+1][0][j]=(LL(g[i+1][0][j])+g[i][0][j]+g[i][1][j])%p;
                (g[i+1][0][j+1]+=g[i][0][j])%=p;
                g[i+1][1][j+1]=(LL(g[i+1][1][j+1])+g[i][0][j]+g[i][1][j])%p;
            }
    repu(i,0,n)
    {
        f[i]=g[m][0][i];
        if (lst)
            (f[i]+=g[m][1][i])%=p;
    }
}

int main()
{
    scanf("%d%d",&n,&k),f[0]=1;
    repu(i,1,min(n,k*2))
        dp((n-i)/k/2+1,i>k,(n-i)%(k*2)>=k);
    int t=1;
    repu(i,0,n)
    {
        if ((n-i)&1)
            ans=(ans+p-LL(t)*f[n-i]%p)%p;
        else
            ans=(ans+LL(t)*f[n-i])%p;
        t=LL(i+1)*t%p;
    }
    printf("%d\n",ans);
    return 0;
}

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

// マクロ
// forループ
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=(a);i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=(a);i>=(ll)(b);i--)
// xにはvectorなどのコンテナ
#define ALL(x) (x)begin(),(x).end()
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
// 出力
#define PRINT(x) cout<<(x)<<endl
#define PRINTA(x,n) REP(i,n)PRINT(x[i])
// 定数
#define INF 1000000000000 // 10^12
// #define MOD 1000000007 // 10^9+7
// 略記
#define PB push_back
#define MP make_pair

ll MOD = 998244353;

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

const int MAX = 200009;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

ll N, M, K;


int main() {
    cin >> N >> M >> K;
    COMinit();

    ll ans = 0;
    FOR(k, 0, K) {
        ll a = (M * modpow(M-1, N-k-1, MOD)) % MOD;
        ll b = (a * COM(N-1, k)) % MOD;
        ans = (ans + b) % MOD;
    }
    PRINT(ans);
    return 0;
}

Measured memory_bytes: 8324
<STDIN>;

sub uniq {
    my $p = {};
    $p->{$_} = 1 foreach(@_);
    return keys(%$p);
}

my $str=<STDIN>;
my $m = 0;
foreach(1...length($str)) {
    my @a = uniq(split(//, substr($str, 0, $_)));
    my @b = uniq(split(//, substr($str, $_)));
    my $s = scalar(grep { my $k = $_;  grep { $k eq $_ } @b } @a);
    $m = $s if $s > $m;
}
print $m;

Measured memory_bytes: 512
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
using P=pair<double,double>;
P operator+(P a,P b){return make_pair(a.first+b.first,a.second+b.second);}
P operator-(P a,P b){return make_pair(a.first-b.first,a.second-b.second);}
P operator*(P a,double t){return make_pair(a.first*t,a.first*t);}
double cross(P a,P b){return a.first*b.second-a.second*b.first;}
int ccw(P a,P b,P c){return cross(b-a,c-a)>0?1:-1;}
bool intersect(pair<P,P>a,pair<P,P>b){
	return ccw(a.first,a.second,b.first)*ccw(a.first,a.second,b.second)<0
		&&ccw(b.first,b.second,a.first)*ccw(b.first,b.second,a.second)<0;
}
double get(pair<P,P>a,pair<P,P>b){
	P base=b.second-b.first;
	double d1=abs(cross(base,a.first-b.first));
	double d2=abs(cross(base,a.second-b.first));
	return d1/(d1+d2);
}
int n,t;
main()
{
	cin>>t;
	for(;t--;)
	{
		pair<P,P>a;
		cin>>a.first.first>>a.first.second>>a.second.first>>a.second.second>>n;
		vector<pair<double,bool> >Q;
		for(;n--;)
		{
			pair<P,P>b;
			cin>>b.first.first>>b.first.second>>b.second.first>>b.second.second;
			int o,l;cin>>o>>l;
			if(intersect(a,b))
			{
				Q.push_back(make_pair(get(a,b),o==l));
			}
		}
		sort(Q.begin(),Q.end());
		int cnt=0;
		for(int i=1;i<Q.size();i++)if(Q[i-1].second!=Q[i].second)cnt++;
		cout<<cnt<<endl;
	}
}



Measured memory_bytes: 3144