akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long lli;
#define mod 1000000007
#define fori(n) for (int i = 0; i < n; i++)
#define forj(n) for (int j = 0; j < n; j++)
#define forr(c, n) for (int i = c; i < n; i++)
#define forli(n) for (lli i = 0; i < n; i++)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define fast ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define endl "\n"
#define sortvec(a) sort(a.begin(), a.end())

//FUNCTONS
lli llipower(lli x, lli y)
{
    lli res = 1;
    while (y > 0)
    {
        if (y & 1)
            res = (res * x);
        y = y >> 1;
        x = (x * x);
    }
    return res;
}
lli llipowerp(lli x, lli y, lli p)
{
    lli res = 1;
    x = x % p;
    while (y > 0)
    {
        if (y & 1)
            res = (res * x) % p;
        y = y >> 1;
        x = (x * x) % p;
    }
    return res;
}
lli gcd(lli a, lli b)
{
    if (!a)
        return b;
    return gcd(b % a, a);
}
lli binarySearch(vector<int> arr, int l, int r, int x)
{
    if (r >= l)
    {
        lli mid = l + (r - l) / 2;
        if (arr[mid] == x)
            return mid;
        if (arr[mid] > x)
            return binarySearch(arr, l, mid - 1, x);
        return binarySearch(arr, mid + 1, r, x);
    }
    return -1;
}
template <typename T>
void printvec(vector<T> inp)
{
    for (int i = 0; i < inp.size(); i++)
    {
        cout << inp[i] << " ";
    }
    cout << endl;
}
template <typename T>
T ceildiv(T x, T y) { return 1 + ((x - 1) / y); }
lli modInverse(lli a, lli m)
{
    lli g = gcd(a, m);
    if (g != 1)
        return -1;
    else
        return llipowerp(a, m - 2, m);
}

int main()
{
    string inp;
    cin>>inp;
    if(inp[2]==inp[3] && inp[4]==inp[5]) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;        
}


Measured memory_bytes: 256
use itertools::Itertools;
use proconio::fastout;
use proconio::input;

#[fastout]
fn main() {
    input! {
        a: i64,
        b: i64,
        c: i64,
        k: i64,
    }
    let mut ans = 0;
    let mut rest = k;
    let aa = rest.min(a);
    rest -= aa;
    ans += aa;
    rest -= rest.min(b);
    ans -= rest;
    println!("{}", ans);
}


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

using namespace std;
using ll = long long;
const int mod = 1e6 + 3;
ll fac[1100000];
ll rev_fac[1100000];

ll ksm(ll x, ll n) {
    ll res = 1;
    while (n) {
        if (n & 1) {
            res = res * x % mod;
        }
        x = x * x % mod;
        n >>= 1;
    }
    return res;
}

ll get_rev(ll x) {
    return ksm(x, mod - 2);
}

void init() {
    fac[0] = 1;
    for (int i = 1; i <= 1000010; ++i) {
        fac[i] = (fac[i - 1] * i) % mod;
    }
    rev_fac[1000002] = get_rev(fac[1000002]);
    for (int i = 1000001; i >= 0; --i) {
        rev_fac[i] = rev_fac[i + 1] * (i + 1) % mod;
    }
}

ll solve(ll x, ll d, ll n) {
    if (d == 0) {
        return ksm(x, n);
    }else {
        ll xd = (x * get_rev(d)) % mod;
        if (xd + (n - 1) >= mod) return 0;
        xd = (fac[xd + n - 1] * rev_fac[xd - 1]) % mod;
        ll rev = ksm(d, n);
        return (xd * rev) % mod;
    }
}

int main() {
    init();
    ll q, x, d, n;
    cin >> q;
    while (q--) {
        cin >> x >> d >> n;
        cout << solve(x, d, n) << endl;
    }
}

Measured memory_bytes: 17280
#include<algorithm>     //sort,二分探索,など
#include<bitset>        //固定長bit集合
#include<cmath>         //pow,logなど
#include<complex>       //複素数
#include<deque>         //両端アクセスのキュー
#include<fstream>       //ファイルストリーム（標準入力変更用）
#include<functional>    //sortのgreater
#include<iomanip>       //setprecision(浮動小数点の出力の誤差)
#include<iostream>      //入出力
#include<iterator>      //集合演算(積集合,和集合,差集合など)
#include<map>           //map(辞書)
#include<numeric>       //iota(整数列の生成),gcdとlcm(c++17)
#include<queue>         //キュー
#include<set>           //集合
#include<stack>         //スタック
#include<string>        //文字列
#include<unordered_map> //イテレータあるけど順序保持しないmap
#include<unordered_set> //イテレータあるけど順序保持しないset
#include<utility>       //pair
#include<vector>        //可変長配列

//名前
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef map<string, int> msi;
typedef map<string, ll> msll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pllll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vector<int>> vvi;
typedef vector<vector<ll>> vvll;
typedef vector<vector<string>> vvs;
typedef vector<vector<bool>> vvb;

//定数
const ll MOD = 1000000007;
const ll INF = 1000000000000000000;

//マクロ
#define rep(i,n) for(int i=0;i<n;i++)
#define reps(i,s,e) for(int i=s;i<e;i++)
#define repse(i,s,e) for(int i=s;i<=e;i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define in1(x1) cin >> x1
#define in2(x1, x2) cin >> x1 >> x2
#define in3(x1, x2, x3) cin >> x1 >> x2 >> x3
#define inN(x, N) rep(i, N) in1(x[i])
#define outl(x) cout << x << endl
#define out2l(x, y) cout << x << " " << y << endl 

//よく使う関数
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

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

    //標準入力をファイルに変更
    //std::ifstream in("input.txt");
    //std::cin.rdbuf(in.rdbuf());

    int X, Y;
    in2(X, Y);

    outl(X + Y / 2);

    return 0;
}


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

int solve(vector<int> a){
  int size=a.size();
  int cnt=0;
  for(int i=0;i+1<size;i++){
    cnt+=a[i]*2;
    a[i+1]=max(0,a[i+1]-a[i]);
  }
  return cnt+a[size-1];
}

int main(){
  int n;
  cin>>n;
  vector<int> a(n);
  for(int i=0;i<n;i++){
    cin>>a[i];    
  }
  int ans=1e9;
  for(int i=0;i<=3;i++){
    ans=min(ans,solve(a)+i);
    a[0]=max(0,a[0]-1);
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 3160
#include <cstdio>
#include <string>
#include <iostream>

using std::string;

int main(){
	string A;
	string B;
	int ALen=0;
	int BLen=0;
	std::cin>>A>>B;
	ALen=(int)A.size();
	BLen=(int)B.size();
	if(ALen==BLen){
		bool EqFlag=true;
		for(int i=0;i<ALen;i++){
			int ATemp=0;
			int BTemp=0;
			ATemp=A[i]-48;
			BTemp=B[i]-48;
			if(ATemp<BTemp){
				EqFlag=false;
				printf("LESS\n");
				break;
			}else if(ATemp>BTemp){
				EqFlag=false;
				printf("GREATER\n");
				break;
			}
		}
		if(EqFlag){
			printf("EQUAL\n");
		}
	}else if(ALen<BLen){
		printf("LESS\n");
	}else if(ALen>BLen){
		printf("GREATER\n");
	}
	return 0;
}

Measured memory_bytes: 256
'use strict'

function Main(input) {
  const A = input.split("\n")[1].split(" ").map(x => Number(x))

  let mother = 0
  for(const a of A) {
    mother += 1/a
  }

  console.log(1/mother)
}
Main(require("fs").readFileSync("/dev/stdin", "utf8").trim())


Measured memory_bytes: 21064
line = input()
stack, edges, pools = [], [], []

for i in range(len(line)):
    if line[i] == '\\':
        stack.append(i)
    elif line[i] == '/' and stack:
        j = stack.pop()
        tmp = i - j
        while edges and edges[-1] > j:
            edges.pop()
            tmp += pools.pop()
        edges.append(j)
        pools.append(tmp)

print(sum(pools))
print(len(pools), *pools)

Measured memory_bytes: 8116
#include "bits/stdc++.h"

using namespace std;
typedef long long int ll;
typedef pair<ll, ll > pi;  
typedef pair<pair<ll, ll >, ll > pii;  
vector<double > vec;
vector<vector<ll > > vec2;
ll MOD = 1000000007;
ll INF = 1145141919454519;

int main() {

    ll N, A, B;
    cin >> N >> A >> B;

    cout << min(A, B) << " " << abs(min(0LL, N - A - B)) << endl;

}

Measured memory_bytes: 256
#include <iostream>
#include <utility>
#include <string>
#include <algorithm>
#include <map>
#include <vector>
#include <climits>
#include <numeric>
#include<stdio.h>
#include <queue>
#include <iomanip>
#include <float.h>
#include <set>
#include<functional>
#include <stack>
#include <time.h>
#include <climits>
#include <bitset>
#include <fstream>
using namespace std;
long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}
typedef pair<int, int> p;
vector< int64_t > divisor(int64_t n) {
	vector< int64_t > ret;
	for (int64_t i = 1; i * i <= n; i++) {
		if (n % i == 0) {
			ret.push_back(i);
			if (i * i != n) ret.push_back(n / i);
		}
	}
	sort(begin(ret), end(ret));
	return (ret);
}
long long mod = 1e9 + 7;
int main(int argc, char* argv[]) {
	int n;
	cin >> n;
	int a[200004];
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	if (n % 2 == 1) {
		long long sum = 0;
		for (int i = 0; i < n; i++) {
			sum+= a[i];
		}
		if (sum % 2) {
			cout << "First\n";
		}
		else {
			cout << "Second\n";
		}
	}
	else {
		sort(a, a + n);
		if (a[0] % 2 == 1) {
			cout << "First\n";
		}
		else {
			long long sum = 0;
			for (int i = 0; i < n; i++) {
				sum += a[i];
			}
			if (sum % 2) {
				cout << "First\n";
			}
			else {
				cout << "Second\n";
			}
		}
	}
}



Measured memory_bytes: 3904
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MM 1000000000
#define MOD MM+7
#define MAX 101000
#define MAP 110
#define initial_value -1
#define Pair pair<int,int>
#define chmax(a,b) (a<b ? a=b:0)
#define chmin(a,b) (a>b ? a=b:0)
int dx[4] = {-1,0,1,0};
int dy[4] = {0,-1,0,1};
int N;
int C[505],S[505],F[505];
int main(){
    cin >> N;
    for(int i = 0; i < N; i++){
        cin >> C[i] >> S[i] >> F[i];
    }
    for(int i = 0; i < N; i++){
        int t = 0;
        for(int j = i; j < N-1; j++){
            if(t < S[j]) t = S[j];
            else if(t % F[j] == 0);
            else t = t + F[j] - t%F[j];
            t += C[j];
        }
        cout << t << endl;
    }
    return 0;
}



Measured memory_bytes: 256
N, M = map(int, input().split())
m = 0
if M > 0:
  broken = int(input())
else:
  broken = 0
a1, a2, a3 = 1, 0, 0
for i in range(1, N+1):
  a3, a2 = a2, a1
  if i == broken:
    a1 = 0
    m += 1
    if m < M:
      broken = int(input())
  else:
    a1 = (a2 + a3) % 1000000007
print(a1)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using ll = long long;
using ld = long double;
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define vd vector<ld>
#define vvd vector<vector<ld>>
#define ALL(a) begin(a), end(a)
#define RALL(a) rbegin(a), rend(a)
#define SORT(a) stable_sort(ALL(a))
#define RSORT(a) stable_sort(RALL(a))
#define REV(a) reverse(ALL(a))
#define lambda(i) [](auto& i)
#define compare(i, j) [](auto& i, auto& j)
#define min_of(a) *min_element(ALL(a))
#define max_of(a) *max_element(ALL(a))
#define sum(a) accumulate(ALL(a), 0)
#define pb push_back
#define mp make_pair
#define SZ(a) ll((a).size())
#define REP(i, n) for (decltype(n) i = 0; i < (n); i++)
#define RREP(i, n) for (auto i = n - 1; i != static_cast<decltype(i)>(-1); i--)
#define FOR(i, a, b) for (auto i = (a); i < (b); i++)
#define RFOR(i, a, b) for (auto i = b - 1; i != a; i--)
#define EACH(i, a) for (auto&& i: (a))
using namespace std;

const ll INF = 1e18;
const ll mod = 1e9 + 7;

vi cum(vi V) {
  vi U(SZ(V));
  partial_sum(ALL(V), begin(U));
  return U;
}

void solve() {
  ll l, r;
  ll ans = 2019;

  cin >> l >> r;
  if (r - l > 2019) {
    cout << 0 << endl;
    return;
  }
  FOR(i, l, r) FOR(j, i + 1, r + 1) {
    ans = min(ans, i * j % 2019);
  }

  cout << ans << endl;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout << fixed << setprecision(15);
  solve();
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <queue>
using namespace std;
 
struct data{
	int v,c;
};
 
bool cmp(data x,data y){
	if(x.c < y.c)	return true;
	else			return false;
}
 
main(){
	int n,m,k;
	long long ans;
	data a[100010];
	priority_queue<int> pq;
	ans = 0;
	k = 1;
	cin>>n>>m;
	for(int i=1;i<=n;i++)
		cin>>a[i].c>>a[i].v;
	sort(a+1,a+n+1,cmp);
	for(int i=1;i<=m;i++){
		while(a[k].c == i){
			pq.push(a[k].v);	
			k++;
		}
		if(!pq.empty()){
			ans += pq.top();
			pq.pop();
		}
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 1660
#include <bits/stdc++.h>
#define ll long long int
#define pb push_back
#define mp make_pair
#define ss second
#define ff first

 using namespace std;
 
 const ll MOD = 1000000007LL;
 
ll ar[500056],br[500056];


vector<ll> vec,pec;
set<ll> st;
map<ll,ll> has;


vector<pair<ll,ll> > vp;




int main() 
{
	
//freopen("input.in","r",stdin);
//freopen("output.out","w",stdout);
    
    ll n,p,t,j,a,x,y=0,k,l,m,z,b,c,e,f,q,s,flag=0,sum=0,res=0,num,g,h;
	ll i,u,v,w,ans,maxm=0,r,minm=999999999999,maxi;
	bool fl=0;
	ll d;
	string str;
	
	cin>>n;
	
	d=n;
	
	while(d)
	{
		p=d%10;
	    res+=p;
	    d/=10;
	}
	
	if(n%res==0)
	cout<<"Yes";
	else
	cout<<"No";
	
	

	
    return 0;
}    




Measured memory_bytes: 256
#include <bits/stdc++.h>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

double dp[1001];
int a,b,k;
int t[35];
int sum[35];
double ct[35];
double dp2[1001][35];

double solve(int sz);
double solve2(int sz,int i);

double solve2(int sz,int i){
	if(dp2[sz][i]>=0.0)return dp2[sz][i];
	if(sz<=0){
		return 1e18;
	}
	if(i==0)return t[0]*sz+solve(sz)*sz;
	double ans=1e18;
	for(int j=1;j<=sz-1;j++){
		double val=solve(j)*j;
		val+=t[i]*j;
		val+=solve2(sz-j,i-1);
		ans=min(ans,val);
	}
	return dp2[sz][i]=ans;
}

double solve(int sz){
	if(dp[sz]>=0.0)return dp[sz];
	if(sz<=1)return 0;
	double ans=1e18;
	for(int i=1;i<=min(k,sz-1);i++){
		ans=min((double)solve2(sz,i)/sz,ans);
	}
	return (dp[sz]=ans);
}

int main(void){
	scanf("%d%d%d",&a,&b,&k);
	int n=b-a;
	for(int i=0;i<=k;i++){
		scanf("%d",&t[i]);
	}
	for(int i=0;i<=k;i++){
		sum[i+1]+=sum[i];
		sum[i+1]+=t[i];
		ct[i+1]=(double)sum[i+1]/(i+1);
	}
	for(int i=0;i<=n+1;i++){
		dp[i]=-1.0;
		for(int j=0;j<=k+1;j++){
			dp2[i][j]=-1;
		}
	}
	printf("%.10f\n",solve(n));
	return 0;
} 


Measured memory_bytes: 3700
import collections as c
ip = lambda : map(int, input().split())
# ##############
mod = 1e9+7
N = int(input())
f,s,fi,si = 0,0,0,0
for i in range(N):
    t = int(input())
    if f<t:
        s,si = f,fi
        f,fi = t,i
    elif s<t:
        s,si = t,i
for i in range(fi):
    print(f)
print(s)
for i in range(N-fi-1):
    print(f)

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

using namespace std;

int main(){
        string s;
        cin >> s;
        int c1=0,c2=0;
        if(s[0]=='A'){
                for(int i=0;i<(int)s.length();i++){
                        if(isupper(s[i])) c1++;
                        if(i>1 && s[i] == 'C') c2++;
                }
        }
        if(c1==2 && c2==1 && s.back()!='C') cout << "AC" << endl;
        else cout << "WA" << endl;
        return 0;
}


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

using namespace std;

int N;
pair<long long, int> priority[100000];
int A[100000], B[100000];

int main(){
    cin >> N;
    for(int i = 0; i < N; i++){
        cin >> A[i] >> B[i];
        priority[i] = make_pair(-A[i]-B[i], i);
    }
    sort(priority, priority + N);
    long long ans = 0;
    for(int i = 0; i < N; i++){
        int j = priority[i].second;
        if(i % 2 == 0){
            ans += A[j];
        }else{
            ans -= B[j];
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 2560
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <queue>
#include <set>
#include <numeric>
#include <cmath>

using namespace std;

typedef long long int lld;

const lld mod = 1e9+7;
const lld INF = 1e9;
//const lld MAXN = 1e9;

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

	int a[100][100] = {0};

	for(int i = 0; i < n; i++)
	{
		int u,k,v[100] = {0};
		cin >> u >> k;
		for(int j = 0; j < k; j++)
		{
			cin >> v[k];
			a[u-1][v[k]-1] = 1;
		}
	}

	for(int i = 0; i < n; i++)
	{
		for(int j = 0; j < n; j++)
		{
			if (j == n-1)
			{
				cout << a[i][j] << endl;
			}else
			{
				cout << a[i][j] << " ";
			}
		}
	}

	return 0;
}

Measured memory_bytes: 3124
import java.util.*;
 
public class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		if((a*b)%2 == 0){
			System.out.println("Even");
        }else{
			System.out.println("Odd");
		}
	} 
}

Measured memory_bytes: 23764
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <bitset>
using namespace std;

#ifdef LOCAL
	#define eprintf(...) fprintf(stderr, __VA_ARGS__);fflush(stderr);
#else
	#define eprintf(...) 42
#endif

using ll = long long;
using ld = long double;
using uint = unsigned int;
using ull = unsigned long long;
template<typename T>
using pair2 = pair<T, T>;
using pii = pair<int, int>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll myRand(ll B) {
	return (ull)rng() % B;
}

#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second

clock_t startTime;
double getCurrentTime() {
	return (double)(clock() - startTime) / CLOCKS_PER_SEC;
}


const int MOD = 998244353;
int add(int x, int y) {
	x += y;
	if (x >= MOD) return x - MOD;
	return x;
}
ll sub(ll x, ll y) {
	x -= y;
	if (x < 0) return x + MOD;
	return x;
}
ll mult(ll x, ll y) {
	return (x * y) % MOD;
}
ll bin_pow(ll x, ll p) {
	if (p == 0) return 1;
	if (p & 1) return mult(x, bin_pow(x, p - 1));
	return bin_pow(mult(x, x), p / 2);
}
ll rev(ll x) {
	return bin_pow(x, MOD - 2);
}


const int N = 303;
int a[N];
int n, k, m;
char s[N];
int dp[N][N][N];

int main()
{
	startTime = clock();
//	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);


	scanf("%s %d", s, &k);
	m = strlen(s);

/*
	m = 300;
	for (int i = 0; i < m; i++)
		s[i] = '0' + myRand(2);
	k = m;
*/
	int cnt = 0;
	a[n++] = 0;
	for (int i = m - 1; i >= 0; i--) {
		if (s[i] == '0') {
			a[n++] = cnt;
		} else {
			cnt++;
		}
	}
	a[n++] = cnt;
	/*
	for (int i = 0; i < n; i++)
		eprintf("%d ", a[i]);
	eprintf("\n");
	*/
	k = min(k, cnt);
	dp[0][0][0] = 1;
	for (int i = 0; i < n - 1; i++)
		for (int sum = 0; sum <= a[i]; sum++)
			for (int ac = 0; ac <= sum; ac++) {
				if (dp[i][sum][ac] == 0) continue;
				for (int x = 0; sum + x <= a[i + 1]; x++) {
					int nac = ac + max(0, x - (a[i + 1] - a[i]));
					dp[i + 1][sum + x][nac] = add(dp[i + 1][sum + x][nac], dp[i][sum][ac]);
				}
			}
	int ans = 0;
	for (int i = 0; i <= k; i++)
		ans = add(ans, dp[n - 1][a[n - 1]][i]);
	printf("%d\n", ans);

	return 0;
}


Measured memory_bytes: 30100
N,M = map(int,input().split())
d = [[10**10]*N for i in range(N)]
a = [0]*M
b = [0]*M
c = [0]*M
for i in range(M):
  a[i],b[i],c[i]=map(int,input().split())
  a[i] -= 1
  b[i] -= 1
  d[a[i]][b[i]] = c[i]
  d[b[i]][a[i]] = c[i]
for i in range(N):
  d[i][i] = 0

for i in range(N):
  for j in range(N):
    for k in range(N):
      d[j][k] = min(d[j][k], d[j][i] + d[i][k])

ans = M
for i in range(M):
  tmp = 0
  for j in range(N):
    if d[j][a[i]] + c[i] == d[j][b[i]]:
      tmp = 1
  ans -= tmp
print(ans)

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

int main(int argc, char const *argv[]) {
  int n,k,ans=0,h;

  scanf("%d %d", &n, &k);

  for (int i = 0; i < n; i++) {
    scanf("%d", &h);
    if (h >= k) {
      ans++;
    }
  }

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

Measured memory_bytes: 128
/* ITP1_9_C: Card Game */
/* 20181124 AOJ */

#define _CRT_SECURE_NO_WARNINGS
#define N 101
#include <stdio.h>
#include <string.h>

int main(void) {
	int n;
	char str1[N], str2[N];
	int score1, score2;
	int i;

	score1 = score2 = 0;
	scanf("%d", &n);
	for(i = 0; i < n; i++) {
		scanf("%s %s", str1, str2);
		if(strcmp(str1, str2) > 0) {
			score1 += 3;
		}else if(strcmp(str1, str2) < 0) {
			score2 += 3;
		}else {
			score1 += 1;
			score2 += 1;
		}
	}

	printf("%d %d\n", score1, score2);

	return 0;
}


Measured memory_bytes: 2112
using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;

namespace ABC128
{
    class PP: IComparable<PP>
    {
        public string S;
        public int P;
        public int idx;
        public PP(string s, int p, int id)
        {
            S = s;
            P = p;
            idx = id;
        }
        public int CompareTo(PP p)
        {
            if (S.CompareTo(p.S) < 0)
            {
                return 1;
            }
            else if (S.CompareTo(p.S) == 0)
            {
                if (P > p.P)
                {
                    return 1;
                }
                else if (P == p.P)
                {
                    return 0;
                }
                else
                {
                    return -1;
                }
            }
            else
            {
                return -1;
            }
        }
    }
    class Program
    {
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            PP[] SP = new PP[N];

            for (int i = 0; i < N; i++)
            {
                string[] s = Console.ReadLine().Split(' ');
                SP[i] = new PP(s[0], int.Parse(s[1]), i + 1);
            }

            Array.Sort(SP);
            Array.Reverse(SP);
            
            for (int i = 0; i < N; i++)
            {
                Console.WriteLine(SP[i].idx);
            }
        }
    }
}

Measured memory_bytes: 11476
#include<bits/stdc++.h>
using namespace std;
#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define READ freopen("in.txt","r",stdin)
#define WRITE freopen("out.txt","w",stdout);
#define pb push_back
#define mem(arr,val) memset(arr,val,sizeof(arr))
#define sf(x) scanf("%d",&x)
#define sf2(x,y) scanf("%d %d",&x,&y)
#define sf3(x,y,z) scanf("%d %d %d",&x,&y,&z)
#define sl(x) scanf("%lld",&x)
#define sl2(x,y) scanf("%lld %lld",&x,&y)
#define sl3(x,y,z) scanf("%lld %lld %lld",&x,&y,&z)
#define sd(x) scanf("%lf",&x);
#define pii pair<int,int>
#define pLL pair<long long,long long>
#define ff first
#define sn second
#define PRINT_CASE  printf("Case %d: ",tc++)
#define PRINT_CASENL  printf("Case %d:\n",tc++)
#define mx 100005
#define lnd tree[ind<<1]
#define rnd tree[(ind<<1)+1]
#define cnd tree[ind]
#define lndp b,(b+e)>>1,(ind<<1)
#define rndp ((b+e)>>1)+1,e,(ind<<1)+1
#define IN(a,x,y) (a>=x && a<=y)
typedef long long ll;
typedef long long int lln;
ll INF=1<<28;
//typedef long long lld;
const double pi=acos(-1.0);
int fx[]={1,-1,0,0}; //direction array
int fy[]={0,0,1,-1};
int dir[4][2]={1,0,-1,0,0,-1,0,1};
const long double EPS=1e-7;
//#define INF 10000
ll gcd(ll a,ll b)
{
    if(b==0)
        return a;
    else
        return gcd(b,a%b);
}
ll lcm(ll a,ll b)
{
    return a/gcd(a,b)*b;
}

bool cmp(int a, int b)
{
    return a<b;
}

struct compare
{
  bool operator()(const int& l, const int& r)
  {
      return l>r;
  }
};
ll inf=1e18;
int mod=1e9+7;
ll dp[3010][3010];
int arr[3010];
ll fun(int x,int y)
{
    if(x>y)
        return 0;
    if(dp[x][y]!=-1)
        return dp[x][y];
    ll ans=arr[x]-fun(x+1,y);
    ans=max(ans,arr[y]-fun(x,y-1));
    return dp[x][y]=ans;
}
int main()
{
//    READ;
    mem(dp,-1);
    int n;
    sf(n);
    for(int i=0;i<n;i++)
    {
        sf(arr[i]);
    }
    cout<<fun(0,n-1)<<endl;
    return 0;
}


Measured memory_bytes: 71168
from heapq import heappush, heappop

N, M = map(int, input().split())
salary = [[] for i in range(M+1)]
for i in range(N):
    A, B = map(int, input().split())
    if A <= M:
        salary[A].append(B)
queue = []
ans = 0

for i in range(1, M+1):
    for s in salary[i]:
        heappush(queue, -s)
    if queue:
        ans += -heappop(queue)

print(ans)


Measured memory_bytes: 18432
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<cstring>
#include<math.h>
#include<bitset>
#include<queue>
#include<set>
#include<iomanip>
#include<math.h>
#include<assert.h>
#include<string>
#include<cstdlib>
#include<cctype>
// #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr ll INF = 1LL << 40;
const double INFD = 1e100;
const ll mod = 1000000007;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
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;
}
// ----------------------------------------------------------------------------

int main(){
  ll N,Y;
  cin >> N >> Y;
  for(ll i=0; i<=N; i++){
    for(ll j=0; j<=N; j++){
      if(i+j > N) continue;
      ll sum;
      sum = i*10000+j*5000;
      if((Y-sum) == (N-(i+j))*1000){
        cout << i << " " << j << " " << N-(i+j) << endl;
        return 0;
      }
    }
  }
  cout << "-1 -1 -1" << endl;
  return 0;
}


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

// Shrotening
#define fst first
#define snd second
#define pb push_back

// Loop
#define FOR(i,a,b) for(long i=(a);i<(b);++i)
#define RFOR(i,a,b) for(long i=(a);i>=(b);--i)

#define REP(i,a) for(long i=0;i<(a);++i)
#define RREP(i,a) for(long i=(a);i>=0;--i)

#define EACH(i,a) for(auto (i)=(a).begin(),_END=(a).end();i!=_END;++i)
#define REACH(i,a) for(auto (i)=(a).rbegin(),_END=(a).rend();i!=_END;++i)

//Algorithm
#define ALL(a) (a).begin(), a.end()
#define RALL(a) (a).rbegin(), a.rend()
#define EXIST(a,x) ((a).find(x)!=(a).end())
#define SORT(a) std::sort((a).begin(), (a).end())
#define UNIQUE(a) std::sort((a).begin(), a.end()), a.erase(std::unique((a).begin(), a.end()), a.end());
#define SUM(a) std::accumulate((a).begin(), (a).end(), 0);

//Setting
#define OPT std::cin.tie(0);std::ios::sync_with_stdio(false);

//debug message
bool debug = true;
#define MSG(s)   if(debug){std::cout << s << std::endl;}
#define DEBUG(x) if(debug){std::cout << "debug(" << #x << "): " << x << std::endl;}

//alias
typedef long long LL;
typedef std::vector<char> VC;
typedef std::vector<int>  VI;
typedef std::vector<long> VL;
typedef std::vector<long long> VLL;

typedef std::vector< VC > VC2;
typedef std::vector< VI > VI2;
typedef std::vector< VL > VL2;
typedef std::vector< VLL > VLL2;

typedef std::pair<int,int> PII;

int n;
VI a;
int main() {
    std::cin >> n;
    a.resize(n);
    REP(i, n) {
        std::cin >> a[i];
    }

    LL sumE = 0;
    LL sumO = 0;
    LL even = 0;
    LL odd = 0;
    REP(i, n) {
        sumE += a[i];
        sumO += a[i];

        

        if(i % 2 == 0) {
            if(sumE <= 0) {
                even += std::abs(sumE) + 1;
                sumE = 1;
            }
            if(sumO >= 0) {
                odd += std::abs(sumO) + 1;
                sumO = -1;
            }
        } else{
            if(sumE >= 0) {
                even += std::abs(sumE) + 1;
                sumE = -1;
            }
            if(sumO <= 0) {
                odd += std::abs(sumO) + 1;
                sumO = 1;
            }
        }
    }

    std::cout << std::min(even, odd) << std::endl;
}


Measured memory_bytes: 640
#include<iostream>
using namespace std;
int main() {
	int x, y;
	int d;
	long long cou = 0;
	while (cin >> d){
		cou = 0;
		for (int i = 0; i < 600/d; i++){
			x = i*d;
			y = x*x;
			cou += y*d;
		}
		cout << cou << endl;
	}
}

Measured memory_bytes: 3096
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		long n = in.nextLong();
		long mincost = n;
		for(long i = 1; i<= Math.sqrt(n);i++) {
			if(n%i == 0) {
				long temp = i + n/i - 2;
				mincost = Math.min(mincost, temp);
			}
		}
		System.out.print(mincost);
	}
}


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

// √a + √b < √c  ですか？ 
// a + b + 2√ab < c
// 2√ab < c - a- b
// 4*a*b < (c - a- b)(c - a- b)

int main()
{
	long long a, b, c;
	cin >> a >> b >> c;
	
	if( (4*a*b < (c - a- b)*(c - a- b)) && ((c - a- b) > 0 )) {
		cout << "Yes" << endl;
	} else {
		cout << "No" << endl;
	}
}

Measured memory_bytes: 256
# D - Lamp

#import numpy as np

H, W = map(int, input().split())
#S = np.array([list(input()) for _ in range(H)])
S = [list(input()) for _ in range(H)]

def trans(M):
    output_list = []
    for col in range(len(M[0])):
        tmp = []
        for row in range(len(M)):
            tmp.append(M[row][col])
        output_list.append(tmp)
    return output_list
            
def n_row_lighten(l):
    output_list = []
    left_block_idx = -1
    
    for idx in range(len(l)):
        if l[idx] == "#":
            right_block_idx = idx
            for _ in range(right_block_idx - left_block_idx - 1):
                output_list.append(right_block_idx - left_block_idx - 1)
            output_list.append(0)
            left_block_idx = right_block_idx
            
        if idx == len(l) - 1 and l[idx] == ".":
            right_block_idx = idx + 1
            for _ in range(right_block_idx - left_block_idx - 1):
                output_list.append(right_block_idx - left_block_idx - 1)
        
    return output_list        

def n_matrix_lighten(S):
    output_list = []
    for row in range(len(S)):
        output_list.append(n_row_lighten(S[row]))
    return output_list

#n_lighten = n_matrix_lighten(S) + np.array(n_matrix_lighten(S.T)).T - 1
ans = 0
tmp1 = n_matrix_lighten(S)
tmp2 = trans(n_matrix_lighten(trans(S)))

for row in range(H):
    for col in range(W):
        ans = max(ans, tmp1[row][col] + tmp2[row][col] - 1)

print(ans)

Measured memory_bytes: 311688
#include <algorithm>
#include <bits/stdc++.h>
#include <cstdint>
#include <iostream>
#include <iterator>
#include <vector>

// lib/util.hpp
#ifndef UTIL_HPP
#define UTIL_HPP


typedef std::int_fast64_t i64;
typedef std::uint_fast64_t u64;
typedef std::int_fast32_t i32;
typedef std::uint_fast32_t u32;

namespace tools {
  template <typename T>
  void read(std::vector<T>& vector, const typename std::vector<T>::size_type size) {
    vector.reserve(size);
    std::copy_n(std::istream_iterator<T>(std::cin), size, std::back_inserter(vector));
  }

  template <typename T, std::size_t N>
  void read(std::array<T, N>& array) {
    std::copy_n(std::istream_iterator<T>(std::cin), N, array.begin());
  }
}

#endif

// main.cpp

int main() {
  std::string S;
  std::cin >> S;
  const i64 N = S.size();

  i64 answer = std::numeric_limits<i64>::max();
  {
    i64 diff = 0;
    for (i64 i = 0; i < N; ++i) {
      if (S[i] != (i % 2 == 0 ? '0' : '1')) ++diff;
    }
    answer = std::min(answer, diff);
  }
  {
    i64 diff = 0;
    for (i64 i = 0; i < N; ++i) {
      if (S[i] != (i % 2 == 0 ? '1' : '0')) ++diff;
    }
    answer = std::min(answer, diff);
  }

  std::cout << answer << std::endl;
  return 0;
}

Measured memory_bytes: 512
import java.util.Scanner;


public class Main
{
	public static void main(String[] args)
	{
		Scanner scanner = new Scanner(System.in);
		
		int[] arabia = {1, 5, 10, 50, 100, 500, 1000};
		String[] roma = {"I", "V", "X", "L", "C", "D", "M",};
		
		for(; scanner.hasNext();)
		{
			String str = scanner.next();
			
			int sum = 0;
			int prev = 0;
			for(int i=0; i<str.length(); i++)
			{
				for(int j=0; j<roma.length; j++)
				{
					if(str.substring(i, i+1).equals(roma[j]))
					{
						int add = arabia[j];
						if(prev < add)
						{
							sum -= 2*prev;
						}
						sum += add;
						prev = add;
						break;
					}
				}
			}
			
			System.out.println(sum);
		}
	}
}

Measured memory_bytes: 26140
#include <cstdio>
int n,f[2005][2005],s[2005],k,P=1e9+7,a;
int main()
{
	scanf("%d%d",&n,&k);f[0][n+1]=1;
	for(int i=1;i<=k;i++) for(int j=n+1;j;j--) s[j]=(s[j+1]+f[i-1][j])%P,f[i][j]=(j<=n-i+1?s[j]:0);
	a=(f[k][1]-f[k-1][1]+P)%P;
	for(int i=1;i<=n-k-1;i++) a=(a+a)%P;
	printf("%d\n",a);
}

Measured memory_bytes: 15872
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define mfill(x,y) memset(x,y,sizeof(x))
#define all(v) v.begin(), v.end()
#define in(x,y,h,w) if(0<=x&&x<h&&0<=y&&y<w)
#define y0 y12345
#define y1 y54321

#ifdef LOCAL
#define debug(...) fprintf(stderr,__VA_ARGS__)
#else
#define debug(...) 42
#endif

using ul = unsigned long;
using ll = long long;
using P = pair<int, int>;
using vint = vector<int>;using vvint = vector<vector<int>>;
using vll = vector<ll>;using vvll = vector<vector<ll>>;
template<class T>bool chmax(T &a, const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a, const T &b){if(a>b){a=b;return 1;}return 0;}
template <class T>void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
    v.assign(a, vector<T>(b, t));
}
template <class T>T gcd(T &a, T &b){if(a<b){swap(a,b);} T r = a%b; while(r!=0){a=b;b=r;r=a%b;} return b;}

vint dx = {-1, 0, 1, 0}, dy = {0, -1, 0, 1};
vint dx8 = {-1, -1, -1, 0, 1, 1, 1, 0}, dy8 = {-1, 0, 1, 1, 1, 0, -1, -1};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    debug("debug test\n");
    int n,k;cin>>n>>k;
    int ans = 0;
    while(n > 0){
        ans++;
        n/=k;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
using System;
 
public class Test{
    public static void Main(){
        string[] line = System.Console.ReadLine().Split(' ');
        string[] sub = System.Console.ReadLine().Split(' ');
		//社員数
      	int memNum = int.Parse(line[0]);
      	//部下の人数用配列
      	int[] subNum = new int[memNum];
      	for(int i = 0; i < memNum; i++){
			subNum[i] = 0;
        }
      	for(int i = 0; i < sub.Length; i++){
			subNum[int.Parse(sub[i])-1]++;
        }
      	//表示
      	for(int i = 0; i < memNum; i++){
          System.Console.WriteLine(subNum[i]);
        }
    }
}


Measured memory_bytes: 41820
//------------------------------------------
// C++ templete 
//------------------------------------------
#include <bits/stdc++.h>
using namespace std;

#define endl "\n"

//typedef
//------------------------------------------
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef vector<PII> VP;

//REPEAT
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//container util
//------------------------------------------
#define pb push_back
#define paired make_pair
#define ALL(a) (a).begin(),(a).end()
#define PRINT(V) for (auto v : (V)) cout << v << " "
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())

//constant
//------------------------------------------
const int MOD = 1000000007;
const int INF = 1061109567;
const double EPS = 1e-10;
const double PI  = acos(-1.0);
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

//math
//------------------------------------------
int QP(int a,int b){int ans=1;do{if(b&1)ans=1ll*ans*a%MOD;a=1ll*a*a%MOD;}while(b>>=1);return ans;}
int QP(int a,int b,int MOD){int ans=1;do{if(b&1)ans=1ll*ans*a%MOD;a=1ll*a*a%MOD;}while(b>>=1);return ans;}
int GCD(int a,int b){return b?GCD(b,a%b):a;}

//debug
//------------------------------------------
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

//grobal variable
//------------------------------------------
int N,M;
VI Vec;

int main() 
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
  
    int N; cin >> N;
    
    int k=1;
    while(k <=N)
    {
        k *= 2;
    }

    cout << k/2 << endl; 

    return 0;
}



Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        double x1 = sc.nextDouble();
        double y1 = sc.nextDouble();
        double x2 = sc.nextDouble();
        double y2 = sc.nextDouble();
        x2 -= x1;
        y2 -= y1;
        double x = Math.pow(x2, 2);
        double y = Math.pow(y2, 2);
        double z = Math.sqrt(x + y);
        System.out.println(z);

    }

}


Measured memory_bytes: 27948
#include<bits/stdc++.h>
using namespace std;
int main(){
int N ,x;
cin >> N >> x;
int a[150];
for(int i = 0; i < N; i++)cin >> a[i];

sort(a,a+N);
int count = 0;
for(int i = 0; i < N; i++){
  if(x >= a[i]){
    x-= a[i];
    count ++;
  }
}
if(count == N && x >0)count--;
  cout << count << endl;
}

Measured memory_bytes: 256
H,W,K=map(int,input().split())
c=[list(input()) for _ in range(H)]
ans=0
for h in range(2**H):
    for w in range(2**W):
        tmp=0
        for i in range(H):
            for j in range(W):
                if h>>i&1 and w>>j&1 and c[i][j]=="#":
                    tmp+=1
        if tmp==K:
            ans+=1

print(ans)


Measured memory_bytes: 9088
#include <stdio.h>

int compare_int(const void *a, const void *b)
{
    return *(int*)a - *(int*)b;
}

int main(void)
{
	//変数の宣言
	int n,x;
	int a[110];
	int i;
	int sum=0;
	int ans=0;
	
	//データの読み込み
	scanf("%d %d",&n,&x);
	
	for(i=0;i<n;i++){
		scanf("%d",&a[i]);
	}
	
//	printf("nは%dです\n", n);
//	printf("データの読み込み終了\n");
	//実際の処理
	
	
	qsort(a, n, sizeof(int), compare_int);
	
	for(i=0;i<n;i++){
		sum=sum+a[i];
		if(sum==x){
			ans=i+1;
			break;
		}else if(sum>x){
			ans=i;
			break;
		}
		
	}
	
	
	if(ans==0&&sum<x){
		ans=n-1;
	}
	
	
//	printf("計算部分終了\n");
	
	//出力
	
	printf("%d",ans);
	
//	printf("結果の出力終了\n");
	
	return 0;
}



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

const long long INF = 100000000;

int main() {
  long long n;
  cin >> n;
  vector<long long> flog(n);
  vector<long long> dp(n);
  for(long long i = 0; i < n; ++i) {
    cin >> flog[i];
    dp[i] = INF;
  }
  auto a = [](long long a, long long b){
    if(a<b) return a;
    else return b;
  };

  dp[0] = 0;
  dp[1] = a(dp[1],dp[0] + abs(flog[1] - flog[0]));
  for(long long i = 2; i < n; ++i) {
      dp[i] = a(dp[i - 1] + abs(flog[i - 1] - flog[i]),dp[i - 2] + abs(flog[i - 2] - flog[i]));
  }
  cout << dp[n - 1] << endl;
  return 0;
}

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

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

	if(*board.begin() == *(board.end()-1))
		cout << *board.begin() << endl;		
	else
		cout << 'o' << endl;

	return EXIT_SUCCESS;
}

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

using namespace std;

//#define int long long
#define FOR(i, j, k) for(int i = j; i < k; ++i)
#define rep(i, j) FOR(i, 0, j)
#define INF (1 << 30)
#define fi first
#define se second

typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> Pi;
typedef pair<P, P> PP;

const int MOD = 1e9 + 7;
const int dy[]={0, 0, 1, -1};
const int dx[]={1, -1, 0, 0};

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

int k;
int dist[100000];

int bfs() {
    deque<P> deq;
    deq.push_front(P(1 % k, 1));

    while(!deq.empty()) {
        P p = deq.front(); deq.pop_front();
        if(p.first % k == 0) return p.second;
        if(dist[(p.first * 10) % k] > p.second) {
            dist[(p.first * 10) % k] = p.second;
            deq.push_front(P((p.first * 10) % k, p.second));
        }
        if(dist[(p.first + 1) % k] > p.second + 1) {
            dist[(p.first + 1) % k] = p.second + 1;
            deq.push_back(P((p.first + 1) % k, p.second + 1));
        }
    }
}

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

    cin >> k;
    rep(i, k + 1) dist[i] = INF;
    cout << bfs() << endl;
    return 0;
}

Measured memory_bytes: 1024
package main

import "fmt"

func main() {
	var n, x, m int
	fmt.Scan(&n, &x, &m)

	ans := 0
	ss := make(map[int]int)
	done := make(map[int]int)
	a := x
	ss[1] = a
	done[a] = 1
	ans += a
	for i := 2; i <= n; i++ {
		a = ((a % m) * a) % m
		ss[i] = ss[i-1] + a
		if done[a] > 0 {
			l, r := done[a], i
			s := ss[r-1] - ss[l-1]
			rem := n - r + 1
			sl := r - l
			ans += s * (rem / sl)

			x := rem % sl
			ans += ss[l+x-1] - ss[l-1]
			break
		}
		done[a] = i
		ans += a
	}
	fmt.Println(ans)
}


Measured memory_bytes: 7660
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <functional>
#define vv(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define vvi vector<vector<int> >
#define vvl vector<vector<ll> >
#define vll vector<ll>
typedef long long int ll;
typedef long double ld;
using namespace std;


vector<int> con(int s, int g, int l){
  if(l==1) return std::vector<int> {s, g};
  int x=0, pre=0;
  for(int i=l-1;i>=0;i--){
    if(g>>i!=s>>i) {
      x = i;
      pre = (s>>i)%2;
      break;
    }
  }
  int sd = ((s>>1)&(((1<<(l-x-1)))-1) << x)+(s&((1<<x)-1));
  int gd = ((g>>1)&(((1<<(l-x-1)))-1) << x)+(g&((1<<x)-1));
  int mid = sd + (sd%2==1?-1:1);
  //std::cout << sd << " " << gd << " " << mid << '\n';
  std::vector<int> a = con(sd, mid, l-1);
  std::vector<int> b = con(mid, gd, l-1);
  int prefix =  ((1<<(l-x-1))-1) << x, suffix = (1<<x) - 1;
  for(int i=0;i<a.size();i++) a[i] = ((prefix&a[i]) << 1) + (pre==1?1<<x:0) + (suffix&a[i]);
  for(int i=0;i<b.size();i++) a.push_back(((prefix&b[i]) << 1) + (pre==1?0:1<<x) + (suffix&b[i]));
  return a;
}
int main(int argc, char const *argv[]) {
  int n, a, b; std::cin >> n >> a >> b;
  int c = 0;
  for(int i=0;i<n;i++) if(((1<<i)&a)!=((1<<i)&b)) c++;
  if(c%2==0){
    std::cout << "NO" << '\n';
    return 0;
  }
  std::cout << "YES" << '\n';
  std::vector<int> ans = con(a, b, n);
  for(int i=0;i<ans.size();i++) std::cout << ans[i] << (i==ans.size()-1?"\n":" ");
  return 0;
}


Measured memory_bytes: 1660
import java.util.*;

public class Main {
	double EPS = 10.e-08;
	private void doit(){
		Scanner sc = new Scanner(System.in);
		while(sc.hasNext()){
			int a = sc.nextInt();
			int b = sc.nextInt();
			System.out.println(Math.max(a + b, Math.max(a - b, a * b)));
		}
	}

	private void debug(Object... o) {
		System.out.println("debug = " + Arrays.deepToString(o));
	}

	public static void main(String[] args) {
		new Main().doit();
	}

}


Measured memory_bytes: 22996
#include <stdio.h>
#include <iostream>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <math.h>
#include <algorithm>
using namespace std;
#define ll long long
const double EPS = 1e-10;
const ll MOD = 7+(1e+9);

int main (){
  ll n,k;
  cin>>n>>k;
  ll a,b,c,ans;
  for(ll i=0;i<k;i++){
    cin>>a>>b;
    a=min(a,n-a+1);
    b=min(b,n-b+1);
    c=min(a,b);
    ans=c%3;
    if(ans==0)ans=3;
    cout<<ans<<endl;
  }
}



Measured memory_bytes: 3092
#create date: 2020-07-03 18:05

import sys
stdin = sys.stdin
from collections import Counter

def ns(): return stdin.readline().rstrip()
def ni(): return int(ns())
def na(): return list(map(int, stdin.readline().split()))

def main():
    n = ni()
    l = list()
    for i in range(n):
        s = ns()
        l.append("".join(sorted(s)))
    ans = 0
    for i in Counter(l).values():
        ans += (i * (i-1))//2
    print(ans)

if __name__ == "__main__":
    main()

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

#define rep(i,n) for(int i=0 ; i<(n) ; i++)
#define repr(i,n) for(int i=(n) ; i>=0 ; i--)
#define ALL(x) (x).begin(),(x).end()

using ll = long long;
using ull = unsigned long long;
 
const ll INF = 1LL<<60;
const int MINF = 1e9;
const int MOD = 1e9+7;

using vi = vector<int>;
using vii = vector<vi>;

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

template<typename T>
T GCD(T a,T b){ return b ? GCD(b,a%b) : a ;}
template<typename T>
T LCM(T a,T b){ return a*b / GCD(a,b) ;}

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

    int x;cin >> x;
    int fiveh = x/500;
    x %= 500;
    int five = x/5;
    cout << fiveh * 1000 + five * 5 << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
signed main()
{
  int a[5],b=0,c=0;
  for(int i=0;i<3;i++){
    cin>>a[i];
    if(a[i]==5){
      b++;
    }else if(a[i]==7){
      c++;
    }
  }
  if(b==2 && c==1){
    cout<<"YES\n";
  }else{
    cout<<"NO\n";
   }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define debug  freopen("in.txt","r",stdin),freopen("out.txt","w",stdout);
#define fs first
#define sc second
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int maxn = 1e6+10;
using namespace std;

int N,M;
queue<int> q;
int dis[maxn],in[maxn];
int h[maxn],ne[maxn],e[maxn],idx;
void add(int a,int b){
    e[++idx] = b,ne[idx] = h[a],h[a] = idx;
}

int solve(){
    for(int i = 1;i<=N;i++) if(in[i] == 0) q.push(i);
    while(q.size()){
        int u = q.front();q.pop();
        for(int i = h[u];i;i = ne[i]){
            int v = e[i];
            dis[v] = max(dis[v],dis[u] + 1);
            if(--in[v] == 0){
                q.push(v);
            }
        }
    }
    int ans = 0;
    for(int i = 1;i<=N;i++) ans = max(ans,dis[i]);
    return ans;
}
int main(){
    // debug;
    ios;
    cin>>N>>M;
    for(int i = 1;i<=M;i++){
        int x,y;cin>>x>>y;
        add(x,y);
        in[y]++;
    }
    cout<<solve()<<'\n';

    
    return 0;
}


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

#define N 4
#define LIM 46


int ans[N][N]={
    {1,2,3,4},
    {5,6,7,8},
    {9,10,11,12},
    {13,14,15,0}};

int x[N*N]={3,0,1,2,
            3,0,1,2,
            3,0,1,2,
            3,0,1,2},
    y[N*N]={3,0,0,0,
            0,1,1,1,
            1,2,2,2,
            2,3,3,3};

int min = LIM;



void dfs(int p[N][N], int pr[N][N], int n)
{
    int i, j, i0, j0, d = 0;
    int f = 0;
    int tmp[N][N];

    for( i = 0 ; i < N ; i++)
    {
        for( j = 0 ; j < N ; j++)
        {
            if( ans[i][j] != p[i][j]) f++;
            if( p[i][j] == 0)
            {
                i0 = i;
                j0 = j;
            }
            else
                d += abs( j - x[p[i][j]] ) + abs( i-y[p[i][j]] );

        }
    }

    if( f == 0 )
    {
        if( min > n )
        {
            min = n;
        }
        return;
    }
    if( d + n > min ) return;


    if( i0 > 0 && i0 < N )
    {
        memcpy( tmp, p, sizeof(int) * N * N );
        f = tmp[i0][j0];
        tmp[i0][j0] = tmp[i0-1][j0];
        tmp[i0-1][j0] = f;
        if(memcmp( tmp, pr, sizeof(int)*N*N) != 0 )
            dfs(tmp, p, n+1);
    }
    if(j0 > 0 && j0 < N)
    {
        memcpy(tmp, p, sizeof(int) * N * N );
        f = tmp[i0][j0];
        tmp[i0][j0] = tmp[i0][j0-1];
        tmp[i0][j0-1] = f;
        if(memcmp(tmp, pr, sizeof(int) * N * N ) != 0)
            dfs(tmp, p, n+1);
    }

    if( i0 >= 0 && i0 < N-1)
    {
        memcpy( tmp, p, sizeof(int) * N * N);
        f = tmp[i0][j0];
        tmp[i0][j0] = tmp[i0+1][j0];
        tmp[i0+1][j0] = f;
        if(memcmp(tmp, pr, sizeof(int) * N * N ) != 0 )
            dfs(tmp, p, n+1);
    }
    if( j0 >= 0 && j0 < N-1)
    {
        memcpy( tmp, p, sizeof(int) * N * N );
        f = tmp[i0][j0];
        tmp[i0][j0] = tmp[i0][j0+1];
        tmp[i0][j0+1] = f;
        if(memcmp( tmp, pr, sizeof(int) * N * N ) != 0)
            dfs( tmp, p, n+1 );
    }

}

int main()
{
    int i,j;
    int p[N][N];

    for( i = 0 ; i < N ; i++)
    {
        for( j = 0 ; j < N ; j++)
        {
            scanf("%d", &p[i][j]);
        }
    }
    dfs( p, p, 0);

    printf("%d\n", min);

    return 0;
}



Measured memory_bytes: 2112
n, m, x = map(int, input().split())
c = [0] * n
a = []
for i in range(n):
    inputs = list(map(int, input().split()))
    c[i] = inputs[0]
    a.append(inputs[1:])

ans = 100000 * n + 1

for bit in range(1 << n):
    A = [0] * m
    csum = 0

    for i in range(n):
        if bit & (1 << i):
            for j in range(m):
                A[j] += a[i][j]
            csum += c[i]

    if min(A) >= x:
        ans = min(ans, csum)

print((ans if ans != 100000 * n + 1 else -1))


Measured memory_bytes: 9224