akhauriyash/Code-Regression huggingface dataset:
from math import floor,ceil,sqrt,factorial,log
from collections import Counter, deque
from functools import reduce
import numpy as np
def S(): return input()
def I(): return int(input())
def MS(): return map(str,input().split())
def MI(): return map(int,input().split())
def FLI(): return [int(i) for i in input().split()]
def LS(): return list(MS())
def LI(): return list(MI())
def LLS(): return [list(map(str, l.split() )) for l in input()]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def LLSN(n: int): return [LS() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]

X,N = MI()

if N == 0:
    print(X)
    exit()

P = LI()

_min = 10**9
ans = []
for p in range(X+1):
    for i in [-1,1]:
        a = X + (i * p)
        if a not in P:
            print(a)
            exit()



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

using namespace std;

typedef long long ll;
typedef long double ld;

#define mp make_pair
#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define popb pop_back
#define popf pop_front
#define all(v) v.begin(),v.end()

const int maxn = 500 + 100;
const ll inf = 2e18, mod = 1e9 + 7;

int h, w;
char a[maxn][maxn], r[maxn][maxn], b[maxn][maxn];

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

	scanf("%d %d", &h, &w);
	for (int i = 0; i < h; i++)
		scanf("%s", a[i]);

	for (int i = 0; i < h; i++)
		for (int j = 0; j < w; j++)
			b[i][j] = r[i][j] = '.';
	
	for (int i = 0; i < w; i++)
		r[0][i] = b[h - 1][i] = '#';
	for (int i = 1; i < h - 1; i++)
		for (int j = 0; j < w; j++)
		{
			if (j & 1)
				r[i][j] = '#';
			else
				b[i][j] = '#';
		}
	
	for (int i = 0; i < h; i++)
		for (int j = 0; j < w; j++)
			if (a[i][j] == '#')
			{
				if (j & 1)
					b[i][j] = '#';
				else
					r[i][j] = '#';
			}

	for (int i = 0; i < h; i++)
		printf("%s\n", b[i]);
	puts("");
	for (int i = 0; i < h; i++)
		printf("%s\n", r[i]);
}



Measured memory_bytes: 1664
import java.util.*;

public class Main {
    public static void main(String[] args) {
	    Scanner sc = new Scanner(System.in);
		String S = sc.next();
		String T = sc.next();
		String SS = S + S;
		if (SS.contains(T)) {
		    System.out.println("Yes");
		} else {
		    System.out.println("No");
		}
	}
}


Measured memory_bytes: 22740
#include<iostream>
#include<iomanip>
#include<sstream>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<string>
#include<numeric>
#include<set>
using namespace std;

int main(){

  for(int i = 1; i <= 9; i++){
    for(int j = 1; j <= 9; j++)
      cout << i << "x" << j << "=" << i*j << endl;
  }
  
  return 0;
}


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

int a['z' - 'a' + 1];
string s;

int main() {
	cin >> s;
	for (int i = 0; i < s.length(); i++) {
		a[s[i]-'a']++;
	}

	for (int i = 0; i < 'z' - 'a' + 1; i++) {
		if (a[i] == 0) {
			char c = ('a' + i);
			cout << c << endl;
			return 0;
		}
	}

	cout << "None" << endl;
}

Measured memory_bytes: 512
import sys,math,collections,itertools
input = sys.stdin.readline

N=int(input())
s = []
if N ==0:
    print(0)
    exit()
    
while N:
    r = N%(-2)
    if r<0:
        r+=2
    N = (N-r)//(-2)
    s.append(str(r))

print(''.join(s)[::-1])


Measured memory_bytes: 9468
def f(n, d):
    while True:
        for x in d:
            try:
                str(n).index(str(x))
            except ValueError:
                pass
            else:
                break
        else:
            return n
        n = n + 1


nk = list(map(int, input().split()))
n = nk[0]

d = list(map(int, input().split()))

print(f(n, d))


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define FOR(i,a,b)  for(int (i)=(a);(i)<(b);(i)++)
#define REP(i,n)    FOR(i,0,n)
#define RER(i,n)    FOR(i,0,(n+1))
#define pb          push_back
#define mp(a,b)     make_pair((a),(b))
#define mset(m,v)   memset(m,v,sizeof(m))
using namespace std;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef vector<pair<int, int> > vpii;
typedef long long ll;
typedef vector<ll> vl;
typedef pair<ll,ll> pll;
typedef vector<pair<ll, ll> > vpll;
typedef vector<string> vs;
typedef long double ld;
const double EPS    = 1e-10;
const int INF       = 1e+9;
const double PI     = acos(-1);


auto main() -> int
{
    int x, a, b;
    cin >> x >> a >> b;

    if ( a - b >= 0 ) {
        cout << "delicious" << endl;
    } else if ( b - a <= x ) {
        cout << "safe" << endl;
    } else {
        cout << "dangerous" << endl;
    }
    return 0;
}



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

int main(){
  while (1){
    string str_num;
    getline(cin,str_num);
    
    if (str_num == "0") break;
    
    int sum=0;
    for (int i=0; i<str_num.size(); i++){
      int num = str_num.at(i) - '0';
      sum += num;
    }
    cout << sum << endl;
  }
  return 0;
}


Measured memory_bytes: 3192
from collections import deque

N = int(input())
A = list(map(int, input().split()))
A = sorted(A)
steps = list()

A_pos = [x for x in A if x >= 0]  # プラスとして使うもの
A_minus = [x for x in A if x < 0]  # マイナスとして使うもの
if len(A_pos) == 0:
    max_tmp = A_minus[-1]
    A_minus = A_minus[:-1]
    A_pos.append(max_tmp)

if len(A_minus) == 0:
    min_tmp = A_pos[0]
    A_pos = A_pos[1:]
    A_minus.append(min_tmp)

A_pos = deque(A_pos)
A_minus = deque(A_minus)

# calc steps
while True:
    if len(A_pos) == 1 and len(A_minus) == 1:
        break
    if len(A_pos) == 1:
        pos = A_pos.pop()
        minus = A_minus.pop()
        steps.append((pos, minus))
        pos -= minus
        A_pos.append(pos)
        continue
    if len(A_minus) == 1:
        # Then len(A_pos) > 1
        pos = A_pos.pop()
        minus = A_minus.pop()
        steps.append((minus, pos))
        minus -= pos
        A_minus.append(minus)
        continue
    pos = A_pos.pop()
    minus = A_minus.pop()
    steps.append((pos, minus))
    pos -= minus
    A_pos.append(pos)

pos = A_pos.pop()
minus = A_minus.pop()

steps.append((pos, minus))
print(pos - minus)
for x, y in steps:
    print('{} {}'.format(x, y))

Measured memory_bytes: 66108
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
using namespace std;
int main()
{
	int i, n , x;
	int a[105];
	int sum = 0;
	scanf("%d %d", &n, &x);
	for(i = 1 ; i <= n ; i++)
	{
		scanf("%d", &a[i]);
		sum += a[i];
	}
	sort(a + 1, a + 1 + n);
	printf("%d\n", n + (x - sum) / a[1]);
	return 0;
}

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

using Int = int;
using namespace std;

#define ARC(i, a, b) for(Int i = (a); i < (b); ++i)
#define RC(i, n) ARC(i, 0, n)
#define ARCH(i, a, b) for(Int i = (a) - 1; i >= (b); --i)
#define RCH(i, n) ARCH(i, n, 0)
template<class T> T ant(const T &a, const T &b){ return a > b ? a : b; };
template<class T> T ont(const T &a, const T &b){ return a < b ? a : b; };
template<class T> T th(T &a, const T &b, T (*f)(const T &, const T &)){ a = f(a, b); }
#define anth(a, b) th(a, b, ant)
#define onth(a, b) th(a, b, ont)

int main(){
	int a;
	cin >> a;
	cout << (a + 1) / 2 << std::endl;
}


Measured memory_bytes: 256
sx, sy, tx, ty = gets.split.map(&:to_i)
w = tx - sx
h = ty - sy
ans = "U" * h + "R" * w + "D" * h + "L" * (w + 1) + "U" * (h + 1) + "R" * (w + 1) + "D" * 1 + "R" * 1 + "D" * (h + 1) + "L" * (w + 1) + "U" * 1
puts ans

Measured memory_bytes: 1916
#include <iostream>
#include <string>
#include <cstdio>
#include <vector>
using namespace std;
int main() {
    string s;
    cin >> s;
    if (s[0] == 'a' || s[0] == 'e' ||s[0] == 'i' ||s[0] == 'o' ||s[0] == 'u')
        cout << "vowel" << endl;
    else
        cout << "consonant" << endl;
    return 0;
}





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



int main() 
{
  ll x; cin>>x;
  ll ans=x/11*2;
  x%=11;
  if(x!=0)
  {
    if(x>=7)
    {
      ans++;
    }
    ans++;
  }  
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
import sys
import math
import string
import fractions
import random
from operator import itemgetter
import itertools
from collections import deque
import copy
import heapq
from bisect import bisect, bisect_left, bisect_right

MOD = 10 ** 9 + 7
INF = float('inf')
input = lambda: sys.stdin.readline().strip()

sys.setrecursionlimit(10 ** 8)

SS = list(input())
S = copy.deepcopy(SS)
N = len(S)
S_ = [S[i] for i in range(len(S) - 1, -1, -1)]
if S_ != S:
    print("No")
    sys.exit()
S1 = [S[i] for i in range(0, (N - 1) // 2)]
S = S1
S_ = [S[i] for i in range(len(S) - 1, -1, -1)]
if S != S_:
    print("No")
    sys.exit()
S2 = [SS[i] for i in range((N + 3) // 2 - 1, N)]
SS = S2
S_ = [SS[i] for i in range(len(SS) - 1, -1, -1)]
if S != S_:
    print("No")
    sys.exit()
print("Yes")

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

#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

using namespace std;
typedef long long ll; typedef vector<int> VI; typedef pair<int,int> pii;
const int MD = (int)1e9 + 7;
void dbg(){ cerr << "\n"; }  template <typename T,typename ...T2>
void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }

ll gcd(ll x, ll y){ return y==0? x: gcd(y, x%y); }

int main(){
	cin.tie(0); ios_base::sync_with_stdio(false);
	string s;
	cin >>s;
	
	int n =sz(s);
	int ok = true;
	if(s[0] != s[n-1]) ok = n%2? true: false; 
	else ok = n%2? false: true;
	
	cout <<(ok? "First": "Second") <<endl;
	return 0;
}

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

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

    priority_queue<int, vector<int>, greater<int>> ai;
    int aiMax = 0;
    for (int i = 0; i < n; ++i) {
        int a;
        cin >> a;
        ai.push(a);
        aiMax = max(aiMax, a);
    }

    vector<bool> bi(aiMax + 1, true);

    int ans = 0;
    int size = ai.size();
    uint64_t prev = -1;
    bool isSame = false;
    for (int i = 0; i < size; ++i) {
        uint64_t x = ai.top();
        ai.pop();
        if (bi.at(x)) {
            if (x != prev) {
                ans++;
                for (int j = 0; x * (j + 2) <= aiMax; j++) {
                    bi.at(x * (j + 2)) = false;
                }
                isSame = false;
            }
            else if (!isSame) {
                ans--;
                isSame = true;
            }
        }
        prev = x;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 4320
#include <iostream>
#include <iomanip>
#include <string>
#include <cstdio>
#include <utility>
#include <algorithm>
#include <functional>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)

int a[10];
int n;

bool dfs(int i,int left,int right){
	if(i==10) return true;
	if(a[i]>left){
		return dfs(i+1,a[i],right);
	}
	if(a[i]>right){
		return dfs(i+1,left,a[i]);
	}
	return false;
}

void solve(){
	rep(i,10) cin >> a[i];
	if(dfs(0,0,0)) cout << "YES" << endl;
	else cout << "NO" << endl;
	return;
}

int main(){
	cin >> n;
	rep(i,n){
		solve();
	}
	return 0;
}

Measured memory_bytes: 1152
import sys
n = int(input())
a = sorted(list(map(int, input().split())))

res = 1
for t in a:
    res *= t
    if res > 10**18:
        print(-1)
        sys.exit()
    if res == 0:
        print(res)
        sys.exit()
else:
    print(res)


Measured memory_bytes: 21704
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> iint;
typedef pair<ll,ll> llll;
#define ALL(x) (x).begin(),(x).end()
const ll zero = 0;
const ll INF = 3000000000000000000; //10^18
const int inINF = 1000000000; //10^9
const ll MOD = 1000000007; //10^9+7
const ll MOD2 = 998244353;
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}

struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

    UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) par[i] = i;
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

int main(){
    int N, K, L;
    cin >> N >> K >> L;
    int p,q,r,s;

    UnionFind P(N), Q(N);
    for (int i = 0; i < K; i++) {
        cin >> p >> q;
        p--; q--;
        P.unite(p,q);
    }
    for (int i = 0; i < L; i++) {
        cin >> p >> q;
        p--; q--;
        Q.unite(p,q);
    }

    map<iint, int> G;
    for (int i = 0; i < N; i++) {
        if(G.count(make_pair(P.root(i), Q.root(i)))){
            G[make_pair(P.root(i), Q.root(i))]++;
        }
        else{
            G[make_pair(P.root(i), Q.root(i))] = 1;
        }
    }
    
    for (int i = 0; i < N; i++) {
        printf("%d ", G[make_pair(P.root(i), Q.root(i))]);
    }
    printf("\n");


}

Measured memory_bytes: 15980
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vl;
typedef vector<string> vs;
typedef vector<char> vc;
typedef queue<ll> ql;
typedef deque<ll> dql;
typedef priority_queue<ll/*, vl, greater<ll>*/> pql; //降順(/*昇順*/)
typedef set<ll> sl;
typedef pair<ll, ll> pl;
typedef vector<vl> vvl;
typedef vector<pl> vpl;
#define rep(i, n) for(ll i = 0; i < ll(n); i++)
#define rep2(i, n) for(ll i = 1; i <= ll(n); i++)
//#define rep(i, k, n) for(ll i = k-1; i < ll(n); i++)
//#define rep2(i, k, n) for(ll i = k; i <= ll(n); i++)
#define all(v) (v).begin(), (v).end()
bool chmin(ll &a, ll b) {if(b < a) {a = b; return 1;} return 0;}
bool chmax(ll &a, ll b) {if(b > a) {a = b; return 1;} return 0;}
const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;
//const ll MOD = 998244353;
const ll MAX = 1e9;
const char newl = '\n';

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

  ll n;
  cin >> n;
  vl a(n), b;
  rep(i, n) {
    cin >> a[i];
    if(i==0 or a[i]!=b.back()) b.push_back(a[i]);
  }
  
  ll bs=b.size(), cnt=1;
  vl vec;
  rep2(i, bs-2) {
    cnt++;
    if((b[i+1]-b[i])*(b[i]-b[i-1])<0) {
      vec.push_back(cnt);
      cnt=1;
    }
  }
  vec.push_back(cnt);
  
  ll vs = vec.size();
  rep2(i, vs-2) if(vec[i-1]>=2 and vec[i]==2) vec[i]=0;
  cout << vs - count(all(vec), 0) << newl;
  return 0;
}

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

int main(){
    int N, a, ans;
    cin >> N >> a >> ans;
    ans = __gcd(a, ans);
    for(int i = 0; i < N - 2; ++i){
        cin >> a;
        ans = __gcd(a, 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 ALL(x) (x).begin(), (x).end()

typedef long long ll;
typedef long double ld;

const int INF = 1e9;
const ld EPS = 1e-8;

int main(){
  int n;
  cin >> n;
  vector<int> a(n);
  REP(i,n) cin >> a[i];
  sort(ALL(a));

  int ret = -1;
  REP(i, n - 1) {
    if((ret == -1) || (abs(a[i] - a[n - 1] / 2.0) < abs(ret - a[n - 1] / 2.0))) {
      ret = a[i];
    }
  }
  cout << a[n - 1] << " " << ret << endl;

  return 0;
}



Measured memory_bytes: 640
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

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

using namespace std;
typedef long long int ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int, int> PI;
const ll mod = 1e9 + 7;

const int BIAS = 2501;
const int W = 5100;
const int N = 51;
ll dp[N][W];

int main(void){
  string s;
cin >> s;
ll tot = 0;
REP(i, 0, s.length()) {
  ll coef = 0;
  ll cur = s.length() - 1 == i ? 1 : 1 << s.length() - i - 2;
  REP(j, i, s.length()) {
    coef += cur;
    cur *= 5;
    if (j == s.length() - 2) { cur *= 2; }
  }
  coef <<= i;
  tot += (s[i] - '0') * coef;
}
cout << tot << endl;
}


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

using namespace std;



#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

int main() {
int n;
vector<string> s(n);
cin >> n;
for (int i = 0; i < n; i++) cin >> s[i];
int cnt = 0;
//まずはそれぞれの文字列にABが何個あるか数える
for (int i = 0; i < n; i++){
    for (int j = 0; j < s[i].size()-1; j++)
    {
        if(s[i][j]=='A' && s[i][j+1]=='B') cnt++;
        }
 
}
//一番左にBが何個あって一番右にAが何個あるか調べる
//このときB〜Aみたいな文字とB~X、Y〜Aみたいな文字列を区別する
int left_B=0,right_A=0;
int x=0;
for(int i=0;i<n;i++){
    int last = s[i].size() - 1;
    if (s[i][0] == 'B' && s[i][last] != 'A')
        left_B++;
    if (s[i][last] == 'A' && s[i][0] != 'B')
        right_A++;
    if (s[i][0] == 'B' && s[i][last] == 'A')
        x++;
}
//B~AがなかったらBの数かAの数の小さい方が答え(文字列をくっつけていくイメージ)
if(x==0) cout<< cnt+min(left_B,right_A)<<endl;

//もし文字列がB〜Aの形だけなら合計から１日引く必要がある(端同士は繋げられない)
else if(left_B==0 && right_A==0 && x>=1) cout<<cnt+x-1<<endl;

//それ以外ではB~A部分の数+B~XとY~Aの小さい方の和を考えれば良い
else cout<<cnt+x+min(left_B,right_A)<<endl;

    return 0;
}

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

int main() {
    int H,W;
    cin >> H >> W;
    vector< vector<char> > A(H);
    for(int i=0; i<H; i++) {
        A[i].resize(W);
        for(int j=0; j<W; j++) {
            cin >> A[i][j];
        }
    }
    vector< vector<int> > B(H);
    for(int i=0; i<H; i++) B[i].resize(W);

    for(int i=0; i<H; i++) {
        for(int j=0; j<W; j++) {
            if(A[i][j] == '.') {
                int cnt = 0;
                if(i-1 >= 0) {
                    if(j-1 >= 0 && A[i-1][j-1] == '#') cnt++;
                    if(A[i-1][j] == '#') cnt++;
                    if(j+1 < W && A[i-1][j+1] == '#') cnt++; 
                }

                if(j-1 >= 0 && A[i][j-1] == '#') cnt++;
                if(j+1 < W && A[i][j+1] == '#') cnt++;

                if(i+1 < H) {
                    if(j-1 >= 0 && A[i+1][j-1] == '#') cnt++;
                    if(A[i+1][j] == '#') cnt++;
                    if(j+1 < W && A[i+1][j+1] == '#') cnt++; 
                }
                B[i][j] = cnt;
            } else {
                B[i][j] = -1;
            }
        }
    }

    for(int i=0; i<H; i++) {
        for(int j=0; j<W; j++) {
            if(B[i][j] >= 0) cout << B[i][j];
            else cout << '#';
        }
        cout << endl;
    }

    return 0;
}

Measured memory_bytes: 256
object Main extends App {
  @scala.annotation.tailrec
  def loop(ints: Seq[Int], i: Int): Int = ints match {
    case Seq() => i
    case x :: xs if x == i => loop(xs, i + 1)
    case _ :: xs => loop(xs, i)
  }
  val sc = new java.util.Scanner(System.in)
  val N = sc.nextInt()
  val count = loop(List.fill(N)(sc.nextInt()), 1) - 1
  println(if (count == 0) -1 else N - count)
}


Measured memory_bytes: 66196
#include<bits/stdc++.h>
#define ll long long
#define For(i,a,b) for (int i=a;i<=b;i++)
#define Rep(i,a,b) for (int i=b;i>=a;i--)
using namespace std;
inline ll read()
{
    ll x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9')x=x*10+ch-'0',ch=getchar();
    return x*f;
} 
int n,m,k,ans;  
int a[305][305],b[305];  
bool ban[305];  
int main()
{  
    n=read();m=read();
    For(i,1,n)For(j,1,m)a[i][j]=read();
    ans=n;  
    For(i,1,m)
    {
    	For(j,1,m)b[j]=0;
    	For(j,1,n)
    		For(k,1,m)
    			if(!ban[a[j][k]])
    			{
    				b[a[j][k]]++;
    				break;
				}
		int k=1;
		For(j,1,m)
			if(b[j]>b[k])k=j;
		ban[k]=true;
		if(b[k]<ans)ans=b[k];
	}
	cout<<ans<<endl;
    return 0;  
}  


Measured memory_bytes: 640
#include <algorithm>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <tuple>
#include <vector>

using namespace std;

#define rep(i, n) for (int64_t i = 0; i < (n); i++)
#define irep(i, n) for (int64_t i = 0; i <= (n); i++)
#define rrep(i, n) for (int64_t i = (n)-1; i >= 0; i--)
#define rirep(i, n) for (int64_t i = n; i >= 0; i--)

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

    int n = s.size();
    int cnt = 0;
    rep(i, n / 2)
    {
        if (s[i] != s[n - 1 - i])
        {
            cnt++;
        }
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(void) {
	int a, b, c;

	cin >> a >> b >> c;

	if (a < b) {
		if (a < c) {
			if (b < c) {
				cout << a << " " << b << " " << c << endl;
			}
			else {
				cout << a << " " << c << " " << b << endl;
			}
		}
		else{
			cout << c << " " << a << " " << b << endl;
		}
	}else{
		if (a < c) {
			cout << b << " " << a << " " << c << endl;
		}
		else {
			if (b < c) {
				cout << b << " " << c << " " << a << endl;
			}
			else {
				cout << c << " " << b << " " << a << endl;
			}
		}
	}

	int ch;
	cin >> ch;

	return 0;
}

Measured memory_bytes: 3080
#include<bits/stdc++.h>
#include <cstring>
#include <iostream>
#define pie acos(-1)
#define si(a) scanf("%d",&a)
#define sii(a,b) scanf("%d %d",&a,&b)
#define siii(a,b,c) scanf("%d %d %d",&a,&b,&c)
#define sl(a) scanf("%lld",&a)
#define sll(a,b) scanf("%lld %lld",&a,&b)
#define slll(a,b,c) scanf("%lld %lld %lld",&a,&b,&c)
#define ss(st) scanf("%s",st)
#define sch(ch) scanf("%ch",&ch)
#define ps(a) printf("%s",a)
#define newLine() printf("\n")
#define pi(a) printf("%d",a)
#define pii(a,b) printf("%d %d",a,b)
#define piii(a,b,c) printf("%d %d %d",a,b,c)
#define pl(a) printf("%lld",a)
#define pll(a,b) printf("%lld %lld",a,b)
#define plll(a,b,c) printf("%lld %lld %lld",a,b,c)
#define pd(a) printf("%lf",a)
#define pdd(a,b) printf("%lf %lf",a,b)
#define pddd(a,b,c) printf("%lf %lf %lf",a,b,c)
#define pch(c) printf("%ch",c)
#define debug1(str,a) printf("%s=%d\n",str,a)
#define debug2(str1,str2,a,b) printf("%s=%d %s=%d\n",str1,a,str2,b)
#define debug3(str1,str2,str3,a,b,c) printf("%s=%d %s=%d %s=%d\n",str1,a,str2,b,str3,c)
#define debug4(str1,str2,str3,str4,a,b,c,d) printf("%s=%d %s=%d %s=%d %s=%d\n",str1,a,str2,b,str3,c,str4,d)
#define for0(i,n) for(i=0;i<n;i++)
#define for1(i,n) for(i=1;i<=n;i++)
#define forab(i,a,b) for(i=a;i<=b;i++)
#define forstl(i, s) for (__typeof ((s).end ()) i = (s).begin (); i != (s).end (); ++i)
#define NL puts("")
#define sd(a) scanf("%lf",&a)
#define sdd(a,b) scanf("%lf %lf",&a,&b)
#define sddd(a,b,c) scanf("%lf %lf %lf",&a,&b,&c)
#define SP printf(" ")
#define LL long long int
#define ULL unsigned long long int
#define N 1000007
#define MOD 100000009
#define pub(x) push_back(x)
#define pob(x) pop_back(x)
#define mem(ara,value) memset(ara,value,sizeof(ara))
#define INF INT_MAX
#define eps 1e-8
#define checkbit(n, pos) (n & (1<<pos))
#define setbit(n, pos) (n | (1<<pos))
#define para(a,b,ara)\
for(int i=a;i<=b;i++){\
    if(i!=0){printf(" ");}\
    printf("%d",ara[i]);\
}\
printf("\n");
#define pvec(vec)\
for(int i=0;i<vec.size();i++){\
    if(i!=0){printf(" ");}\
    printf("%d",vec[i]);\
}\
printf("\n");
#define ppara(n,m,ara)\
for(int i=0;i<n;i++){\
    for(int j=0;j<m;j++){\
        if(j!=0){printf(" ");}\
        printf("%d",ara[i][j]);\
    }\
    printf("\n");\
}
#define ppvec(n,vec)\
for(int i=0;i<n;i++){\
    for(int j=0;j<vec[i].size();j++){\
        if(j!=0){printf(" ");}\
        printf("%d",vec[i][j]);\
    }\
    printf("\n");\
}
#define sara(a,b,ara)\
for(int i=a;i<=b;i++){\
    scanf("%d",&ara[i]);\
}
using namespace std;
int n,ara[2010];
bitset <2010*2010> dp[2];
int sum=0;
void input(){
    int i,j,ans;
    si(n);
    for0(i,n){si(ara[i]);sum+=ara[i];}
    dp[0].set(0);
    for1(i,n){
        dp[i&1]=dp[(i-1)&1]|(dp[(i-1)&1]<<ara[i-1]);
    }
    ans=0;
    for(i=(sum+1)/2;i<2005*2005;i++){
        if(dp[n&1][i]){
            ans=i;
            break;
        }
    }
    pi(ans);NL;
}
int main(){
    input();
    return 0;
}



Measured memory_bytes: 2816
N = int(input())

p = [int(x) for x in input().split(' ')]
sorted_p = sorted(p)
count = 0
for i in range(N):
    if p[i] != sorted_p[i]:
        count += 1
if count == 0 or count == 2:
    print("YES")
else:
    print("NO")


Measured memory_bytes: 2940
#include <bits/stdc++.h>
#define rep(i,n) for(int i=(0);i<(n);i++)

using namespace std;

typedef long long ll;

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

const ll MOD = 998244353;

ll mypow(ll a, ll b){
	if(b == 0) return 1;
	if(b % 2 == 1) return a * mypow(a, b - 1) % MOD;

	ll d = mypow(a, b / 2) % MOD;
	return d * d % MOD;
}

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

	ll n, s;
	cin >> n >> s;

	vector<ll> a(n);
	rep(i, n) cin >> a[i];

	ll dp[n+1][s+1];
	rep(i, n+1) rep(j, s+1) dp[i][j] = 0;
	dp[0][0] = mypow(2, n);
	ll inv2 = mypow(2, MOD - 2);

	rep(i, n){
		rep(j, s+1){
			dp[i+1][j] += dp[i][j];
			dp[i+1][j] %= MOD;
			
			if(j + a[i] <= s) {
				dp[i+1][j+a[i]] += dp[i][j] * inv2 % MOD;
				dp[i+1][j+a[i]] %= MOD;
			}
		}
	}
	
	cout << dp[n][s] << endl;

}


Measured memory_bytes: 74020
n,x=map(int,input().split())
b=[0]*(n+1)
p=[0]*(n+1)
s=[0]*(n+1)
p[0]=1
s[0]=1
for i in range(1,n+1):
    b[i]=2+b[i-1]*2
    p[i]=1+p[i-1]*2
    s[i]=b[i]+p[i]

def f(n,x):
    a=s[n-1]
    if n==0:
        return 1
    elif x==1:
        return 0
    elif x<=a+1:
        return f(n-1,x-1)
    elif x==a+2:
        return p[n-1]+1
    elif x<=2*a+2:
        return f(n-1,x-2-a)+p[n-1]+1
    else:
        return 2*p[n-1]+1
print(f(n,x))

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

int main() {
	int a,b;
  	cin>>a>>b;
  
  	int ch=0;
  	
  
  	if(b/10==0){
    	a *=10;
      	ch =a+b;
    }
  
  	else if(b/10==10){
    	a*=1000;
      	ch =a+b;
    }
  
  	else{
    	a*=100;
      	ch =a+b;
    }
  
  	int m=ceil(sqrt(ch));
  
  	if(ch/m==m){
    	cout<<"Yes"<<endl;
    }
  
  	else cout<<"No"<<endl;
  
  
  
  
}

Measured memory_bytes: 3680
#include <bits/stdc++.h>
using  namespace std;
typedef long long ll;
#define RAP(i, n) for(ll i=0;i<(n);i++)
#define FOR(i, a, b) for(ll i=(a);i<(b);i++)
int main(){
    ll n, ans = pow(10,9), check=0;
    cin >> n;
    ll F[n];
    RAP(i,n){
        cin >> F[i];
    }
    for(ll i=-100;i<=100;i++){
        check = 0;
        RAP(j,n){
            check += pow(F[j]-i, 2);
        }
        ans = min(ans, check);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
import Data.List
import Data.Ord
import Data.Char
import Data.Ratio
import Data.Maybe

main = do
  [n,m,c] <- map (read::String->Int) . words <$> getLine
  bs <- map (read::String->Int) . words <$> getLine
  as <- map (map (read::String->Int)) . map words . lines <$> getContents
  let result = map ((>0) .(+c) .sum .(zipWith(*)bs)) as
  print $ length $ filter (==True) result

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

int main(){
  int N,M,K,A;
  cin>>N>>M;
  int like[M],i,j,num=0;
  
  for(i=0;i<M;i++){
    like[i]=0;
  }
  
  for(i=0;i<N;i++){
    cin>>K;
    for(j=0;j<K;j++){
      cin>>A;
      like[A-1]++;
    }
  }
  for(i=0;i<M;i++){
    if(like[i]==N) num++;
  }
  cout<<num<<endl;
}

Measured memory_bytes: 256
// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>   
#include<map>
#include<set>
#include<unordered_map>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(ll i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define FOR(i,a) for(auto i:a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define show1d(v) rep(i,v.size())cout<<" "<<v[i];cout<<endl;
#define show2d(v) rep(i,v.size()){rep(j,v[i].size())cout<<" "<<v[i][j];cout<<endl;}
using namespace std;
//kaewasuretyuui
typedef long long ll;
//#define int ll
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
#define mt make_tuple
typedef tuple<int,int,int,int> tp;
typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
//template<class C>constexpr int size(const C &c){return (int)c.size();}
//template<class T,size_t N> constexpr int size(const T (&xs)[N])noexcept{return (int)N;}
const double PI=acos(-1);
const double EPS=1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
int main(){
	int a,b;
	cin>>a>>b;
	int t=b-a;
	t=t*(t-1)/2;
	cout<<t-a<<endl;
}















Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstdio>
using namespace std;
int n,d,ans;
int x[15][15];
bool check(int a,int b){
	int res=0;
	for(int i=1;i<=d;i++) res+=(x[a][i]-x[b][i])*(x[a][i]-x[b][i]);
	for(int i=1;i<=res;i++)
	  if(i*i==res) return 1;
	return 0; 
}
int main()
{
	scanf("%d%d",&n,&d);
	for(int i=1;i<=n;i++)
	  for(int j=1;j<=d;j++) scanf("%d",&x[i][j]);
	for(int i=1;i<=n;i++)
	  for(int j=i+1;j<=n;j++)
	    if(check(i,j)) ans++;
	printf("%d",ans);
	return 0;
} 

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define pb push_back
#define INF 0x3f3f3f3f
#define LINF 0x3f3f3f3f3f3f3f3f
#define endl '\n'
#define ll long long
#define f first
#define s second
#define int long long
#define FAST cin.tie(0), cout.tie(0), ios::sync_with_stdio(0)
#define debug(x) cout << "DEBUG " << x << endl
#define debug2(x, y) cout << "DEBUG " << x << " " << y << endl
#define debug3(x, y, z) cout << "DEBUG " << x << " " << y << " " << z<< endl
#define debug4(x, y, z, o) cout << "DEBUG " << x << " " << y << " " << z<< " " << o << endl
using namespace std;
typedef pair<ll, ll> pii;
typedef vector<vector<ll>> mat;
const ll mod = 1e9+7;
const int MAXN = 1e4+5;

int32_t main() {
	int n, m;
	cin >> n >> m;
	cout << (n == m ? "Yes" : "No") << endl;
}


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

#define REPR(i,n) for(int i=(n); i >= 0; --i)
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)
#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define ALL(a)  (a).begin(),(a).end()
int gcd(int a,int b){return b?gcd(b,a%b):a;}
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }

typedef long long ll;



int main() {
    int N;
    cin >> N;
    vector<int> A(N),lv(N),rv(N);
    REP(i,N) cin >> A[i];
    if (N==2) {
        cout << max(A[0],A[1]) << endl;
        exit(0);
    }

    lv[0]=A[0];
    FOR(i,1,N) lv[i]=gcd(A[i],lv[i-1]);
    rv[N-1]=A[N-1];
    for(int i=N-2;i>=0;i--) rv[i]=gcd(A[i],rv[i+1]);
    int maximum = 0;
    chmax(maximum,rv[1]);
    chmax(maximum,lv[N-2]);
    FOR(i,1,N-1) chmax(maximum,gcd(lv[i-1],rv[i+1]));
    cout << maximum << endl;
    return 0;
}


Measured memory_bytes: 1408
#include<bits/stdc++.h>
#define pi 3.1415926
using namespace std;


int main()
{


     ios_base::sync_with_stdio(false);
     cin.tie(NULL);
    
    int t=1;
    while(t--)
    {
      
    int a;
    cin>>a;
    unordered_map<int,int>nish;
    for(int i=2;i<=a;i++)
    {
      int first;
      cin>>first;
      if(i>first)
        nish[first]++;
    }  
    for(int i=1;i<=a;i++)
    {
      cout<<nish[i]<<endl;
    }


     }

return 0;

}

Measured memory_bytes: 11432
#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>;

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};

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(10);
    char x, y;
    cin >> x >> y;
    cout << (x < y ? "<\n" : x == y ? "=\n" : ">\n");
    return 0;
}

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

int main(){
    int N;
    cin >> N;
    vector<int> H(N);
    rep(i, N){
        cin >> H[i];
    }
    int jump = 0;
    int ans = 0;
    rep(i, N-1){
        if(H[i] >= H[i+1]){
            jump++;
        }else{
            if(ans < jump){
                ans = jump;
            }
            jump = 0;
        }
    }
    if(ans < jump){
        ans = jump;
    }
    cout << ans << endl;
return 0;}

Measured memory_bytes: 640
#include <iostream>
#include <iomanip>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <memory>
#include <cstring>
#include <cassert>
#include <numeric>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <cctype>
#include <unordered_map>
#include <unordered_set>
using namespace std;

#define REP2(i, m, n) for (int i = (int)(m); i < (int)(n); i++)
#define REP(i, n) REP2(i, 0, n)
#define ALL(S) (S).begin(), (S).end()
typedef long long ll;

string best;

string Cipher(const string &str, size_t &cur);

char Letter(const string &str, size_t &cur){
  char c = str[cur++];
  
  if (isupper(c)){
    return c;
  } else {
    char res = Letter(str, cur);
    if (c == '-'){
      res = res == 'A' ? 'Z' : (res - 1);
    } else {
      res = res == 'Z' ? 'A' : (res + 1);
    }
    return res;
  }
}


string String(const string &str, size_t &cur){
  if (str[cur] == '['){
    cur++;
    string res = Cipher(str, cur);
    cur++;
    reverse(ALL(res));
    return res;
    
  } else {
    return string(1, Letter(str, cur));
  }
}

string Cipher(const string &str, size_t &cur){
  string res;
  while (str[cur] != ']' && cur < str.size()){
    res += String(str, cur);
  }
  return res;
}

string decrypt(const string &str){
  size_t cur = 0;
  return Cipher(str, cur);
}

void rec(string &str, size_t pos){
  if (pos == str.size()){
    if (best == ""){
      best = decrypt(str);
    } else {
      best = min(best, decrypt(str));
    }
    
  } else if (str[pos] != '?'){
    rec(str, pos + 1);
  } else {
    for (char c = 'A'; c <= 'Z'; c++){
      str[pos] = c;
      rec(str, pos + 1);
    }
    str[pos] = '?';
  }
}

int main(){
  ios::sync_with_stdio(false);

  string str;
  
  while (cin >> str && str != "."){
    best = "";
    rec(str, 0);

    cout << best << endl;
  }
  return 0;
}

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

using namespace std;

using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;

ll P = 998244353;

template<typename T>
struct RSQRAQ2 {
  int n;
  T unit;
  function<T(T, T)> update_f, sum_f, query_f;
  vector<T> dat, lazy;

  RSQRAQ2() {}

  RSQRAQ2(int n_, T unit, function<T(T, T)> update_f, function<T(T, int)> sum_f, function<T(T, T)> query_f)
      : unit(unit), update_f(update_f), sum_f(sum_f), query_f(query_f) {
    n = 1;
    while (n < n_)
      n *= 2;
    dat.assign(n * 2, unit);
    lazy.assign(n * 2, unit);
  }

  RSQRAQ2(vector<T> v, T unit, function<T(T, T)> update_f, function<T(T, int)> sum_f, function<T(T, T)> query_f)
      : unit(unit), update_f(update_f), sum_f(sum_f), query_f(query_f) {
    n = 1;
    while (n < v.size()) n <<= 1;
    dat.assign(n * 2, unit);
    lazy.assign(n * 2, unit);
    for (int i = 0; i < v.size(); i++) {
      dat[n + i - 1] = v[i];
    }
    for (int i = n - 2; i >= 0; i--) {
      dat[i] = query_f(dat[i * 2 + 1], dat[i * 2 + 2]);
    }
  }

  void eval(int len, int k) {
    if (lazy[k] == unit)
      return;
    if (k * 2 + 1 < n * 2 - 1) {
      lazy[2 * k + 1] = update_f(lazy[2 * k + 1], lazy[k]);
      lazy[2 * k + 2] = update_f(lazy[2 * k + 2], lazy[k]);
    }
    dat[k] = update_f(dat[k], sum_f(lazy[k], len));
    lazy[k] = unit;
  }

  // [a, b)
  T update(int a, int b, T x, int k, int l, int r) {
    eval(r - l, k);
    if (b <= l || r <= a)
      return dat[k];
    if (a <= l && r <= b) {
      lazy[k] = update_f(lazy[k], x);
      return query_f(dat[k], sum_f(lazy[k], r - l));
    }
    return dat[k] = query_f(update(a, b, x, 2 * k + 1, l, (l + r) / 2),
                            update(a, b, x, 2 * k + 2, (l + r) / 2, r));
  }

  T update(int a, int b, T x) { return update(a, b, x, 0, 0, n); }

  // [a, b)
  T query(int a, int b, int k, int l, int r) {
    eval(r - l, k);
    if (b <= l || r <= a)
      return unit;
    if (a <= l && r <= b)
      return dat[k];
    return query_f(query(a, b, 2 * k + 1, l, (l + r) / 2), query(a, b, 2 * k + 2, (l + r) / 2, r));
  }

  T query(int a, int b) { return query(a, b, 0, 0, n); }
};

using segtree = RSQRAQ2<ll>;

ll power(ll e, ll x, ll p) {
  ll r = 1;
  while (x) {
    if (x % 2) {
      r = (r * e) % p;
    }
    e = (e * e) % p;
    x >>= 1;
  }
  return r;
}

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int n, k, a;
  cin >> n >> k >> a;
  segtree r(k, 0, [](ll l, ll r) {
    return (l + r) % P;
  }, [](ll v, int l) {
    return (v * l) % P;
  }, [](ll l, ll r) {
    return (l + r) % P;
  });

  r.update(0, 1, 1);
  ll ans = 0;
  ll ninv = power(n, P - 2, P);
  ll perc = (a * power(100, P - 2, P)) % P;

  for (int i = 0; i < k; i++) {
    ll v = r.query(i, i + 1);

    r.update(i + 1, min(k, i + n + 1), ((v * ninv) % P * perc) % P);
    if (n - k + i + 1 > 0) {
      ans += ((v * ninv) % P * (n - k + i + 1)) % P;
      ans %= P;
    }
  }

  cout << ans << endl;

  return 0;
}



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

int main(){
	ios_base::sync_with_stdio(false), cin.tie(nullptr);
	string s;
	cin >> s;
	int n = (int)s.size();
	vector<int> left0(n+1, 0), left1(n+1, 0);
	{
		int min0 = 0;
		int min1 = 0;
		int cur0 = 0;
		int cur1 = 0;
		for(int i = 0; i < n; i++){
			if(s[i] == '0') cur0++;
			if(s[i] != '0') cur0--;
			if(s[i] == '1') cur1++;
			if(s[i] != '1') cur1--;
			min0 = min(min0, cur0);
			min1 = min(min1, cur1);
			left0[i+1] = cur0 - min0;
			left1[i+1] = cur1 - min1;
		}
	}
	int odd0 = 0, odd1 = 0, even0 = 0, even1 = 0;
	for(int i = 0; i <= n; i++){
		if(i & 1){
			odd0 = max(odd0, left0[i]);
			odd1 = max(odd1, left1[i]);
		} else {
			even0 = max(even0, left0[i]);
			even1 = max(even1, left1[i]);			
		}
	}
	int ans = 0;
	ans = max(ans, odd0);
	ans = max(ans, odd1);
	ans = max(ans, even0);
	ans = max(ans, even1);
	if(odd0 == even0) ans = max(ans, odd0+1);
	if(odd1 == even1) ans = max(ans, odd1+1);
	cout << ans << '\n';
}

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

int main(void) {
  long long int k, n;
  scanf("%lld %lld", &n, &k);

  long long int diff[k];
  long long int start = 0;
  long long int point = 0;
  long long int max = 0;
  long long int max_i = 0;

  scanf(" %lld", &start);
  point = start;
  for (long long int i = 0; i < k; i++) {
    
    if (i == k - 1) {
      // printf("i: %lld\n", i);
      diff[i] = n - point + start;
    } else {
      scanf(" %lld", &diff[i]);
      diff[i] -= point;
      point += diff[i];
    }

    if (max < diff[i]) {
      max = diff[i];
      max_i = i;
    }
    // printf("%lld\n", diff[i]);
  }

  long long int result = 0;
  long long int pointer_i = max_i + 1;
  for (long long int i = 0; i < k - 1; i++) {
    result += diff[(i + pointer_i) % k];
  }

  printf("%lld\n", result);

  return 0;
}


Measured memory_bytes: 1792
#include<iostream>
using namespace std;
int main()
{
int n;
cin>>n;
if(n<2)
 cout<<n;
else
  if(n<4)
   cout<<"2";
else
  if(n<8)
    cout<<"4";
  else
     if(n<16)
      cout<<"8";
    else
       if(n<32)
         cout<<"16";
       else
          if(n<64)
            cout<<"32";
         else
            cout<<"64";
return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

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

	/* 入力 */
	int h = scan.nextInt();
	int w = scan.nextInt();
	String[] c = new String[h];
	for(int i = 0 ; i < h; i++){
	    c[i] = scan.next();
	}

	/* 出力 */
	for(int i = 0; i < h; i++){
	    System.out.println(c[i]);
	    System.out.println(c[i]);
	}

    }
}


Measured memory_bytes: 23636
#include <stdio.h>
int main(void){
  int A[100][100];  /* 最大サイズの配列を作る */
  int B[100];
  int C[100] = {0}; /* 0 で初期化 */
int i, j;
    int n, m;
   scanf("%d%d", &n, &m);
  for(i = 0; i < n; i++) {
    for(j = 0; j < m; j++) 
         scanf("%d", &A[i][j]);
    }
    for (j = 0; j < m; j++) scanf("%d", &B[j]);
    for (i = 0; i < n; i++) {
        C[i] = 0;
        for (j = 0; j < m; j++)
      C[i] += A[i][j] * B[j];
    }
   for (i = 0; i < n; i++) {
        printf("%d\n", C[i]);
    }
  

  return 0;
}




Measured memory_bytes: 2768
use std::io::*;
use std::str::FromStr;

pub fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let n: usize = read();
    let m: usize = read();
    let k: i64 = read();
    let mut a: Vec<i64> = vec![];
    let mut b: Vec<i64> = vec![];

    let mut tmp: i64 = 0;
    for _ in 0..n {
        tmp += read::<i64>();
        a.push(tmp);
    }

    let mut tmp: i64 = 0;
    for _ in 0..m {
        tmp += read::<i64>();
        b.push(tmp);
    }
    // println!("{}", a.lower_bound(k as i64));

    let mut maxv = b.upper_bound(k);
    for i in 0..a.upper_bound(k as i64) {
        let r = k - a[i];
        let ans = (i + 1) + b.upper_bound(r);
        if ans > maxv {
            maxv = ans;
        }
    }
    println!("{}", maxv);

    // start from n
}

use std::cmp::Ordering;

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

impl<T: Ord> BinarySearch<T> for [T] {
    fn lower_bound(&self, x: T) -> usize {
        let mut low = 0;
        let mut high = self.len();

        while low != high {
            let mid = (low + high) / 2;
            match self[mid].cmp(&x) {
                Ordering::Less => {
                    low = mid + 1;
                }
                Ordering::Equal | Ordering::Greater => {
                    high = mid;
                }
            }
        }
        low
    }
    fn upper_bound(&self, x: T) -> usize {
        let mut low = 0;
        let mut high = self.len();

        while low != high {
            let mid = (low + high) / 2;
            match self[mid].cmp(&x) {
                Ordering::Less | Ordering::Equal => {
                    low = mid + 1;
                }
                Ordering::Greater => {
                    high = mid;
                }
            }
        }
        low
    }
}


Measured memory_bytes: 5268
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <math.h>
#include <queue>
#include <stack>

using namespace std;

stack<int> s;
int n;

int main(void){
	while (cin >> n){
		if (n != 0) s.push(n);
		else if (n == 0) {
			cout << s.top() << endl;
			s.pop();
		}
	}
}

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

using ll = long long;
using namespace std;

#define FOR(i,a,b) for(int i = (int)(a); i <= (int)(b); i++)
#define FORR(i,a,b) for(int i = (int)(a); i >= (int)(b); i--)
#define REP(i,n) FOR(i,0,(int)(n)-1)
#define REPR(i,n) FORR(i,(int)(n)-1,0)

#define LFOR(i,a,b) for(ll i = (ll)(a); i <= (ll)(b); i++)
#define LFORR(i,a,b) for(ll i = (int)(a); i >= (ll)(b); i--)
// #define LREP(i,n) LFOR(i,0,(ll)(n)-1)
// #define LREPR(i,n) LFORR(i,(ll)(n)-1,0)

#define SIZ(v) int(v.size())
const int INF = 1e8;
const ll LINF = 1e15;
const int MOD = 1e9+7;



int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  ll h[100000];
  memset(h,0,sizeof(h));
  cin >> n;
  REP(i,n){
    int k; cin >> k; h[i]=k;
  }
  int ans=0,tmp=0;
  REP(i,n){
    if(i==n-1 || h[i]<h[i+1])  {ans = max(ans,tmp); tmp = 0;}
    else tmp++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 1024
# Author: cr4zjh0bp
# Created: Mon Mar 23 15:10:04 UTC 2020
import sys
 
stdin = sys.stdin
inf = 1 << 60
mod = 1000000007
 
ni      = lambda: int(ns())
nin     = lambda y: [ni() for _ in range(y)]
na      = lambda: list(map(int, stdin.readline().split()))
nan     = lambda y: [na() for _ in range(y)]
nf      = lambda: float(ns())
nfn     = lambda y: [nf() for _ in range(y)]
nfa     = lambda: list(map(float, stdin.readline().split()))
nfan    = lambda y: [nfa() for _ in range(y)]
ns      = lambda: stdin.readline().rstrip()
nsn     = lambda y: [ns() for _ in range(y)]
ncl     = lambda y: [list(ns()) for _ in range(y)]
nas     = lambda: stdin.readline().split()

from decimal import *

a, b, c = na()

d, e, f = Decimal(a), Decimal(b), Decimal(c)
if d.sqrt() + e.sqrt() < f.sqrt():
    print("Yes")
else:
    print("No")

Measured memory_bytes: 5024
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; ++i)
#define REPR(i, n) for (int i = n - 1; i >= 0; --i)
#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define FORR(i, a, b) for (int i = b - 1; i >= a; --i)
#define SORT(v) sort(v.begin(), v.end())
#define SORTR(v) sort(v.rbegin(), v.rend())
#define REV(v) reverse(v.begin(), v.end())
#define ITER(itr, v) for (auto itr = v.begin(); itr != v.end(); ++itr)
#define LB(v, x) (lower_bound(v.begin(), v.end(), x) - v.begin())
#define UB(v, x) (upper_bound(v.begin(), v.end(), x) - v.begin())
#define SZ(v) (int)v.size()
using namespace std;
using ll = long long;
using P = pair<int, int>;

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

    int N;
    ll K;
    cin >> N >> K;
    vector<ll> A(N);
    REP(i, N) {
        cin >> A[i];
    }
    const ll INF = 1000000000;
    ll l = 0, r = INF;
    while (l + 1 < r) {
        ll m = (l + r) / 2;
        ll k = K;
        REP(i, N) {
            int n = A[i] / m + (bool)(A[i] % m) - 1;
            if (n > k) {
                l = m;
                break;
            }
            k -= n;
            if (i == N - 1) {
                r = m;
            }
        }
    }
    cout << r << endl;

    return 0;
}


Measured memory_bytes: 4640
#include <iostream>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <bitset>
#include <string.h>

using namespace std;

// #define for(i,a,b) for (int i=(a);i<(b);++i)
typedef long long ll;
typedef pair<ll,ll> P;
#define REP(i,n) for(long long i = 0; i < (long long)(n); i++)
#define pb push_back // vectorに要素追加
#define INF (ll)1e18

ll mod = 1e9+7;
  
// 検索タグ
int main() {
	// 入力
	ll a,b,c;cin>>a>>b>>c;
    
	//出力
	bool ans = (4*a*b<((c-a-b)*(c-a-b)));
	if (c-a-b<0) ans = false;
	if (ans) printf("Yes\n");
	else printf("No\n");
}


Measured memory_bytes: 256