akhauriyash/Code-Regression huggingface dataset:
# abc115_c.py
# https://atcoder.jp/contests/abc115/tasks/abc115_c

# C - Christmas Eve /
# 実行時間制限: 2 sec / メモリ制限: 1024 MB
# 配点 : 300点

# 問題文
# とある世界では、今日はクリスマスイブです。
# 高羽氏の庭には N本の木が植えられています。i 本目の木 (1≤i≤N) の高さは hiメートルです。
# 彼は、これらの木のうち K本を選んで電飾を施すことにしました。
# より美しい光景をつくるために、できるだけ近い高さの木を飾り付けたいです。
# より具体的には、飾り付ける木のうち最も高いものの高さを hmaxメートル、最も低いものの高さを hmin メートルとすると、
# hmax−hmin が小さいほど好ましいです。
# hmax−hminは最小でいくつにすることができるでしょうか？

# 制約
#     2≤K<N≤105
#     1≤hi≤109
#     hiは整数である。

# 入力
# 入力は以下の形式で標準入力から与えられる。
# N K
# h1
# h2
# :
# hN

# 出力
# hmax−hminとしてありうる最小の値を出力せよ。

# 入力例 1
# 5 3
# 10
# 15
# 11
# 14
# 12

# 出力例 1
# 2

# 1,3,5本目の木を飾り付けると hmax=12,hmin=10 となり hmax−hmin=2で、これが最適です。

# 入力例 2
# 5 3
# 5
# 7
# 5
# 7
# 7

# 出力例 2
# 0

# 2,4,5本目の木を飾り付けると hmax=7,hmin=7 となり hmax−hmin=0で、これが最適です。

# これらの入力例では木の数がそれほど多くありませんが、最大で 10万本の木がある可能性に注意してください 
# (ここに 10 万行の入力例を貼るわけにはいかないのです)。


def calculation(lines):
    # X = lines[0]
    # N = int(lines[0])
    N, K = list(map(int, lines[0].split()))
    values = list()
    for i in range(N):
        values.append(int(lines[i+1]))
    
    # 並び替え
    values.sort()

    dif = values[K-1] - values[0]

    for i in range(1, N-K+1):
        tmp = values[K-1+i] - values[i]
        if dif > tmp:
            dif = tmp
    return [dif]


# 引数を取得
def get_input_lines():
    line = input()
    N, M = list(map(int, line.split()))
    lines = list()
    lines.append(line)
    for _ in range(N):
        lines.append(input())
    return lines


# テストデータ
def get_testdata(pattern):
    if pattern == 1:
        lines_input = ['5 3', '10', '15', '11', '14', '12']
        lines_export = [2]
    if pattern == 2:
        lines_input = ['5 3', '5', '7', '5', '7', '7']
        lines_export = [0]
    return lines_input, lines_export


# 動作モード判別
def get_mode():
    import sys
    args = sys.argv
    if len(args) == 1:
        mode = 0
    else:
        mode = int(args[1])
    return mode


# 主処理
def main():
    import time
    started = time.time()
    mode = get_mode()
    if mode == 0:
        lines_input = get_input_lines()
    else:
        lines_input, lines_export = get_testdata(mode)

    lines_result = calculation(lines_input)

    for line_result in lines_result:
        print(line_result)

    # if mode > 0:
    #     print(f'lines_input=[{lines_input}]')
    #     print(f'lines_export=[{lines_export}]')
    #     print(f'lines_result=[{lines_result}]')
    #     if lines_result == lines_export:
    #         print('OK')
    #     else:
    #         print('NG')
    # finished = time.time()
    # duration = finished - started
    # print(f'duration=[{duration}]')


# 起動処理
if __name__ == '__main__':
    main()


Measured memory_bytes: 20304
#include <iostream>
#include <vector>
#include <algorithm>
#define pb push_back
using namespace std;

int main(){
    int n;
    cin >> n;
    int a[n];
    int ans = 0;
    vector<int> b;
    //cin >> n;
    for(int i=0;i<n;i++){
        cin >> a[i];
        if(a[i]%2 == 0){
            b.pb(a[i]);
        }
    }
    for(int j=0;j<b.size();j++){
        if(b[j]%3 == 0 || b[j]%5 == 0){
        }else{
            ans = 1;
            break;
        }
    }
    if(ans == 1) cout << "DENIED" << endl;
    if(ans == 0) cout << "APPROVED" << endl; 

}

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

int main(){
    long long int a, b, v, w, t;
    cin >> a >> v;
    cin >> b >> w;
    cin >> t;
    long long int speed = v-w;
    long long int d = b-a;
    if(b > a){
        if(a+v*t >= b+w*t) cout << "YES" << endl;
        else cout << "NO" << endl;
    }else{
        if(a-v*t <= b-w*t) cout << "YES" << endl;
        else cout << "NO" << endl;
    } 
    return 0;
}

Measured memory_bytes: 3632
from math import *

def cin(): # To take limited number of inputs
    return map(int,input().split())

def cins(): # To take space sepreated strings
    return input.split()

def cino(test=False): # To take individual int input (test = False)
    if not test:
        return int(input())
    else: # To take string input (test = True)
        return input()

def cina(): # array input
  return list(map(int,input().split()))

def ssplit(): # multiple string input
    return list(input().split())

def printlist(l): # To print space seperated array
    for i in l:
        print(i,end=" ")

def main():
    a = cina()
    for i in range(len(a)):
        if a[i]==0:
            print(i+1)
            break

if __name__ == '__main__':
    main()


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

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            List<restaurant> restaurants = new List<restaurant>();
            for (int i = 0; i < N; i++)
            {
                restaurants.Add(new restaurant(Console.ReadLine(), i+1));
            }
            restaurants.Sort();
            for (int i = 0; i < N; i++)
            {
                Console.WriteLine(restaurants[i].id.ToString());
            }
        }
        class restaurant : System.IComparable
        {
            public string city;
            public int point;
            public int id;
            public restaurant(string input, int id)
            {
                string[] inp = input.Split(' ');
                city = inp[0];
                point = int.Parse(inp[1]);
                this.id = id;
            }

            public int CompareTo(object obj)
            {
                if (this.city != ((restaurant)obj).city)
                {
                    return this.city.CompareTo(((restaurant)obj).city);
                }
                else
                {
                    return ((restaurant)obj).point.CompareTo(this.point);
                }
            }
        }
    }
}

Measured memory_bytes: 11360
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,a,b,c,t,i;
    double ans;
    cin>>n;
    ans = 2.0*acos(-1.0)*(n*1.0);
    cout<<fixed<<setprecision(20)<<ans<<endl;
    string str;

    return 0;
}



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

int main(){
    int n, m;
    cin >> n >> m;
    if (n > m) n = m;
    vector<int> x(m), dist(m-1);
    rep(i, m) cin >> x[i];
    sort(all(x));
    ll ans = 0;
    rep(i, m-1) {
        int tmp = abs(x[i] - x[i+1]);
        ans += tmp;
        dist[i] = tmp;
    }
    sort(all(dist), greater<>());
    rep(i, n-1) {
        ans -= dist[i];
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1024
fn main() {
	let mut s = String::new();
	use std::io::Read;
	std::io::stdin().read_to_string(&mut s).unwrap();
	let mut s = s.split_whitespace();
	let n: usize = s.next().unwrap().parse().unwrap();
	let m: usize = s.next().unwrap().parse().unwrap();
	let mut a: Vec<i32> = s.map(|a| a.parse().unwrap()).collect();
	a.sort();
	let mut l = 2;
	let mut r = 200001;
	let pattern = |n| a.iter().fold(0, |r, b| r + a.len() - a.lower_bound(&(n - *b)));
	while r - l > 1 {
		let mid = l + (r - l) / 2;
		if pattern(mid) >= m {
			l = mid;
		} else {
			r = mid;
		}
	}
	let pat = pattern(l);
	let mut cum = vec![0; n + 1];
	for i in 0..a.len() {
		cum[i + 1] = cum[i] + a[a.len() - 1 - i] as i64;
	}
	let ans = a.iter().fold(0, |r, b| {
		let c = a.len() - a.lower_bound(&(l - *b));
		r + c as i64 * *b as i64 + cum[c]
	}) - (pat - m) as i64 * l as i64;
	println!("{}", ans);
}

pub trait BinarySearch<'a, T: 'a> {
	fn lower_bound(&self, x: &T) -> usize;
}

impl<'a, T: 'a + Ord> BinarySearch<'a, T> for [T] {
	fn lower_bound(&self, x: &T) -> usize {
		let mut first = 0;
		let mut len = self.len() - first;
		while len > 0 {
			let half = len >> 1;
			let mid = first + half;
			use std::cmp::Ordering;
			match self[mid].cmp(x) {
				Ordering::Less => {
					first = mid + 1;
					len = len - half - 1;
				}
				Ordering::Equal | Ordering::Greater => {
					len = half;
				}
			}
		}
		first
	}
}


Measured memory_bytes: 6396
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = s; i < (int)(n); i++)
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

using namespace std;
using ll = long long;
using pii = pair<int, int>;

//const ll INF = 1e18L + 5;
//const int INF = 1e9 + 5;
//const double pi = 3.14159265358979323846;

void	solve()
{
	int p, q, r;
	cin >> p >> q >> r;

	cout << min({p + q, q + r, p + r}) << endl;
}

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

	solve();
}

Measured memory_bytes: 256
class UnionFind :
    def __init__(self, size) :
        self.parent = list(range(size))
        self.height = [0] * size
        self.size = [1] * size
        self.component = size

    def root(self, index) :
        if self.parent[index] == index :  # 根の場合
            return index
        rootIndex = self.root(self.parent[index])  # 葉の場合親の根を取得
        self.parent[index] = rootIndex  # 親の付け直し
        return rootIndex

    def union(self, index1, index2) :  # 結合
        root1 = self.root(index1)
        root2 = self.root(index2)

        if root1 == root2 :  # 連結されている場合
            return

        self.component -= 1  # 連結成分を減らす

        if self.height[root1] < self.height[root2] :
            self.parent[root1] = root2  # root2に結合
            self.size[root2] += self.size[root1]
        else :
            self.parent[root2] = root1  # root1に結合
            self.size[root1] += self.size[root2]
            if self.height[root1] == self.height[root2] :
                self.height[root1] += 1
        return

    def isSameRoot(self, index1, index2) :
        return self.root(index1) == self.root(index2)

    def sizeOfSameRoot(self, index) :
        return self.size[self.root(index)]

    def getComponent(self) :
        return self.component

N, M = map(int, input().split())
P = tuple(map(int, input().split()))

tree = UnionFind(N + 1)
for _ in range(M):
    x, y = map(int, input().split())
    tree.union(x, y)

ans = 0
for i, p in enumerate(P, start=1):
    if tree.isSameRoot(i, p):
        ans += 1
print(ans)

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

using namespace std;

const vector<int> dx = {1, -1, 0, 0}, dy = {0, 0, 1, -1};
const int INF = 1 << 30;

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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int H, W, K;
  cin >> H >> W >> K;
  int sy, sx, gy, gx;
  cin >> sy >> sx >> gy >> gx;
  sy--, sx--, gy--, gx--;
  vector<string> S(H);
  for (int i = 0; i < H; i++) {
    cin >> S[i];
  }
  vector<vector<int>> D(H, vector<int>(W, INF));
  D[sy][sx] = 0;
  queue<pair<int, int>> que;
  que.push(make_pair(sy, sx));
  while (!que.empty()) {
    auto q = que.front();
    que.pop();
    int y = q.first, x = q.second;
    for (int i = 0; i < 4; i++) {
      int ny = y, nx = x;
      for (int k = 0; k < K; k++) {
        ny += dy[i], nx += dx[i];
        if (ny < 0 || ny >= H || nx < 0 || nx >= W) continue;
        if (S[ny][nx] == '@') break;
        if (chmin(D[ny][nx], D[y][x] + 1)) {
          que.push(make_pair(ny, nx));
        } else {
          if (D[ny][nx] != D[y][x] + 1) break;
        }
      }
    }
  }
  if (D[gy][gx] == INF) {
    cout << -1 << '\n';
  } else {
    cout << D[gy][gx] << '\n';
  }
  return 0;
}


Measured memory_bytes: 12168
A,B,K=map(int,input().split())
s=[]
for i in range(K):
  s.append(A+i)
  s.append(B-i)
s=sorted(list(set(s)))
for j in range(len(s)):
  if A<=s[j] and s[j]<=B:
    print(s[j])

Measured memory_bytes: 8940
#include <iostream>
#include <string>
#include <vector>
using namespace std;
#define REP(i,n) for(int i=0;i<(n);i++)

int main(){
  int A,B,C,D,E,F,G,H,I;
  cin >> A >> B >> E;
  C=3*E-A-B;
  G=2*E-C;
  H=2*E-B;
  I=2*E-A;
  D=3*E-A-G;
  F=3*E-C-I;
  cout << A << " " << B << " " << C << endl;
  cout << D << " " << E << " " << F << endl;
  cout << G << " " << H << " " << I << endl;
  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <complex>
#include <string>
#include <algorithm>
#include <numeric>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#ifndef LOCAL
#define debug(x) ;
#else
#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;

template <typename T1, typename T2>
ostream &operator<<(ostream &out, const pair<T1, T2> &p) {
  out << "{" << p.first << ", " << p.second << "}";
  return out;
}

template <typename T>
ostream &operator<<(ostream &out, const vector<T> &v) {
  out << '{';
  for (const T &item : v) out << item << ", ";
  out << "\b\b}";
  return out;
}
#endif

#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 200010

int N, K;
vector<int> G[SIZE];

ll dfs(int now, int back = -1) {
  ll res = 1;

  ll x = K - (back != -1);

  for (int to : G[now]) {
    if (back == to) continue;
    x--;
    res = res * x % mod;
    res = res * dfs(to, now) % mod;
  }

  return res;
}

int main() {

  scanf("%d%d", &N, &K);

  for (int i=0; i<N-1; i++) {
    int a, b;
    scanf("%d%d", &a, &b);
    a--; b--;

    G[a].push_back(b);
    G[b].push_back(a);
  }

  cout << dfs(0) * K % mod << endl;

  return 0;
}


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

int main(){
    int n,m,sum=0;
    cin>>n>>m;
    for(int i=0;i<m;i++){
        int x;
        cin>>x;
        sum+=x;
    }
    if(sum>n){
        cout<<"-1\n";
    }else{
        cout<<n-sum<<"\n";
    }
    return 0;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define ll int64_t
#define _GLIBCXX_DEBUG
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
int main(){
  int a,b,c,k;
  cin >> a >> b>>c>>k;
  int ans;
  if(k<=a){
    ans=k;
  }
  else if(k-a<=b)
    ans=a;
  else
    ans=a-(k-a-b);
  cout << ans << endl;
}

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


public class Main {
    static HashMap<Integer,Integer>[] g; //<toRoom, keyNecessary>
    static int n,m;
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        //BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        //String[] buf = reader.readLine().split(" ");
        //n = Integer.parseInt(buf[0]); m = Integer.parseInt(buf[1]);
        String s = sc.next();
        int cnt = 0;
        for(char w:s.toCharArray()){
            if(w=='x') cnt++;
        }
        String ans = cnt<8?"YES":"NO";
        PrintWriter out = new PrintWriter(System.out);
        out.println(ans);
        out.flush();
    }
}



Measured memory_bytes: 22484
import numpy
import itertools

if __name__ == "__main__":
  N = int(input())
  L = [int(a) for a in input().split()]
  cnt = 0
  L_comb = list(itertools.combinations(L, 3))
  for i in L_comb:
    if len(set(i)) <= 2:
      continue
    i = numpy.asarray(i)
    max_index = numpy.argmax(i)
    if i[max_index] < sum(i) - i[max_index]:
      cnt += 1
    else:
      pass   
  print(cnt)


Measured memory_bytes: 38316
#include <bits/stdc++.h>
using namespace std;
int main(){
  vector<vector<char>> s(2, vector<char>(3));
  for (int i=0;i<2;i++){
    for (int j=0;j<3;j++){
      cin >> s.at(i).at(j);
    }
  }
  if (s[0][0]==s[1][2]&&s[0][1]==s[1][1]&&s[0][2]==s[1][0]){
    cout << "YES" << endl;
  }else {
    cout << "NO" << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,m,n) for(int i=m;i<n;i++)
#define c(n) cin>>n
#define co(n) cout<<n<<endl
using namespace std;

int main(){
  long a,b=2,c=0,d=0,e,n,m,x,y;
  cin>>n>>m>>x>>y;
  int r=0,xx[n],yy[m];
  rep(i,0,n) c(xx[i]);
  rep(i,0,m) c(yy[i]);
  sort(xx,xx+n); sort(yy,yy+m);
  if(xx[n-1]<yy[0]) r++;
  if(xx[n-1]<y) r++;
  if(x<yy[0]) r++;
  if(r==3) co("No War");
  else co("War");
  
  return 0;
}

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

typedef long long llong;
typedef unsigned long long ullong;
// -2.1e-9 <= int <= 2.1e9
// 0 <= unsigned int <= 4.2e9

void record(int v, vector<vector<int>>& A, vector<vector<bool>>& Map)
{
    for (size_t i=0; i<3; i++) {
        for (size_t j=0; j<3; j++) {
            if (v == A[i][j]) Map[i][j] = true;
        }
    }
}

int main()
{
    vector<vector<bool>> Map(3, vector<bool>(3, false));
    vector<vector<int>> A(3, vector<int>(3, 0));

    for (size_t i=0; i<3; i++) {
        for (size_t j=0; j<3; j++) {
            cin >> A[i][j];
            Map[i][j] = false;
        }
    }
    size_t N; cin >> N;
    for (size_t i=0; i<N; i++) {
        int b; cin >> b;
        record(b, A, Map);
    }

    for (size_t i=0; i<3; i++) {
        if (Map[i][0] && Map[i][1] && Map[i][2]) {
            cout << "Yes" << endl;
            return 0;
        }
    }

    for (size_t j=0; j<3; j++) {
        if (Map[0][j] && Map[1][j] && Map[2][j]) {
            cout << "Yes" << endl;
            return 0;
        }
    }

    if (Map[0][0] && Map[1][1] && Map[2][2]) {
        cout << "Yes" << endl;
        return 0;
    }

    if (Map[0][2] && Map[1][1] && Map[2][0]) {
        cout << "Yes" << endl;
        return 0;
    }

    cout << "No" << endl;
}

Measured memory_bytes: 256
#include<vector>
#include<cmath>
#include<map>
#include<cstdlib>
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<set>
#include<stack>
#include<bitset>
#include<functional>
#include<ctime>
#include<queue>
#include<deque>
#include<complex>
#include<cassert>
using namespace std;
#define pb push_back
#define pf push_front
typedef long long lint;
typedef complex<double> P;
#define mp make_pair
#define fi first
#define se second
typedef pair<int,int> pint;
#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
//問題文および制約はちゃんと確認しよう！
//サイズは10^5じゃなくて2×10^5とかかもしれないし、重要な制約・条件を見落としているかも
//とりあえずサンプルを読んでから解法を考えよう？
map<int,int> me;
int a[200100];
int n,m;
bool f;
//meからboより大きいのを消す
void cl(int bo){
	//if(me.size()<1) return;
	//cout<<bo<<endl;
	//map<int,int>::iterator it=me.end();
	//cout<<bo<<endl;
	//it--;
	//cout<<bo<<endl;
	while(me.size()>0 && me.rbegin()->fi>bo){
		me.erase(me.rbegin()->fi);
	}
	//cout<<bo<<endl;
}
void update(int x){
	if(x<1) f=false;
	else{
		me[x]++;
		if(me[x]>=m){
			me[x]=0;update(x-1);
		}
	}
}
bool cal(int mi){
	me.clear();f=true;m=mi;
	rep(i,n-1){
		if(a[i+1]<=a[i]){
			if(a[i+1]<a[i]) cl(a[i+1]);
			update(a[i+1]);
		}
		if(!f) return false;
	}
	return f;
}
int main()
{
	cin>>n;rep(i,n) cin>>a[i];
	int fl=0;
	rep(i,n-1){
		if(a[i+1]<=a[i]) fl=1;
	}
	if(fl<1){
		cout<<1<<endl;return 0;
	}
	int lo=2,hi=n;
	while(hi>lo){
		int mi=(hi+lo)/2;
		if(cal(mi)) hi=mi;else lo=mi+1;
	}
	cout<<lo<<endl;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
const int mod=1e9+7;
// I'm in Love with Experience. �😎�
void solve()
{
   ll K;cin>>K;
   for(ll i=0;i<K;++i)cout<<"ACL";
}
int main(void)
{
ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
int T=1;      ///  cin>>T;
while(T--){solve();}exit(0);
}/*Solved By:- Ritik Agarwal*/

Measured memory_bytes: 3644
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);
#define all(x) x.begin(),x.end()
#define pb push_back
#define pf push_front
#define ff first
#define ss second
#define vll vector<ll>
#define sll set<ll>
#define pll pair<ll, ll>
#define vpll vector<pll>
#define endl "\n"
const ll maxn = 2e5+2;
ll dp[100002][102];

ll recur(vpll &a, ll pos, ll W)
{
    if(pos>=a.size()) 
        return 0;
    if(a[pos].ff>W) 
        return dp[W][pos]=recur(a,pos+1,W);
    if(dp[W][pos]!=-1) 
        return dp[W][pos];

    return dp[W][pos]=max(a[pos].ss+recur(a,pos+1,W-a[pos].ff),recur(a,pos+1,W));
}

int main()
{
    fastio; //remove for interactive
    ll i, j, k, n, m, t;
    vpll a;
    memset(dp,-1,sizeof(dp));

    cin>>n>>k;
    for ( i = 0; i < n; i++)
    {
        ll w,v;
        cin>>w>>v;
        a.pb({w,v});
    }
    recur(a,0,k);
    
    cout<<dp[k][0]<<endl;
    return 0;
}

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

using namespace std;

typedef long long lld;
int main() {
	int n;
	cin >> n;
	lld sum = 0;
	for (int i = 1; i <= n; i++) {
		if (i % 3 == 0 && i % 5 == 0) {
			continue;
		}
		else if (i % 3 ==0) {
			continue;
		}
		else if (i % 5 == 0) {
			continue;
		}
		sum += i;
	}
	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 3564
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main() {
	string ans = "";
	string str[100];
	int N,L;

	cin >> N >> L;
	for (int i = 0;i < N;i++) {
		cin >> str[i];
	}

	sort(str, str + N);

	for (int i = 0;i < N;i++) {
		ans = ans + str[i];
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
int main(void){
    int n,i;
    double total,temp;
    char *s;
    s=(char*)malloc(sizeof(char)*10);
    scanf("%d",&n);
    total=0;
    for(i=0;i<n;i++){
        scanf("%lf %s",&temp,s);
        if(s[0]=='J'){
            total+=temp;
        }else{
            total+=temp*380000.0;
        }
    }
    printf("%lf\n",total);
    free(s);
    return 0;
}

Measured memory_bytes: 384
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();
        int c = sc.nextInt();
        char[] arr = sc.next().toCharArray();
        int[] fronts = new int[k];
        int idx = 0;
        for (int i = 0; i < k; i++) {
            while (arr[idx] == 'x') {
                idx++;
            }
            fronts[i] = idx;
            idx += c + 1;
        }
        idx = n - 1;
        int[] reers = new int[k];
        for (int i = k - 1; i >= 0; i--) {
            while(arr[idx] == 'x') {
                idx--;
            }
            reers[i] = idx;
            idx -= c + 1;
        }
        StringBuilder sb = new StringBuilder();
        int count = 0;
        for (int i = 0; i < k; i++) {
            if (fronts[i] == reers[i]) {
                sb.append(fronts[i] + 1).append("\n");
                count++;
            }
        }
        if (count == 0) {
            System.out.println();
        } else {
            System.out.print(sb);
        }
    }
}


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

int main() {
  ll tmp,n,m,l,r=1000000000,ans;
  cin >> n >> m;
  rep(i,m){
  	cin >> tmp;	l=max(l,tmp);
  	cin >> tmp;	r=min(r,tmp);
  }
  cout << max(r-l+1,(ll)0) << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <queue>
#include <algorithm>
#include <iomanip>
#include <stack>
#include <cstring>
#include <string>

using namespace std;
#define long long long

const int N = 1e2 + 10;
const long INF = 1e9 + 7;

int n;
long total, v[N], w[N], f[N][(int) 1e5 + 10];

int main()
{
//    freopen(".INP", "r", stdin);
//    freopen(".OUT", "w", stdout);
    cin.tie(NULL); ios_base::sync_with_stdio(false);

    cin >> n >> total;
    for (int i = 1; i <= n; ++i) cin >> w[i] >> v[i];

    for (int i = 1; i <= n; ++i)
        for (long j = 1; j <= total; ++j) {
            f[i][j] = f[i - 1][j];
            if (w[i] <= j) f[i][j] = max(f[i][j], f[i - 1][j - w[i]] + v[i]);
        }
    cout << f[n][total];

    return 0;
}


Measured memory_bytes: 79360
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<bitset>
#include<vector>
#include<deque>
#include<list>
#include<queue>
#include<map>
#include<set>
#include<stack>
#include<cmath>
#include<iomanip>
#include <functional>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int mod = 1000000007;
const long long INF = 1LL << 55;
const double EPS = 1e-10;
//cout << fixed << std::setprecision(9)
//memset(a, 0, sizeof(a));
//--------------------------

int gcd(int a, int b) {
	if (!b) return a;
	return gcd(b, a % b);
}

int n;
int a[100005];

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

	int ans = a[0];
	for (int i = 0;i < n;i++) ans = gcd(ans, a[i]);

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define ll long long
#define INF 1000000005
#define MOD 1000000007
#define EPS 1e-10
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define srep(i,s,t) for(int i=(int)(s);i<(int)(t);++i)
#define each(a,b) for(auto& (a): (b))
#define all(v) (v).begin(),(v).end()
#define len(v) (int)(v).size()
#define zip(v) sort(all(v)),v.erase(unique(all(v)),v.end())
#define cmx(x,y) x=max(x,y)
#define cmn(x,y) x=min(x,y)
#define fi first
#define se second
#define pb push_back
#define show(x) cout<<#x<<" = "<<(x)<<endl
#define spair(p) cout<<#p<<": "<<p.fi<<" "<<p.se<<endl
#define sar(a,n) cout<<#a<<":";rep(pachico,n)cout<<" "<<a[pachico];cout<<endl
#define svec(v) cout<<#v<<":";rep(pachico,v.size())cout<<" "<<v[pachico];cout<<endl
#define svecp(v) cout<<#v<<":";each(pachico,v)cout<<" {"<<pachico.first<<":"<<pachico.second<<"}";cout<<endl
#define sset(s) cout<<#s<<":";each(pachico,s)cout<<" "<<pachico;cout<<endl
#define smap(m) cout<<#m<<":";each(pachico,m)cout<<" {"<<pachico.first<<":"<<pachico.second<<"}";cout<<endl

using namespace std;

typedef pair<int,int> P;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<P> vp;
typedef vector<string> vs;

const int MAX_N = 100005;

int sa[MAX_N], ta[MAX_N];

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s,t;
    cin >> s >> t;
    rep(i,len(s)){
        if(s[i] == 'A'){
            sa[i+1] = sa[i] + 1;
        }else{
            sa[i+1] = sa[i];
        }
    }
    rep(i,len(t)){
        if(t[i] == 'A'){
            ta[i+1] = ta[i] + 1;
        }else{
            ta[i+1] = ta[i];
        }
    }
    int q;
    cin >> q;
    rep(i,q){
        int a,b,c,d;
        cin >> a >> b >> c >> d;
        --a,--c;
        int v1 = (INF+sa[b]-sa[a]-(b-a-(sa[b]-sa[a]))) % 3;
        int v2 = (INF+ta[d]-ta[c]-(d-c-(ta[d]-ta[c]))) % 3;
        cout << ((v1 == v2) ? "YES" : "NO") << "\n";
    }
    return 0;
}


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

const int N = 1e5 + 1000;
int  main(){
	ll a,b,c;
	cin>>a>>b>>c;
	a -= c;
	if(a < 0) {
		b += a;
	}
	a = max(a,0LL);
	b = max(b,0LL);
	cout<<a<<' '<<b;
}

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

int main(){

    int n;

    cin >> n;
    int count = 0;
    bool cont =false;
    for(int i = 0; i < n; i++){
        int num1,num2;
        cin >> num1 >> num2;
        if(num1 == num2) {
            count++;
            if(count == 3) cont = true;
        }else{
            count = 0;
        }

    }
    if(cont){
        cout <<"Yes" <<endl;
    }else{
        cout <<"No" <<endl;
    }
    return 0;

}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#define itn int

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int h, w;
    cin >> h >> w;
    vector<vector<int>> b(h, vector<int>(w));
    int cnt = 0;
    vector<pair<int, int>> que;
    for (itn i = 0; i < h; i++) {
        string s;
        cin >> s;
        for (int j = 0; j < w; j++) {
            if (s[j] == '#') {
                b[i][j] = 1;
                que.emplace_back(i, j);
            }
            else cnt++;
        }
    }
    int dx[] = {-1, 1, 0, 0};
    int dy[] = {0, 0, -1, 1};
    int ans = 0;
    while (que.size()) {
        vector<pair<int, int>> nxt;
        for (auto &p : que) {
            for (int i = 0; i < 4; i++) {
                int x = p.first + dx[i], y = p.second + dy[i];
                if (0 <= x && x < h && 0 <= y && y < w && b[x][y] == 0) {
                    nxt.emplace_back(x, y);
                    b[x][y] = 1;
                }
            }
        }
        ans++;
        que = move(nxt);
    }
    cout << ans - 1 << endl;
}

Measured memory_bytes: 16752
# 入力の高速化
import sys
input = sys.stdin.readline
N, X = map(int, input().split())
L = [int(x) for x in input().split()]

ans = 1
point = 0

for i in range(N) :
    point += L[i]
    if point <= X :
        ans += 1

print(ans)


Measured memory_bytes: 3060
#include<stdio.h>

int n, A[50];

int solve(int i, int m)
{
	if (m == 0) return 1;
	if (i >= n) return 0;
	int res = solve(i + 1, m) || solve(i + 1, m - A[i]);
	return res;
}

int main()
{
	int q, M, i;

	scanf("%d", &n);
	for (i = 0; i < n; i++) scanf("%d", &A[i]);
	scanf("%d", &q);
	for (i = 0; i < q; i++)
	{
		scanf("%d", &M);
		if (solve(0, M)) printf("yes\n");
		else printf("no\n");
	}

	return 0;
}


Measured memory_bytes: 2092
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
//#include <math.h>

int min(int a, int b) {

	return (a < b) ? a : b;

}

int main() {

	int num, k;
	int y;
	int res = 0;
	int i;

	scanf("%d", &num);
	scanf("%d", &k);


	for (i = 0; i < num; i++) {
		scanf("%d", &y);
		res += min(y * 2, abs(y - k) * 2);

	}

	printf("%d", res);

	return 0;

}


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

struct node{
  int key;
  struct node *r,*l,*p;
};

typedef struct node Node;

Node *root,*nil;

void insert(int t){
  Node *x=root,*y=nil,*z;

  z=malloc(sizeof(Node));
  z->key = t;
  z->r=nil;
  z->l=nil;

  while(x!=nil){
    y=x;

    if(z->key < x->key){
      x = x->l;
    }
    else {
      x = x->r;
    }
  }

  z->p = y;
  if(y==nil)root = z;
  else {
    if(z->key < y->key){
      y->l = z;
    }
    else {
      y->r = z;
    }
  }
}

void inorder(Node *q){
  if(q==nil)return;

  inorder(q->l);
  printf(" %d",q->key);
  inorder(q->r);
}
void preorder(Node *q){
  if(q==nil)return;

  printf(" %d",q->key);
  preorder(q->l);
  preorder(q->r);
}

void find(int t){
  Node *aaa=root;

  while(1){
    if(aaa==nil){
      printf("no\n");
      break;
    }
    else if(aaa->key == t){
      printf("yes\n");
      break;
    }
    else if(aaa->key < t){
      aaa = aaa -> r;
    }
    else {
      aaa = aaa-> l;
    }
  }
}

int main(){
  int n,i,j,t;
  char s[10];

  root = nil;
  
  scanf("%d",&n);

  for(i=0;i<n;i++){
    scanf("%s",s);
    if(s[0]=='i'){
      scanf("%d",&t);
      insert(t);
    }
    else if(s[0]=='p'){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }
    else if(s[0]=='f'){
      scanf("%d",&t);
      find(t);
    }
  }
  return 0;
}



Measured memory_bytes: 20496
#include <bits/stdc++.h>
#define ABS(x) ((x) >= 0 ? (x) : -(x))

using namespace std;

int main () {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  long long x, k, d;
  cin >> x >> k >> d;
  if (x > 0) {
    long long cat = ABS(x) / ABS(d);
    if (k >= cat) {
      x -= cat * d;
      k -= cat;
    }
    else {
      x -= k * d;
      k = 0;
    }
  }
  else
    if (x < 0) {
      long long cat = ABS(x) / ABS(d);
      if (k >= cat) {
        x += cat * d;
        k -= cat;
      }
      else {
        x += k * d;
        k = 0;
      }
    }
  if (k & 1)
    cout << min (ABS(x - d), ABS(x + d));
  else
    cout << ABS(x);
}


Measured memory_bytes: 3644
package main

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

const (
	initialBufSize = 10000
	maxBufSize     = 1000000
)

var (
	sc *bufio.Scanner = func() *bufio.Scanner {
		sc := bufio.NewScanner(os.Stdin)
		buf := make([]byte, initialBufSize)
		sc.Buffer(buf, maxBufSize)
		sc.Split(bufio.ScanWords)
		return sc
	}()
	mod int = 1e9 + 7
)

func main() {
	N := getInt()
	var X []int
	avg := 0
	for i := 0; i < N; i++ {
		x := getInt()
		X = append(X, x)
		avg += x
	}
	avg = calcRound(float64(avg) / float64(N))
	
	sum := 0
	for i := 0; i < N; i++ {
		sum += pow(X[i] - avg, 2)
	}

	fmt.Println(sum)
}

func getInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func getString() string {
	sc.Scan()
	return sc.Text()
}

func abs(a int) int {
	return int(math.Abs(float64(a)))
}

func pow(p, q int) int {
	return int(math.Pow(float64(p), float64(q)))
}

func min(nums ...int) int {
	if len(nums) == 0 {
		panic("funciton min() requires at least one argument.")
	}
	res := nums[0]
	for i := 0; i < len(nums); i++ {
		res = int(math.Min(float64(res), float64(nums[i])))
	}
	return res
}

func max(nums ...int) int {
	if len(nums) == 0 {
		panic("funciton max() requires at least one argument.")
	}
	res := nums[0]
	for i := 0; i < len(nums); i++ {
		res = int(math.Max(float64(res), float64(nums[i])))
	}
	return res
}

func strSearch(a []string, b string) bool {
	for i := 0; i < len(a); i++ {
		if a[i] == b {
			return true
		}
	}
	return false
}

func printIntArray(array []int) {
	strArray := fmt.Sprint(array)
	fmt.Println(strArray[1 : len(strArray) - 1])
}

func calcMod(x int) int {
	return x % mod
}

func calcRound(x float64) int {
	result := int(x)
	if int(x * 10) % 10 >= 5 {
		result++
	}
	return result
}

Measured memory_bytes: 640
#include <iostream>
using namespace std;
 
int main(void)
{
	int N;
	int count = 1;
	cin >> N;
	int highest;
	cin >> highest;
	for (int i = 1; i < N; i++) {
		int H;
		cin >> H;
		if (highest <= H) {
			count++;
			highest = H;
		}
 
	}
	cout << count << endl;
 
	return 0;
}

Measured memory_bytes: 256
# -*- coding:utf-8 -*-
a, b, c, x = (int(input()), int(input()), int(input()), int(input()))
factor = []
for tmp in range(a+1):
    for tmp2 in range(b+1):
        for tmp3 in range(c+1):
            if 500*tmp+100*tmp2+50*tmp3 == x:
                factor.append((tmp,tmp2,tmp3))
print(len(factor))

Measured memory_bytes: 3188
import java.util.*;

public class Main {
    //-------------------------------------------------------------//
    public static final void main(String[] args) {
        new Main().solve();
    }
    //-------------------------------------------------------------//
    private final Scanner sc = new Scanner(System.in);
    void solve() {
        int N = sc.nextInt();
        int M = sc.nextInt();
        long[] cnt = new long[N];
        Arrays.fill(cnt, 0L);
        for (int i = 0; i < M; i++) {
            cnt[sc.nextInt() - 1]++;
            cnt[sc.nextInt() - 1]++;
        }
        boolean check = true;
        for (int i = 0; i < N; i++) {
            if (cnt[i] % 2 == 1)
                check = false;
        }
        if (check) System.out.println("YES");
        else System.out.println("NO");
    }
}

Measured memory_bytes: 85992
#include <iostream>
#include <algorithm>
#include <vector>
#include <math.h>
#include <stdio.h>
using namespace std;
int main(int argc, char* argv[])
{
	int N,i;
	cin>>N;
	vector<int> x(N),y(N);
	for (i=0;i<N;i++){
		cin>>x[i]>>y[i];
	}
	vector<int> path;
	for (i=0;i<N;i++){
		path.push_back(i);
	}
	int n=0;
	double d=0;
	do {
		for (i=0;i<N-1;i++){
			int Xij=x[path[i]]-x[path[i+1]];
			int Yij=y[path[i]]-y[path[i+1]];			
			d+=sqrt((double)(Xij*Xij + Yij*Yij));
		}
		n++;
	} while (next_permutation(path.begin(), path.end()));
	d/=n;
	printf("%.10f\n",d);	
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int h,n,a[1009],b[1009];
vector<int>dp;
int main() {
	scanf("%d%d",&h,&n);
	for(int i=0;i<n;i++) scanf("%d%d",a+i,b+i);
	dp.push_back(0);
	for(int j=1;;j++) {
		dp.push_back(0);
		for(int i=0;i<n;i++)
			if(j>=b[i])
				dp[j]=max(dp[j],dp[j-b[i]]+a[i]);
		if(dp[j]>=h) {
			printf("%d\n",j);
			return 0;
		}
	}
}

Measured memory_bytes: 526420
N, M = map(int, input().split())
seitou = [0 for _ in range(N)]
penalty = [0 for _ in range(N)]

for i in range(M):
	S = list(input().split())
	# print(S)
	num = int(S[0])
	res = S[1]
	if res == "AC":
		seitou[num - 1] = 1
	else:
		if seitou[num - 1] == 0:
			penalty[num - 1] += 1
			
# print(*seitou)
# print(*penalty)
print(sum(seitou), end=" ")

ans = 0

for i in range(N):
	if seitou[i] == 1:
		ans += penalty[i]
print(ans)

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

int f(int n){
 if(n % 2 == 0) return n / 2;
  else return 3 * n + 1;
}

int main(void){
  int N, T, c, tin, min_c;
  cin >> N >> T;
  min_c = 10000;
  for(int i = 0; i < N; i++){
    cin >> c >> tin;
    if(tin <= T){
      if(c < min_c) min_c = c;
    }
    
  }
  if(min_c == 10000) cout << "TLE";
  else cout << min_c;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod=1e9+7;
inline int add(int a,int b){a+=b;return a>=mod?a-mod:a;}
inline int sub(int a,int b){a-=b;return a<0?a+mod:a;}
inline int mul(int a,int b){return (ll)a*b%mod;}
inline int qpow(int a,int b){int ret=1;for(;b;b>>=1,a=mul(a,a))if(b&1)ret=mul(ret,a);return ret;}
/* math */


int n,k;
const int N=2e3+5;
int fac[N*N],ifac[N*N];
inline void init(int n){
	fac[0]=ifac[0]=1;for(int i=1;i<=n;i++)fac[i]=mul(fac[i-1],i);
	ifac[n]=qpow(fac[n],mod-2);for(int i=n-1;i;i--)ifac[i]=mul(ifac[i+1],i+1);
}
inline int comb(int a,int b){
	if(b>a)return 0;
	return mul(fac[a],mul(ifac[b],ifac[a-b]));
}
int f[N][N];
int main()
{
	cin>>n>>k;
	if(k==1){
		puts("1");
		return 0;
	}
	init(n*k);
	f[0][0]=1;
	for(int j=1;j<=n;j++){
		f[0][j]=mul(f[0][j-1],comb(j*(k-1)-1,k-2));
	}
	for(int i=1;i<=n;i++){
		for(int j=i;j<=n;j++){
			f[i][j]=add(f[i-1][j],mul(f[i][j-1],comb(j*(k-1)+i-1,k-2)));
		}
	}
	printf("%d\n",mul(f[n][n],fac[n]));
	return 0;
}


Measured memory_bytes: 47360
#include <bits/stdc++.h>
using namespace std;
 
int main() {

    int n, h, w;
    cin >> n >> h >> w;
    int ans = 0;
    for(int i = 0; i < n; ++i){
        int a, b;
        cin >> a >> b;
        if(a >= h && b >= w)++ans;
    }

    cout << ans << endl;

}

Measured memory_bytes: 256
N, P = map(int, input().split())
A = list(map(int, input().split()))

resZero = resOne = 0
for a in A:
    if a % 2 == 0:
        resZero += 1
    else:
        resOne += 1

if resOne == 0:
    if P == 1:
        print(0)
    else:
        print(2 ** N)
else:
    print(2**(N-1))

Measured memory_bytes: 38256
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<string>
#include<stack>
#include<queue>
#include<vector>
#include<algorithm>
#include <iomanip>
typedef long long int ll;
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define REP(i,n) for (int i=0;i<(n);i++)
#define EREP(i,n) for (int i=1;i<=(n);i++)
#define ALL(a) (a).begin(),(a).end()
#define EVEL 1

#ifndef EVEL
#define DEB(X) cout << #X << ":" <<X<<" " ;
#define TF(f) f ? cout<<"true  " : cout<<"false ";
#define END cout<<"\n";
#else
#define DEB(X) {X=X;}
#define TF(f) {f=f;}
#define END {}
#endif
const int MOD = 1000000007;
const int INF = 1000000;
#define NMAX 50
#define MAX 10

    int N,M,A,B;
    ll temp=0,id=0,mem,yui=1,sum=0;
    ll x[100010],y[100010];
    ll w,h;
    bool fir=true;



int main(){
    ios_base::sync_with_stdio(false);
    cin>>N>>M;
    REP(i,N)cin>>x[i];
    REP(i,M)cin>>y[i];
    REP(i,N){
        w+=(x[i]%MOD)*((i-(N-1)+i)%MOD);
        w%=MOD;
        DEB(w)
    }END
    REP(i,M){
        h+=(y[i]%MOD)*((i-(M-1)+i)%MOD);
        h%=MOD;
        DEB(h)
    }END
    cout<<w*h%MOD<<endl;
}
//ABC057 Maximum Average Sets


Measured memory_bytes: 1792
import bisect
import math
import sys
from collections import defaultdict
from copy import copy
from heapq import heapify, heappop, heappush, heapreplace
from operator import itemgetter
from queue import LifoQueue, PriorityQueue, Queue

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines


def main():
    N, M = map(int, readline().split())
    S, T = readlines()

    def gcd(a, b):
        while b > 0:
            a, b = b, a%b
        return a
    
    GCD = gcd(N, M)
    if S[0::N//GCD] == T[0::M//GCD]:
        print(N*M//GCD)
    else:
        print(-1)
    
if __name__ == "__main__":
    main()

Measured memory_bytes: 4336
k = int(input())
x = [1,2,3,4,5,6,7,8,9]
i = 0
xa = x.append
while len(x) < k:
  if x[i]%10 == 0:
    xa(10*x[i])
    xa(10*x[i]+1)
  elif x[i]%10 == 9:
    xa(10*x[i]+8)
    xa(10*x[i]+9)
  else:
    j = x[i]%10
    xa(10*x[i]+j-1)
    xa(10*x[i]+j)
    xa(10*x[i]+j+1)
  i += 1
print(x[k-1])  
  
  
  

Measured memory_bytes: 7172
module Main where

import Data.List

main :: IO ()
main =  putStr . unlines . map (unwords . map show . sort) . unfoldr phi . map (map readInt . words) . lines =<< getContents

phi :: [[Int]] -> Maybe ([Int],[[Int]])
phi [] = Nothing
phi ([0,0]:_) = Nothing
phi (x:xs) = Just (x,xs)

readInt :: String -> Int
readInt = read

Measured memory_bytes: 4572
#include<bits/stdc++.h>
#define fo(i,a,b) for(int i=(a);i<(b);i++)
#define qi queue<int>
#define vi vector<int>
#define ll long long
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define pii pair<int,int>
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define fi first
#define se second 
#define prq priority_queue
#define foreach(it,c) for(__typeof((c).begin()) it=c.begin();it!=c.end();it++)
//#define KEY_DOWN(VK_NONAME) ((GetAsyncKeyState(VK_NONAME) & 0x8000) ? 1:0)
using namespace std;
inline ll read(){
	ll x=0;
	int f=1;
	char c=getchar();
	for(;!isdigit(c);c=getchar()) if(c=='-')f=-f;
	for(;isdigit(c);c=getchar())x=x*10+(c-'0');
	return x*f;
}
inline void out(int x){
	if(x>=10)out(x/10);
	putchar(x%10+'0');
}
int n,a[202020];
int main(){
	//freopen("a.in","r",stdin);
	//freopen("a.out","w",stdout); 
	cin>>n;
	int ans=0;
	fo(i,0,n){
		cin>>a[i];
		ans^=a[i];
	}
	fo(i,0,n-1)cout<<(ans^a[i])<<' ';
	cout<<(ans^a[n-1])<<endl;
	return 0;
}


Measured memory_bytes: 4400
N,L = map(int,input().split())
T = [L + n for n in range(N)]
del_taste = []
for i in range(N):
    del_taste.append(sum(T) - T[i])
diff = []
for i in range(N):
    diff.append(abs(sum(T)-del_taste[i]))
print(del_taste[diff.index(min(diff))])

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

using namespace std;

const double PI = 3.14159265358979323846;
typedef long long ll;
const double EPS = 1e-9;
#define rep(i, n) for (int i = 0; i < (n); ++i)
//#define rep(i, n) for (ll i = 0; i < (n); ++i)
//typedef pair<ll, ll> P;
typedef pair<double, double> P;
const ll INF = 10e17;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
#define ret() return 0;

double equal(double a, double b) {
    return fabs(a - b) < DBL_EPSILON;
}

std::istream &operator>>(std::istream &in, set<string> &o) {
    string a;
    in >> a;
    o.insert(a);
    return in;
}

std::istream &operator>>(std::istream &in, queue<int> &o) {
    ll a;
    in >> a;
    o.push(a);
    return in;
}

bool contain(set<int> &s, int a) { return s.find(a) != s.end(); }

//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);
//const ll mod = 1e10;

typedef priority_queue<ll, vector<ll>, greater<ll> > PQ_ASK;

const int mod = 1000000007;

struct mint {
    ll x; // typedef long long ll;
    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;
    }

    friend std::istream &operator>>(std::istream &in, mint &o) {
        ll a;
        in >> a;
        o = a;
        return in;
    }

    friend std::ostream &operator<<(std::ostream &out, const mint &o) {
        out << o.x;
        return out;
    }

};


ll sum(ll a, ll b) {
    ll k = b - a + 1;
    return k * (a + b) / 2;
}

int main() {
    ll n, k;
    cin >> n >> k;

    mint ans = 0;

    for (ll i = k; i <= n + 1; i++) {
        ll mi = sum(0, i - 1);
        ll ma = sum(n - i + 1, n);

        ll now = ma - mi + 1;
        ans += now;
    }

    cout << ans << endl;
}


Measured memory_bytes: 3612
#include<iostream>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<set>
#include<string>
#include<map>
#include<string.h>
#include<complex>
#include<math.h>
#include<queue>
#include<time.h>
using namespace std;
typedef long long int llint;
typedef pair<int, int> pint;
typedef vector<int> vint;
typedef vector<llint> vllint;
typedef vector<pair<int, int>> vpint;
typedef vector<pair<llint, llint>> vpllint;
#define rep(i,n) for(int i=0;i<n;i++)
#define drep(i,n) for(int i=n-1;0<=i;i--)
#define yes(ans) if(ans)cout<<"yes"<<endl;else cout<<"no"<<endl;
#define Yes(ans) if(ans)cout<<"Yes"<<endl;else cout<<"No"<<endl;
#define YES(ans) if(ans)cout<<"YES"<<endl;else cout<<"NO"<<endl;
#define POSSIBLE(ans) if(ans)cout<<"POSSIBLE"<<endl;else cout<<"IMPOSSIBLE"<<endl;
#define Pi 3.1415926535897932384626

class UnionFind {
public:
	//親の番号を格納する。親だった場合は-(その集合のサイズ)
	vector<int> Parent;

	//作るときはParentの値を全て-1にする
	//こうすると全てバラバラになる
	UnionFind(int N) {
		Parent = vector<int>(N, -1);
	}

	//Aがどのグループに属しているか調べる
	int root(int A) {
		if (Parent[A] < 0) return A;
		return Parent[A] = root(Parent[A]);
	}

	//自分のいるグループの頂点数を調べる
	int size(int A) {
		return -Parent[root(A)];//親をとってきたい
	}

	//AとBをくっ付ける
	bool connect(int A, int B) {
		//AとBを直接つなぐのではなく、root(A)にroot(B)をくっつける
		A = root(A);
		B = root(B);
		if (A == B) {
			//すでにくっついてるからくっ付けない
			return false;
		}

		//大きい方(A)に小さいほう(B)をくっ付けたい
		//大小が逆だったらひっくり返しちゃう。
		if (size(A) < size(B)) swap(A, B);

		//Aのサイズを更新する
		Parent[A] += Parent[B];
		//Bの親をAに変更する
		Parent[B] = A;

		return true;
	}
};

//aとbの最大公約数を求めるよ
long long GCD(long long a, long long b) {
	if (b == 0) return a;
	else return GCD(b, a % b);
}

// 返り値: a と b の最大公約数
// ax + by = gcd(a, b) を満たす (x, y) が格納される
long long extGCD(long long a, long long b, long long& x, long long& y) {
	if (b == 0) {
		x = 1;
		y = 0;
		return a;
	}
	long long d = extGCD(b, a % b, y, x);
	y -= a / b * x;
	return d;
}

bool check(int a, int b) {
	return a > b;
}

// mod. m での a の逆元 a^{-1} を計算する
long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}

//aCbを1000000007で割った余りを求める
llint convination(llint a, llint b) {
	llint ans = 1;
	for (llint i = 0; i < b; i++) {
		ans *= a - i;
		ans %= 1000000007;
	}
	for (llint i = 1; i <= b; i++) {
		ans *= modinv(i, 1000000007);
		ans %= 1000000007;
	}
	return ans;
}

int main() {
	double r;
	cin >> r;
	printf("%.15f %.15f\n", r * r * Pi, 2 * r * Pi);
	return 0;
}


Measured memory_bytes: 3200