akhauriyash/Code-Regression huggingface dataset:
n = int(input())
aa = list(map(int, input().split()))
sol = 0
for i in range(n-2):
    for j in range(i+1, n-1):
        for k in range(j+1, n):
            a, b, c = aa[i], aa[j], aa[k]
            if a != b and b != c and a != c and a+b > c and a+c > b and b+c > a:
                sol += 1
print(sol)

Measured memory_bytes: 68108
s = (input()[::-1]) # 入力文字列を逆順でsに格納
n = len(s)
counts = [0]*2019
counts[0]=1
b = 1
num = 0
for i in s:
    num += int(i)*b
    num %=2019
    b *=10
    b %=2019
    counts[num]+=1

# print(counts)
ans = 0
for j in counts:
    ans +=j*(j-1)/2


print(int(ans))

Measured memory_bytes: 9212
use std::io;

fn main() {
  let mut word = String::new();
  io::stdin().read_line(&mut word).ok();
  let vec: Vec<&str> = word.split_whitespace().collect();
  let a: i32 = vec[0].trim().parse().ok().unwrap();
  let b: i32 = vec[1].trim().parse().ok().unwrap();
  let ans = a * b;
  println!("{}", ans);
}


Measured memory_bytes: 2064
#include <bits/stdc++.h>
using namespace std;
#define dhoom ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);  
typedef long long ll;
typedef long double ld;
const ll inf = 1e18;
const int nax = 2e6 + 7;
const ll mod = 1e9 + 7;
//ll tree[4 * nax];
//9uS-22RSwk7gQqh
ll gcd(ll a , ll b){
	if(b == 0) return a;
	return gcd(b , a % b);	
}
ll lcm(ll a , ll b){
	ll g = gcd(a , b);
	ll lc = (a/g) * b;
	return lc;
}
char a[55][55];
int h , w;
int main()
{
	int a , d , b , c;
	cin >> a >> b >> c >> d;
	if(abs(a-c) <= d || (abs(a - b) <= d && abs(b-c) <= d))
		cout << "Yes" << endl;
	else
		cout << "No" << endl;

	return 0;
} 



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

int main() {
  int N; cin >> N;
  vector<int> a(N+2);
  vector<int> b(N+1);
  a.at(0)=0;
  for(int i=1; i<=N; i++) cin >> a.at(i);
  a.at(N+1)=0;
  
  int before=0;
  for(int i=0; i<=N; i++){
    b.at(i)=abs(a.at(i)-a.at(i+1));
    before+=b.at(i);
  }
  
  for(int i=1; i<=N; i++)
    cout << before-b.at(i-1)-b.at(i)+abs(a.at(i-1)-a.at(i+1)) << endl;
  
}

Measured memory_bytes: 2048
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  char c;
  cin >> c;
  if ( c == 'a' || c == 'i' || c == 'u' || c == 'e' || c == 'o' )
    cout << "vowel" << endl;
  else cout << "consonant" << endl;

}


Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Scanner;

public class Main {

	static int[][] map;
	static int[][] directions8 = { { -1, -1 }, { -1, 0 }, { -1, 1 }, { 0, -1 }, { 0, 1 }, { 1, -1 }, { 1, 0 },
			{ 1, 1 } };
	static int[][] directions4 = { { -1, 0 }, { 1, 0 }, { 0, -1 }, { 0, 1 } };
	static double ans;

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		while (true) {

			int D = sc.nextInt();
			int E = sc.nextInt();

			if ((D | E) == 0) {
				break;
			}

			int tmpX = 0;
			int tmpY = D;

			ans = Double.MAX_VALUE;

			for (int j = 0; j <= D; j++) {
				tmpX = j;
				tmpY = D - j;
				double tmpAns = Math.sqrt(tmpX * tmpX + tmpY * tmpY) - E;
				tmpAns = Math.abs(tmpAns);
				ans = Double.min(ans, tmpAns);
			}
			System.out.println(ans);
		}
	}

	// 素数判定
	static boolean isPrime(long n) {
		if (n == 2)
			return true;
		if (n < 2 || n % 2 == 0)
			return false;

		int i = 3;
		while (i <= Math.sqrt(n)) {
			if (n % i == 0)
				return false;
			else
				i += 2;
		}
		return true;
	}

	// BFS用に二つの配列を足し算する
	static int[] addArrayElms(int[] a, int[] b) {
		int[] c = new int[a.length];
		for (int i = 0; i < a.length; i++) {
			c[i] = a[i] + b[i];
		}
		return c;
	}

	// //二分探索
	// k <= num となる最小の配列要素kのインデックスを返す
	static private int binarySearch(long num, long[] orderedArray) {
		int lowerBorder = -1;
		int upperBorder = orderedArray.length;
		int mid;

		while (upperBorder - lowerBorder > 1) {
			mid = (upperBorder + lowerBorder) / 2;
			if (orderedArray[mid] <= num) {
				lowerBorder = mid;
			} else {
				upperBorder = mid;
			}
		}
		return lowerBorder;
	}

	// 二分探索
	// k <= num となる最小のList要素kのインデックスを返す
	static private int binarySearch(long num, ArrayList<Long> orderedList) {
		int lowerBorder = -1;
		int upperBorder = orderedList.size();
		int mid;

		while (upperBorder - lowerBorder > 1) {
			mid = (upperBorder + lowerBorder) / 2;
			if (orderedList.get(mid) <= num) {
				lowerBorder = mid;
			} else {
				upperBorder = mid;
			}
		}
		return lowerBorder;
	}

	// aとbの最小公倍数を求める
	public static int gcd(int a, int b) {
		return b == 0 ? a : gcd(b, a % b);
	}

	public static long gcd(long a, long b) {
		return b == 0 ? a : gcd(b, a % b);
	}
}



Measured memory_bytes: 26512
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <fstream>
#include <numeric>
using namespace std;
typedef long long int ll;

#define EPS (1e-7)
#define INF 1e18
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))
#define PI (acos(-1))

#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define rep(i, init, n) for(int i = init; i <(int)(n); i++)

int main() {

    ll N, K;
    cin >> N >> K;
    ll tmp = N % K;
    tmp = min(tmp, K - tmp);
    cout << tmp << endl;

    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<functional>
#include<vector>
#include<queue>
#include<stack>
#include<set>
using namespace std;
#define MOD 1000000007
#define f(i,n) for(int i=0;i<int(n);i++)
#define N 200000
int main(){
	bool a[N];
	int n, m, x, s;
	scanf("%d", &n);
	f(i, n)a[i] = true;
	scanf("%d", &m);
	f(i, m){
		scanf("%d", &x);
		a[x - 1] = false;
	}
	scanf("%d", &m);
	f(i, m){
		scanf("%d", &x);
		a[x - 1] = true;
	}
	s = 0;
	scanf("%d", &m);
	f(i, m){
		scanf("%d", &x);
		if (a[x - 1])s++;
	}

	printf("%d\n", s);
	return 0;
}


Measured memory_bytes: 2776
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repp(i, a, b) for (int i = a; i <= (b); ++i)
#define repr(i, a, b) for (int i = a; i >= (b); --i)
#define bit(n) (1LL << (n))
#define len(x) ((ll)(x).size())
#define debug(var) cout << "[" << #var << "]\n" << var << "\n\n"
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1000000007;
const double EPS = 1e-9;

template <typename T>
ostream& operator<<(ostream& s, const vector<T>& v) {
  int len = v.size();
  for (int i = 0; i < len; ++i) {
    s << v[i];
    if (i < len - 1)
      s << ' ';
  }
  return s;
}

template <typename T>
ostream& operator<<(ostream& s, const vector<vector<T>>& vv) {
  int len = vv.size();
  for (int i = 0; i < len; ++i) {
    s << vv[i];
    if (i != len - 1)
      cout << '\n';
  }
  return s;
}

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

template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

__attribute__((constructor)) void initial() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
}

signed main() {
  int N;
  cin >> N;

  int ans = (N - 2) * 180;
  cout << ans << "\n";
}

Measured memory_bytes: 256
#include <stdio.h>

int grading(int pm, int pe, int pj);

int main(void)
{
    int number;
    int pm, pe, pj;
    while (1) {
      scanf("%d", &number);// number of students to grade                                                                                                                            
      if (number == 0) {
        break;
      } else {
        for (int j = 0; j < number; j++) {
          int grade;
          scanf("%d %d %d", &pm, &pe, &pj);
          grade = grading(pm, pe, pj);
          if (grade == 1) {// grade 1 means class A                                                                                                                                  
            printf("A\n");
          } else if (grade == 2) {//grade 2 means class B                                                                                                                            
            printf("B\n");
          } else if (grade == 3) {//grade 3 means class C                                                                                                                            
            printf("C\n");
          }
        }
      }
    }
    return 0;
}

int grading(int pm, int pe, int pj)
{
    int grade;
    if ((pm == 100 || pe == 100 || pj == 100)) {
      grade = 1;
    } else if ((pm + pe) / 2 >= 90) {
      grade = 1;
    } else if ((pm + pe + pj) / 3 >= 80) {
      grade = 1;
    } else if ((pm + pe + pj) / 3 >= 70) {
      grade = 2;
    } else if ((pm + pe + pj) / 3 >= 50 && (pm >=80 || pe >=80)) {
      grade = 2;
    } else {
      grade = 3;
    }
    return grade;
}

Measured memory_bytes: 1012
#include <bits/stdc++.h>
using namespace std;
const int INF=0x3f3f3f3f;
#define mem(a,n) memset(a,n,sizeof(a))
typedef long long ll;
const int N=50+5;
int main()
{
    int n,pos,mx,tmp,flag;
    while(~scanf("%d",&n))
    {
        pos=1,mx=0;
        for(int i=1;i<=n;i++)
        {
            scanf("%d",&tmp);
            if(abs(tmp)>mx) mx=abs(tmp),pos=i,flag=(tmp<0)?1:0;
        }
        printf("%d\n",2*n-2);
        for(int i=1;i<=n;i++)
            if(i!=pos) printf("%d %d\n",pos,i);
        if(flag)
            for(int i=n;i>1;i--)
            printf("%d %d\n",i,i-1);
        else
            for(int i=2;i<=n;i++)
            printf("%d %d\n",i-1,i);
    }
    return 0;
}


Measured memory_bytes: 3792
n=int(input())
arr=list(input() for _ in range(n))
dic={}

for i in range(n):
  if arr[i] not in dic:
    dic[arr[i]]=1
  else:
    dic[arr[i]]+=1
     
largest=max(dic.values())
ans=[]
for keys in dic.keys():
  if dic[keys]==largest:
    ans.append(keys)
ans=sorted(ans)

for words in ans:
  print(words)

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

int top, S[1000];

void push(int x)
{
	//topを加算してからその位置へ挿入
	S[++top]=x;
}

int pop()
{
	top--;
	//topが指していた要素を返す
	return S[top+1];
}

int main()
{
	int a , b;
	top = 0;
	char s[100];
	while(scanf("%s",s) != EOF){
		if(s[0] == '+'){
			a = pop();
			b = pop();
			push(a+b);
		}else if(s[0] == '-'){
			b = pop();
			a = pop();
			push(a-b);
		}else if(s[0] == '*'){
			a = pop();
			b = pop();
			push(a*b);
		}else{
			push(atoi(s));
		}
	}
	
	printf("%d\n",pop());
	
	return 0;
}


Measured memory_bytes: 2092
#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  string s;
  cin >> s;
  int l = s.length();
  sort(s.begin(), s.end());
  long long ans = (long long)l * (l - 1) / 2 + 1;
  int crr = 0;
  int nxt, mlt;
  for (int i = 0; i < 26; i++) {
    int nxt = upper_bound(s.begin(), s.end(), 'a' + i) - s.begin();
    mlt = nxt - crr;
    ans -= (long long)mlt * (mlt - 1) / 2;
    crr = nxt;
  }
  cout << ans << '\n';
  return 0;
}

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

int main(){
  int a, b, c;
  cin >> a >> b >> c;
  
  int abc,acb,bac,bca,cab,cba;
  abc=abs(b-a)+abs(c-b);
  acb=abs(c-a)+abs(b-c);
  bac=abs(a-b)+abs(c-a);
  bca=abs(c-b)+abs(a-c);
  cab=abs(a-c)+abs(b-a);
  cba=abs(b-c)+abs(a-b);
  cout << min({abc,acb,bac,bca,cab,cba}) << endl;

  
}

Measured memory_bytes: 256
while True:
    m, f, r = map(int, input().split())
    if m == -1 and f == -1 and r == -1:
        break
    if m == -1 or f == -1:
        print('F')
    elif m + f >= 80:
        print('A')
    elif m + f >= 65:
        print('B')
    elif m + f >= 50 or r >= 50:
        print('C')
    elif m + f >= 30:
        print('D')
    else:
        print('F')


Measured memory_bytes: 5592
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using pi = pair<int, int>;
using Pld = pair<ld, ld>;
using Vec = vector<ll>;
using VecP = vector<pi>;
using VecB = vector<bool>;
using VecC = vector<char>;
using VecD = vector<ld>;
using VecS = vector<string>;
using Graph = vector<VecP>;
#define REP(i, m, n) for(ll (i) = (m); (i) < (n); ++(i))
#define REPR(i, m, n) for(ll (i) = (m); (i) > (n); --(i))
#define rep(i, n) REP(i, 0, n)
#define R cin>>
#define repr(i, n) REPR(i, n, 0)
#define all(s) (s).begin(), (s).end()
#define pb push_back
#define mp make_pair
#define fs first
#define sc second
#define in(a) insert(a)
#define P(p) cout<<(p)<<endl;
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define SORT(a) sort((a).begin(), (a).end())
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<long long int> vll;
typedef vector<string> vs;
void sonic(){ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);}
void setp(const ll n){cout << fixed << setprecision(n);}
const ll INF = 1e9+1;
const ll LINF = 1e18+1;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const ld PI = acos(-1);
const ld EPS = 1e-11;
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>bool chmin(T &a,const T &b){if(a>b){a=b;return true;}return false;}
template<typename T> void co(T e){cout << e << "\n";}
template<typename T> void co(const vector<T>& v){for(const auto& e : v)
    { cout << e << " "; } cout << "\n";}
ll gcd(ll a, ll b) {
    if (a < b)swap(a, b);
    if (b == 0) return a;
    unsigned r;
    while ((r = a % b)) {
        a = b;
        b = r;
    }
    return b;
}
ll lcm(ll a, ll b) {
    ll g = gcd(a, b);
    return a * b / g;
}
bool prime(ll n) {
    for (ll i = 2; i <= sqrt(n); i++) {
        if (n%i == 0)return false;
    }
    return n != 1;
}

Vec fac, finv;

ll PowMod(ll a, ll n){
    if(n == 1) return a;
    if(n%2 == 0) return PowMod(a*a%MOD, n/2);
    return a*PowMod(a*a%MOD, n/2)%MOD;
}

ll combi(ll n, ll k){
    if(k>n) return 0;
    return fac[n]*finv[k]%MOD*finv[n-k]%MOD;
}


double memo[310][310][310];
double f(int i, int j, int k, int n) {
    if(i + j + k == 0) return 0.0;
    if(memo[i][j][k] != 0.0) return memo[i][j][k];
    double s = i + j + k;
    double ret = n - s;
    if(i) ret += (f(i - 1, j, k, n) + 1) * i;
    if(j) ret += (f(i + 1, j - 1, k, n) + 1) * j;
    if(k) ret += (f(i, j + 1, k - 1, n) + 1) * k;
    ret /= s;
    memo[i][j][k] = ret;
    return ret;
}



int main(){
    double n, r, a = 0, b = 0, c = 0;
    cin >> n;
    rep(i, n) {
        cin >> r;
        if (r == 1) a ++;
        else if (r == 2) b ++;
        else c ++;
    }
    cout << fixed << setprecision(15) << f(a, b, c, n) << endl;
}



Measured memory_bytes: 114252
l = [int(x) for x in input().split()]
ans = 0
for i in range(2):
  if l[i] == 1:
    ans += 300000
  elif l[i] == 2:
    ans += 200000
  elif l[i] == 3:
    ans += 100000
if l[0] == 1 and l[1] == 1:
  ans += 400000
print(ans)

Measured memory_bytes: 3064
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<iomanip>



#define REP(i,n) for (int i = 0; (i) < (n); ++ (i))

using namespace std;
int a,b,c;

int main(){
  cin >> a >> b >> c;
  cout << (a+b)*c/2 << endl;
  return 0;
}


Measured memory_bytes: 256
#include <cmath>
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>

#define endl '\n'
#define ll long long
#define M_PI 3.14159265358979323846

using namespace std;

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

	int r;
	cin >> r;

	cout << 2 * M_PI * r << endl;

	return 0;
}

Measured memory_bytes: 3804
#include <bits/stdc++.h>
using namespace std;
 
int main(){
    int N;
    cin >> N;
    vector<string> S(N);
    for(int i = 0; i < N; i++){
        cin >> S.at(i);
    }
    sort(S.begin(), S.end());
    int res = 0;
    for(int i = 0; i < N; i++){
        if(i == 0){
            res++;
        }else if(S.at(i) != S.at(i - 1)){
            res++;
        }
    }
    cout << res << endl;
}

Measured memory_bytes: 9592
#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
int  main()
{
    int a,b,k;
    while(cin>>a>>b>>k)
    {
        int t=1;
        int c[200];
        int num=max(a,b);
        for(int i=1;i<=num;i++)
        {
            if((a%i==0)&&(b%i==0))
            {
                //cout<<"i=="<<i<<endl;
                c[t++]=i;
            }
        }
        cout<<c[t-k]<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define rep2(i, a, n) for(ll i = a; i < (ll)(n); i++)
#define memi cout << endl
#define kono(n) cout << fixed << setprecision(n)
#define all(c) (c).begin(), (c).end()
#define pb push_back
#define hina cout << ' '
#define in(n) cin >> n
#define in2(n, m) cin >> n >> m
#define in3(n, m, l) cin >> n >> m >> l
#define out(n) cout << n
const ll mei = (ll)1e9 + 7;

int main(){
  ll a, b, c, d, e, f, s, t, u, v;
  double x, y;
  x = 0;
  v = 0;
  in3(a, b, c);
  in3(d, e, f);
  u = 100 * a;
  rep(i, f / (100 * a) + 1){
    rep(j, f / (100 * b) + 1){
      s = i * 100 * a + j * 100 * b;
      if(s == 0)
        continue;
      if(s > f)
        continue;
      rep(k, (s / 100 * e) / c + 1){
        rep(l, (s / 100 * e) / d + 1){
          t = k * c + l * d;
          if(s + t > f)
            continue;
          if(100 * t > s * e)
            continue;
          y = (double)t / (double)(s + t);
          if(x < y){
            x = y;
            u = s + t;
            v = t;
          }
        }
      }
    }
  }
  out(u);
  hina;
  out(v);
  memi;
}


Measured memory_bytes: 384
using System;
using System.Collections;
using System.Collections.Generic;

public class Prigram
{
	public static void Main()
	{
        string[] str = Console.ReadLine().Split(' ');
        int a,b;
        a = int.Parse(str[0]);
        b = int.Parse(str[1]);
        if (b % a == 0)
            Console.WriteLine(a + b);
        else
            Console.WriteLine(b-a);
    }
}


Measured memory_bytes: 11092
#include <bits/stdc++.h>
#define ALL(A) (A).begin(),(A).end()
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)

const ll mod = 1e9+7;
const ll INF = 2*1e18;
const int inf = 1e9+7;

using namespace std;
int ok[100005];
int s [100005];

bool isPrime(int num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false; // 偶数はあらかじめ除く

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            // 素数ではない
            return false;
        }
    }

    // 素数である
    return true;
}

void init(){
	ok[0] = 0;
	ok[1] = 0;
	ok[2] = 1;
	for(int i=3;i<=1e5+2;i++){
		if(isPrime(i))ok[i] = 1;
	}
	for(int i=1;i<=1e5;i++){
		if(ok[i]){
			if(ok[(i+1)/2])s[i] = 1;
		}
	}
	for(int i=1;i<=1e5;i++){
		s[i] +=s[i-1];
	}
}
int main(void){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int Q;
	cin >> Q;
	vector<int> l(Q),r(Q);
	rep(i,Q){
		cin >> l[i] >> r[i];
	}
	init();
	rep(i,Q){
		cout << s[r[i]] - s[max(l[i],1)-1] << endl;
	}
}

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

using namespace std;
#define ll long long
const int N=2e5+5;
int ans[N];
vector<int> adj[N];
void bfs()
{
    queue<int>q;
    q.push(1);
    memset(ans,-1,sizeof ans);
    ans[1]=1;
    while(!q.empty())
    {
        int u=q.front();
        q.pop();
        for(auto v:adj[u])
            if(ans[v]==-1)
            {
                ans[v]=u;
                q.push(v);
            }
    }
}
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    int n,m;
    cin>>n>>m;
    for(int i=0;i<m;i++)
    {
        int u,v;
        cin>>u>>v;
        adj[u].push_back(v);
        adj[v].push_back(u);
    }
    bfs();
    cout<<"Yes"<<'\n';
    for(int i=2;i<=n;i++)
        cout<<ans[i]<<'\n';

	return 0;
}


Measured memory_bytes: 13280
'''
N, M = map(int, input().split())
A = list(list(input()) for _ in range(N))
B = list(list(input()) for _ in range(M))

ans = 'No'
d = N - M + 1
for i in range(d):
    for j in range(d):
        cnt = 0
        for x in range(M):
            if A[i+x][j:j+M+1] == B[x]:
                cnt += 1
            else:
                break
        if cnt == M:
            ans = 'Yes'

print(ans)
'''
N, M = map(int, input().split())
A = list(list(input()) for _ in range(N))
B = list(list(input()) for _ in range(M))

ans = 'No'
d = N - M + 1
for i_a in range(d):
    for j_a in range(d):
        cnt = 0
        for i_b in range(M):
            for j_b in range(M):
                if A[i_a + i_b][j_a + j_b] == B[i_b][j_b]:
                    cnt += 1
                else:
                    break
            
        if cnt == M**2:
            ans = 'Yes'
            break
    if ans == 'Yse':
        break

print(ans)


Measured memory_bytes: 3064
let split target =
  Str.split (Str.regexp " ") target
  |> List.map int_of_string


let rec print_array arr =
  let n = Array.length arr in
  for i = 0 to n - 2 do
    Printf.printf "%d " arr.(i)
  done;
  Printf.printf "%d\n" arr.(n-1)


let insertion_sort l =
  let arr = Array.of_list l in
  let n = Array.length arr in
  for i = 1 to n - 1 do
    print_array arr;
    let v = arr.(i) in
    let j = ref (i-1) in
    while !j >= 0 && arr.(!j) > v do
      arr.(!j+1) <- arr.(!j);
      j := !j-1
    done;
    arr.(!j+1) <- v
  done;
  print_array arr


let () =
  let _ = read_int () in
  read_line ()
  |> split
  |> insertion_sort

Measured memory_bytes: 4060
#include <iostream>
#include <math.h>
#include <algorithm>
#include <vector>
#include <numeric>
#include <string>
using namespace std;
const double PI = acos(-1.0);
const string alp = "abcdefghijklmnopqrstuvwxyz";
const string ALP = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
const int INTMAX = 2147483647;
const int INTMIN = -2147483648;
const unsigned int UINTMAX = 4294967295;
const long LONGMAX = 9223372036854775807;
const long LONGMIN = -9223372036854775808;
const unsigned long ULONGMAX = 18446744073709551615;
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define REP1(i,n) FOR(i,1,n+1)
#define SUM(c) accumulate((c).begin(),(c).end(),0)
#define UNIQ(c) (c).erase(unique((c).begin(), (c).end()), (c).end());
#define Yn(b) puts(b?"Yes":"No")
#define YN(b) puts(b?"YES":"NO")

bool isprime(int p) {
  if (p==1) return false;
  FOR(i,2,p) {
    if (p%i==0) return false;
  }
  return true;
}

long a[200010];

bool chk(int l, int r){
  int rp=0;
  FOR (i,l,r){
    if (rp&a[i]) return false;
    rp+=a[i];
  }
  return true;
}

int main(){
  int n,k,a[100010],m;
  m = INTMAX;
  cin >> n >> k;
  REP(i,n){
    cin >> a[i];
    if (a[i]<m) m=a[i];
  }
  int t=n;
  REP(i,n){
    if (m==a[i]) {
      t--;
    }
  }
  //cout << t << ';' << k-1;
  cout << t/(k-1)+(t%(k-1)>0);
  return 0;
}

Measured memory_bytes: 640
#include<stdio.h>
#include<string.h>

void change(char str[]) {
	int len = strlen(str);
	int i;
	for (i = 0; i < len; i++) {
		if ('a' <= str[i] && str[i] <= 'z') {
			str[i] -= 32;
		}
	}
}

int main() {
	char t[10000];
	char key[10000];
	char eofstr[] = { "END_OF_TEXT" };
	int ans = 0;

	scanf("%s", key);
	change(key); //大文字に変換

	while (1) {
		scanf("%s", t);
		if (strcmp(t, eofstr) == 0) { //文字比較(END_OF_TEXT)
			break;
		}
		change(t); //大文字に変換
		if (strcmp(t, key) == 0) { //文字比較(1行目の文字)
			ans++;
		}
	}

	printf("%d\n", ans);
	return 0;
}


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

long GCD(long a, long b){
  long dividend, divisor;
  if (a >= b) {
    dividend = a;
    divisor = b;
  } else {
    dividend = b;
    divisor = a;
  }
  long remainder;
  while (1) {
    if (divisor == 1) {
      return 1;
    }
    remainder = dividend % divisor;
    if (remainder == 0) {
      break;
    } else {
      dividend = divisor;
      divisor = remainder;
    }
  }
  return divisor;
}

int main(void) {

  long a,b;
  scanf("%ld %ld", &a, &b);
  long gcd_ab = GCD(a,b);
  long number = gcd_ab;
  long count = 1;
  for (long i = 2; i <= sqrt(number); i++) {
    if (number%i == 0) {
      count++;
      number /= i;
      while (number%i == 0) {
        number /= i;
      }
    }
  }
  if (number != 1 && number != gcd_ab) {
    count++;
  }
  if (count == 1 && number != 1) {
    count++;
  }
  printf("%ld\n", count);

  return 0;
}

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

int main()
{
    string str;
    cin >> str;

    bool flag = false;
    for( int i = 0; str[ i ] != '\0'; i++ ){
        if( str[ i ] == 'A' && str[ i + 1 ] == 'C' ){
            flag = true;
        }
    }

    cout << ( flag == true ? "Yes" : "No" ) << endl;

    return EXIT_SUCCESS;
}

Measured memory_bytes: 256
n, k = map(int, input().split())

xs = [i for i in range(1, k + 1)]
xs.reverse()

dict_x = {}

mod = 10 ** 9 + 7

def pow(x, y):
    global mod
    a = 1
    b = x
    c = y
    while c > 0:
        if c & 1:
            a = (a * b) % mod
        b = (b * b) % mod
        c = c >> 1
    return a

answer = 0
for x in xs:
    num = k // x
    a = pow(num, n)
    # print(a)
    s = 2
    while x * s <= k:
        a -= dict_x[x * s]
        s += 1
    dict_x[x] = a
    answer = (answer + a * x) % mod

print(answer)

Measured memory_bytes: 21796
n, x = [ int(v) for v in input().split() ]



if x in [1,2*n-1]:
    print("No")
else:
    print("Yes")
    ans_list = [ None for i in range(2*n-1) ]
    num_list = [ i+1 for i in range(2*n-1) ]

    for i in range(3):
        ans_list[n-2+i] = x-1+i
        num_list[x-2+i] = None
    if x > n:
        ans_list[n+1] = 1
        num_list[0] = None
    elif x < n:
        ans_list[n-3] = 2*n-1
        num_list[2*n-2] = None
    
    num_list = [ i for i in num_list if i != None ]

    t = 0
    for i in ans_list:
        if i == None:
            print(num_list[t])
            t += 1
        else:
            print(i)


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

#define CEIL(a,b) ((a) / (b) + ((a) % (b) == 0 ? 0 : 1))

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

constexpr int MOD = 1'000'000'007;
constexpr int INF = 1'000'000'001;
constexpr ll LLINF = 4'000'000'000'000'000'001;
// constexpr int INF = 2147483647; // 2 * 1e9
// constexpr ll LLINF = 9223372036854775807; // 9 * 1e18

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

vector<int> g[100'000];

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(10);
    int n, m;
    cin >> n >> m;
    for(int i = 0; i < m; ++i){
        int a, b;
        cin >> a >> b;
        --a; --b;
        g[a].push_back(b);
    }
    int s, t;
    cin >> s >> t;
    --s; --t;
    vector<vector<int>> d(n, vector<int>(3, INF));
    d[s][0] = 0;
    priority_queue<piii, vector<piii>, greater<piii>> que;
    que.push({0, {s, 0}});
    while(!que.empty()){
        auto p = que.top(); que.pop();
        int a = p.second.first;
        int cost = p.first;
        int mod = p.second.second;
        if(d[a][mod] < cost) continue;
        for(auto && e : g[a]){
            int nmod = (mod+1) % 3;
            if(cost + 1 < d[e][nmod]){
                d[e][nmod] = cost + 1;
                que.push({cost+1, {e, nmod}});
            }
        }
    }
    if(d[t][0] == INF){
        cout << "-1\n";
    }
    else cout << d[t][0] / 3 << "\n";
    return 0;
}

Measured memory_bytes: 11264
#include <bits/stdc++.h>
#define repz(i, z, n) for (decltype(n) i = (z); i < (n); i++)
#define rep(i, n) for (decltype(n) i = 0; i < (n); i++)
#define ALL(v) v.begin(), v.end()
#define SIZE(v) ((ll)(v).size())
#define MAX(v) (*max_element(ALL(v)))
#define MIN(v) (*min_element(ALL(v)))
#define INF 1000000000000 //1E+12

// 略
#define PB push_back
#define F first
#define S second
#define MP make_pair
#define READ cin >>
#define PRINT cout <<
#define PYES cout << "Yes" << endl;
#define POK cout << "OK" << endl;
#define PNO cout << "No" << endl;
#define PNG cout << "NG" << endl;

using namespace std;

// デバッグ用
void debug_out() { cout << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T)
{
  cout << H << " ";
  debug_out(T...);
}

#ifdef _DEBUG
#define debug(...) debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif

// typedef
typedef long long ll;
typedef unsigned long long ul;

// const
// 円周率
const double pi = M_PI;
// mod用
// 1E+9 +7
const ll mod = (int)1e+9 + 7;
// 1s間で可能なループ回数2E+8回
// int        最大値2147483647         〜2E+9
// long long  最大値9223372036854775807〜9E+18
// 総和accumulate
// 単純リストvector<type> push_back
// 連想配列map<key,value> insert,
// 集合set<type>
// pair キーとバリューを格納 firstとsecondでアクセス
// 小数点指定 cout << fixed << setprecision(15) << endl;
// to_string<->stoi
// stoll(longlong)
// stod(double)
// deep copy v1->v2 copy(v1.begin(), v1.end(), back_inserter(v2) );
// 大文字65-90(-32)
// 小文字97-122(+32)

int main()
{
  // faster
  ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  ll a,b,c; cin >> a >> b >> c;
  if(c-a-b>0 and (c-a-b)*(c-a-b)>4*a*b) PYES
  else PNO


  return 0;
}


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

int main() {
	int N;
	cin >> N;
	vector <int> X(N);

	int xMax = 0;
	int xMin = 101;
	for (int i = 0; i < N; i++) {
		cin >> X.at(i);
		xMax = max(X.at(i), xMax);
		xMin = min(X.at(i), xMin);
	}

	int ans;
	for (int P = xMin; P < xMax; P++) {
		int toughness = 0;
		for (int i = 0; i < N; i++) {
			toughness += pow(X.at(i) - P, 2);
		}
		if (P == xMin) {
			ans = toughness;
		}
		else {
			ans = min(toughness, ans);
		}

	}

	cout << ans << endl;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#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 _GLIBCXX_DEBUG

template <typename T>
bool chmax(T &a, const T& b) {
  if (a < b) {
    a = b;  // aをbで更新
    return true;
  }
  return false;
}

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

string s;
int sum = 0;

int main(){
    getline(cin, s);

    int m=1, i=0;
    while(i++ < s.length()-1){
        if(i % 2 != 0){
            sum += m*9;
        }
        m *= 10;
    }

    int n = stoi(s);
    if(s.length() % 2 != 0) sum += n-m +1;
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 3572
#include <bits/stdc++.h>
using namespace std;
int main(void){
    
    int n;
    int ans=0;
    int m=0;
    int tmp=0;
    
    cin >> n;
    
    vector<int> a(n);
    
    for(int i=0; i<=n-1; i++){
        
        cin >> a.at(i);
        
    }
    
    sort(a.begin(), a.end());
    
    for(int i=0; i<=n-1; i++){
        
        if(m!=a.at(i)){
            
            if(tmp>=m){
                
                ans += tmp - m;
                
            } else {
                
                ans += tmp;
                
            }
            
            m = a.at(i);
            tmp = 1;
            
        } else {
            //cout << "aaa" << endl;
            tmp += 1;
            
        }
        
    }
    
    if(tmp>=m){
        
        ans += tmp - m;
        
    } else {
        
        ans += tmp;
        
    }
    
    cout << ans << endl;
    
    return 0;
    
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define RNG(i,from,to) for(int i=(from); i<(int)(to); i++)
#define gcd(i,j) __gcd((i), (j))
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<ll> vecll;
template<typename S, typename T> string to_string(pair<S, T> p) { return "("+to_string(p.first)+","+to_string(p.second)+")"; }
template<typename T> string to_string(T p[2]) { return "["+to_string(p[0])+","+to_string(p[1])+"]"; }
template<typename T> void println(T e){ cout << to_string(e) << endl; }
template<typename T> void println(const vector<T>& v){ cout << "[";for(const auto& e : v){ cout << to_string(e) << ","; }cout << "]";cout << endl; }
template<typename T> void println(const vector<vector<T>>& vv){ for(const auto& v : vv){ println(v); } }
template<typename Iter> void println(Iter first, Iter last){ for(auto it=first; it != last; it++){ cout << *it << " "; }; cout << endl; }
template<typename T> T mod_pow(T x, T n, const T &p) { T ret = 1; while(n > 0) { if(n & 1) (ret *= x) %= p; (x *= x) %= p; n >>= 1; } return ret; }
template<typename T> T mod_inv(T x, const T &p) { return mod_pow(x, p-2, p); }
const ll DVSR = 1e9+7;


int main(int argc, char const *argv[])
{
  ll N, buf; cin >> N;
  vector<ll> A(N+1);
  RNG(i, 1, N+1) A[i] = 0;
  RNG(i, 2, N+1) {
    cin >> buf;
    A[buf] += 1;
  }
  RNG(i, 1, N+1) {
    cout << A[i] << endl;
  }
  return 0;
}


Measured memory_bytes: 4828
#include <bits/stdc++.h>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/range/irange.hpp>
#include <boost/range/adaptor/indexed.hpp>

using namespace std;
using namespace boost::adaptors;
using namespace std::string_literals;
using ll = int64_t;
using vecint = vector<int>;
using vecll = vector<ll>;
using boost::irange;

int main()
{
  int n;
  cin>>n;
  vecint a(n), b(n), c(n);
  for(auto&& e:a) cin>>e;
  for(auto&& e:b) cin>>e;
  for(auto&& e:c) cin>>e;
  boost::sort(a);
  boost::sort(b);
  boost::sort(c);
  vecll mc;
  mc.push_back(0);
  for(auto&& e:b) {
    mc.push_back(boost::lower_bound(a, e) - begin(a));
  }
  for(auto&& i:irange(0,n)) {
    mc[i+1] += mc[i];
  }
  ll cnt = 0;
  for(auto&& e:c) {
    cnt += mc[boost::lower_bound(b, e) - begin(b)];
  }
  cout<<cnt<<endl;
  return 0;
}


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

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

i64 n;
double x[8], y[8];

double f(int c, int s) {
  double a = 0;
  int cnt = 0;
  for (int i = 0; i < n; ++i) {
    int b = 1 << i;
    if (!(s & b)) {
      double d = x[i] - x[c], e = y[i] - y[c];
      a += f(i, s | b) + hypot(d, e);
      ++cnt;
    }
  }
  return cnt == 0 ? 0 : a / cnt;
}

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

  double ans = 0;
  for (int i = 0; i < n; ++i) {
    ans += f(i, 1 << i) / n;
  }

  printf("%.10f\n", ans);
  return 0;
}

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

using namespace std;

main()
{
  	long int N,i,ac=0,wa=0,tle=0,re=0;
  	char word[10];
	cin>>N;
    char word1[]="AC";
    char word2[]="WA";
    char word3[]="TLE";
    char word4[]="RE";

	for(i=0;i<N;i++)
    {
      cin.ignore(80, '\n');
      cin>>word;
      

      if(!strcmp(word,word1))
      {
        ac++;
      }
      if(!strcmp(word,word2))
      {
        wa++;
      }
      if(!strcmp(word,word3))
      {
        tle++;
      }
      if(!strcmp(word,word4))
      {
        re++;
      }
    }
    cout<<"AC x "<<ac<<endl;
    cout<<"WA x "<<wa<<endl;      
    cout<<"TLE x "<<tle<<endl;
    cout<<"RE x "<<re<<endl;
}

Measured memory_bytes: 3568
# N = int(input())
# N, K = map(int, input().split())
# A = list(map(int, input().split()))

def f(S):
    F = int(S[:2])
    B = int(S[2:])

    if 1 <= F <= 12:
        if 1 <= B <= 12:
            print("AMBIGUOUS")
        else:
            print("MMYY")
    else:
        if 1 <= B <= 12:
            print("YYMM")
        else:
            print("NA")

f(input())


Measured memory_bytes: 2940
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;
struct edge{int to;ll cap;int rev;};
int main(){
    ll n;
    cin>>n;
    int n2 = 1<<n;
    vector<ll> a(n2);
    rep(i,n2) cin>>a[i];
    sort(a.begin(),a.end());
    vector<ll> s;
    s.push_back(a.back());
    a.back() = -1;
    rep(i,n){
        vector<ll> p = s;
        sort(p.begin(),p.end());
        int ai = n2 - 1;
        while(p.size() > 0 && ai >= 0){
            if(a[ai] == -1){
                --ai;
                continue;
            }
            if(a[ai] < p.back()){
                s.push_back(a[ai]);
                p.pop_back();
                a[ai] = -1;
            }
            --ai;
        }
        if(p.size() > 0){
            puts("No");
            return 0;
        }
    }
    puts("Yes");
    return 0;
}

Measured memory_bytes: 5484
from collections import defaultdict as dd
import bisect
from sys import exit
n = int(input())
A = list(map(int, input().split()))

coutner = 0
dp = dd(int)
dp[1] = 1
limit = [0] * (n + 1)
total = 0
for i in range(n, -1, -1):
    total += A[i]
    limit[i] = total
#print(limit)

"""
for depth in range(n):
    mov_dic = dd(lambda: 0)
    for now_num, total in dp.items():
        if now_num - A[depth] > 0:
            mov_dic[now_num - A[depth]] = total
    #print("mov_dic", mov_dic)

    dp = dd(int)
    mov_dic_keys = set(mov_dic.keys())
    for now_num, total in mov_dic.items():
        mov_dic_keys.remove(now_num)
        for next_num in range(now_num, min(now_num*2 + 1, limit[depth] + 1)):
            if now_num in mov_dic_keys:
                break
            dp[next_num] = max(total + next_num, dp[next_num])
    #print(limit[depth], "dp", dp)

if dp[A[-1]] == 0:
    print(-1)
else:
    print(dp[A[-1]])
"""

if n == 0:
    if A[0] == 1:
        print(1)
    else:
        print(-1)
    exit()

now_num = 1
now_total = 1
for depth in range(n):
    mov_num = now_num - A[depth]
    #print(mov_num)

    if mov_num > 0:
        now_num = min(mov_num * 2, limit[depth+1])
        now_total += now_num
    else:
        print(-1)
        exit()
if now_num == A[n]:
    print(now_total)
else:
    print(-1)

Measured memory_bytes: 82024
#include <iostream>
#include <string>
using namespace std;
int main(){
 
  int n,sa=0,sb=0;
  string ca,cb;
 
  cin >>n;
 
  for( int i=0; i < n ; i++ ){
     
    cin >>ca>>cb;
 
    if( ca > cb ){
      sa+=3;
    }else if( ca < cb ){
      sb+=3;
    }else if( ca == cb ){
      sa++;
      sb++;
    }
   
  }
 
  cout<<sa<<" "<<sb<<endl;
 
  return 0;
}


Measured memory_bytes: 3140
#include "bits/stdc++.h"
using namespace std;
typedef long long LL;
const LL MOD = 1000000007LL;
LL dp[100001];
int main() {
	LL A, B, P;
	while (cin >> A >> B >> P, A) {
		memset(dp, 0, sizeof(dp));
		dp[0] = 1;
		LL ans = 0;
		for (LL i = A; i <= B; i++) {
			if (i > A) (dp[i - A] += dp[i - A - 1]) %= P;
			(ans += dp[i - A]) %= P;
			for (LL j = i; j <= B; j *= 10) {
				LL ten = 1;
				while (ten <= j) ten *= 10;
				LL x = max(i - A + 1, j - A), y = min(B - A + 1, ten - A);
				(dp[x] += dp[i - A]) %= P;
				dp[y] = (dp[y] - dp[i - A] + P) % P;
			}
		}
		cout << ans << endl;
	}
}


Measured memory_bytes: 3832
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

/**
 * Grid
 */
public class Main {

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

		while (!(line = br.readLine()).equals("0")) {
			int n = Integer.parseInt(line);
			byte[][] grid = new byte[n][n];

			for (int i = 0; i < n; i++) {
				line = br.readLine();
				for (int j = 0; j < n; j++) {
					grid[i][j] = (byte) (line.charAt(j) - '0');
				}
			}

			short max = 0;
			// 左右
			for (int i = 0; i < n; i++) {
				short sum = 0;
				for (int j = 0; j < n; j++) {
					if (grid[i][j] > 0) {
						sum++;
						if (sum > max)
							max = sum;
					} else {
						sum = 0;
					}
				}
			}
			// 上下
			for (int i = 0; i < n; i++) {
				short sum = 0;
				for (int j = 0; j < n; j++) {
					if (grid[j][i] > 0) {
						sum++;
						if (sum > max)
							max = sum;
					} else {
						sum = 0;
					}
				}
			}
			// 対角線(右上->左下)
			for (int i = 0; i < 2 * n - 1; i++) {
				short sum = 0;
				int p, q, r;
				if (i < n) {
					p = i;
					q = 0;
					r = i + 1;
				} else {
					p = n - 1;
					q = i - n + 1;
					r = n;
				}
				for (int j = q; j < r; j++) {
					// try {
					// System.out.print(grid[p][j]);
					if (grid[p][j] > 0) {
						sum++;
						if (sum > max)
							max = sum;
					} else {
						sum = 0;
					}
					p--;
					// } catch (ArrayIndexOutOfBoundsException e) {
					// System.err.println(String.format("i=%d:j=%d:p=%d:q=%d",
					// i, j, p, q));
					// }
				}
				// System.out.print("|");
			}
			// System.out.println("");
			// 対角線(左上->右下)
			for (int i = 0; i < 2 * n - 1; i++) {
				short sum = 0;
				int p, q, r;
				if (i < n) {
					p = 0;
					q = n - i - 1;
					r = n;
				} else {
					p = i - n + 1;
					q = 0;
					r = 2 * n - i - 1;
				}
				for (int j = q; j < r; j++) {
					// try {//
					// System.out.print(grid[p][j]);//
					if (grid[p][j] > 0) {
						sum++;
						if (sum > max)
							max = sum;
					} else {
						sum = 0;
					}
					p++;
					// } catch (ArrayIndexOutOfBoundsException e) {//
					// System.err.println(String.format("i=%d:j=%d:p=%d:q=%d",//
					// i, j, p, q));//
					// }//
				}
				// System.out.print("|");//
			}
			// System.out.println();//
			System.out.println(max);
		}
	}
}

Measured memory_bytes: 24280
#include <bits/stdc++.h>
#include<iostream>
#include<vector>
#include<map>
#include<math.h>
#include<algorithm>

#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rep2(i,a,n) for(int i = (int)(a); i <= (int)(n); i++)
#define rrep(i,n) for(int i = (int)(n-1); i > -1; i--)
#define rrep2(i,n,a) for(int i = (int)(n); i >= (int)(a); i--)

#define fi first
#define se second

using namespace std;

using ll = long long;
using v_int = vector<int>;
using v2_int = vector<v_int>;
using v_ll = vector<ll>;
using v2_ll = vector<v_ll>;
using v_string = vector<string>;
using v_bool = vector<bool>;
using v2_bool = vector<v_bool>;
using pii = pair<int, int>;
using mii = map<int, int>;

const double PI = 3.1415926535897932;
const int INF = (int)2e9;
const ll LINF = (ll)2e18;
const ll MOD = 1000000007;
const int dc[8] = {1, -1, 0,  0, 1, -1,  1, -1};
const int dr[8] = {0,  0, 1, -1, 1,  1, -1, -1};

template<typename T, typename U> inline
ostream& operator<<(ostream &o, pair<T,U> &p) {
    return o << "{" << p.first << "," << p.second << "}";
}
template<typename T> inline
istream& operator>>(istream &is, vector<T> &vec) {
    for(auto &v : vec) { is >> v; }
    return is;
}
template<typename T> inline
ostream& operator<<(ostream &os, vector<T> &vec) {
    for(auto &v : vec) { os << v << ",";}
    return os;
}
template<typename T> inline
ostream& operator<<(ostream &os, vector<vector<T> > &mat) {
    for(auto &row : mat) { os << row << endl; }
    return os;
}

template<typename T> inline
void chmin(T &a, T b) { a = min(a, b); }
template<typename T> inline
void chmax(T &a, T b) { a = max(a, b); }

int main(void)
{
    int n, k;
    cin >> n >> k;
    string s;
    cin >> s;

    int ans = 0;
    int cnt = 0;

    rep(i,n-1) {
        if(s[i] == s[i+1]) {
            ans++;
        }
    }
    ans += 2*k;
    ans = min(n-1,ans);
    cout << ans << endl;
    return 0;
} /*atcoder*/



Measured memory_bytes: 3732
#include<bits/stdc++.h>
using namespace std;
typedef  long long ll;
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}

template<class T> ll llpow(T x,T n){ll ans=1;if(x==0)ans=0;while(n){if(n&1)ans*=x;x*=x;n>>=1;}return ans;}
template<class T> inline T gcd(T x,T y){if(y==0)return x; else {return gcd(y,x%y);}}
template<class T> inline T lcm(T x,T y){return x/gcd(x,y)*y;}

#define rep(i,n) for(ll i=0;i<(ll)n;i++)
#define rep2(i, begin_i, end_i) for (ll i = (ll)begin_i; i < (ll)end_i; i++)

long long INF = 1LL<<60;
int main(){
    int n;
    cin>>n;
    vector<int> l(n);
    rep(i,n){
        cin>>l[i];
    }
    ll ans=0;
    sort(l.begin(),l.end());
    for(int mid=n-1;mid>=1;mid--){
      for(int low=mid-1;low>=0;low--){
          auto iter=lower_bound(l.begin(),l.end(),l[mid]+l[low]);
          ll ng=distance(iter,l.end());
                 ans+=n-1-mid-ng;
            }
        }
    cout<<ans<<endl;
    return 0;
}




Measured memory_bytes: 256
//#include<bits/stdc++.h>
//#include<tr1/unordered_map>
#include<iostream>
#include<string>
#include<algorithm>
#include<utility>
#include<functional>
#include<vector>

#pragma GCC optimize ("Ofast")
#define ll long long
#define pll pair<long long,long long>
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define F first
#define S second
#define forn(i, n) for(int i=0; i<int(n); i++)
#define Forn(i, n) for(int i=1; i<=int(n); i++)

using namespace std;

/*#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
typedef tree<pii, null_type, less<pii>, rb_tree_tag, tree_order_statistics_node_update> rbtree;*/

string s;

int main()
{
    cin.tie(0);ios_base::sync_with_stdio(false);
    cin >> s;
    sort(s.begin(), s.end());
    for(char c = 'a'; c<='z'; c++)
    {
        if(!binary_search(s.begin(), s.end(), c))
        {
            cout << c << endl;
            return 0;
        }
    }
    cout << "None" << endl;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
template<int mod>
class Combination {
    std::vector<long long> fact, finv, inv;
public:
    Combination(int sz) {
        fact.resize(sz);
        finv.resize(sz);
        inv.resize(sz);
        fact[0] = 1;
        for(int i=1;i<sz;++i) {
            fact[i] = fact[i-1] * i % mod;
        }
        inv[0] = 0;
        inv[1] = 1;
        for(int i=2;i<sz;++i) {
            inv[i] = mod - inv[mod%i] * (mod/i) % mod;
        }
        finv[0] = 1;
        for(int i=1;i<sz;++i) {
            finv[i] = finv[i-1] * inv[i] % mod;
        }
    }
    long long C(long long n, long long k) {
        if(n < k) return 0;
        if(n < 0 || k < 0) return 0;
        return (fact[n] * finv[k] % mod) * finv[n-k] % mod;
    }
    long long P(long long n, long long k) {
        if(n < k) return 0;
        if(n < 0 || k < 0) return 0;
        return fact[n] * finv[n-k] % mod;
    }
    long long H(long long n, long long k) {
        return this->C(n + k - 1, k);
    }
    long long getfact(int i) {
        return fact[i];
    }
    long long getinv(int i) {
        return inv[i];
    }
    long long getfinv(int i) {
        return finv[i];
    }
};
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
const double eps = 1e-10;
const ll MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1ll<<50;
template<typename T>
void printv(const vector<T>& s) {
  for(int i=0;i<(int)(s.size());++i) {
    cout << s[i];
    if(i == (int)(s.size())-1) cout << endl;
    else cout << " ";
  }
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  int n, k; cin >> n >> k;
  vll a(n);
  for(int i=0;i<n;++i) {
    cin >> a[i];
  }
  sort(a.begin(), a.end());
  Combination<MOD> comb(1000000);
  ll g = 0, h = 0;
  for(int i=k-1;i<n;++i) {
    ll tmp = comb.C(i, k-1) * a[i] % MOD;
    g += tmp;
    g %= MOD;
  }
  reverse(a.begin(), a.end());
  for(int i=k-1;i<n;++i) {
    ll tmp = comb.C(i, k-1) * a[i] % MOD;
    h += tmp;
    h %= MOD;
  }
  cout << (g + MOD - h) % MOD << endl;
}


Measured memory_bytes: 24448