akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <fstream>
#include <bits/stdc++.h> 
#include <string>

using namespace std;

typedef double db;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi; 
typedef vector<ll> vl;
typedef vector<ld> vd;
typedef pair<int,int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;
typedef priority_queue<int> pqi;
typedef priority_queue<int, vi, greater<int>> mpqi;

#define IOS std::ios::sync_with_stdio(false); cin.tie(0);
#define F0R(i,a) for(int i = 0; i < a; i++)
#define R0F(i,a) for(int i = a - 1; i >= 0; i--)
#define S0RT(a,n) sort(a, a + n)
#define pb push_back
#define mp make_pair
#define f first
#define s second

const int MOD = 1000000007;
const ll INF = 1000000000000000000;
const ld PI = 4*atan((ld)1);

/* NOTES TO SELF:
    Int overflow? Use all ll if in doubt.
    Edge cases? (n = 1, n = 0)
*/

int n;
int a[200002];

int main(){
    IOS;
    cin >> n;
    F0R(i,n){
        cin >> a[i];
    }
    sort(a,a+n);
    F0R(i,n-1){
        if(a[i] == a[i+1]){
            cout << "NO";
            return 0;
        }
    }
    cout << "YES";
    return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int  n,i,j,k,x,H,xx;
    cin>>n;
    long long int   X[n],Y[n],h[n];
    int indx;
    for(i=0; i<n; i++)
    {
        cin>>X[i]>>Y[i]>>h[i];
        if(h[i] > 0)
        {
            indx= i;
        }
    }

    for(i=0; i<=100; i++)
    {
        for(j=0; j<=100; j++)
        {
            H=h[indx]+abs(X[indx]-i)+abs(Y[indx]-j);
            bool its_ok=true;
            for(k=0; k<n; k++)
            {
                xx=(H-abs(X[k]-i)-abs(Y[k]-j));
                if(xx<0)   xx=0;

                if(xx!=h[k])
                {
                    its_ok=false;
                    break;
                }
            }
            if(its_ok)
            {
                cout<<i<<' '<<j<<' '<<H<<endl;
                return 0;
            }
        }
    }
    return 0;
}


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

int main(){

    int A,B,C;

    cin >> A >> B;

    if((A%2 == 0)||(B%2 == 0)){
        cout << "No" << endl;
    }else{
        cout << "Yes" << endl;
    }
    
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N,ok=0;
  cin >> N;
  vector<int> ans(N);
  string S,T,X,Y;
  cin >> S;
  T="abcdefghijklmnopqrstuvwxyz";
  
  for(int i=1;i<N;i++){
    for(int m=0;m<26;m++){
      for(int j=0;j<i;j++){
        if(T.at(m)==S.at(j)){
          ok=1;
          break;
        }
      }
      if(ok){
        for(int k=i;k<N;k++){
          if(T.at(m)==S.at(k)){
            ans.at(i)++;
            break;
          }
        }
        ok=0;
      }
    }
  }
  sort(ans.begin(),ans.end());
  reverse(ans.begin(),ans.end());
  cout << ans.at(0) << endl;
}


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

int main(){
    int h,w;
    cin >> h >> w;

    int hs, ws;
    cin >> hs >> ws;

    int ans = (h-hs)*(w-ws);

    cout << ans << endl;
}

Measured memory_bytes: 256
// https://atcoder.jp/contests/arc068/tasks/arc068_a
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
 
int main() {
    ll x, moves;
    cin>>x;
    moves = x/11;
    x -= moves*11;
    moves *= 2;
    if (x > 6) moves += 2;
    else if (x > 0) moves += 1;
    cout<<moves<<"\n";
}

Measured memory_bytes: 3596
s = gets.chomp
n = s.to_i
len = s.size

ans = 0
1.upto(len){|tlen|
  (3**tlen).times{|i|
    tmp = (3**tlen+i).to_s(3)[1..-1].chars.map{|c|[3,5,7][c.to_i]}*""
    if tmp.to_i<=n && [?3,?5,?7].map{|x|tmp.count(x)>=1}.all?
      ans += 1
    end
  }
}
p ans

Measured memory_bytes: 1916
import sys
input = sys.stdin.readline

import heapq
import copy
def main(): 
    N,K = map(int,input().split())
    v=list(map(int, input().split()))
    l_count = []
    heapq.heapify(l_count)
    ans = 0
    for l in range(N+1):
        if l!=0: heapq.heappush(l_count,v[l-1])
        r_count = copy.deepcopy(l_count)
        for r in range(N-l+1):
            if r!=0: heapq.heappush(r_count,v[N-r])
            d_count = copy.deepcopy(r_count)
            for d in range(K-l-r+1):
                if not(len(d_count) == 0 or d==0):
                    heapq.heappop(d_count)
                sum_d_count = sum(d_count)
                if sum_d_count > ans:
                    ans = sum_d_count
    print(ans)
            
if __name__ == "__main__":
    main()
    

Measured memory_bytes: 57308
#include<stdio.h>

int main(){
 int a[3];
  scanf("%d %d %d", &a[0],&a[1],&a[2]);
  int m= a[0];
  for(int i=1;i<3;i++){
    if(m<=a[i]){
		m = a[i];
    }
  }
  int an = a[0]+a[1]+a[2]-m;
  printf("%d" ,an);
  return 0;
}

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

int main(void){
	int n;
	cin >> n;
	if (n < 1000) {
		cout << "ABC";
	}
	else {
		cout << "ABD";
	}
	return 0;
}

Measured memory_bytes: 256
program Project1;
     
{$APPTYPE CONSOLE}
     
uses
SysUtils;
var
n,i,j,t,a,b,c,d:integer;
begin
try
  { TODO -oUser -cConsole Main : abc83}
  read(a);
  read(b);
  read(c);
  readln(d);

  if a+b>c+d then
    Writeln('Left')
  else if a+b=c+d then
    Writeln('Balanced')
  else
    Writeln('Right');

  readln;
except
  on E: Exception do
    Writeln(E.ClassName, ': ', E.Message);
end;
end.

Measured memory_bytes: 128
def main():
    a, b = map(int, input().split())
    if a > 0: # a, b > 0
        return "Positive"
    elif b >=0 and a <=0: # a <= 0 <= b
        return "Zero"
    else: # a < 0 and b < 0
        if (b-a+1) % 2 == 0:
            return "Positive"
        else:
            return "Negative" 

if __name__ == '__main__':
    print(main())

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

const ll INF = 1LL << 60;


int main() {
    long long X;
    scanf("%lld",&X);

    // for (ll a = 0; a * a * a * a * a <= X; a++) {
    //     ll tmp_a = a * a * a * a * a;
    //     // for (ll b = -10; b * b * b * b * b <= X - tmp_a; b++) {
    //     //     ll tmp_b = b * b * b * b * b;
    //     //     if (tmp_a - tmp_b == X) {
    //     //         cout << a << " " << b << endl;
    //     //         return 0;
    //     //     }
    //     // }
    // }

    // -200 < a < 200
    // -200 < b < 200
    for (ll a = -5000; a <= 5000; a++) {
        for (ll b = -5000; b <= 5000; b++) {
            if (a * a * a * a * a - b * b * b * b * b == X) {
                cout << a << " " << b << endl;
                return 0;
            }
        }
    }
}


Measured memory_bytes: 3692
while True:    
    h, w = map(int, input().split())
    if h == 0 and w == 0:
        break
    
    for i in range(h):
        if i % 2 == 0:
            for j in range(w):
                if j % 2 == 0:
                    print("#", end="")
                else:
                    print(".", end="")
        else:
            for j in range(w):
                if j % 2 == 0:
                    print(".", end="")
                else:
                    print("#", end="")
        print()
    print()


Measured memory_bytes: 7004
#include <algorithm>
#include <bitset>
#include <cassert>
#include <deque>
#include <fstream>
#include <iostream>
#include <map>
#include <math.h>
#include <memory>
#include <queue>
#include <sstream>
#include <stdio.h>
#include <string>
#include <vector>

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define POW(n) ((n) * (n))
#define ALL(a) (a).begin(), (a).end()
#define dump(v) (cerr << #v << ": " << v << endl)
#define cerr                                                                   \
  if (true)                                                                    \
  cerr

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<unsigned long long> vull;

// ll n = to_T<ll>("114514")
template <class T> T to_T(const string &s) {
  istringstream is(s);
  T res;
  is >> res;
  return res;
}
template <class T> string to_s(const T &a) {
  ostringstream os;
  os << a;
  return os.str();
}

void solve(long long N) {
  string ans = to_s(N);
  if (ans[0] == ans[2]) {
    std::cout << "Yes" << '\n';
  } else {
    cout << "No" << endl;
  }
}

int main() {
  ios::sync_with_stdio(false);
  long long N;
  cin >> N;
  solve(N);
  return 0;
}


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

int main()
{
    long N;
    std::cin >> N;
    std::vector<long> P;
    for(long i=0; i<N; i++){
        long temp;
        std::cin >> temp;
        P.push_back(temp);
    }

    long tempmin=P[0];
    long count=1;
    for(long i=1; i<N; i++){
        if(tempmin>P[i]){
            tempmin=P[i];
            count++;
        }
    }
    std::cout << count << std::endl;
    return 0;
}

Measured memory_bytes: 2420
N, K = map(int, input().split())			# "5 7" -> ["5", "7"] -> 5, 7 => N=5,K=7

X=[0]*N

for k in range(K):
	d = int(input())
	A =        list( map(int, input().split()) )	# 1 2 3 4 5 ...
	for a in A:
		X[a-1]+=1

print( X.count(0) )


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

using namespace std;

struct DSU {
    int n;
    vector<int> ps;
    vector<int> size;
    int num_components;
    DSU(int n): n(n), ps(n), num_components(n), size(n) {
        for (int i = 0 ; i < n; ++i) {
            ps[i] = i;
            size[i] = 1;
        }
    }
    int get_size(int i) {
        return size[parent(i)];
    }
    int parent(int i) {
        if (ps[i] == i) {
            return i;
        }
        return ps[i] = parent(ps[i]);
    }
    int merge(int i, int j) {
        i = parent(i);
        j = parent(j);
        if (i != j) {
            if (size[i] <= size[j]) {
                swap(i, j);
            }
            size[i] += size[j];
            ps[j] = i;
            --num_components;
            return true;
        }
        return false;
    }
};


int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, m;
    cin >> n >> m;
    vector<pair<int, int>> edges(m);
    for (auto& edge : edges) {
        cin >> edge.first >> edge.second;
        --edge.first;
        --edge.second;
    }
    vector<long long> results(m+1);
    results[m] = (long long)n*(n-1)/2;
    DSU dsu(n);
    for (int i = m-1; i >= 0; --i) {
        auto& edge = edges[i];
        int a = dsu.get_size(edge.first);
        int b = dsu.get_size(edge.second);
        results[i] = results[i+1];
        if (dsu.merge(edge.first, edge.second)) {
            results[i] -= (long long)a*b;
        }
    }
    for (int i = 1; i <= m; ++i) {
        cout << results[i] << endl;
    }
    return 0;
}


Measured memory_bytes: 3712
#include <bits/stdc++.h>
using namespace std;
#define rep(i,s,t) for(int i=s;i<t;i++)
#define pii pair<int,int>
typedef long long ll;
map<pii,ll> dp[20][20];ll num[22];
ll dfs(int l,int r,int lx,int rx)
{
    if(l>=r-1)return 0;
    if(dp[l][r].count({lx,rx}))return dp[l][r][{lx,rx}];
    dp[l][r][{lx,rx}]=1e18;
    rep(i,l+1,r)
    {
        ll res=num[i]*(lx+rx);
        res+=dfs(l,i,lx,lx+rx)+dfs(i,r,lx+rx,rx);
        dp[l][r][{lx,rx}]=min(dp[l][r][{lx,rx}],res);
    }
    return dp[l][r][{lx,rx}];
}
int main()
{
    int n;scanf("%d",&n);
    rep(i,1,n+1)scanf("%lld",&num[i]);
    printf("%lld\n",dfs(1,n,1,1)+num[1]+num[n]);
}

Measured memory_bytes: 16512
/* ALDS1_4_C: Dictionary */

#include <iostream>
#include <cstdio>

const int MAX_KEY_LENGTH = 12;
const int N_KEY_CHARS = 4;

class Dict {
    int *KEYS;
    int char_to_id(char);
    int to_hash(char*);
    public:
        Dict();
        void insert(char*);
        bool has(char*);
};

Dict::Dict() {
    int max_hash = 0, w = 1;
    for (int i = 0; i < MAX_KEY_LENGTH; i++, w *= N_KEY_CHARS) {
        max_hash += N_KEY_CHARS * w;
    }
    KEYS = new int[max_hash + 1];
    std::fill_n(KEYS, max_hash, 0);
}

void Dict::insert(char *key) {
    KEYS[ to_hash(key) ] = true;
}

bool Dict::has(char *key) {
    return KEYS[ to_hash(key) ];
}

int Dict::char_to_id(char c) {
    switch (c) {
        case 'A': return 1;
        case 'C': return 2;
        case 'G': return 3;
        case 'T': return 4;
    }
    return 0;
}

int Dict::to_hash(char *key) {
    int hash = 0;
    int w = 1;
    for (int i = 0; key[i]; i++, w *= N_KEY_CHARS) {
        hash += w * char_to_id(key[i]);
    }
    return hash;
}

int main() {
    int n_ops;
    scanf("%d", &n_ops);

    Dict dict;
    char op[10], key[MAX_KEY_LENGTH + 1];

    for (int i = 0; i < n_ops; i++) {
        scanf("%s %s", op, key);
        switch (op[0]) {
            case 'i': // insert
                dict.insert(key);
                break;
            case 'f': // find
                puts( dict.has(key) ? "yes" : "no" );
                break;
        }
    }

    return 0;
}

Measured memory_bytes: 88556
while True:
  n = int(input())
  if n == 0:
    break
  alst = list(map(int, input().split())) * 16
  turn = 0
  rest = 32
  while True:
    if turn % 2 == 0:
      rest -= (rest - 1) % 5
    else:
      rest -= alst[turn // 2]
      rest = max(rest, 0)
    print(rest)
    turn += 1
    if rest == 0:
      break


Measured memory_bytes: 5588
#include    <bits/stdc++.h>
#include    <ext/pb_ds/assoc_container.hpp>
#include    <ext/pb_ds/trie_policy.hpp>
#include    <ext/rope>

#pragma     03
#pragma     GCC             optimize("Ofast")
#pragma     GCC             optimization("unroll-loops, no-stack-protector")
#pragma     GCC             target("sse,sse2,sse3,ssse3,sse4.1,sse4.2")

#define     ll              long long
#define     ld              long double
#define     fi              first
#define     se              second
#define     sz(x)           x.size()
#define     mp              make_pair
#define     pb              push_back
#define     eb              emplace_back
#define     all(x)          begin(x), end(x)
#define     rall(x)         rbegin(x), rend(x)
#define     rep(i, x, n)    for (ll i = x; i < n; i++)
#define     fastio()        ios_base::sync_with_stdio(NULL); cin.tie(0); cout.tie(0)
#define     min(a, b)       (a < b) ? a : b
#define     max(a, b)       (a > b) ? a : b
#define     int             long long

using       namespace std;
using       namespace __gnu_pbds;
using       namespace __gnu_cxx;

mt19937     rng(chrono::steady_clock::now().time_since_epoch().count());

typedef     vector<int>     vi;
typedef     vector<vi>      vvi;
typedef     pair<int, int>  ii;
typedef     vector<ii>      vii;
typedef     vector<ll>      vl;
typedef     vector<vl>      vvl;
typedef     pair<ll, ll>    pll;
typedef     vector<pll>     vll;

inline void EXECUTE_TIME() {cout << endl << setprecision(10) << fixed << "CPU Time: " << clock() / double(CLOCKS_PER_SEC) << " sec(s)\n";}

template <class T> inline T RD(T &a) {T x; cin >> x; return a = x;}
template <class T> inline T gcd(T a, T b) {if (b) return gcd(b, a % b); else return a;}
template <class T> inline T lcm(T a, T b) {return a / gcd(a,b) * b;}
template<typename T> using ordered_set=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
typedef trie<string, null_type, trie_string_access_traits<>, pat_trie_tag, trie_prefix_search_node_update> pref_trie;

const int N = 1e5 + 10;

string s, t;
int pres[N], pret[N];

#define c(x) (x == 'A' ? 1 : -1)

signed main() {
//    freopen("bubbletea.inp", "r", stdin);
//    freopen("bubbletea.out", "w", stdout);
    fastio();

    cin >> s >> t;
    for (int i = 1; i <= s.size(); i++) pres[i] = c(s[i - 1]) + pres[i - 1];
    for (int i = 1; i <= t.size(); i++) pret[i] = c(t[i - 1]) + pret[i - 1];
    int q; cin >> q;
    for (int i = 0; i < q; i++) {
        int a, b, c, d;
        cin >> a >> b >> c >> d;
        int x = pres[b] - pres[a - 1],
            y = pret[d] - pret[c - 1];
        x += 30000, y += 30000;
        x %= 3, y %= 3;
        if (x == y) cout << "YES\n";
        else cout << "NO\n";
    }

//    EXECUTE_TIME();
}


Measured memory_bytes: 5372
#!/usr/bin/env ruby
# encoding: UTF-8
loop do
  edges = gets.split.map(&:to_i)
  break if edges.all?{|i| i.zero?}
  phi_squared = edges.sort.take(2).reduce(0){|m, i| m += i**2}
  n = gets.to_i
  n.times do
    r = gets.to_i
    puts phi_squared < (2*r)**2 ? "OK" : "NA"
  end
end


Measured memory_bytes: 6104
use std::io;
fn main() {
    let mut S = String::new();
    io::stdin().read_line(&mut S);
    let S: i32 = S.trim().parse().expect("Cannot parse");
    let h = S / (60 * 60);
    let m = (S / 60) % 60;
    let s = S % 60;
    println!("{}:{}:{}", h, m, s);
}



Measured memory_bytes: 5024
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
#define rep(i,a,n) for(int i=a;i<n;++i)
#define per(i,a,n) for(int i=n-1;i>=a;--i)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define sz(x) ((int)x.size())
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
const ll mod=1000000007; // 998244353 = (119<<23)+1
ll powmod(ll a,ll b) {ll res=1;a%=mod;assert(b>=0);for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
// head
const int N=1e5+5;
vector<vi> edge(N);
vi h(N);
int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n,m;
	cin>>n>>m;
	rep(i,0,n) {
		cin>>h[i];
	}
	rep(i,0,m) {
		int a,b;
		cin>>a>>b;
		a--;
		b--;
		edge[a].pb(b);
		edge[b].pb(a);
	}
	int ret=0;
	rep(i,0,n) {
		bool ok=true;
		rep(j,0,sz(edge[i])) {
			if(h[i]<=h[edge[i][j]]) ok=false;
		}
		//if(ok==true) cout<<i+1<<'\n';
		ret+=(ok==true);
	}
	cout<<ret;
	return 0;
}

Measured memory_bytes: 8724
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<ctime>
#include<algorithm>
#include<list>
#include<queue>
#include<stack>
#include<vector>
#include<set>
#include<map>
#include<string>
using namespace std;
typedef long long ll;

const double eps=1e-9;
inline int sgn(double v){return abs(v)<eps?0:(v<0?-1:1);}
inline double sqr(double v){return v*v;}
int n;
double w,h,r,x,y;
const int maxn=150;
struct Point 
{
	double x,y;
	double len()
	{
		return sqrt(sqr(x)+sqr(y));
	}
}R[maxn],v;
struct Len
{
	int idx;
	double len;
	Len(int id=0,double L=0)
	{
		idx=id;len=L;
	}
	bool operator <(const Len &p)const
	{
		return len<p.len;
	}
}stk[122];
int stnum=0;
void solve()
{
	int i;
	double sum=0,tx,ty,tmp;
	scanf("%lf %lf %lf %lf %lf",&w,&h,&r,&v.x,&v.y);
	tmp=v.len();
	v.x/=tmp;
	v.y/=tmp;
	scanf("%lf %lf",&x,&y);
	for(i=0;i<n-1;i++)
		scanf("%lf %lf",&R[i].x,&R[i].y);
	w-=r;
	h-=r;
	stnum=0;
	while(sum<=10000)
	{
		stnum=0;
		for(i=0;i<n-1;i++)
		{
			double a=sqr(v.x)+sqr(v.y);
			double b=2*(x-R[i].x)*v.x+2*(y-R[i].y)*v.y;
			double c=sqr(x-R[i].x)+sqr(y-R[i].y)-4*sqr(r);
			double delta=b*b-4*a*c;
			if(sgn(delta)>=0)
			{
				double t1=(-b+sqrt(delta))/2/a;
				double t2=(-b-sqrt(delta))/2/a;
				if(sgn(t1)>=0)stk[stnum++]=Len(i,t1);
				if(sgn(t2)>=0)stk[stnum++]=Len(i,t2);
			}
		}
		if(stnum>0)
		{
			sort(stk,stk+stnum);
			//for(int j=0;j<stnum;j++)cout <<stk[j].len<<" "<<stk[j].idx<<endl;
			if(sum+stk[0].len<=10000)
			{
				printf("%d\n",stk[0].idx+2);
				return;
			}
			else break;
		}
		if(sgn(v.x))
		{
			ty=y+v.y*((r-x)/v.x);
			if(ty>-eps&&ty<h+eps&&(r-x)/v.x>eps)stk[stnum++]=Len(0,(r-x)/v.x);
			ty=y+v.y*((w-x)/v.x);
			if(ty>-eps&&ty<h+eps&&(w-x)/v.x>eps)stk[stnum++]=Len(1,(w-x)/v.x);
		}
		if(sgn(v.y))
		{
			tx=x+v.x*((r-y)/v.y);
			if(tx>-eps&&tx<w+eps&&(r-y)/v.y>eps)stk[stnum++]=Len(2,(r-y)/v.y);
			tx=x+v.x*((h-y)/v.y);
			if(tx>-eps&&tx<w+eps&&(h-y)/v.y>eps)stk[stnum++]=Len(3,(h-y)/v.y);
		}
		if(stnum==2)
		{
			x=x+v.x*stk[0].len;
			y=y+v.y*stk[0].len;
			v.x=-v.x;
			v.y=-v.y;
		}
		else
		{
			x=x+v.x*stk[0].len;
			y=y+v.y*stk[0].len;
			if(stk[0].idx==0||stk[0].idx==1)v.x=-v.x;
			else v.y=-v.y;
		}
		sum+=stk[0].len;
	}			
	printf("-1\n");
	return;
}
int main()
{
	while(scanf("%d",&n))
	{
		if(!n)break;
		solve();
	}
	return 0;
}

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

int main() {
  int a, b;
  cin >> a >> b;
  if ((a + b) % 2 == 0) {
  cout << (a + b) / 2  << endl;
  }
  else {
  cout << (a + b) / 2 + 1 << endl;
  }
}


Measured memory_bytes: 256
/*
 _     _                             
| |__ | |__   __ _  __ _ _   _  __ _ 
| '_ \| '_ \ / _` |/ _` | | | |/ _` |
| |_) | | | | (_| | (_| | |_| | (_| |
|_.__/|_| |_|\__,_|\__, |\__, |\__,_|
                   |___/ |___/       
*/
#include<bits/stdc++.h>

#define ll          long long
#define pb          push_back
#define ppb         pop_back
#define BigInt      __int128
#define endl        '\n'
#define mii         map<ll int,ll int>
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define hell        1000000007
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define sim         template < class c
#define ris         return * this
#define dor         > debug & operator <<
#define eni(x)      sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {

using namespace std;

sim > struct rge {c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug 
{
	~debug() 
	{ 
		cerr<<endl; 
	}
	eni(!=) cerr << boolalpha << i; ris; }
	eni(==) ris << range(begin(i), end(i)); }
	sim, class b dor(pair < b, c > d) 
	{
		ris << "(" << d.first << ", " << d.second << ")";
	}
	sim dor(rge<c> d) 
	{
	  	*this << "[";
	  	for (auto it = d.b; it != d.e; ++it)
	    	*this << ", " + 2 * (it == d.b) << *it;
	  	ris << "]";
	}
};
#define fuck(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

#define N  100005

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int TESTS=1;
	// cin>>TESTS;
	while(TESTS--)
	{
		ll int n,m,x;
		cin>>n>>m>>x;
		ll int c[n];
		ll int arr[n][m];
		for(ll int i=0;i<n;i++)
		{
			cin>>c[i];
			for(ll int j=0;j<m;j++)
			{
				cin>>arr[i][j];
			}
		}
		ll int mini=1e18;
		for(ll int mask=0;mask<(1ll<<n);mask++)
		{
			ll int tot[m];
			ll int sm=0;
			memset(tot,0,sizeof(tot));
			for(ll int i=0;i<n;i++)
			{
				if((mask>>i)&1ll)
				{
					sm+=c[i];
					for(ll int j=0;j<m;j++)
					{
						tot[j]+=arr[i][j];
					}
				}
			}
			ll int minlvl=1e18;
			for(ll int i=0;i<m;i++)
			{
				minlvl=min(minlvl,tot[i]);
			}
			if(minlvl>=x)
			{
				mini=min(mini,sm);
			}
		}
		if(mini==1e18) mini=-1;
		cout<<mini<<endl;
	}
	return 0;
}

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

namespace _030_SumofIntegers
{
	class Program
	{
		static void Main ( string[] args )
		{
			while (true)
			{
				int[] inputNum = Console.ReadLine ().Split (' ').Select (int.Parse).ToArray ();

				bool isEnd = inputNum.All (item => item == 0);

				if (isEnd)
				{
					break;
				}

				int result = Process.PairCount (inputNum[0], inputNum[1]);

				Console.WriteLine (result);
			}
		}
	}

	static class Process
	{
		private static int Count { set; get; }

		public static int PairCount ( int restCount, int sum )
		{
			Count = 0;

			//??????????????£???????±????????????°????????????
			int maxValue = 0;
			for (int i = 9; i > 9 - restCount; i--)
			{
				maxValue += i;
			}

			int minValue = 0;
			for (int i = 0; i < restCount; i++)
			{
				minValue += i;
			}

			if (minValue <= sum && sum <= maxValue)
			{
				bool[] choiceArray = { true, true, true, true, true, true, true, true, true, true };

				PairCount (restCount, sum, choiceArray);
			}

			return Count;
		}

		private static void PairCount ( int restCount, int sum, bool[] choiceArray )
		{
			if (sum < 0)
			{
				return;
			}
			if (0 < restCount)
			{
				for (int lp = 0; lp <= 9; lp++)
				{
					if (choiceArray[lp])
					{
						choiceArray[lp] = false;

						bool[] copy = new bool[choiceArray.Length];
						choiceArray.CopyTo (copy, 0);

						PairCount (restCount - 1, sum - lp, copy);
					}
				}
			}
			else if (sum == 0)
			{
				Count++;
			}
		}
	}
}

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

#define Imposter ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define ll long long int
#define mp make_pair
#define se second
#define fi first

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("O3")
using namespace __gnu_pbds;
#define ordered_set tree<ll, null_type,less_equal<ll>, rb_tree_tag,tree_order_statistics_node_update>//s.order_of_key(val) *s.find_by_order(ind)

using namespace std;
#define f(n) for(ll i=0;i<n;i++)
#define rep(i,a,b) for(i=a;i<b;i++)
#define input(arr,n) for(ll i1=0;i1<n;i1++ )cin>>arr[i1]
#define vll vector<ll>
#define vlll vector<vll>
#define all(x) x.begin(),x.end()

ll power(ll x, ll y, ll p) {
    ll res = 1;    x = x % p;
    while(y > 0) {
        if(y & 1) res = (res*x) % p;
        y = y>>1;    x = (x*x) % p;
    } return res;
}

int main()
{
    Imposter

    string s,t;
    cin>>s>>t;int maxi=0;
    for(int i=0;i<s.length()-t.length()+1;i++)
    {
        int p=0,ans=0;
        for(int j=i;j<i+t.length() ;j++)
        {
            if(s[j]==t[p])
            {
                ans++;
            }
            p++;
        }
        maxi=max(maxi,ans);
    }
    cout<<t.length()-maxi<<endl;
    return 0;
}


Measured memory_bytes: 3556
use std::io::*;
use std::str::FromStr;
#[allow(unused_imports)]
use std::collections::*;
#[allow(unused_imports)]
use std::cmp::{min, max};

struct Scanner<R: Read> {
    reader: R,
    buffer: String,
}

#[allow(dead_code)]
impl<R: Read> Scanner<R> {
    fn new(reader: R) -> Scanner<R> {
        Scanner { reader: reader, buffer: String::new() }
    }

    // fn line(&mut self) -> String {
    //     self.buffer = self.reader.by_ref().bytes().map(|c| c.unwrap() as char)
    //         .skip_while(|&c| c == '\n' || c == '\r')
    //         .take_while(|&c| !(c == '\n' || c == '\r'))
    //         .collect::<String>();
    //     self.buffer.clone()
    // }

    fn read_buffer(&mut self) {
        self.buffer = self.reader.by_ref().bytes().map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>();
    }

    fn safe_read<T: FromStr>(&mut self) -> Option<T> {
        self.read_buffer();
        if self.buffer.is_empty() {
            None
        } else {
            self.buffer.parse::<T>().ok()
        }
    }

    fn read<T: FromStr>(&mut self) -> T {
        if let Some(s) = self.safe_read() {
            s
        } else {
            writeln!(std::io::stderr(), "Terminated with EOF").unwrap();
            std::process::exit(0);
        }
    }

    fn vec<T: FromStr>(&mut self, len: usize) -> Vec<T> {
        (0..len).map(|_| self.read()).collect()
    }

    fn mat<T: FromStr>(&mut self, row: usize, col: usize) -> Vec<Vec<T>> {
        (0..row).map(|_| self.vec(col)).collect()
    }
}

trait Joinable {
    fn join(self, sep: &str) -> String;
}

impl<U: ToString, T: Iterator<Item=U>> Joinable for T {
    fn join(self, sep: &str) -> String {
        self.map(|x| x.to_string()).collect::<Vec<_>>().join(sep)
    }
}

fn main() {
    std::thread::Builder::new()
        .stack_size(104_857_600)
        .spawn(solve)
        .unwrap()
        .join()
        .unwrap();
}

fn solve() {
    let cin = stdin();
    let cin = cin.lock();
    let mut sc = Scanner::new(cin);

    let n = sc.read();
    let q: i32 = sc.read();
    let mut name = Vec::with_capacity(n);
    let mut rem = Vec::with_capacity(n);
    let mut queue = VecDeque::with_capacity(n);
    for i in 0..n {
        let s: String = sc.read();
        name.push(s);
        let t = sc.read();
        rem.push(t);
        queue.push_back(i);
    }

    let mut time = 0;
    while let Some(p) = queue.pop_front() {
        let t = min(rem[p], q);
        rem[p] -= t;
        time += t;
        if rem[p] > 0 {
            queue.push_back(p);
        } else {
            println!("{} {}", name[p], time);
        }
    }
}



Measured memory_bytes: 11076
#include<stdio.h>
int main(void){
	int n,m,a[1000],b[1000],i,j,cnt,temp,hiyou;
	scanf("%d %d",&n,&m);
	for(i=0;i<m;i++) scanf("%d %d",&a[i],&b[i]);
	for(i=0;i<m-1;i++){
		for(j=i+1;j<m;j++){
			if(a[i]<a[j]){
				temp=a[i];
				a[i]=a[j];
				a[j]=temp;
			}
		}
	}
	cnt=0;
	hiyou=0;
	for(i=0;i<m;i++){
		if(a[i]>=n) cnt++;
		else {
			hiyou+=n-a[i];
			cnt++;
		}
		if(m-1<=cnt) break;
	}
	printf("%d\n",hiyou);
	return 0;
}

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

using namespace std;

//平方数は元の数x,平方数yとして
//x >= 4y
//と考えられるからfor文は元の数のx/4までしか回さなくていい。

int main()
{
  string a, b;

  cin >> a >> b;

  a += b;

  int num = 0;
  for (int i = 0; i < a.length(); i++)
  {
    num *= 10;
    num += a[i] - '0';
  }

  for (int i = 0; i <= (num * num) / 4; i++)
  {
    if (i * i == num)
    {
      cout << "Yes" << endl;
      exit(0);
    }
  }

  cout << "No" << endl;
}


Measured memory_bytes: 256
use proconio::{input, fastout};

#[fastout]
fn main() {
    input! {
        n: usize,
        h: [usize; n],
    }

    let mut ans: usize = 0;
    let mut curr: usize = 0;
    for i in 1..n {
        if h[i-1] >= h[i] { curr += 1 }
        else {
            if curr > ans { ans = curr }
            curr = 0
        }
    }
    println!("{}", std::cmp::max(ans, curr))
}


Measured memory_bytes: 3712
#include<bits/stdc++.h>
using namespace std;
#define rkc ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
typedef long long ll;
#define fl(i,a,b) for(ll i=a;i<b;i++)
#define rfl(i,a,b) for(ll i=a;i>b;i--)
#define pb push_back
#define mp make_pair
#define test ll t;cin>>t;while(t--)
#define lld long double
const ll M = 1e9 + 7;
const double pi  =3.141592653589793238463;
int main()
{
    rkc;
    ll n,m,q=0,w=M;
    cin>>n>>m;
    ll a[n]={0};
    fl(i,0,m)
    {
        ll l,r;
        cin>>l>>r;
        if(l>=q)
        q=l;
        if(r<=w)
        w=r;
    }
    if(w-q+1>0)
    cout<<w-q+1;
    else cout<<0;
}

Measured memory_bytes: 1024
#!/usr/bin/env python3
from queue import Queue

n, m = map(int, input().split())
g = [[] for _ in range(n)]
for i in range(m):
    a, b = map(lambda x: int(x) - 1, input().split())
    g[a].append(b)
    g[b].append(a)

used = [-1] * n
q = Queue()
used[0] = 0
q.put(0)
while not q.empty():
    s = q.get()
    for t in g[s]:
        if used[t] != -1:
            continue
        used[t] = s
        q.put(t)

if any(x == -1 for x in used):
    print("No")
    exit()

print("Yes")
for x in used[1:]:
    print(x + 1)


Measured memory_bytes: 35308
#include<bits/stdc++.h>
#define rep(i,n) for(int (i) = 0;(i) < (n);(i)++)
#define SORT(c) sort((c).begin(),(c).end())
#define INF 1000000007
//S.size()

using namespace std;


typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<char> VC;
typedef vector<bool> VB;
typedef unsigned long long ll;



int main(void){
  int N,M;cin>>N;
  string blue[N];rep(i ,N)cin>>blue[i];
  cin>>M;
  string red[M];rep(t , M)cin>>red[t];
  int cnt = 0;
  int ans = -INF;
  for(int j = 0;j < N;j++){
    cnt = 0;
    for(int q = 0;q < N;q++){
      if(blue[j] == blue[q])cnt++;
    }

    for(int r = 0;r < M;r++){
      if(blue[j] == red[r])cnt--;
    }

    if(cnt >= ans)ans = cnt;
  }
  cout<<(ans >= 0?ans:0);
}


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

using namespace std;
using ll = long long;


int main(){
    int m, n;
    cin >> n >> m;
    int ai;
    double s=0;
    vector<double> a(n);
    for(int i=0; i<n; i++){
        cin >> ai;
        a[i] = ai;
        s += ai;
    }
    double x = s/4/m;

    int count = 0;
    for(int i=0; i<n; i++){
        if(a[i] >= x){
            count += 1;
        }
    }
    if(count>=m){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define drep(i,n) for(int i = (n-1); i >= 0; i--)
#define all(v) (v).begin(),(v).end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
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> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template <class T> T lcm(T a, T b) { return a/gcd(a,b)*b; }
typedef pair<int, int> P;
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001002003004005006ll;
const ll MOD = 1e9+7;

int a[3005][3005];
ll dp[3005][3005][4];

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
	ll r, c, k;
	cin >> r >> c >> k;
    rep(i,k) {
        int _r, _c, _v;
        cin >> _r >> _c >> _v;
        a[_r-1][_c-1] = _v;
    }
    rep(i,r) rep(j,c) {
        for (int k = 2; k >= 0; k--) {
            chmax(dp[i][j][k+1], dp[i][j][k] + a[i][j]);
        }
        rep(k,4) {
            chmax(dp[i+1][j][0], dp[i][j][k]);
            chmax(dp[i][j+1][k], dp[i][j][k]);
        }        
    }
    ll ans = 0;
    rep(k,4) chmax(ans, dp[r-1][c-1][k]);
    cout << ans << "\n";
	return 0;
}


Measured memory_bytes: 320620
import java.util.Scanner;
public class Main{

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int w = scan.nextInt();
		int h = scan.nextInt();
		int x = scan.nextInt();
		int y = scan.nextInt();
		int r = scan.nextInt();
		if(x>w||x<0||y>h||y<0)
			System.out.println("No");
		else if(x+r<=w&&x-r>=0&&y+r<=h&&y-r>=0){
			System.out.println("Yes");
		}else
			System.out.println("No");
	}
}

Measured memory_bytes: 17324
module.exports=function(e){var r={};function t(n){if(r[n])return r[n].exports;var o=r[n]={i:n,l:!1,exports:{}};return e[n].call(o.exports,o,o.exports,t),o.l=!0,o.exports}return t.m=e,t.c=r,t.d=function(e,r,n){t.o(e,r)||Object.defineProperty(e,r,{enumerable:!0,get:n})},t.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},t.t=function(e,r){if(1&r&&(e=t(e)),8&r)return e;if(4&r&&"object"==typeof e&&e&&e.__esModule)return e;var n=Object.create(null);if(t.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&r&&"string"!=typeof e)for(var o in e)t.d(n,o,function(r){return e[r]}.bind(null,o));return n},t.n=function(e){var r=e&&e.__esModule?function(){return e.default}:function(){return e};return t.d(r,"a",r),r},t.o=function(e,r){return Object.prototype.hasOwnProperty.call(e,r)},t.p="",t(t.s=0)}([function(e,r,t){t(1)(t(2).readFileSync("/dev/stdin","UTF-8"))},function(e,r){e.exports=function(e){for(var r=e.split("\n"),t=Number(r[0]),n=[],o=0;o<t;o++){var u=Number(r[o+1]);n.push(u)}n.sort(function(e,r){return r-e});for(var i=0,f=0;f<t;f++)i+=0==f?n[f]/2:n[f];console.log(i)}},function(e,r){e.exports=require("fs")}]);

Measured memory_bytes: 7372
N, K, L = gets.split.map(&:to_i)
k = Array.new(N+1) { |i| i }
l = Array.new(N+1) { |i| i }

def readtimes(n, arr)
  n.times do
    p, q = gets.split.map(&:to_i)
    a = arr[p]
    while a != arr[a]
      t = a
      a = arr[a]
      arr[t] = arr[a]
    end
    b = arr[q]
    while b != arr[b]
      t = b
      b = arr[b]
      arr[t] = arr[b]
    end
    arr[a] = b
  end
end
readtimes(K, k)
readtimes(L, l)
def a(arr)
  (1..N).each do |i|
    path = []
    t = i
    while t != arr[t]
      path << t
      t = arr[t]
    end
    path.each do |j|
      arr[j] = t
    end
  end
end
a(k)
a(l)

c = (1..N).map { |i| [k[i], l[i]] }
d = c.group_by(&:itself)
puts N.times.map { |i| d[c[i]].count }.join(" ")



Measured memory_bytes: 43552
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int main() {
	int N; cin >> N;
	string S; cin >> S;
	int A[300005];
	int B[300005];
	for (int i = 0; i < N; i++)
		A[i] = 0;
	if (S[0] == 'W') A[0]++;
	for (int i = 1; i < N; i++) {
		if (S[i] == 'W') A[i] = A[i - 1] + 1;
		else A[i] = A[i - 1];
	}
	A[N + 1] = A[N];

	for (int i = 0; i < N; i++)
		B[i] = i + 1 - A[i];
	
	int res = B[N - 1] - B[0];
	for (int i = 1; i + 1 < N; i++) {
		int sum = A[i - 1] + B[N - 1] - B[i];
		res = min(res, sum);
	}
	res = min(res, A[N-2]);
	cout << res << endl;
	return 0;
}

Measured memory_bytes: 3076
using System;

namespace B___Ringo_s_Favorite_Numbers
{
    class Program
    {
        static void Main (string[] args)
        {
            var input = Console.ReadLine ().Split (' ');
            var d = int.Parse (input[0]);
            var n = int.Parse (input[1]);
            var countD = 0;
            for (var i = 1; i < int.MaxValue; i++)
            {
                var x = i;
                var count = 0;
                while (x % 100 == 0)
                {
                    x = x / 100;
                    count++;
                }
                if (count == d)
                {
                    countD++;
                    if (countD == n)
                    {
                        Console.WriteLine (i);
                        break;
                    }
                }
            }
        }
    }
}

Measured memory_bytes: 13140
#include<bits/stdc++.h>
using namespace std;
int main(){
    long long int n,w;
    cin>>n>>w;
    long long int wt[n+1],vl[n+1];
    for(int i=1;i<=n;i++){
        cin>>wt[i]>>vl[i];
    }
    long long ans[w+1]={0};
    for(long long int i=1;i<=n;i++){
        for(long long int j=w;j>=wt[i];j--){
            ans[j]=max(ans[j],vl[i]+ans[j-wt[i]]);
        }
    }
    cout<<ans[w];
    return 0;
}


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

int main()
{
    std::string s;
    std::string ans = "Yes";
    std::cin >> s;

    for (size_t i = 0; i < s.length(); i++) {
        if (i %2 && s[i] == 'R') {
            ans = "No";
            break;
        }
        else if (i %2 == 0 && s[i] == 'L') {
            ans = "No";
            break;
        }
    }

    std::cout << ans << std::endl;

    return 0;
}


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

int main(){
  int N, M;
  cin >> N >> M;
  if(M==0){
    if(N==3){
      cout << "100" << endl;
      return 0;
    }
    if(N==2){
      cout << "10" << endl;
      return 0;
    }
    if(N==1){
      cout << "0" << endl;
      return 0;
    }
  }
  vector<int> num(N,-1);
  for(int i=0; i<M; i++){
    int s, c; cin >> s >> c;
    if(num[s-1]==-1){
      num[s-1]=c;
    }
    else if(num[s-1]!=c){
      cout << -1 << endl;
      return 0;
    }
  }
  if(N==1){
    if(num[0]==0 || num[0]==-1){
      cout << "0" << endl;
    }else{
      cout << num[0] << endl;
    }
    return 0;
  }
  for(int i=pow(10,N-1); i<pow(10, N); i++){
    int c=0;
    int tmp = i;
    bool f= true;
    while(c!=N){
      if(tmp%10==num[N-c-1] || num[N-c-1]==-1){
          tmp/=10;
          c++;
          continue;
      }
      f=false;
      break;
    }
    if(f){
      cout << i << endl;
      return 0;
    }
  }
  cout << "-1" << endl;
  return 0;
}

Measured memory_bytes: 256
import sys
stdin=sys.stdin


ns = lambda:stdin.readline().rstrip()
ni = lambda:int(stdin.readline().rstrip())
nm = lambda:map(int,stdin.readline().split())
nl = lambda:list(map(int,stdin.readline().split()))


p=998244353
N,M,K=nm()

fact=[1,1]
factinv=[1,1]
inv=[0,1]
for i in range(2,N):
    fact.append((fact[-1]*i)%p)
    inv.append((-inv[p%i]*(p//i))%p)
    factinv.append(factinv[-1]*inv[-1]%p)

def comb(n,r,p):
    if(r<0) or (n<r):
        return 0
    r=min(r,n-r)
    return fact[n]*factinv[r]*factinv[n-r]%p

mod_M=[1,(M-1)%p]
for i in range(2,N):
    mod_M.append((mod_M[i-1]*(M-1))%p)

ans=0
ans+=(M*mod_M[N-1])%p

if(K>0):
    for i in range(1,K+1):
        ans+=(M*mod_M[N-i-1]%p)*comb(N-1,i,p)
        ans%=p

print(ans)

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

#define fi first
#define intt long long
#define se second
#define pb push
#define endl '\n'
#define all(x) (x).begin(), (x).end()
#define digits(x) floor(log10(n) + 1)
#define countbits(x) ((int)log2(x)+1);
#define pn(x) cout << x <<"\n";
#define ps(x) cout << x <<" ";
#define deb(x) cout << #x << "=" << x << endl;
#define test() int tet;cin >> tet;while(tet--)
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);cout.precision(10);cout << fixed;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef vector<long long> vi;
typedef vector<char> vc;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const ll MOD = 1e9 + 7;
const ll INF = 1e9 + 9;
const int MAX=100;

intt gcd(intt a, intt b)
{
    if (a == 0)
        return b;
    return gcd(b % a, a);
 }

intt lcm(intt a, intt b)
{
    return (a*b)/gcd(a, b);
}
 intt n,m,k,a,b,c,W;
 intt dp[106][100005];
intt solve(intt w[],intt v[],intt W,intt n)
{
    if(n==0 || W==0)
    {
        return 0;
    }
    if(dp[n][W]==-1)
    {
        if(w[n-1]<=W)
        {
            return dp[n][W]=max(solve(w,v,W-w[n-1],n-1)+v[n-1],solve(w,v,W,n-1));
        }else{
            return dp[n][W]=solve(w,v,W,n-1);
        }
    }else{
        return dp[n][W];
    }
}

int main()
{
    fastio
    //test()
    {
        cin>>n>>W;
        intt w[n+1],v[n+1];
        memset(dp,-1,sizeof(dp));
        for(int i=0;i<n;i++)
        {
            cin>>w[i]>>v[i];
        }
        cout<<solve(w,v,W,n)<<"\n";


    }
    return 0;
}
/*
for(int i=0;i<n;i++)
    {
    }

*/



Measured memory_bytes: 86488
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using llpair=pair<ll,ll>;
using llvec=vector<ll>;
using llmat=vector<vector<ll>>;
#define llmattp(name,a,b,num) name(a,vector<ll>(b,num))
#define LLINF 1LL<<60
#define ABS(x) ( (x)>0 ? (x) : -(x) )

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

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

ll gcd(ll a, ll b) {
	if(a==0||b==0) return 0;
	if(a<b) swap(a,b);
	ll tmp = a%b;
	while(tmp!=0) {
		a = b;
		b = tmp;
		tmp = a%b;
	}
	return b;
}

ll factorial(ll x) {
	ll f=1;
	for(ll i=2; i<x; i++) {
		f*=i;
	}
	return f;
}

ll nPr(ll n, ll r) {
	ll result=1;
	for(ll i=r+1; i<=n; i++) result*=i;
	return result;
}

ll nCr(ll n, ll r) {

	if (n == 0) { return 0; }
	if (r == 0) { return 1; }
	if (r == 1) { return n; }
	if (n == r) { return 1; }

	if (r > n / 2) { r = n / 2; }

	double result = 1;
	for (double i = 1; i <= r; i++) {
		result *= (n - i + 1) / i;
	}

	return (ll)result;
}

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

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

	// 素数である
	return true;
}

ll GreaterBinarySearch(ll *array, ll key, ll max, ll min) {
	if(array[max]<array[min]) {
		return NULL;
	} else {
		ll mid = max + (min-max)/2;
		if(array[mid]<key) {
			return GreaterBinarySearch(array,key,max,mid-1);
		} if(array[mid]>key) {
			return GreaterBinarySearch(array,key,mid+1,min);
		} else {
			return mid;
		}
	}
}

ll value[101][100001]; // グローバル変数は初期化不要

int main() {
	int N,W; cin>>N>>W;
	for(int i=0; i<N; i++) {
		int w,v; cin>>w>>v;
		for(int j=0; j<=W; j++) {
			if(j+w<=W) chmax(value[i+1][j+w],value[i][j]+v); // ナップサックに突っ込む
			chmax(value[i+1][j],value[i][j]);				 // 突っ込まない
		}
	}
	sort(value[N],value[N]+W+1,greater<ll>());
	cout<<value[N][0]<<endl;
}


Measured memory_bytes: 78336
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);i++)
const int MOD=(int)1e9+7;
using namespace std;
int main(){
    string s;
    cin>>s;
    int stlen=s.size();
    REP(i,stlen){
        if((stlen-i)%2==1 or i==0){
            continue;
        }
        string t,v;
        t=s.substr(0,((stlen-i)/2));
        v=s.substr(((stlen-i)/2),((stlen-i)/2));
        if(t==v){
            cout<<(stlen-i)<<endl;
            return 0;
        }
    }
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
#define se second
#define fi first
#define pb push_back
#define rep(i,a,b) for(int i = a; i < b; i++)
#define all(v) v.begin(), v.end()

#define _ ios::sync_with_stdio(0); cin.tie(0);

#define vi vector<int>
#define ii pair<int,int>
#define vii vector<ii>
#define ll long long
#define vll vector<ll>

const int INF = 1e8;

using namespace std;

int main(){
	_



	int n, aux, maxi = -1, mini = 1e9 + 1;
	cin>>n;
	rep(i,0,n){
		cin>>aux;
		maxi = max(maxi, aux);
		mini = min(mini, aux);
	}

	cout<<maxi - mini<<"\n";

	return 0;
}

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

#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define pii pair<int,int>

int N;
int M;
vector<pii> mem[100010];
int P[100010];
int num[100010];

signed main()
{
    cin >> N >> M;
    rep(i, M)
    {
        int p, y;
        cin >> p >> y;
        P[i] = p;
        mem[p].push_back({y, i});
    }

    rep(i, N + 1)
    {
        sort(mem[i].begin(), mem[i].end());
        for(int j = 0; j < mem[i].size(); j++)
        {
            pii p = mem[i][j];
            num[p.second] = j + 1;
        }
    }

    rep(i, M)
    {
        vector<char> ans;
        int tmp = 1;
        rep(j, 6)
        {
            ans.push_back((P[i] / tmp) % 10 + '0');
            tmp *= 10;
        }
        reverse(ans.begin(), ans.end());
        for(auto a : ans) cout << a;

        ans.clear();
        tmp = 1;
        rep(j, 6)
        {
            ans.push_back((num[i] / tmp) % 10 + '0');
            tmp *= 10;
        }
        reverse(ans.begin(), ans.end());
        for(auto a : ans) cout << a;
        cout << endl;
    }

    return 0;
}

Measured memory_bytes: 10552
import java.util.Scanner;
import java.util.ArrayList;
import java.util.Arrays;

public class Main{
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        int num1 = scan.nextInt();
        long array[] = new long[num1];
        long dp[] = new long[num1];
        Arrays.fill(dp, 1000000000); 
        
        for(int i=0; i<num1; i++){
            int num2 = scan.nextInt();
            array[i] = num2;
        }
        
        dp[0] = 0;
        dp[1] = Math.abs(array[1] - array[0]);
        
        for(int i=2; i<num1; i++){
            if(dp[i] > dp[i-1] + Math.abs(array[i] - array[i-1])){
                dp[i] = dp[i-1] + Math.abs(array[i] - array[i-1]);
            }

            if(dp[i] > dp[i-2] + Math.abs(array[i] - array[i-2])){
                dp[i] = dp[i-2] + Math.abs(array[i] - array[i-2]);
            }


        }
        
        
        System.out.println(dp[num1-1]);



        


    }
}

Measured memory_bytes: 51184
#include<bits/stdc++.h>
#define y1 yy1
using namespace std;
int x1,y1,x2,y2;
main(){
  cin>>x1>>y1>>x2>>y2;
  const int x=x2-x1;
  const int y=y2-y1;
  const int x3=x2-y;
  const int y3=y2+x;
  const int x4=x3-x;
  const int y4=y3-y;
  printf("%d %d %d %d\n",x3,y3,x4,y4);
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
int main(int argc, char* argv[])
{
	enum COLOR{
		R=1,
		W=2,
	};
	int N,M;
	cin>>N>>M;
	vector<int> B(N,W);
	vector<int> n(N,1);
	B[0]=R;
	n[0]=1;
	int i;
	int xi,yi;
	for (i=0;i<M;i++){
		cin>>xi>>yi;
		xi--;
		yi--;
		if (n[xi]>0){
			if (B[xi]==R){
				B[yi]=R;
			}else{
				if (n[yi]==0){
					B[yi]=W;
				}
			}
			n[yi]++;
			n[xi]--;
			if (n[xi]==0){
				B[xi]=W;
			}
		}
	}
	int num=0;
	for (i=0;i<N;i++){
		if (B[i]==R){
			num++;
		}
	}
	cout<<num<<endl;
	return 0;
}

Measured memory_bytes: 1024