akhauriyash/Code-Regression huggingface dataset:
#pragma GCC optimize ("Ofast")
#pragma GCC target ("avx2")
//#include<bits/stdc++.h>
#include<cstdio>
#include<cstring>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

const int CM = 1400000;
char cn[CM], * ci = cn, ct;
const ll ma0 = 1157442765409226768;
const ll ma1 = 1085102592571150095;
const ll ma2 = 71777214294589695;
const ll ma3 = 281470681808895;
const ll ma4 = 4294967295;
inline int getint() {
	ll tmp = *(ll*)ci;
	int dig = 68 - __builtin_ctzll((tmp & ma0) ^ ma0);
	tmp = tmp << dig & ma1;
	tmp = tmp * 10 + (tmp >> 8) & ma2;
	tmp = tmp * 100 + (tmp >> 16) & ma3;
	tmp = tmp * 10000 + (tmp >> 32) & ma4;
	ci += (72 - dig >> 3);
	return tmp;
}
const int MAX = 200000;
class shuturyoku_unko {
public:
	char C[MAX * 6 + 10];
	int K[MAX + 10];
	constexpr shuturyoku_unko() : C(), K() {
		auto di = C + 1;
		C[0] = '0';
		K[0] = 0;
		K[1] = 1;
		rep1(i, MAX) {
			int X = i;
			int keta = 0;
			char c[10] = {};
			while (X) {
				*(c + keta) = '0' + X % 10;
				X /= 10;
				keta++;
			}
			for (int j = keta - 1; j >= 0; j--)* di++ = (*(c + j));
			K[i + 1] = K[i] + keta;
		}
	}
} f;
char* di = cn;
inline void putint(int X) {
	for (int i = f.K[X]; i < f.K[X + 1]; i++)* di++ = f.C[i];
	*di++ = '\n';
}

int A[200001];
int main() {
	//cin.tie(0);
	//ios::sync_with_stdio(false);

	fread(cn, 1, CM, stdin);
	int N = getint();
	rep(i, N - 1) A[getint()]++;

	rep1(i, N) putint(A[i]);

	fwrite(cn, 1, di - cn, stdout);


	Would you please return 0;
}

Measured memory_bytes: 5412
#include <iostream>
#include <string>
#include <utility>
#include <stack>
#include <vector>
#include <queue>
#include <algorithm>
#include <map>
#include <climits>
#include <set>
#include <cmath>
#include <numeric>

using namespace std;

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

    vector <pair <int, int> > P_to_ind;
    for(int i = 0; i < N; i++){
        P_to_ind.push_back(make_pair(P[i], i));
    }    
    sort(P_to_ind.begin(), P_to_ind.end());
    
    long long ans = 0;
    set <int> inds;
    inds.insert(P_to_ind[P_to_ind.size() - 1].second);
    for(int i = P_to_ind.size() - 2; i >= 0; i--){
        int cur_p = P_to_ind[i].first;
        int cur_ind = P_to_ind[i].second;
        auto it = inds.lower_bound(cur_ind);
        auto it_next = next(it, 1);
        auto it_before = prev(it, 1);
        auto it_two_before = prev(it, 2);
        
        int left_1;
        if(it == inds.begin() || (it_before == inds.begin() && *it_before > cur_ind)){
            left_1 = -1;
        } else {
            left_1 = *it_before;
        }
        int right_1;
        if(it == inds.end()){
            right_1 = N;
        } else {
            right_1 = *it;
        }
        int left_2;
        if(left_1 < 0 || it_before == inds.begin() || (it_two_before == inds.begin() && *it_two_before > cur_ind)){
            left_2 = -1;
        } else {
            left_2 = *it_two_before;
        }
        int right_2;
        if(right_1 == N || it_next == inds.end()){
            right_2 = N;
        } else {
            right_2 = *it_next;
        }

        if(it != inds.end()){
            ans += (long long) cur_p * (right_2 - right_1) * (cur_ind - left_1);
        }
        if(!(it_before == inds.begin() && *it_before > cur_ind)){
            ans += (long long) cur_p * (left_1 - left_2) * (right_1 - cur_ind);
        }
        //cout << *it_two_before << " " << *it_before <<" " <<  cur_ind << " " << *it << " " << *it_next << endl;
        //cout << left_2 << " " << left_1 << " " << cur_ind << " " << right_1 << " " << right_2 << endl;
        //cout << ans << endl;
        inds.insert(cur_ind);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 6132
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;


public class C
{
	public static void Main()
	{
		string[] args = Console.ReadLine().Split(' ');
		int A = Int32.Parse(args[0]);
		int B = Int32.Parse(args[1]);
		int C = Int32.Parse(args[2]);

		int flag = 0;
		flag |= A % 2;
		flag |= (B % 2) << 1;
		flag |= (C % 2) << 2;

		List<int> newABC = new List<int>(3);
		newABC.Add(A);
		newABC.Add(B);
		newABC.Add(C);

		int ans = 0;
		switch(flag)
		{
			case 0:  // 000
			case 7:  // 111
				break;

			case 1:  // 001
				newABC[1]++;
				newABC[2]++;
				ans++;
				break;

			case 2:  // 010
				newABC[0]++;
				newABC[2]++;
				ans++;
				break;

			case 3:  // 011
				newABC[0]++;
				newABC[1]++;
				ans++;
				break;

			case 4:  // 100
				newABC[0]++;
				newABC[1]++;
				ans++;
				break;

			case 5:  // 101
				newABC[0]++;
				newABC[2]++;
				ans++;
				break;

			case 6:  // 110
				newABC[1]++;
				newABC[2]++;
				ans++;
				break;

			default:
				throw new Exception();
		}
		newABC.Sort();

		ans += (newABC[2] - newABC[0]) / 2;
		ans += (newABC[2] - newABC[1]) / 2;

		Console.WriteLine(ans);
	}
}





Measured memory_bytes: 11220
//#include <boost/multiprecision/cpp_dec_float.hpp>
//#include <boost/multiprecision/cpp_int.hpp>
#include <stdio.h>
#include <iostream>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <math.h>
#include <algorithm>
#include <bitset>
#include <iomanip>
using namespace std;
//namespace mp = boost::multiprecision;
//using llll = mp::cpp_int;
// 仮数部が1024ビットの浮動小数点数型(TLEしたら小さくする)
//using Real = mp::number<mp::cpp_dec_float<1024>>;
using ll = long long;
const double EPS = 1e-10;
const ll MOD = 7+(1e+9);

#define max 2000000
ll big=1e9+7;
ll ff=0;
vector<ll> p(max,1);
vector<ll> ip(max,1);
ll pow_ans(ll x, ll n) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) {
          res *= x;
          res %= big;
        }
        x *= x;
        x %= big;
        n >>= 1;
    }
    return res;
}
void initialize(){
  for(int i=1;i<max;i++){
    p[i]=p[i-1]*i%big;
  }
  for(int i=1;i<max;i++){
    ip[i]=pow_ans(p[i],big-2);
  }
}
ll nPk(int i,int j){
  if(ff==0){
    initialize();
    ff=1;
  }
  if(i<0||j<0||i<j)return 0;
  else{
    ll tem;
    tem=p[i]*ip[i-j]%big;
    return tem;
  }
}
ll nCk(int i,int j){
  if(ff==0){
    initialize();
    ff=1;
  }
  if(i<0||j<0||i<j)return 0;
  ll tmp=nPk(i,j);
  tmp=tmp*ip[j]%big;
  return tmp;
}

int main(){
  ll n,ans=0;
  ll x,y;
  cin>>x>>y;
  if((x+y)%3!=0){
    cout<<0<<endl;
    return 0;
  }
  ans=nCk((x+y)/3,x-(x+y)/3);
  cout<<ans<<endl;
}


Measured memory_bytes: 31488
#include <iostream>
#define LLINF 1100000000000000000LL

using namespace std;
typedef long long ll;

int main()
{
  ll A, B, C;
  cin >> A >> B >> C;

  ll ans = LLINF;
  if (A % 2) ans = min(ans, B * C);
  else ans = 0;
  if (B % 2) ans = min(ans, C * A);
  else ans = 0;
  if (C % 2) ans = min(ans, A * B);
  else ans = 0;
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
typedef long long ll;
typedef pair<ll,ll> P;
const int INF=INT_MAX / 3;
const ll LINF=LLONG_MAX / 3LL;
#define CONST 1000000007
#define EPS (1e-8)
#define PB push_back
#define MP make_pair
#define sz(a) ((int)(a).size())
#define reps(i,n,m) for(int i=(n);i<int(m);i++)
#define rep(i,n) reps(i,0,n)
#define SORT(a) sort((a).begin(),(a).end())
ll mod(ll a,ll m){return (a%m+m)%m;}
int dx[9]={0,1,0,-1,1,1,-1,-1,0},dy[9]={1,0,-1,0,1,-1,1,-1,0};
ll n,m;
int main(){
  ll a, b;
  cin >> a >> b;
  a = (a == 1) ? 14 : a;
  b = (b == 1) ? 14 : b;

  cout << ((a < b) ? "Bob" : ((a == b) ? "Draw" : "Alice")) << endl;

  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<functional>
#include<map>
#include<cstdlib>
#include<complex>
#include<numeric>
#include<set>
#include<deque>
#include<queue>

using namespace std;
using Int = long long;
Int INF = 1LL << 60;
const Int MOD = 1000000000 + 7;

/*使い方
Prime a;//まずPrimeクラスのaを作成
（※デフォルトで110000が入っているが、もっと大きいNまでの素数を予め計算したい場合
Prime a(1000000);
などと置く必要がある）

auto s = a.factorize(12);//12を素因数分解する → sに(2,2)(3,1)が得られる
//ある整数Mを素因数分解したい場合、√Mまでの素数を全てリストアップする必要がある（篩）
//逆に言えば、√Mまででよい

bool t = a.isPrime(12);//12が素数かどうか判定する → tにfalseが得られる
*/
class Prime {
private:
	vector<Int> min_pf; // min_pf[i] = minimum prime factor of i
	vector<Int> prime;

	// エラトステネスの篩
	//Primeクラスを呼び出した際、Nまでの素数を予め篩にかける
	//Nはデフォルトで1100000
	void sieve(Int N) {
		min_pf[0] = min_pf[1] = -1;
		for (Int i = 2; i < N; i++) {
			if (min_pf[i] == 0) {
				prime.emplace_back(i);
				min_pf[i] = i;
			}
			for (Int j = 0; j < (Int)(prime.size()); ++j) {
				if (prime[j] > min_pf[i] || i * prime[j] >= N) break;
				min_pf[i * prime[j]] = prime[j];
			}
		}
	}

public:
	Prime(Int N = 1100000) : min_pf(N + 1) { sieve(N + 1); }

	//素因数分解
  //ある整数Mを素因数分解したい場合、√Mまでの素数を全てリストアップする必要がある（上記の篩）
	//逆に言えば、√Mまででよい
	vector<pair<Int, Int>> factorize(Int n) {//（数字、個数）
		vector<pair<Int, Int>> res;
		Int sz = (Int)min_pf.size();

		for (Int i = 2; i * i <= n; i++) {
			if (n < sz) break;
			Int cnt = 0;
			while (n % i == 0) {
				cnt++;
				n /= i;
			}
			if (cnt) res.emplace_back(i, cnt);
		}

		if (n >= sz) res.emplace_back(n, 1);
		else {
			Int prev = min_pf[n], cnt = -1;
			while (n > 0) {
				Int now = min_pf[n];
				n /= now;
				cnt++;
				if (prev != now) {
					res.emplace_back(prev, cnt);
					prev = now;
					cnt = 0;
				}
			}
		}

		return res;
	}

	// 素数判定
	bool isPrime(Int n) {
		if (n < (Int)(min_pf.size())) return min_pf[n] == n;
		else if (n == 2 || n == 3) return true;
		else if (n % 2 == 0 || n % 3 == 0) return false;
		else if (n % 6 != 1 && n % 6 != 5) return false;
		for (Int i = 5; i * i <= n; i += 6) {
			if (n % i == 0) return false;
			if (n % (i + 2) == 0) return false;
		}
		return true;
	}
};

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	Int x;
	cin >> x;

	Prime a;
	while (true) {
		if (a.isPrime(x)) {
			cout << x << "\n";
			return 0;
		}
		else {
			x++;
		}
	}



}


Measured memory_bytes: 9976
#! /usr/bin/env python3

from fractions import gcd
from collections import Counter, deque, defaultdict
from heapq import heappush, heappop, heappushpop, heapify, heapreplace, merge
from bisect import bisect_left, bisect_right, bisect, insort_left, insort_right, insort
from itertools import accumulate, product, permutations, combinations

K = int(input())
A, B = [int(_) for _ in input().split(" ")]

for i in range(A, B+1, 1):
    if i % K == 0:
        print("OK")
        exit()
print("NG")


Measured memory_bytes: 10468
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<stack>
#include<set>
#include<climits>
#include<cstdlib>
#include<cmath>
#include<string>

using namespace std;

#define INF 1 << 29
#define LL long long int

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

    int n;
    cin >> n;

    vector<bool> sosu(55556,true);
    sosu[0] = false;
    sosu[1] = false;
    for(int i = 0; i < 55556; i++){
        if(sosu[i]){
            for(int j = 2 * i; j < 55556; j += i){
                sosu[j] = false;
            }
        }
    }

    int count = 0;

    for(int i = 0; i < 55556 && count < n; i++){
        if(i % 10 == 1 && sosu[i]){
            if(count > 0){
                cout << " ";
            }
            count++;
            cout << i;
        }
    }
    cout << endl;

    return 0;
}

Measured memory_bytes: 384
#include <stdio.h>
#include <stdlib.h>
#define MAX 2000001
#define VMAX 10000

void CountingSort(int *,int *,int);

int main(){
  unsigned short *A, *B;
  int C[VMAX+1];
  int n, i, j;

  scanf("%d", &n);

  A = malloc(sizeof(short)*n+1);
  B = malloc(sizeof(short)*n+1);


  for(i = 1; i < n+1; i++){
    scanf("%d",&A[i]);
  }
  

  for(i = 0; i <= VMAX; i++){
    C[i] = 0;
  }

  for(j = 1; j < n+1; j++){
    C[A[j]]++;
  }

  for(i = 1; i < VMAX; i++){
    C[i] = C[i] + C[i-1];
  }

  for(j = n; j > 0; j--){
    B[C[A[j]]] = A[j];
    C[A[j]]--;
  }

  for(i = 1; i <= n; i++){
    if(i == n){
      printf("%d",B[i]);
    }else{
    printf("%d ",B[i]);
    }
  }

  printf("\n");


  return 0;
}






Measured memory_bytes: 9600
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i, s, n) for(int i = s, i##_len=(n); i < i##_len; ++i)
#define VFOR(i, s, n) for(int i = s; i < (n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define VREP(i, n) VFOR(i, 0, n)
#define ALL(v) (v).begin(), (v).end()
#define SORT(v) sort(ALL(v))
#define PB push_back
#define MP make_pair
using ll = long long;
using PII = pair<int, int>;
using VI = vector<int>;
using VD = vector<double>;
const int MOD = 1000000007;
const int INF = 1000000000;


int main(){
    int n; cin >> n;
    priority_queue<double, VD, greater<double>> que;
    REP(i, n){
        int v; cin >> v;
        que.push(v);
    }

    while(que.size() > 1){
        double s1, s2;
        s1 = que.top(); que.pop();
        s2 = que.top(); que.pop();

        que.push((s1 + s2) / 2);
    }
    cout << fixed << setprecision(10) << que.top() << "\n";
    return 0;
}


Measured memory_bytes: 256
n = int(input())
if n == 111:
    print(999)
elif n == 119:
    print(991)
elif n == 191:
    print(919)
elif n == 199:
    print(911)
elif n == 911:
    print(199)
elif n == 919:
    print(191)
elif n == 991:
    print(119)
elif n == 999:
    print(111)

Measured memory_bytes: 3060
/// hi_im_manh :D
#include <bits/stdc++.h>
#define reset(a,n) memset(a,0,(n+1)*sizeof(int))
#define endl "\n"
#define llmin LLONG_MIN
#define llmax LLONG_MAX
#define intmax INT_MAX
#define intmin INT_MIN
#define ll long long
#define fast ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)

#define duckman "TASK"

#define input freopen(duckman".inp", "r", stdin);
#define output freopen(duckman".out", "w", stdout);

#define nmax 22000
using namespace std;


int main()
{
    fast;
//    input;
//    output;
    string s;
    int q;
    cin >> s >> q;
    bool r = 0;
    string add[2];
    while (q--) {
        int t;
        cin >> t;
        if (t == 1) {
            r = !r;
        }
        else {
            int f;
            char c;
            cin >> f >> c;
            if (f == 1) {
                if (r == 1) {
                    add[1] += c;
                }
                else {
                    add[0] = c + add[0];
                }
            }
            else {
                if (r == 0) {
                    add[1] += c;
                }
                else {
                    add[0] = c + add[0];
                }
            }
        }
    }
    string res = add[0] + s + add[1];
    if (r) {
        reverse(res.begin(), res.end());
    }
    cout << res;
}
/*


*/


Measured memory_bytes: 1416
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
 
using namespace std;
 
typedef long long ll;
 
#define sz size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(c) (c).begin(), (c).end()
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define per(i,a,b) for(ll i=(b-1);i>=(a);--i)
#define clr(a, b) memset((a), (b) ,sizeof(a))
#define ctos(c) string(1,c)
#define print(x) cout<<#x<<" = "<<x<<endl;
 
#define MOD 1000000007
 
int main(){
  ll n,m;
  cin>>n>>m;
  if(m>n){
    cout << "No" << endl;
    return 0;
  }
  vector<string> va;
  vector<string> vb;
  rep(i,0,n){
    string s;
    cin>>s;
    va.pb(s);
  }
  rep(i,0,m){
    string s;
    cin>>s;
    vb.pb(s);
  }
  int flag = 0;
  rep(y,0,n-m+1){
    rep(x,0,n-m+1){
      int flag1 = 1;
      rep(y1,0,m){
        rep(x1,0,m){
          if(va[y+y1][x+x1]!=vb[y1][x1]){
            flag1 = 0;
          }
        }
      }
      if(flag1 == 1)flag = 1;
    }
  }
  if(flag == 1){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
  return 0;
}
 

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#define _SCL_SECURE_NO_WARNINGS
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <utility>
#include <algorithm>
#include <functional>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <iomanip>
#include <sstream>
#include <bitset>
#include <limits>
#include <numeric>

using namespace std;
typedef unsigned int uint;
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<LL, LL> PP;
#define REP(i,a,n) for(LL i = (a); i < (LL)(n); ++i)
#define REM(i,a,n) for(LL i = ((n) - 1); i >= (a); --i)
#define FLOAT setprecision(16)
#define SPEEDUP {cin.tie(0); ios::sync_with_stdio(false);}
#define INSIDE(i,j,H,W) ((i) >= 0 && (i) < (H) && (j) >= 0 && (j) < (W))
#define YesNo(b) (b ? "Yes" : "No")
#define YESNO(b) (b ? "YES" : "NO")
const int INF = 0x3FFFFFFF;
const LL INFLL = 0x3FFFFFFF3FFFFFFF;
const double INFD = 1.0e+308;
const string INFSTR = "\x7f";
const double EPS = 1.0e-9;

template <class T, class U>
istream& operator>>(istream& ist, pair<T, U>& right) { return ist >> right.first >> right.second; }
template <class T, class U>
ostream& operator<<(ostream& ost, const pair<T, U>& right) { return ost << right.first << ' ' << right.second; }
template <class T, class TCompatible, size_t N>
void Fill(T(&dest)[N], const TCompatible& val) { fill(begin(dest), end(dest), val); }
template <class T, class TCompatible, size_t M, size_t N>
void Fill(T(&dest)[M][N], const TCompatible& val) { for (int i = 0; i < M; ++i) Fill(dest[i], val); }
template<class T>
T Compare(T left, T right) { return left > right ? 1 : (left < right ? -1 : 0); }

// all_of
// partial_sum, adjacent_difference

#ifdef ONLY_MY_ENVIR
#include "IntMod.h"
#include "Union_Find.h"
#include "Graph.h"
#include "Range.h"
#include "Global.h"
#include "Flow_Solver.h"
#include "Tree.h"
#include "Suffix_Array.h"
#endif

#if 1234567891
#include <array>
#include <unordered_set>
#include <unordered_map>
template<typename T>
using PriorityQ = priority_queue<T, vector<T>, greater<T> >;	// コスト小を優先
#endif

LL N;

LL func(LL a) {
	LL sum = 0;
	while (a > 0) {
		sum += a % 10;
		a /= 10;
	}
	return sum;
}

LL A[100001];
LL B[100001];
LL DP[100001];

int main() {
	cin >> N;
	while (N % 5 == 0) {
		N /= 5;
	}
	while (N % 2 == 0) {
		N /= 2;
	}

	LL mn = INFLL;
	REP(i, 1, 1000001) {
		LL p = func(N * i);
		if (mn > p) {
			mn = p;
		}
	}

	LL res = 1;
	int bnum = 0;
	REP(i, 0, N) {
		A[res] = 1;
		B[i] = res;
		res *= 10;
		res %= N;
	}
	LL ans = 0;
	LL sum = 0;
	REM(i, 0, N + 1) {
		if (A[i] >= 1 && sum + i <= N) {
			int q = (N - sum) / i;
			sum += i * q;
			ans += q;
		}
	}
	if (N == 1) ans = 1;
	Fill(DP, INF);
	REP(i, 0, N) {
		if (A[i] >= 1) {
			DP[i] = 1;
		}
	}
	int con = 0;
	REP(i, 0, N) {
		if (A[i] == 0) continue;
		int k = 0;
		REP(j, 0, N * 2) {
			DP[k] = min(DP[k], DP[(k + N - i) % N] + 1);
			k =  (k + i) % N;
		}
		con++;
		if (con >= 350) break;
	}

	cout << min(mn, min(ans, DP[0])) << endl;
	return 0;
}


Measured memory_bytes: 2560
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

public class Main {
	static List<List<Hen>> list;

	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] sa = br.readLine().split(" ");
		int n = Integer.parseInt(sa[0]);
		Hen[] hens = new Hen[n - 1];
		list = new ArrayList<>(n);
		for (int i = 0; i < n; i++) {
			list.add(new ArrayList<>());
		}
		for (int i = 0; i < n - 1; i++) {
			sa = br.readLine().split(" ");
			Hen h = new Hen();
			h.a = Integer.parseInt(sa[0]) - 1;
			h.b = Integer.parseInt(sa[1]) - 1;
			h.i = i;
			hens[i] = h;
			list.get(h.a).add(h);
			list.get(h.b).add(h);
		}
		int m = Integer.parseInt(br.readLine());
		Cond[] conds = new Cond[m];
		for (int i = 0; i < m; i++) {
			sa = br.readLine().split(" ");
			Cond c = new Cond();
			c.u = Integer.parseInt(sa[0]) - 1;
			c.v = Integer.parseInt(sa[1]) - 1;
			c.i = i;
			conds[i] = c;
		}
		br.close();

		for (Cond c : conds) {
			dfs(c.u, -1, c.v, new ArrayList<>(), c);
		}

		long rem = 0;
		int end = 1 << m;
		for (int i = 1; i < end; i++) {
			Set<Integer> set = new HashSet<>();
			for (int j = 0; j < m; j++) {
				if ((i >> j & 1) == 1) {
					set.addAll(conds[j].visit);
				}
			}
			int num = n - 1 - set.size();
			long val = 1L << num;
			int cnt = Integer.bitCount(i);
			if (cnt % 2 == 1) {
				rem += val;
			} else {
				rem -= val;
			}
		}
		System.out.println((1L << n - 1) - rem);
	}

	static void dfs(int x, int p, int v, List<Integer> visit, Cond c) {
		if (x == v) {
			c.visit.addAll(visit);
			return;
		}
		for (Hen h : list.get(x)) {
			int next = h.a;
			if (next == x) {
				next = h.b;
			}
			if (next == p) {
				continue;
			}
			visit.add(h.i);
			dfs(next, x, v, visit, c);
			visit.remove(visit.size() - 1);
		}
	}

	static class Hen {
		int a, b, i;
	}

	static class Cond {
		int u, v, i;
		List<Integer> visit = new ArrayList<>();
	}
}


Measured memory_bytes: 339908
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin>>n;
  vector<int> a(n);
  for(int i=0;i<n;i++){
    cin>>a[i];
  }
  sort(a.begin(),a.end());
  int s=a.size()/2;
  if(a[s]==a[s-1]){
    cout<<0<<endl;
  }
  else {
    cout<<a[s]-a[s-1]<<endl;
  }
}

Measured memory_bytes: 640
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int count = 0;
        for (int i = a; i <= b; i++) {
            String str = String.valueOf(i);
            if (str.charAt(0) == str.charAt(4) && str.charAt(1) == str.charAt(3)) {
                count++;
            }
        }
        System.out.println(count);
    }
}

Measured memory_bytes: 28628
import java.math.BigInteger;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        BigInteger c = BigInteger.valueOf(a).multiply(BigInteger.valueOf(b));
        int d = a % b;
        while(d != 0) {
            a = b;
            b = d;
            d = a % b;
        }
        System.out.println(c.divide(BigInteger.valueOf(b)));
    }
}


Measured memory_bytes: 35920
#include<stdio.h>
int main(){
  int i,j,t,n,k,l[51],sum=0;
  scanf("%d%d", &n, &k);
  for(i=0; i<n; i++){
    scanf("%d",&l[i]);
  }
  for(i=0; i<n; i++){
    for(j=i+1; j<n; j++){
      if(l[i]<l[j]){
        t=l[i];
        l[i]=l[j];
        l[j]=t;
      }
    }
  }
  for(i=0; i<k; i++){
    sum=sum+l[i];
  }
  printf("%d\n",sum);
  return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int main(){
int64_t L,R;
  cin>>L>>R;
  if(2019<=R-L)
    cout<<0<<endl;
  else{
    int ans=2018;
  for(int64_t i=L;i<=R-1;i++){
  for(int64_t j=i+1;j<=R;j++){
  int64_t a=((i%2019)*(j%2019))%2019;
    if(a<ans)
      ans=a;
  
  }
  }cout<<ans<<endl;
  
  }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
#include <sstream>
#include <algorithm>
#include <bitset>
#include <limits>
#include <map>
#include <set>
#include <iomanip>
#include <cmath>
#include <numeric>

using namespace std;

typedef long long int ll;
typedef std::numeric_limits<double> dbl;
const long long int LL_INF=1LL<<60;

vector<string> split(const string& input, char delimiter)
{
    stringstream stream(input);
    
    string field;
    vector<string> result;
    while (getline(stream, field, delimiter)) {
        result.push_back(field);
    }
    return result;
}
 
//#define DEBUG

ll A, B, M, N, D, K, L, Q, W, H, T, X, Y, S;

struct edge {
    int from, to;
    ll cost;
};

void bellmanFord(vector<edge>& es, vector<ll>& ds, int start)
{
    for (auto& d : ds) d = INT64_MAX;
    ds[start] = 0;
    for (int j = 0; j < N-1; ++j) {
        for (int i = 0; i < es.size(); ++i) {
            edge e = es[i];
            if (ds[e.from] != INT64_MAX && ds[e.to] > ds[e.from] + e.cost) {
                ds[e.to] = ds[e.from] + e.cost;
            }
        }
    }
}

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

    vector<edge> edges(M);
    vector<ll> ds(N+1);
    
    for (int i = 0; i < M; ++i) {
        edge e; cin >> e.from >> e.to >> e.cost;
        e.cost *= -1;
        edges[i] = e;
    }

    bellmanFord(edges, ds, 1);

    ll ans = ds[N];
    vector<bool> neg(N+1);
    for (int j = 0; j < N; ++j) {
        for (int i = 0; i < edges.size(); ++i) {
            edge e = edges[i];
            if (ds[e.from] != INT64_MAX && ds[e.to] > ds[e.from] + e.cost) {
                ds[e.to] = ds[e.from] + e.cost;
                neg[e.to] = true;
            }

            if (neg[e.from]) neg[e.to] = true;
        }
    }

    if (!neg[N])
        cout << -ds[N] << endl;
    else
        cout << "inf" << endl;
    
    return 0;
}

Measured memory_bytes: 384
import java.util.Scanner;

class Dice{
	int pip_top;
	int pip_front;
	int pip_right;
	int pip_left;
	int pip_back;
	int pip_bottom;
}

class Main{

	public static void main(String[] args){

		Scanner sc =new Scanner(System.in);

		Dice d1= new Dice();

		d1.pip_top=sc.nextInt();
		d1.pip_front=sc.nextInt();
		d1.pip_right=sc.nextInt();
		d1.pip_left=sc.nextInt();
		d1.pip_back=sc.nextInt();
		d1.pip_bottom=sc.nextInt();

		String s=sc.next();

		for(int i = 0; i < s.length(); i++) {
			if( s.charAt(i)=='S')
				roll_S(d1);
			else if( s.charAt(i)=='N')
				roll_N(d1);
			else if( s.charAt(i)=='E')
				roll_E(d1);
			else 
				roll_W(d1);
		}

		System.out.println(d1.pip_top);

	}

	private static void roll_S(Dice d1) {
		int temp=d1.pip_top;
		d1.pip_top=d1.pip_back;
		d1.pip_back=d1.pip_bottom;
		d1.pip_bottom=d1.pip_front;
		d1.pip_front=temp;
	}

	private static void roll_N(Dice d1) {
		int temp=d1.pip_top;
		d1.pip_top=d1.pip_front;
		d1.pip_front=d1.pip_bottom;
		d1.pip_bottom=d1.pip_back;
		d1.pip_back=temp;
	}

	private static void roll_E(Dice d1) {
		int temp=d1.pip_top;
		d1.pip_top=d1.pip_left;
		d1.pip_left=d1.pip_bottom;
		d1.pip_bottom=d1.pip_right;
		d1.pip_right=temp;
	}

	private static void roll_W(Dice d1) {
		int temp=d1.pip_top;
		d1.pip_top=d1.pip_right;
		d1.pip_right=d1.pip_bottom;
		d1.pip_bottom=d1.pip_left;
		d1.pip_left=temp;
	}


}



Measured memory_bytes: 26416
from sys import stdin 
from collections import defaultdict, Counter


N, P = map(int, stdin.readline().split())
S, = stdin.readline().split()

ans = 0 


# 2 cases
if P == 2 or P == 5:
	digitdiv = []
	for i in range(N):
		if int(S[i]) % P == 0:
			ans += i + 1

else:
	#
	count = Counter()
	prefix = []
	ten = 1
	mod = 0
	for i in range(N):
		x = (int(S[N - i - 1])*ten + mod) % P 
		prefix.append(x)
		count[x] += 1
		ten = (ten * 10) % P 
		mod = x
	prefix.append(0)
	count[0] += 1
	for val in count.values():
		ans += val*(val - 1)//2


print (ans)





Measured memory_bytes: 52176
#include <stdio.h>
int main(void){
    int N, i, ans = 0;
    int l[100000];
    int r[100000];
    
    scanf("%d", &N);
    
    for(i = 0; i < N; i++){
        scanf("%d %d", &l[i], &r[i]);
        //printf("%d\n %d\n", l[i], r[i]);
        ans = ans + (r[i] - l[i] + 1);
    }
    printf("%d\n", ans);
    
}


Measured memory_bytes: 1712
import sys
sys.setrecursionlimit(10**9)


N, M = map(int, input().split())
to = [[] for _ in range(N)]

for _ in range(M):
    x, y = map(int, input().split())
    to[x - 1].append(y - 1)

# dp[i] : iを始点とする最長経路
dp = [0] * N
seen = [0] * N

def dfs(v):
    if seen[v]:
        return dp[v]
    seen[v] = 1
    res = 0
    for nv in to[v]:
        res = max(res, dfs(nv) + 1)
    dp[v] = res
    return res


def main():
    ans = 0
    for i in range(N):
        ans = max(ans, dfs(i))
    print(ans)


if __name__ == "__main__":
    main()

Measured memory_bytes: 62288
#include<stdio.h>
int main()
{
    int X,A;
    scanf("%d%d",&X,&A);
    if((X>=0 && X<=10) && (A>=0 && A<=10))
    {
        if(X<A)
            {
                printf("0\n");
              
            }

        else
            {
                printf("10\n");
            }
    }
    else
        printf("Not within limit ");
    return 0;
}

Measured memory_bytes: 128
import java.util.*;

public class Main {

  public static void main(String args[]) {
    int rep = 1;
    if( args.length > 0 ) { rep = Integer.parseInt(args[0]); }
    (new Main()).__solve(rep);
  }

  void __solve(int rep) {

    try (
      Scanner cin = new Scanner(System.in);
    ) {

      for( int i = 0; i < rep; ++i ) {
        __solve(cin);
      }

    }

  }

  void __solve(Scanner cin) {
	  
	  int N = cin.nextInt();
	  int K = cin.nextInt();
	  
	  int arr[] = new int[N];
	  for( int i = 0; i < N; ++i ) {
		  arr[i] = cin.nextInt();
	  }
	  Arrays.sort(arr);
	  int val[][] = new int[K][2];
	  for( int i = 0; i < K; ++i ) {
		  val[i][0] = cin.nextInt();
		  val[i][1] = cin.nextInt();
	  }
	  Arrays.sort(val, new Comparator<int[]>() {
		  public int compare(int a[], int b[]) {
			  if( a[1] > b[1] ) { return -1; }
			  if( a[1] < b[1] ) { return 1; }
			  return 0;
		  }
	  });

	  long sumRest[] = new long[N + 1];
	  for( int i = N - 1; i >= 0; --i ) {
		  sumRest[i] = sumRest[i + 1] + arr[i];
	  }
	  
	  long max = sumRest[0];
	  int L = 0;
	  long sum = 0;
	  for( int i = 0; i < K; ++i ) {
		  for( int j = 0; j < val[i][0]; ++j ) {
			  if( L == N ) { break; }
			  ++L;
			  sum += val[i][1];
			  max = Math.max(max, sum + sumRest[L]);
		  }
	  }

	  System.out.println(max);

  }

}


Measured memory_bytes: 95924
import Control.Monad
import Control.Applicative
import Data.List as List
import Data.Array as Array
import Data.Maybe as Maybe
import Debug.Trace

f a = do
  map ((\xs -> filter (== head xs) xs).(map (a !)).g) $ Array.indices a
  where
  r = Array.inRange $ Array.bounds a
  g (y, x) = filter r [(y + i, x + j) | (i, j) <- [(0,0),(0,1),(0,-1),(1,0),(-1,0)]]


main = do
  _ <- getLine
  s <- words <$> getContents
  --let s = ["#.#",".#."]
  let ly = length s
  let lx = (`div` ly).length.join $ s
  let a = Array.listArray ((0, 0), (ly - 1, lx - 1)) $ join s
  let b = and.map (\xs -> if head xs == '#' then length xs /= 1 else True) $ f a
  putStrLn $ if b then "Yes" else "No"


Measured memory_bytes: 1020
# 160 A

def swap(l, a, b, c):
    l[a], l[b] = l[b], l[a] 
    l[a], l[c] = l[c], l[a]
    return l

k = list(map(int, input().split()))
swap(k, 0, 1, 2)
for i in k:
    print(i, end  = " ")

Measured memory_bytes: 9096
#include <iostream>

using namespace std;

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

    for(int i=1;i<n-1;i++)
    {
        if(a[i]>min(a[i-1],a[i+1])  && a[i]<max(a[i-1],a[i+1]))
        {
            cnt++;
        }
    }

    cout<<cnt;
}


Measured memory_bytes: 256
n, k = map(int, input().split())
d = list(map(int, input().split()))
s = {'0','1','2','3','4','5','6','7','8','9'} - set(str(d))
ans = n

while (s >= set(str(n))) == False:
  n += 1
  if (s >= set(str(n))) == True:
    ans = n
    break
    
print(ans)
  

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

long long nums[100000];

int main()
{
    ios_base::sync_with_stdio(false);
    long long n, total = 1;
    cin >> n;
    for (int i = 0; i < n; i++)
    {
        cin >> nums[i];
    }
    sort(nums, nums + n);
    if (nums[0] == 0)
    {
        cout << 0;
        return 0;
    }
    for (int i = 0; i < n; i++)
    {
        total *= nums[i];
        if (total <= 0 || total > (long long)1e18)
        {
            cout << -1;
            return 0;
        }
    }
    cout << total;
    cin >> n;
}

Measured memory_bytes: 4448
#include <bits/stdc++.h>
using namespace std;
int n,a[100005];
long long ans;
int main()
{
    cin>>n;
    for(int i=1;i<=n;i++)
    	cin>>a[i];
    for(int i=1;i<=n;i++)
    {
        ans+=a[i]/2;
        a[i]%=2;
        if(i<n&&a[i]&&a[i+1])
        {
            ans++;
            a[i]--;
            a[i+1]--;
        }
    }
    cout<<ans;
    return 0;
}

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

#define IOS          ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl         "\n"
#define int          long long
#define all(v)       v.begin(),v.end()
#define sz(v)        (int)v.size()
#define pii          pair<int,int>
#define fi           first
#define se           second
#define forn(i,a,b)  for(int i=a;i<b;i++)

void INPUT() {
	#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
}

int32_t main(){
    IOS 
    int n,m;
    cin>>n>>m;
    int sm=0;
    int a[n];
    forn(i,0,n) {
    	cin>>a[i]; sm+=a[i];
    }
    sm=ceil(sm/(4.0*(double)m));
    int ans=0;
    forn(i,0,n) {
    	ans+=(a[i]>=sm);
    }
    cout<<(ans>=m ? "Yes" : "No")<<endl;
    return 0;
}

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

int main() {
    float a, b;
    cin >> a >> b;

    cout << ceil((b - 1) / (a - 1)) << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
#define MAX_V 605
#define MAX_E 1005

struct edge {int to,cost;};
vector<edge> G[MAX_V];
int V,E,A,B;
vector < vector < int > > t,u;

bool visited[MAX_V];
vector<int> a,b;

void dfs(int pos,bool flg){
  if(visited[pos])return;
  if(flg)a.push_back(pos);
  else b.push_back(pos);
  visited[pos]=true;
  for(int i=0;i<(int)G[pos].size();i++){
    bool f=G[pos][i].cost;
    dfs(G[pos][i].to,f^(!flg));
  }
}

void make_data(){
  for(int i=0;i<MAX_V;i++)visited[i]=false;
  for(int i=0;i<V;i++){
    if(visited[i])continue;
    a.clear();
    b.clear();
    dfs(i,true);
    t.push_back(a);
    u.push_back(b);
    /*
    for(int j=0;j<(int)a.size();j++)
      cout<<a[j]+1<<",";
    cout<<"=";

    for(int j=0;j<(int)b.size();j++)
      cout<<b[j]+1<<",";
    cout<<endl;
    */
  }
  //cout<<"---"<<endl;
}

void solve(){
  make_data();
  int prev[MAX_V][MAX_V];
  int dp[MAX_V][MAX_V],N=t.size();
  for(int i=0;i<MAX_V;i++)
    for(int j=0;j<MAX_V;j++)
      dp[i][j]=0;
  dp[0][0]=1;
  for(int i=0;i<N;i++){
    int a=t[i].size(),b=u[i].size();
    for(int j=0;j<MAX_V;j++){
      if(dp[i][j]==0)continue;
      if(j+a<MAX_V){
	dp[i+1][j+a]+=dp[i][j];
	prev[i+1][j+a]=j;
      }
      if(j+b<MAX_V){
	dp[i+1][j+b]+=dp[i][j];
	prev[i+1][j+b]=j;
      }
    }
  }


  if(dp[N][A]!=1){cout<<"no"<<endl;return;}


  vector<int> ans;
  int j=A;
  for(int i=N;i>0;i--){
    int nj=prev[i][j];
    if(j-nj==0)continue;
    if(j-nj==(int)t[i-1].size()){
      for(int k=0;k<j-nj;k++)ans.push_back(t[i-1][k]);
    }else{
     for(int k=0;k<j-nj;k++)ans.push_back(u[i-1][k]);
    }
    j=nj;
  }

  sort(ans.begin(),ans.end());
  for(int i=0;i<(int)ans.size();i++)
    cout<<ans[i]+1<<endl;
  cout<<"end"<<endl;
}

void init(){
  for(int i=0;i<MAX_V;i++){
    t.clear();
    u.clear();
    G[i].clear();
  }
  t.clear();
}

int main(){
  while(cin>>E>>A>>B){
    if(E==0&&A==0&&B==0)break;
    init();
    V=A+B;
    for(int i=0;i<E;i++){
      int a,b;
      string str;
      cin>>a>>b>>str;
      a--,b--;
      G[a].push_back((edge){b,(str=="yes")});
      G[b].push_back((edge){a,(str=="yes")});
    }
    //make_data();
    solve();
  }
  return 0;
}

Measured memory_bytes: 3752
#include<bits/stdc++.h>
    #define ll long long
    #define rep(i,a,b) for(i=a;i<b;i++)
    #define pb push_back
    #define all(v) v.begin(),v.end()
    #define F first
    #define S second
    #define vi vector < ll  int >
    #define CLR(a) memset((a),0,sizeof(a))
    #define mp make_pair
    #define hell 1000000007
    using namespace std;

    #define MAXN 1000005
    int spf[MAXN];
    void sieve()
    {
        spf[1] = 1;
        for (int i=2; i<MAXN; i++)
            spf[i] = i;
        for (int i=4; i<MAXN; i+=2)
            spf[i] = 2;

        for (int i=3; i*i<MAXN; i++)
        {
            if (spf[i] == i)
            {
                for (int j=i*i; j<MAXN; j+=i)

                    if (spf[j]==j)
                        spf[j] = i;
            }
        }
    }


    vector<int> gf(int x)
    {
        vector<int> ret;
        while (x != 1)
        {
            ret.push_back(spf[x]);
            x = x / spf[x];
        }
        return ret;
    }
    int BIT[100050]; //fenwick
    void upd(int x) { ++x;  while(x<=MAXN)  {  BIT[x]++;  x+=(x&-x);  } }
    int cal(int x) {  ++x;  int res=0;  while(x>0)  {  res+=BIT[x];  x-=(x&-x);  } return res; }
    ll Com[1051][1051];
    void pre()
    {

        ll i,j,n=1051;
        rep(i,0,n) Com[i][0]=Com[i][i]=1;
        rep(i,2,n)
        {
            rep(j,1,i)
            {
                Com[i][j]=Com[i-1][j]+Com[i-1][j-1];
                Com[i][j]%=hell;
            }
        }

    }
    ll mod=hell;
    ll pr( ll x , ll y)
    {
        ll ans=1;
        if(y==0) return ans;
        while(y>1)
        {
            if(y&1) ans*=x;
            x*=x;
            y/=2;
            x%=mod;
            ans%=mod;
        }
        ans*=x;
        ans%=mod;
        return ans;
    }
    ll inv(ll n)
    {
        return pr(n,mod-2);
    }
    ll stoi(string s)
    {
        int n=s.size();
        ll k=0; int i;
        rep(i,0,n)
        {
            k+=s[i]-'0';
            k*=10;
        }
        return k/10;
    }
    string to_string(ll n)
    {  if(!n) return "0";
        string s=""; int a,b;
        while(n>0)
        {
            b=n%10;
            s+=(b+'0');
            n/=10;
        }
        reverse(all(s));
        return s;
    }


    void solve()
    {
    //double i,j=0,r=200,p,q,k=0,d,y=0,n,h=10000000,flag=0,m=0,a=hell,b=hell,id,h1,h2,a1,b1,a2,w,x,u,f,l,c=0,e,ans=0;
    double n;
     cin>>n;
     double pie=6.28318530;
     n*=pie;
     cout<<fixed<<setprecision(10)<<n;
    }
    signed main()
    {
        ios::sync_with_stdio(false);
        cin.tie(0);
        cout.tie(0);
        int t=1;
       // cin>>t;
        while(t--)
        solve();
    }


Measured memory_bytes: 3844
#include<bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define REP(i,a,b) for(inti=a;i<=b;i++)

#define MOD 1000000009
typedef long long int ll;
typedef vector<int>vi;
typedef pair<int,int>pi;




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

cout<<(n-1)*(k-1)<<endl;
 return 0;
}


Measured memory_bytes: 3604
#include <iostream>

using namespace std;

int main() {
  long long mod = 1000000007;
  int n, m;
  cin >> n >> m;
  long long a = 0, b = 0;
  for (int i = 0; i < n; i++) {
    long long x;
    cin >> x;
    a = (x * ((i << 1) - n + 1) + a) % mod;
  }
  for (int i = 0; i < m; i++) {
    long long y;
    cin >> y;
    b = (y * ((i << 1) - m + 1) + b) % mod;
  }
  cout << (a * b) % mod << endl;
  return 0;
}


Measured memory_bytes: 256
import itertools
n,m,r = map(int, input().split())
towns = list(map(int, input().split()))
INF = float("inf")
cost = [[INF] * n for _ in range(n)]
#同じ場所にはコスト0で移動（というか移動しないので０）
for i in range(n):
    cost[i][i] = 0

for i in range(m):
    a,b,c = map(int, input().split())
    cost[a-1][b-1] = c
    cost[b-1][a-1] = c

# ワーシャルフロイド法
# スタート、中継地点、ゴールを全組み合わせで見ていくことで、ある地点からある地点への最短距離を求める
# 負の閉路があるとコストがいくらでも下げられるので使えない
for k in range(n): #中継地点
    for i in range(n): #スタート
        for j in range(n): #ゴール
            cost[i][j] = min(cost[i][j], cost[i][k] + cost[k][j])


ans = INF

for node in itertools.permutations(range(r)): #町移動順の全組み合わせを作成
    tmp = 0
    for x, y in zip(node, node[1:]):
        s, g = towns[x], towns[y] 
        tmp += cost[s-1][g-1] # 町ｓからｇまでの最短距離を足していく
    ans = min(ans, tmp)

print(ans)

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

void solve(int t, int d, int l){
        int tmp = 0;    
        int ans = 0;
        for(int i=0; i<t; ++i){
                if(tmp > 0) ++ans;
                --tmp;
                int x;
                cin >> x;
                if(x >= l) tmp = d;
        }
        cout << ans << "\n";
}

int main(){
//      cin.tie(0);
//      ios::sync_with_stdio(false);
        while(1){
                int t, d, l;
                cin >> t >> d >> l;
                if(t == 0) return 0;
                solve(t, d, l);
        }
}


Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <algorithm>
#include <ctime>
#include <cmath>
#include <string>
#include <stdlib.h>
#include <fstream>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <deque>
#include <iterator>
#include <iomanip>
using namespace std;


int main(){
    long long n, m, fr, to, s, t;
    cin >> n >> m;
    vector<vector<long long> > g(3 * 1e5 + 3);
    for(int i = 0; i < m; ++i){
        cin >> fr >> to;
        fr--, to--;
        g[fr].push_back(to + n);
        g[fr + n].push_back(to + 2 * n);
        g[fr + 2 * n].push_back(to);
    }
    cin >> s >> t;
    s--, t--;
    vector<long long> d(3 * 1e5 + 3, 1e9);
    d[s] = 0;
    vector<char> used(3 * 1e5 + 3, false);
    queue<long long> q;
    q.push(s);
    used[s] = true;
    while(!q.empty()){
        long long v = q.front();
        q.pop();
        for(long long a: g[v]){
            if(!used[a]){
                d[a] = d[v] + 1;
                q.push(a);
                used[a] = true;
            }
            if(a == t){
                cout << d[t] / 3;
                return 0;
            }
        }
    }
    cout << -1;
}


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

int main(){

	int a=0,b=0;

	for(int i = 0;i < 4;i++){
		int tmp=0;
		scanf("%d",&tmp);
		a += tmp;
	}
	for(int i = 0;i < 4;i++){
		int tmp = 0;
		scanf("%d",&tmp);
		b += tmp;
	}
	printf("%d\n",max(a,b));

	return 0;
}


Measured memory_bytes: 1184
/* ex 7_3
   TakayukiY*/

#include<stdio.h>
#include<stdlib.h>

int main(void){
    //indexと行列の要素数と空行チェック用の配列のポインタの定義
    int i,j,row,column,*chkrow,*chkcol;
    //aijの格納配列の定義
    char **ptr;

    //要素数を代入して各行のメモリ確保、エラーチェック
    scanf("%d%d\n",&row,&column);
    ptr=(char**)calloc(row,sizeof(char*));
    if(ptr==NULL) exit(1);

    for(i=0;i<row;i++){
        //各列のメモリ確保、エラーチェック
        ptr[i]=(char*)calloc(column,sizeof(char));
        if(ptr==NULL) exit(1);
        
        //各要素を代入
        for(j=0;j<column;j++){
            scanf("%c",&ptr[i][j]);
        }
        //末尾の改行をスキップ
        getchar();
    }

    //空行チェック用の配列のメモリ確保
    chkrow=(int*)calloc(row,sizeof(int));
    chkcol=(int*)calloc(column,sizeof(int));

    //0で初期化
    for(i=0;i<row;i++) *(chkrow+i)=0;
    for(j=0;j<column;j++) *(chkcol+j)=0;

    //行列の各要素のいずれかが空白でないならチェック用配列に1を代入
    for(i=0;i<row;i++){
        for(j=0;j<column;j++){
            if(ptr[i][j]=='#'){
                *(chkrow+i)=1;
                *(chkcol+j)=1;
            }
        }
    }

    //空白でない行・列に対して出力→圧縮
    for(i=0;i<row;i++){
        if(chkrow[i]==1){
            for(j=0;j<column;j++){
                if(chkcol[j]==1){
                    printf("%c",ptr[i][j]);
                }
            }
            printf("\n");
        }
    }

    //メモリの解放
    for(i=0;i<row;i++){
        free(ptr[i]);
    }
    free(ptr);

    return 0;
}


Measured memory_bytes: 1660
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#define MOD 1000000007
typedef long long ll;
using namespace std;

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

int rig[100010];
int lef[100010];

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

  lef[0]=a[0];
  for(int i=1;i<n;i++){
    lef[i]=gcd(lef[i-1],a[i]);
  }
  rig[n-1]=a[n-1];
  for(int i=n-2;i>=0;i--){
    rig[i]=gcd(rig[i+1],a[i]);
  }

  int ans=max(lef[n-2],rig[1]);
  for(int i=1;i<n-1;i++){
    ans=max(ans,gcd(lef[i-1],rig[i+1]));
  }
  cout<<ans<<endl;
  

  return 0;
}


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

int main(){
	int N;
	cin>>N;
	
	int ans=1;
	
	while(1){
		if(ans>N)
			break;
		ans*=2;
	}
	
	cout<<ans/2<<endl;
	return 0;
	
}

Measured memory_bytes: 256
parseInt(x)=parse(Int,x)
parseMap(x::Array{SubString{String},1})=map(parseInt,x)

function main()
	n,m = readline() |> split |> parseMap
	flg = zeros(Int,m)
	for i in 1:n
		a = readline() |> split |> parseMap
		for j in 1:m
			if !(j in a[2:length(a)])
				flg[j] = 1
			end
		end
	end
	println(m-sum(flg))
end

main()

Measured memory_bytes: 113640
#include <bits/stdc++.h>
using namespace std;
 
int N, r, t;
 
int main()
{
    cin >> N;
    for (int _i = 0; _i < N; _i++)
    {
        cin >> r >> t;
        int pr = r % 100;
        r /= 100;
        int pt = t % 30;
        t /= 30;
        int x = r + 5 * t;
        if (pr == 0)
        {
            if (pt == 0)
                cout << x << endl;
            else
                cout << x << " " << x + 5 << endl;
        }
        else
        {
            if (pt == 0)
                cout << x << " " << x + 1 << endl;
            else
                cout << x << " " << x + 1 << " " << x + 5 << " " << x + 6 << endl;
        }
 
    }
 
    return 0;
}

Measured memory_bytes: 3088
import sys

def solve(tile):
    count = 0
    prev = ""
    for i in xrange(len(tile)):
       if tile[i] == prev:
           count += 1
           if tile[i] == "0":
               prev = "1"
           else:
               prev = "0"
       else:
           prev = tile[i]

    return count

if __name__ == '__main__':

    tile = sys.stdin.readline().strip()
    ans = solve(tile)
    print ans

Measured memory_bytes: 2948
#include<bits/stdc++.h>
char str[256],*c,*f;
int main(void){
    scanf("%s",str);
    c=strchr(str,'C');
    if(c!=NULL) f=strchr(c+1,'F');
    printf("%s",c!=NULL&&f!=NULL?"Yes":"No");
    return 0;
}

Measured memory_bytes: 256
s=input()
k= ''.join(list(reversed(s)))
l=""
if s!=k:
    print("No")
    exit()
n=int((len(s)-1)/2)
for i in range(n):
    l=l+s[i]
if l!= ''.join(list(reversed(l))):
    print("No")
    exit()
print("Yes")


Measured memory_bytes: 3060
#この問題のポイント一つ目　３つ動くときは真ん中を固定する
#真ん中を固定したら下の段からはそれより小さいもの、上の段はそれより大きいものを選べる
#上の段と下の段をsortするとある境界を境にokとngがはっきり分かれる
#二部探索
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=list(map(int,input().split()))
a.sort()
b.sort()
c.sort()
from bisect import bisect_left
from bisect import bisect_right
ans=0
for i in range(n):
  #b[i]を固定する
  ans=ans+bisect_left(a,b[i])*(n-bisect_right(c,b[i]))

  
print(ans)

  

Measured memory_bytes: 29412