akhauriyash/Code-Regression huggingface dataset:
#define TEMPLATE_USED
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> pl;
typedef vector<pl> vp;
const ll INF=1001001001;
const ll LINF=1001001001001001001;
const ll D4[]={0,1,0,-1,0};
const ll D8[]={0,1,1,0,-1,-1,1,-1,0};
#define _overload3(_1,_2,_3,name,...) name
#define _rep2(i,n) for(ll i=0;i<(n);++i)
#define _rep3(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(...) _overload3(__VA_ARGS__,_rep3,_rep2)(__VA_ARGS__)
#define _repe2(i,n) for(ll i=0;i<=(n);++i)
#define _repe3(i,a,b) for(ll i=(a);i<=(b);++i)
#define repe(...) _overload3(__VA_ARGS__,_repe3,_repe2)(__VA_ARGS__)
#define _rrep2(i,n) for(ll i=(n)-1;i>=0;i--)
#define _rrep3(i,a,b) for(ll i=(b)-1;i>=(a);i--)
#define rrep(...) _overload3(__VA_ARGS__,_rrep3,_rrep2)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
template<class T>
bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>
bool chmin(T &a,const T &b){if(b<a){a=b;return 1;}return 0;}
template<class T>
using pq=priority_queue<T,vector<T>,greater<T>>;
const string YES = "Yes";

ll N;
ll M;
vl A;
vl B;

void solve();

int main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    cin >> N;
    cin >> M;
    A = vl(M);
    B = vl(M);
    for(int i = 0; i < M; ++i){
        cin >> A[i];
        cin >> B[i];
    }
    solve();
}

// 入力はすべて整数
// 2 <= N <= 10^5
// 1 <= M <= 2 × 10^5
// 1 <= A_i, B_i <= N\ (1 <= i <= M)
// A_i != B_i\ (1 <= i <= M)
// どの 2 部屋間も、通路をいくつか通って行き来できる

// ll N, ll M, vl A, vl B
// 目標を達成できる道しるべの配置が存在しなければ No を出力せよ。
// 存在する場合、N 行出力せよ。1 行目には Yes を、i\ (2 <= i <= N) 行目には部屋 i の道しるべが指す部屋の番号を出力せよ。
void solve(){
    vvl g(N);
    rep(i,M){
        g[A[i]-1].push_back(B[i]-1);
        g[B[i]-1].push_back(A[i]-1);
    }

    vl d(N);
    d[0]=1;
    queue<ll> q;
    q.push(0);
    vl ans(N);
    while(q.size()){
        ll src=q.front();q.pop();
        for(ll to:g[src]){
            if(d[to])continue;
            q.push(to);
            ans[to]=src+1;
            d[to]=1;
        }
    }

    rep(i,1,N){
        if(!d[i]){
            cout<<"No"<<endl;
            return;
        }
    }
    cout<<"Yes"<<endl;
    rep(i,1,N)cout<<ans[i]<<endl;
}


Measured memory_bytes: 16932
import java.util.Scanner;

public class Main {

    public static void main(String args[]) {

        // 入力
        Scanner sc = new Scanner(System.in);
        int x = Integer.parseInt(sc.next());

        // 主処理
        int result = 0;
        int position = 0;
        for (int i = 1; position < x; i++) {
            position += i;
            result++;
        }

        // 出力
        System.out.println(result);
        sc.close();
    }
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)

int N, M;
constexpr int MAX = 300;

bool nibu(int c, vector<queue<int> > A)
{
    set<int> del;
    while (true)
    {
        map<int, int> d;
        for (auto v : A) d[v.front()]++;
        bool endflg = true;
        for (auto k : d) if (k.second > c) {
            del.insert(k.first);
            endflg = false;
        }
        if (endflg) return true;
        for (auto &v : A) while (true) {
            if (del.find(v.front()) == del.end()) break;
            v.pop();
            if (v.empty()) return false;
        }
    }
}

int main()
{
    cin >> N >> M;
    vector<queue<int>> A(N);
    REP(i, N) REP(j, M) {
        int tmp;
        cin >> tmp;
        A[i].push(tmp);
    }
    int l = 0, r = N; // l:不可能 r:可能
    while (r - l > 1) {
        int c = (l + r) / 2;
        // int c = l + 1;
        (nibu(c, A) ? r : l) = c;
    }
    cout << r << endl;
}


Measured memory_bytes: 1280
#include <iostream>

using namespace std;
char maps[1001][1001];
int n;
bool rectn(int y,int x,int k){
	for(int i=0;i<k;i++){
		for(int j=0;j<k;j++){
			if(i+y>=n||j+x>=n||maps[i+y][j+x]=='*')return false;
		}
	}
	return true;
}
int rect(int y,int x){
	for(int k=1;1;k++){
		if(!rectn(y,x,k))return k-1;
	}
}
void solve(){
	int ans=0;
	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++){
			if(maps[i][j]=='.'){
				int tmp=rect(i,j);
				ans=max(ans,tmp);
			}
		}
	}
	cout<<ans<<endl;
}

int main(){
	while(cin>>n&&n){
		for(int i=0;i<n;i++){
			cin>>maps[i];
		}
		solve();
	}
	return 0;
}

Measured memory_bytes: 1636
n=int(input())
l=list(map(int,input().split()))
l2=sorted(l)
for _ in range(n):
    if len(l2)==1:
        break
    a=l2.pop(0)
    b=l2.pop(0)
    l2.insert(0, (a+b)/2)
print(l2[0])

Measured memory_bytes: 3060
<?php
fscanf(STDIN, "%d%d", $H, $W);
for($i = 0; $i < $H; $i++){
    $str = fgets(STDIN);
    for($j = 0; $j < $W; $j++){
        $map[$i][$j] = $str[$j];
    }
}
$sum = 0;
for($y = 0; $y < $H; $y++){
    for($x = 0; $x < $W; $x++){
        $ad = [];
        $black = dfs($y, $x);
        $white = count($ad, true) - count($ad);
        $sum += $black*$white;
    }
}
echo $sum,"\n";


function dfs($y, $x){
    global $map, $ad;
    if($map[$y][$x] != "#"){
        return 0;
    }else{
        $count = 1;
        $map[$y][$x] = "x"; 
    }
    foreach([[1,0],[-1,0],[0,1],[0,-1]] as list($dy, $dx)){
        if(isset($map[$y+$dy][$x+$dx]) && $map[$y+$dy][$x+$dx] == "."){
            $ad[$y+$dy][$x+$dx] = true;
            foreach([[1,0],[-1,0],[0,1],[0,-1]] as list($ddy, $ddx)){
                if(isset($map[$y+$dy+$ddy][$x+$dx+$ddx]) && $map[$y+$dy+$ddy][$x+$dx+$ddx] == "#"){
                    $count += dfs($y+$dy+$ddy, $x+$dx+$ddx);
                }
            }    
        }
    }
    return $count;
}

Measured memory_bytes: 109048
import java.util.Scanner;
import java.util.Arrays;
import java.util.Comparator;
 
class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    Integer a[] = new Integer[N];
    for(int i=0;i<N;i++){
      a[i] = sc.nextInt();
    }
    Arrays.sort(a,Comparator.reverseOrder());
    
    int Alice = 0;
    int Bob = 0;
    for(int i=0;i<N;i+=2){
      Alice += a[i];
    }
    for(int i=1;i<N;i+=2){
      Bob += a[i];
    }
    
    System.out.println(Alice-Bob);
  }
}

Measured memory_bytes: 23124
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
typedef vector<vector<P>> vvP;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;
ll ceil(ll a, ll b) {  // a÷b以上の最小の整数
    if(b == 0) {
        return 0;
    }
    if(a%b == 0) {
        return a/b;
    }
    else {
        return a/b + 1;
    }
}

int main() {
    ll h, a;
    cin >> h >> a;
    out(ceil(h, a));
    re0;
}

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

int main() {
  int n, counter=0;
  cin >> n;
  vector<int> p(n);
  for (int i=0; i<n; i++) {
    cin >> p.at(i);
  }
  for (int i=0; i<n-2; i++) {
    bool increase = (p.at(i)<p.at(i+1) && p.at(i+1)<p.at(i+2));
    bool decrease = (p.at(i)>p.at(i+1) && p.at(i+1)>p.at(i+2));
    if (increase || decrease) {
      counter++;
    }
  }
  cout << counter << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define INF_LL 1LL << 40
#define INF 200000000
#define MOD 1000000007
#define ll long long
#define all(x) x.begin(), x.end()
#define REP(i, a, b) for(int i = a; i < b; i++)
#define rep(i, n) REP(i, 0, n)
// typedef float double;
// typedef priority_queue prique;
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<P> vp;
typedef vector<ll> vl;
typedef vector<vi> matrix;
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};
int sign[2] = {1, -1};
template <class T> bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T> bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return 1;
    }
    return 0;
}

ll modpow(ll a, ll b, ll m) {
    if(b == 0)
        return 1;
    ll t = modpow(a, b / 2, m);
    if(b & 1) {
        return (t * t % m) * a % m;
    } else {
        return t * t % m;
    }
}
struct edge {
    int to, cap, rev;
};

typedef struct binary_indexed_tree {
    int n;
    int bit[1000010];
    void add(int a, int w) {
        for(int x = a; x <= n; x += x & -x)
            bit[x] += w;
    }
    int sum(int a) {
        int ret = 0;
        for(int x = a; x > 0; x -= x & -x)
            ret += bit[x];
        return ret;
    }
} BIT;

signed main() {
    int n, q;
    string s;
    cin >> n >> s >> q;
    vector<BIT> t(26);
    rep(i, 26) { t[i].n = n; }
    rep(i, n) { t[s[i] - 'a'].add(i + 1, 1); }
    rep(_, q) {
        int a;
        cin >> a;
        if(a == 1) {
            int i;
            string c;
            cin >> i >> c;
            t[s[i - 1] - 'a'].add(i, -1);
            t[c[0] - 'a'].add(i, 1);
            s[i - 1] = c[0];
        } else {
            int l, r;
            cin >> l >> r;
            int res = 0;
            rep(i, 26) {
                if(t[i].sum(r) - t[i].sum(l - 1) > 0)
                    res++;
            }
            cout << res << endl;
        }
    }
}


Measured memory_bytes: 106372
import java.util.Scanner;

class Main {
    static Scanner in = new Scanner(System.in);

    public static void main(String[] args) {
        int n = Integer.parseInt((in.nextLine().split(" "))[0]);
        String[] s = new String[n];
        for(int i = 0; i < n; i++){
            s[i] = in.nextLine();
        }
        for(int i = 0; i < n * 2; i++){
            System.out.println(s[i / 2]);
        }
        
    }
}

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

#define rep(i,n) for(ll (i)=0;(i)<(ll)(n);(i)++)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007LL
#define INF (1LL<<60LL)
#define int long long
typedef long long ll;

using namespace std;

#define MAX_N 1000000

signed main() {
	while (1) {
		ll m, f, r; cin >> m >> f >> r;
		if (m == -1 && f == -1 && r == -1) break;
		if (m == -1 || f == -1) {
			cout << "F" << endl;
		}
		else if (m + f >= 80) {
			cout << "A" << endl;
		}
		else if (m + f >= 65) {
			cout << "B" << endl;
		}
		else if (m + f >= 50) {
			cout << "C" << endl;
		}
		else if (m + f >= 30 && r >= 50) {
			cout << "C" << endl;
		}
		else if (m + f >= 30) {
			cout << "D" << endl;
		}
		else cout << "F" << endl;
	}
}


Measured memory_bytes: 3096
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
      Scanner sc = new Scanner(System.in);
      
      int a = sc.nextInt();
      int b = sc.nextInt();
      int c = sc.nextInt();
      
      if (a < b && b < c){
          System.out.println("Yes");
      }else if (!(a < b && b < c)){
          System.out.println("No");
      }
    }
}



Measured memory_bytes: 26188
#include <bits/stdc++.h>
using namespace std;
 
#define FAST ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
 
#define MAXX 200010
 
#define PI   3.14159265358979323846264338327950
 
#define PB push_back 
#define F first
#define S second
 
#define ll 	long long int
 
#define mod  1000000007
 

 
int main()
{
	FAST;
	int a, b, c;
	cin >> a >> b >> c;
	cout << max(0, b+c-a);
	return 0;
}

Measured memory_bytes: 3652
def main():
    N = int(input())

    A = []
    for _ in range(N):
        a = sorted(list(input()))
        A.append(''.join(a))
    td = {}
    for t in A:
        if t not in td.keys():
            td[t] = 1
        else:
            td[t] += 1
    count = 0
    for v in td.values():
        count += v * (v - 1) // 2
    print(count)


main()



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

int main(){
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	int n; cin>>n;
	if(n==0){ cout<<1<<"\n"; }
	else if(n==1){ cout<<0<<"\n"; }
	return 0;
}

Measured memory_bytes: 3648
#include <iostream>
#include <algorithm>
using namespace std;
const long long mod = 1e9 + 7ll;
const int N = 2 * 1e5 + 10;

long long fac[ N ];

long long pw( long long a, long long b )
{
    if ( b == 0ll ) return 1ll;
    long long r = pw( a, b / 2ll );
    r = ( r * r ) % mod;
    if ( b % 2ll ) r = ( a * r ) % mod;
    return r;
}
long long inv( long long x )
{
    return pw( x, mod - 2ll );
}//这一个是计算逆元的
long long path( long long a, long long b )
{
    long long ans = fac[ a + b ];
    ans = ( ans * inv( fac[ a ] ) ) % mod;
    ans = ( ans * inv( fac[ b ] ) ) % mod;
    return ans;
}//这一个是计算组合数的
int main ( void )
{

    int h, w, a, b;
    std::cin >> h >> w >> a >> b;

    fac[0] = 1ll;
    for ( int i = 1 ; i < N ; i++ )
    {
        fac[i] = ( i * fac[i-1] ) % mod;
    }

    long long ans = 0ll;
    for ( int i = h - a, j = b + 1 ; i > 0 and j <= w ; i--, j++ )
    {
        ans += ( path( i - 1, j - 1 ) * path( h - i, w - j ) ) % mod;
    }

    ans = ( ans % mod + mod ) % mod;
    std::cout << ans << std::endl;

    return 0;
}


Measured memory_bytes: 1792
#include <stdio.h>

#define SWAP(A,B) { int __tempora = B; B = A; A = __tempora; }
#define SQUARE(X) ((X)*(X))

/** Application main entry point. */
int main (
  int argc,
  char *argv[ ]
  )
{
  int n;

  scanf ( "%d", &n );

  while ( n-- )
  {
    int a, b, c;

    scanf ( " %d %d %d", &a ,&b ,&c );
    if ( b > a && b > c )
    {
      SWAP(a,b); 
    }
    else if ( c > a && c > b )
    {
      SWAP(a,c); 
    }

    puts ( SQUARE(a) == SQUARE(b) + SQUARE(c)
      ? "YES"
      : "NO" );
  }

  return ( 0 );
}

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

typedef long long ll;
typedef long double ld; //
typedef double db; //
typedef string str; //
//
typedef pair<int, int> pi;
typedef pair<ll,ll> pl; //
typedef pair<ld,ld> pd; //
#define mp make_pair
#define f first
#define s second

typedef vector<int> vi;
typedef vector<ll> vll; //
typedef vector<ld> vd; //
typedef vector<str> vs; //
typedef vector<pi> vpi; //
typedef vector<pl> vpl; //
typedef vector<pd> vpd; //
typedef vector<vi> vvi;
typedef vector<vll> vvll;

//
#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define rall(x) (x).rbegin(), (x).rend() //
#define rsz resize
#define ins insert //
#define ft front() //
#define bk back() //
#define pf push_front //
#define pb push_back
#define eb emplace_back //
#define lb lower_bound //
#define ub upper_bound //

#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define F0R(i,a) FOR(i,0,a)
#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define R0F(i,a) ROF(i,0,a)
#define trav(a,x) for (auto& a: x)

const int MOD = 1e9+7; // 998244353; // = (119<<23)+1
const int MX = 2e5+5; //
const ll INF = 1e18; //
const ld PI = 4*atan((ld)1); 
const int xd[4] = {0,1,0,-1}, yd[4] = {1,0,-1,0}; //

template<class T> bool ckmin(T& a, const T& b) { 
    return a > b ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { 
    return a < b ? a = b, 1 : 0; }
mt19937 rng((uint32_t)chrono::steady_clock::now().time_since_epoch().count());

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

    int N;
    cin >> N;

    vll A(N);
    vll B(N);

    for (int i=0;i<N;i++) cin >> A[i];
    for (int i=0;i<N;i++) cin >> B[i];

    vll surplus;
    int num_deficit = 0;
    ll total_deficit = 0;
    ll Asum = 0;
    ll Bsum = 0;
    for (int i=0; i<N; i++) {
        Asum += A[i];
        Bsum += B[i];
        if (A[i] < B[i]) {
            num_deficit++;
            total_deficit += B[i] - A[i];
        } else if (A[i] > B[i]) {
            surplus.pb(A[i] - B[i]);
        }
    }

    if (Asum < Bsum) {
        cout << -1 << endl;
        return 0;
    }

    sort(all(surplus));
    reverse(all(surplus));

    int ind = 0;
    while (total_deficit > 0) {
        total_deficit -= surplus[ind];
        ind++;
    }

    cout << num_deficit + ind << endl;
}

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

#include <vector>
#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)
using namespace std;

int main() {
  long N, M, result, tmp;
  cin >> N >> M;
  //   int A[M];
  result = N;
  rep(i, M) {
    cin >> tmp;
    result -= tmp;
  }
  cout << max(long(-1), result) << endl;
}

Measured memory_bytes: 3624
import itertools
n,m = map(int,input().split())
all_li = []
for _ in range(m):
    li = list(map(int,input().split()))
    li.pop(0)
    all_li.append(li)
p_li = list(map(int,input().split()))

kumi = list(itertools.product([0,1], repeat=n))
# print(list(itertools.product([0,1], repeat=n)))
# [(0, 0), (0, 1), (1, 0), (1, 1)]

#print(all_li)
# [[1, 2], [2]]

count = 0
for k in kumi:
    flag = True
    for i,each_li in enumerate(all_li):
        tmp = 0
        for e in each_li:
            if list(k)[e-1] == 1:
                tmp += 1
        if tmp%2 != p_li[i]:
            flag = False
    if flag:
        count += 1
print(count)

Measured memory_bytes: 42224
#include <iostream>
#include <string>

using namespace std;

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

    int n = 0;
    for (int i = 0; i < 3; i++) {
        n += grid[i] == '1' ? 1 : 0;
    }

    cout << n << endl;
}


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

int main() {
  int n, m;
  cin >> n >> m;
  int sum = 0;
  rep(i, m) {
    int ai;
    cin >> ai;
    sum += ai;
  }

  cout << (sum > n ? -1 : n - sum) << endl;
  return 0;
}

Measured memory_bytes: 3620
// I look at my watch
// it say nine twenty-five
// And I think oh God
// I'm still alive
 
#include <bits/stdc++.h>
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define sz(x) int((x).size())
#define all(v) (v).begin(),(v).end()
#define trace(x) cerr << #x << " = " << x << endl
#define fastio ios_base::sync_with_stdio(0);cin.tie(0)
#define For(i,a,b) for(int i = int(a); i < int(b); ++i)
#define roF(i,a,b) for(int i = int(a); i >= int(b); i--)
using namespace std;
 
typedef long long ll;
typedef pair<int,int> ii;
typedef long double ld;


int main(){	
	ll n,k;cin>>n>>k;
	ll ans=n*(n-k);
	if(k==0){
		cout<<ans<<endl;
		return 0;
	}
	// no contar a=0
	for(ll b=k+1;b<n+1;b++){
		ll comp=(n+1)/b;
		ll taminc=(n+1)%b;
		ans-=k*comp;
		ans-=min(k,taminc);
		ans++;
	}
	cout<<ans<<endl;

	return 0;
}


Measured memory_bytes: 256
s=list(input())
t=list(input())
dp=[[0 for _ in range(len(t)+1)] for _ in range(len(s)+1)]

for i in range(len(s)):
    for j in range(len(t)):
        if s[i]==t[j]:
            dp[i+1][j+1]=max(dp[i][j]+1,dp[i+1][j],dp[i][j+1])
        else:
            dp[i+1][j+1]=max(dp[i+1][j],dp[i][j+1])

path=[]

lens=len(s)
lent=len(t)
while lens>-1 and lent>-1 :
    if dp[lens][lent]==dp[lens-1][lent]:
        lens-=1
    elif dp[lens][lent]==dp[lens][lent-1]:
        lent-=1
    else:
        path.append(lens)
        lens-=1
        lent-=1

path.sort()
if path==[]:
    print("")
else:
    for i in path:
    	print(s[i-1],end="")

Measured memory_bytes: 120028
def solve(string):
    n, m, *a = map(int, string.split())
    ans = [0] * (n + 1)
    for _a in a:
        ans[_a] = -1
    ans[0] = 1
    ans[1] = 1 if ans[1] == 0 else 0
    for i in range(2, n + 1):
        if ans[i] == -1:
            ans[i] = 0
            continue
        ans[i] += ans[i - 2] % 1000000007
        ans[i] += ans[i - 1] % 1000000007
    return str(ans[-1] % 1000000007)


if __name__ == '__main__':
    n, m = map(int, input().split())
    print(solve('{} {}\n'.format(n, m) + '\n'.join([input() for _ in range(m)])))


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

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

  for(int i=0;i<n;i++){
    int v=a[i];
    int j=i-1;
    while(j>=0&&a[j]>v) {
      a[j+1]=a[j];
      j--;
    }
    a[j+1]=v;
    for(int k=0;k<n-1;k++) cout<<a[k]<<" ";
    cout << a[n-1]<<endl;
  }
  return 0;
}

Measured memory_bytes: 1164
use std::cmp::min;

fn read<T: std::str::FromStr>(
    stdin_lock: &mut std::io::StdinLock,
    buf: &mut Vec<u8>,
    delimiter: u8,
) -> T {
    buf.clear();
    let l = std::io::BufRead::read_until(stdin_lock, delimiter, buf).unwrap();
    buf.truncate(l - 1); // remove delimiter
    let s = unsafe { std::str::from_utf8_unchecked(&buf) };
    s.parse().unwrap_or_else(|_| panic!("read"))
}

fn main() {
    let stdin = std::io::stdin();
    let mut stdin_lock = stdin.lock();
    let mut buf: Vec<u8> = Vec::new();
    let n: usize = read(&mut stdin_lock, &mut buf, b' ');
    let k: usize = read(&mut stdin_lock, &mut buf, b'\n');
    let mut xv = vec![0i64; n];
    for i in 0..n - 1 {
        xv[i] = read(&mut stdin_lock, &mut buf, b' ');
    }
    xv[n - 1] = read(&mut stdin_lock, &mut buf, b'\n');

    let mut ans = xv[0].abs() + (xv[n - 1] - xv[0]).abs();
    for i in 0..n - k + 1 {
        ans = min(
            ans,
            min(
                xv[i].abs() + (xv[i + k - 1] - xv[i]).abs(),
                (xv[i + k - 1] - xv[i]).abs() + xv[i + k - 1].abs(),
            ),
        );
    }
    println!("{}", ans);
}


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

using namespace std;

#define int long long
#define endl "\n"

constexpr long long INF = (long long)1e18;
constexpr long long MOD = 1'000'000'007; 

string yn(bool f){return f?"Yes":"No";}
string YN(bool f){return f?"YES":"NO";}



signed main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(10);
	
	int X, A, B;
	
	cin>>X>>A>>B;
	if(B-A <= 0) cout<<"delicious"<<endl;
	else if(B-A <= X) cout<<"safe"<<endl;
	else cout<<"dangerous"<<endl;
	
	
	return 0;
}

Measured memory_bytes: 256
// I look at my watch
// it say nine twenty-five
// And I think oh God
// I'm still alive
 
#include <bits/stdc++.h>
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define sz(x) int((x).size())
#define all(v) (v).begin(),(v).end()
#define trace(x) cerr << #x << " = " << x << endl
#define fastio ios_base::sync_with_stdio(0);cin.tie(0)
#define For(i,a,b) for(int i = int(a); i < int(b); ++i)
#define roF(i,a,b) for(int i = int(a); i >= int(b); i--)
using namespace std;
 
typedef long long ll;
typedef pair<int,int> ii;
typedef long double ld;




int main(){	
	int n,a,b;cin>>n>>a>>b;
	vector<int>ga;
	For(i,1,n+1)ga.pb(i);
	if(a>n||b>n){
		cout<<"-1"<<endl;
		return 0;
	}
	vector<int>ans;
	For(i,n-a+1,n+1)ans.pb(i);
	n-=a;
	if(n<b-1){
		cout<<"-1"<<endl;
		return 0;
	}
	b--;
	if(b==0){
		for(int val:ans)cout<<val<<" ";
		cout<<endl;
		return 0;
	}
	vector<int>bb(b,n/b);
	For(i,0,n%b)bb[i]++;
	For(i,0,sz(bb)){
		if(bb[i]>a){
			cout<<"-1"<<endl;
			return 0;
		}
	}

	For(g,0,b){
		For(i,n-bb[g]+1,n+1)ans.pb(i);
		n-=bb[g];
	}
	for(int val:ans)cout<<val<<" ";
	cout<<endl;
	sort(all(ans));
	assert(ans==ga);
	
	
	return 0;
}


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

int main(void){
  string a, b;
  cin >> a >> b;

  if(a.size() > b.size()){
    cout << "GREATER" << endl;
    return 0;
  } else if(a.size() < b.size()){
    cout << "LESS" << endl;
    return 0;
  }

  // When a and b has same digit
  int i = 0;
  while(true){
    if(a[i] == '\0' && b[i] == '\0'){
      cout << "EQUAL" << endl;
      return 0;
    }
    if(a[i] > b[i]){
      cout << "GREATER" << endl;
      return 0;
    } else if(a[i] < b[i]){
      cout << "LESS" << endl;
      return 0;
    }
    i++;
  }
  return 0;
}


Measured memory_bytes: 256
import std.stdio, std.string, std.conv, std.algorithm, std.numeric;
import std.range, std.array, std.math, std.typecons, std.container, core.bitop;


void main() {
    int x, y, z;
    scan(x, y, z);
    int ans = (x - z) / (y + z);
    writeln(ans);
}



void scan(T...)(ref T args) {
    string[] line = readln.split;
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}



void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}

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

int main()
{
	int a, b, c;
	cin >> a>> b>> c;
	if (a > b) swap(a, b);
	if (a > c) swap(a, c);
	if (b > c) swap(b, c);
	cout << a << " " << b << " " << c << endl;
    return 0;
}


Measured memory_bytes: 3052
x, y, a, b, c = map(int, input().split())

p = list(map(int, input().split()))
q = list(map(int, input().split()))
r = list(map(int, input().split()))

p.sort(reverse=True)
p = p[:x]
q.sort(reverse=True)
q = q[:y]

apples = p + q + r
apples.sort(reverse=True)

print(sum(apples[:x+y]))

Measured memory_bytes: 23328
N = int(input())
a = list(map(int,input().split()))
col = [0]*9
for i in range(N):
    if a[i] <=399:
        col[0] = 1
    elif a[i] <= 799:
        col[1] = 1
    elif a[i] <= 1199:
        col[2] = 1
    elif a[i] <= 1599:
        col[3] = 1
    elif a[i] <= 1999:
        col[4] = 1
    elif a[i] <= 2399:
        col[5] = 1
    elif a[i] <= 2799:
        col[6] = 1
    elif a[i] <= 3199:
        col[7] = 1
    else: col[8] += 1
ansmax = sum(col)
if col[8]>0:
    ansmin = max(sum(col[:8]),1)
else: ansmin = sum(col[:8])
print(ansmin, ansmax)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
typedef long long       ll;
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
#define pb                push_back
#define mp                make_pair
#define all(a)            (a).begin(), (a).end()
#define clr(a,h)          memset(a, (h), sizeof(a))
#define fore(i, b, e)      for(int i = b; i < e; i++)
#define forr(i, b, e)      for(int i = b; i < e; i++)
#define forg(i, b, e, m)  for(int i = b; i < e; i+=m)
#define F first
#define S second
int faster_in(){int r=0,c;for(c=getchar();c<=32;c=getchar());if(c=='-') return -faster_in();for(;c>32;r=(r<<1)+(r<<3)+c-'0',c=getchar());return r;}

using namespace std;
//using namespace __gnu_pbds;

typedef pair<int, int>  ii;
typedef pair<int, ii>  iii;
typedef vector<int>     vi;

typedef vector<ii>      vii;
typedef vector<ll>      vll;
//typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
const int INF = int(1e9 + 7);
const double PI = acos(-1);
const double EPS = 1e-9;
#define tam 1234567
#define news int newnodo=nodo*2,mid=(iz+der)/2;
int tree[tam*4];
string txt;
void init(int nodo,int iz,int der)
{
    if (iz==der)
    {
        //cout<<char(txt[iz])<<" ";
        tree[nodo]=(1<<(txt[iz]-'a'));
        //cout<<tree[nodo]<<endl;
        return;
    }
    news
    init(newnodo,iz,mid);
    init(newnodo+1, mid+1,der);
    tree[nodo]=(tree[newnodo]|tree[newnodo+1]);
}
void update(int nodo,int iz,int der,int pos)
{
    if (iz==der)
    {
        tree[nodo]=(1<<(txt[iz]-'a'));
        return;
    }
    news
    if (pos<=mid)
    update(newnodo,iz,mid,pos);
    else
    update(newnodo+1, mid+1,der,pos);
    tree[nodo]=(tree[newnodo]|tree[newnodo+1]);
}
int query(int nodo,int iz,int der,int li,int ri)
{
    if (iz>ri|| der<li)
        return 0;
    if (iz>=li && der<=ri)
        return tree[nodo];
    news
    return (query(newnodo,iz,mid,li,ri)|
                query(newnodo+1,mid+1,der,li,ri));
}
int main()
{
    int n;
    cin>>n;
    
    cin>>txt;
    txt=" "+txt;
    int q;
    cin>>q;
    int pos,iz,der,tipo;
    char chr;
    init(1,1,n);
    forr(i,0,q)
    {
        cin>>tipo;
        if (tipo==1)
        {
            cin>>pos>>chr;
            txt[pos]=chr;
            update(1,1,n,pos);
        }
        else
        {
            cin>>iz>>der;
            int answer=query(1,1,n,iz,der);
            cout<<__builtin_popcount(answer)<<endl;
        }
    }
}
// PLUS ULTRA!

Measured memory_bytes: 7064
#include <bits/stdc++.h>
using namespace std;
 
#define lli long long int
#define REP(i,s,n) for(int i=s;i<n;i++)
#define NUM 2520
#define INF (1LL<<50)
#define DEBUG 0
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())
#define PI (3.141592653589794)
#define TO_STRING(VariableName) # VariableName
#define LOG(x) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<endl;
#define LOG2(x,y) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<endl;
#define LOG3(x,y,z) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<" "<<TO_STRING(z)<<"="<<z<<endl;
#define LOG4(w,x,y,z) if(DEBUG)cout<<TO_STRING(w)<<"="<<w<<" "<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<" "<<TO_STRING(z)<<"="<<z<<endl;
 
template<class T>bool chmax(T & a, const T & b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }

lli x[30][30];
lli d;
lli distance(lli i,lli j){

	lli ans = 0;

	REP(k,0,d){

		lli diff = x[i][k]-x[j][k];
		ans += (diff)*diff;
	}

	return ans;
}

bool judge(lli num){
	for(lli i=1;i*i<=num;i++){
		if(i*i==num){
			return true;
		}
	}
	
		return false;

}

int main(){

	lli n;

	cin>>n>>d;

	REP(i,0,n)REP(j,0,d)cin>>x[i][j];

	lli cnt=0;
	REP(i,0,n)REP(j,i+1,n){
		if(judge(distance(i,j)))cnt++;
	}
	cout<<cnt<<endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#include<iostream>
#include<string>
#include<vector>
#include<utility>
#include<cmath>
#include<map>
#include<functional>
#include<queue>
#include<set>
#include<stack>
#include<iomanip>
#include<algorithm>
#include<unordered_map>
#include <numeric>
#include<string_view>
using namespace std;
using ll = long long;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define all(i) i.begin(),i.end()
template<typename T =ll> using v = vector<T>;
template<typename T =ll> using vv = v<v<T>>;
template<typename T =ll,typename U =ll> using p = pair<T,U>;
template<typename T> T chmin(T &a,T b) {return a=min(a,b);}
template<typename T> T chmax(T &a,T b) {return a=max(a,b);}
const ll INF = (ll)1e9;
template <int MOD>
struct ModInt {
    using lint = long long;
    int val;

    // constructor
    ModInt(lint v = 0) : val(v % MOD) {
        if (val < 0) val += MOD;
    };

    // unary operator
    ModInt operator+() const { return ModInt(val); }
    ModInt operator-() const { return ModInt(MOD - val); }
    ModInt inv() const { return this->pow(MOD - 2); }

    // arithmetic
    ModInt operator+(const ModInt& x) const { return ModInt(*this) += x; }
    ModInt operator-(const ModInt& x) const { return ModInt(*this) -= x; }
    ModInt operator*(const ModInt& x) const { return ModInt(*this) *= x; }
    ModInt operator/(const ModInt& x) const { return ModInt(*this) /= x; }
    ModInt pow(lint n) const {
        auto x = ModInt(1);
        auto b = *this;
        while (n > 0) {
            if (n & 1) x *= b;
            n >>= 1;
            b *= b;
        }
        return x;
    }

    // compound assignment
    ModInt& operator+=(const ModInt& x) {
        if ((val += x.val) >= MOD) val -= MOD;
        return *this;
    }
    ModInt& operator-=(const ModInt& x) {
        if ((val -= x.val) < 0) val += MOD;
        return *this;
    }
    ModInt& operator*=(const ModInt& x) {
        val = lint(val) * x.val % MOD;
        return *this;
    }
    ModInt& operator/=(const ModInt& x) { return *this *= x.inv(); }

    // compare
    bool operator==(const ModInt& b) const { return val == b.val; }
    bool operator!=(const ModInt& b) const { return val != b.val; }

    // I/O
    friend std::istream& operator>>(std::istream& is, ModInt& x) noexcept { return is >> x.val; }
    friend std::ostream& operator<<(std::ostream& os, const ModInt& x) noexcept { return os << x.val; }
};

constexpr int MOD = 1e9 + 7;
using mint = ModInt<MOD>;

void a(){
  ll x; cin >> x;
  cout << (x?0:1) << endl; 
}

void b(){

}

void c(){
  
}


void d(){

}

void e(){
   
}

void f(){
    
}

int main(void){
    a();
    return 0;
 }

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#include <boost/range/irange.hpp>

using namespace std;
using namespace boost;

main() {
    int64_t n, k;
    cin >> n >> k;

    constexpr auto M = 1000000007;

    int64_t s = sqrt(n);
    if ((s + 1) * (s + 1) <= n) {
        ++s;
    }

    vector<vector<int64_t>> counts(k + 1, vector<int64_t>(s + 1, 0));
    vector<vector<int64_t>> counts2(k + 1, vector<int64_t>(s + 1, 0));
    std::fill(counts[0].begin(), counts[0].end(), 1);
    std::iota(counts[1].begin(), counts[1].end(), 0);
    for (auto i : irange(0L, 2L)) {
        for (int64_t l = 1; l <= s; ++l) {
            counts2[i][l] = counts2[i][l - 1] +
                            (counts[i][l] * (n / l - n / (l + 1))) % M;
            counts2[i][l] %= M;
        }
    }

    for (auto i : irange(2L, k + 1)) {
        for (auto j : irange(1L, s + 1)) {
            int64_t num = counts[i - 1][s];

            num += (counts2[i - 2][n / (s + 1)] - counts2[i - 2][j - 1] + M) %
                   M;
            num %= M;

            counts[i][j] = (counts[i][j - 1] + num) % M;
        }

        for (int64_t l = 1; l <= s; ++l) {
            counts2[i][l] = counts2[i][l - 1] +
                            (counts[i][l] * (n / l - n / (l + 1))) % M;
            counts2[i][l] %= M;
        }
    }

    int64_t ans = (counts[k][s] + counts2[k - 1][n / (s + 1)]) % M;

    cout << ans << endl;
}

Measured memory_bytes: 50440
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i < (n); i++)
using namespace std;
using ll = long long;
int main(){
  ll n,k;
  cin >> n >> k;
  vector<int> a(n);
  rep(i,n) cin >> a[i];
  vector<ll> sum(n);
  sum[0] = a[0];
  for(int i=1;i<n;i++) sum[i]= sum[i-1]+a[i];
  ll max_sum = sum[k-1];
  for(int i =1; i<(n-k+1);i++){
    max_sum=max(sum[i+k-1]-sum[i-1],max_sum);
    //cout << sum[i+k-1]-sum[i-1] << endl;
  }
  long double ans = (double)(max_sum+k)/2.0;
  cout <<setprecision(25)<< ans << endl;
}

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

using namespace std;

int main()
{
    int n, m, x, y;
    int xi[101];
    int yi[101];

    cin >> n >> m >> x >> y;
    for (int i = 1; i <= n; i++) {
        cin >> xi[i];
    }
    xi[0] = x;
    for (int i = 1; i <= m; i++) {
        cin >> yi[i];
    }
    yi[0] = y;

    sort(&xi[0], &xi[n+1]);
    sort(&yi[0], &yi[m+1]);

    // for (int i=0; i<n; i++) {
    //     cout << xi[i] << ",";
    // }
    // cout << endl;
    // for (int i=0; i<m; i++) {
    //     cout << yi[i] << ",";
    // }
    // cout << endl;

    if (xi[n] >= yi[0]) {
        cout << "War" << endl;
    } else {
        cout << "No War" << endl;
    }

    return 0;
}


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

int main() {

  int K = 0;
  int N = 0;

  cin >> K >> N;

  int A[N];
  int ans = 0;

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

  int distance = A[0] + (K - A[N - 1]);

  for (int i = 0; i < N - 1; i++) {
    int a = A[i + 1] - A[i];
    if (distance < a) {
      distance = a;
    }
  }


  ans = K - distance;
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 1656
#include<stdio.h>
int main() {
	int a, b, c;
	scanf("%d %d %d", &a, &b, &c);
	int sum = 0;
	for (int i = a; i <= b; i++) {
		if (c % i == 0) {
			sum++;
		}
	}
	printf("%d\n", sum);
}



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

#define rep(i,a,b) for(int i=int(a);i<=int(b);++i)
#define nrep(i,a,b) for(int i=int(a);i>=int(b);--i)
#define trv(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define watch(x) cout<<"\n"<<#x<<" is "<<x<<"\n"
#define fast ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL);
#define ZERO(box) memset(box, 0, sizeof(box));
#define pb push_back
#define mt make_tuple
#define eb emplace_back
#define chkbit(s, b) (s & (1<<b))
#define leadzero(a) __builtin_clz(a) // count leading zeroes
#define trailzero(a) __builtin_ctz(a) // count trailing zeroes
#define bitcount(a) __builtin_popcount(a) // count set bits (add ll)
typedef long long ll;
typedef pair<int,int> pi;
typedef vector<int> vi;
typedef vector<vi> vvi;
const int mod=1e9+7;

bool check(ll n,ll b,ll s){
    ll sm=0;
    while(n){
        sm += n%b;
        n/=b;
    }
    return sm==s;
}

void solve(){
	ll n,s;
    cin>>n>>s;
    // base cases
    if(s>n){
        cout<<-1;
        return;
    }
    if(n==s){
        cout<<n+1;
        return;
    }
    ll b = 9e18;
    for(ll i=2;i*i<=n;i++){
        ll z = i;
        if(check(n,i,s)){
            cout<<i;
            return;
        }
    }
    // not any ans yet so let n=pb+q;
    ll p,q,tb;
    //n-=s;
    // now n = p(b-1);
    for(p=1;p*p<=n;p++){
        q = s-p;
        if(q<0) continue;
        if((n-q)%p ==0){
            tb = (n-q)/p;
            
            if(p==tb) tb++;
            // iske bina accept nhi hoga ~~\(:P)/~~
            
            if(q<tb){
                b = min(b,tb);
                
                //cout<<p<<" "<<q<<" "<<p+q<<" "<<s<<" "<<tb<<"\n";
            }
        }
    }
    if(b == 9e18){
        cout<<"-1";
    } else cout<<b;

}


int main(){
	int t=1;
	//cin>>t;
	while(t--){
		solve();	
	}	
}
/*input
4 2

49
7
99999515529
316227
100000000000
2
99999999977
49999999989
*/

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

int main() {
    ll n;
    cin >> n;
    if(n == 0 || n == 1 || n%2 == 1) cout << "0" << endl;
    else {
        ll ans = 0;
        ll now = 10;
        while(now <= n) {
            ans += n/now;
            now *= 5;
        }
        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++)

int main() {
	int N;
	string S;
	long long p;
	long long q;
	long long r;
	long long aa;

	cin >> N;
 	vector<int> a0(5);
 	vector<int> a1(11);
 	vector<int> a2(N);
 	vector<int> a5(N);
	vector<vector<int>> x(25, vector<int>(25));

   	rep(i,N) {
   		rep(j,5) a0.at(j)=0;
   		rep(j,10) a1.at(j)=0;
		cin >> S;
		p=0;
		q=-1;
		aa=0;
		r=S.size();
   		rep(j,r) {
			if(S.at(j)=='.') q=0;
			else if(q<0) {
				a0.at(p)=S.at(j)-'0';
				p++;
			} else {
				a1.at(q)=S.at(j)-'0';
				q++;
			}
		}
		if (p>0) {
	   		rep(j,p) {
				aa*=10;
				aa+=a0.at(j);
			}
		}
   		rep(j,9) {
			aa*=10;
			aa+=a1.at(j);
		}
		p=0;
   		rep(j,20) {
			if (aa%2>0) break;
			aa/=2;
			p++;
		}
        a2.at(i)=p;
		p=0;
   		rep(j,20) {
			if (aa%5>0) break;
			aa/=5;
			p++;
		}
        a5.at(i)=p;
	}

   	rep(i,25) {
   		rep(j,25) {
			x.at(i).at(j)=0;
		}
	}
   	rep(i,N) {
			x.at(a2.at(i)).at(a5.at(i))++;
	}

	p=0;
   	rep(i1,21) {
	   	rep(i2,21) {
			if(i1+i2>=18){
	   			rep(j1,21) {
   					rep(j2,21) {
						if(j1+j2>=18) {
							q=x.at(i1).at(j1);
							r=x.at(i2).at(j2);
							p+=q*r;
							if((i1==i2)&&(j1==j2)) p-=q;
						}
					}
				}
			}
		}
	}
	cout << p/2 << endl;
	return 0;
}


Measured memory_bytes: 4788
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
typedef long long ll;
typedef pair<int, int> P;
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
struct Edge {
  ll to;
  ll cost;
};
int main() {
  ll N, M, K;
  cin >> N >> M >> K;
  vector<ll> A(N);
  vector<ll> B(M);
  cin >> A[0];
  REP(i, N - 1) cin >> A[i + 1], A[i + 1] += A[i];
  cin >> B[0];
  REP(i, M - 1) cin >> B[i + 1], B[i + 1] += B[i];
  ll mx = 0;
  REP(i, N) {
    ll tmp = K - A[i];
    if (tmp < 0) break;
    auto itr = upper_bound(B.begin(), B.end(), tmp);
    ll tmp2 = (ll)distance(B.begin(), itr);

    mx = max(mx, tmp2 + i+1);
  }
  REP(i,M){
    if (B[i] <= K) mx = max(mx, (ll)i+1);
  }
  cout << mx << endl;
}


Measured memory_bytes: 6372
#include <bits/stdc++.h>
const double PI = acos(-1);
#define rep(i, n) for (int i = 0; i < (int)(n); i++ )
using namespace std;
int findSumOfDigits(int n) {
  int sum = 0;
  while (n > 0) { // n が 0 になるまで
    sum += n % 10;
    n /= 10;
  }
  return sum;
}
int fn(long long x, long long y, long long z){
  return x*x + y*y + z*z + x*y + y*z + z*x;
}
int main(){
  string s;
  cin >> s;
  vector<int> n(s.size());
  rep(i,s.size()){
    if(s.at(i) == '1') n.at(i) = 1;
    else if(s.at(i) == '2') n.at(i) = 2;
    else if(s.at(i) == '3') n.at(i) = 3;
    else if(s.at(i) == '4') n.at(i) = 4;
    else if(s.at(i) == '5') n.at(i) = 5;
    else if(s.at(i) == '6') n.at(i) = 6;
    else if(s.at(i) == '7') n.at(i) = 7;
    else if(s.at(i) == '8') n.at(i) = 8;
    else if(s.at(i) == '9') n.at(i) = 9;
  }
  int num;
  if(n.at(0)*100 + n.at(1)*10 + n.at(2) >= 753 ){
    num = n.at(0)*100 + n.at(1)*10 + n.at(2) - 753;
  }
  else num = 753 - (n.at(0)*100 + n.at(1)*10 + n.at(2)); 
  int ans = num;
  rep(i,s.size()-2){
    if(n.at(i)*100 + n.at(i+1)*10 + n.at(i+2) >= 753 ){
    num = n.at(i)*100 + n.at(i+1)*10 + n.at(i+2) - 753;
    }
    else num = 753 - (n.at(i)*100 + n.at(i+1)*10 + n.at(i+2)); 
    if(num < ans  ) ans = num;
  }
  cout << ans << endl;
}

Measured memory_bytes: 3628
#include<bits/stdc++.h>
#define PI 2.0*acos(0.0)
#define ll              long long int
#define gcd(a,b)        __gcd(a,b)
#define lcm(a,b)        ((a)*(b))/gcd(a,b)
#define MOD             1000000007
#define mx              123456789
using namespace std;
int main()
{
    ll s, w;
    cin>>s>>w;
    if(w>=s)
        cout<<"unsafe"<<endl;
    else
        cout<<"safe"<<endl;
    return 0;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#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, m, n) for(int i = m; i < n; i++)
#define FORR(i, m, n) for(int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)

int main(){
 int a[3];
 REP(i, 3) cin >> a[i];
 SORT(a, 3);
 cout << 10 * a[2] + a[1] + a[0];
}


Measured memory_bytes: 256
N = int(input())
a = list(map(int,input().split()))
a.sort()
n = a[-1]
k = n/2
#n/2までの距離の最小
for i in range(N-1):
  r = n/2 - a[i]
  if abs(r) < abs(k): k = r
#print(k,n)
print(n,int(n/2-k))

Measured memory_bytes: 14428
#include <iostream>
#include <string>
#include <algorithm>
#include <cstring>
#include <vector>
#include <cmath>
#include <cstdio>
#include <utility>

using namespace std;

int main()
{
    string s;
    int w;
    cin>>s>>w;
    for (int i=0; i<s.size(); i+=w) cout<<s[i];
    cout<<endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.*;
public class Main
{
	public static void main(String args[])
	{
		Scanner input = new Scanner(System.in);
		int[] s = new int[111];
		int r = input.nextInt();
		int c = input.nextInt();
		int t, sum;
		for(int i = 0; i < r; i++)
		{
			sum = 0;
			for(int k = 0; k < c; k++)
			{
				t = input.nextInt();
				sum += t;
				s[k] += t;
				System.out.print(t + " ");
			}
			s[c] += sum;
			System.out.println(sum);
		}
		for(int i = 0; i < c; i++)
			System.out.print(s[i] + " ");
		System.out.println(s[c]);
	}
}

Measured memory_bytes: 40720
memo = set([])
def f(a):
    global ans
    ans += eval('+'.join(a))
    if len(a) < 3 : return
    for i in range(len(a)-1):
        b = a[:i] + [a[i]+a[i+1]]
        if i != len(a)-2 : b += a[-(len(a)-2-i):]
        c = '+'.join(b)
        if not c in memo:
            memo.add(c)
            f(b)
s = input()
l = list(s)
ans = int(s)
if len(l)>1:
    f(l)
print(ans)

Measured memory_bytes: 3316
#include <iostream>
#include <vector>
using namespace std;
int main(void){
    // Your code here!
    int n,m;cin>>n>>m;
    vector<int> c(n,0),a(m),b(m);
    for(int i=0;i<m;i++){
        cin>>a[i]>>b[i];
        c[a[i]-1]++;
        c[b[i]-1]++;
    }
    for(int i=0;i<n;i++){
        cout<<c[i]<<endl;
    }
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int n;
long long int a[55];
int main(){
	long long int k,k2;
	cin >> k;
	n = 50;
	for(int i=0; i<n; i++)
		a[i] = i;
	k2 = k/50;
	for(int i=0; i<n; i++)
		a[i] += k2;
	k -= k2 * 50;
	for(int i=n-1,j=0; j<k; i--,j++)
		a[i] ++;
	cout << n << endl;
	for(int i=0; i<n; i++)
		cout << a[i] << (i<n-1?' ':'\n');
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
long long a,b;
string st;
int main()
{
	cin>>a>>b;
	cin>>st;
	if(st[a]!='-')
	{
		cout<<"No"<<endl;
		return 0;
	}
	for(int i=0;i<st.size();i++)
	{
		if(i!=a)
		{
			if(!('0'<=st[i]&&st[i]<='9'))
			{
				cout<<"No"<<endl;
				return 0;
			}
		}
	}
	cout<<"Yes"<<endl;
	return 0;
}

Measured memory_bytes: 256
/// kazuki08
/*
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define int long long
typedef long long ll;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef vector<pi> vpi;
#define ar array
//#define inf 1000000000
#define mod 1000000007
#define dmp(x) cerr<<"line "<<__LINE__<<" "<<#x<<":"<<x<<endl
#define fs first
#define sc second
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define mt make_tuple
#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){
    return o<<"("<<p.fs<<","<<p.sc<<")";
}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){
    o<<"{";
    for(const T& v:vc) o<<v<<",";
    o<<"}";
    return o;
}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int h1,h2,m1,m2,k;

signed main(){
IOS;
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
  
  string s;
  cin >> s;
  for(int i=0;i<s.size();i++){
    if(s[i]=='?')s[i]='D';
  }
  cout << s << endl;

return 0;
}
///....


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

#define MAXN (100010)

int n, m, q;
int ss[MAXN], tt[MAXN];
char s[MAXN], t[MAXN];

int main(){
	scanf("%s%s", s, t);
	n = strlen(s);
	m = strlen(t);
	for(int i = 1; i <= n; ++ i){
		ss[i] = ss[i - 1] + (s[i - 1] == 'A' ? 1 : 2);
	}
	for(int i = 1; i <= m; ++ i){
		tt[i] = tt[i - 1] + (t[i - 1] == 'A' ? 1 : 2);
	}
	scanf("%d", &q);
	for(int i = 1; i <= q; ++ i){
		int a, b, c, d;
		scanf("%d%d%d%d", &a, &b, &c, &d);
		printf((ss[b] - ss[a - 1] - tt[d] + tt[c - 1]) % 3 ? "NO\n" : "YES\n");
	}
	return 0;
}

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

int main(){
	bool isprime[10001];
	for(int i=0; i<10001; ++i) isprime[i]=true;

	for(int i=2; i<=10000; ++i){
		if(isprime[i]){
			for(int j=2; i*j<=10000; ++j) isprime[i*j]=false;
		}
	}

	while(1){
		int n;
		scanf(" %d", &n);
		if(n==0) break;
		if(n%2 == 0) n--;
		
		for(int i=n; i>=5; --i){
			if(isprime[i] && isprime[i-2]){
				printf("%d %d\n", i-2, i);
				break;
			}
		}
	}

	return 0;
}

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

int main() {
	int a, b;
	cin >> a >> b;
	string out;
	int mul = a * b % 2; 
	if (mul == 0) {out = "Even";} else {out = "Odd";}
	
	cout << out << endl;
	return 0;
}

Measured memory_bytes: 256