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

//using namespace boost::multiprecision;
using namespace std;
typedef long long ll;
//typedef unsigned long long ll;
const double EPS = 1e-9;
#define rep(i, n) for (int i = 0; i < (n); ++i)
//#define rep(i, n) for (ll i = 0; i < (n); ++i)
//#define sz(x) ll(x.size())
typedef pair<int, int> P;
//typedef pair<ll, int> P;
//typedef pair<ll, ll> P;
//const double INF = 1e10;
const ll INF = LONG_LONG_MAX / 100;
//const ll INF = (1ll << 31) - 1;
//const ll INF = 1e15;
const ll MINF = LONG_LONG_MIN;
//const int INF = INT_MAX / 10;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
//typedef pair<int, int> P;
//typedef pair<double, double> P;
#define ret() return 0;

bool contain(set<char> &s, char a) { return s.find(a) != s.end(); }

//ifstream myfile("C:\\Users\\riku\\Downloads\\0_00.txt");
//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);
const int mod = 1000000007;
//const ll mod = 1e10;
typedef priority_queue<long long, vector<long long>, greater<long long> > PQ_ASK;

class CumulativeSum {
    vector<ll> numbers;
    vector<ll> sums;

public:
    CumulativeSum(int n) {
        numbers.resize(n);
        sums.resize(n);
    }

    void set(int i, ll value) {
        numbers[i] = value;
    }

    ll getSum(int i) {
        if (i == -1) return 0;
        if (i == sums.size()) return 0;
        return sums[i];
    }

    ll getSectionSum(int start, int end) {
        return getSum(end) - getSum(start - 1);
    }

    void calculate() {
        for (int i = 0; i < numbers.size(); i++) {
            sums[i] = getSum(i - 1) + numbers[i];
        }
    }

};


int main() {

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

    ll asum = accumulate(a.begin(), a.end(), 0ll),
            bsum = accumulate(b.begin(), b.end(), 0ll);
    if (bsum > asum) {
        cout << -1 << endl;
        ret();
    }

    vector<ll> d(n);
    rep(i, n) d[i] = a[i] - b[i];
    sort(d.rbegin(), d.rend());

    ll minus = 0;
    ll minus_count = 0;
    rep(i, n) {
        if (d[i] < 0) {
            minus += abs(d[i]);
            minus_count++;
        }
    }

    if (minus_count == 0) {
        cout << 0 << endl;
        ret();
    }

    CumulativeSum cs(n);
    rep(i, n) cs.set(i, d[i]);
    cs.calculate();
    rep(i, n) {
        if (cs.getSum(i) >= minus) {
            cout << i + 1 + minus_count << endl;
            ret();
        }
    }

}

Measured memory_bytes: 4096
import java.util.Arrays

fun main(args: Array<String>) {
    val numbers = (1..100000 step 2)
            .filter { isPrime(it) && isPrime((it + 1) / 2) }

    val q = readLine()!!.toInt()
    for (i in 1..q) {
        val (l, r) = readLine()!!.split(" ").map(String::toInt)
        val count = count(numbers, r) - count(numbers, l - 1)
        println(count)
    }
}

fun isPrime(x: Int): Boolean {
    if (x == 1) return false
    for (k in 2..x) {
        if (k * k > x) {
            break
        }
        if (x % k == 0) {
            return false
        }
    }
    return true
}

fun count(numbers: List<Int>, x: Int): Int {
    val returnValue = numbers.binarySearch(x)
    return if (returnValue >= 0) {
        returnValue + 1
    } else {
        -returnValue - 1
    }
}


Measured memory_bytes: 56460
import sys
import bisect

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

N, M = lr()
MOD = 10 ** 9 + 7
A = lr(); A.sort()
B = lr(); B.sort()
if len(set(A)) != N or len(set(B)) != M or min(A) < M or min(B) < N:
    print(0); exit()

Aset = set(A); Bset = set(B)
total_set = Aset | Bset
answer = 1
for x in total_set:
    if x in Aset and x in Bset:
        continue
    if x in Aset:
        i = bisect.bisect_left(B, x)
        answer *= (M - i)
    else:
        i = bisect.bisect_left(A, x)
        answer *= (N - i)
    answer %= MOD

remain_set = set(range(1, N*M+1)) - total_set
# 残った物を決めていく
for x in remain_set:
    ai = bisect.bisect_left(A, x)
    bi = bisect.bisect_left(B, x)
    y = (N-ai) * (M-bi) - (N*M - x)
    answer *= y
    answer %= MOD
    
print(answer)
#46


Measured memory_bytes: 100572
#include<cstdio>
#include<algorithm>
using namespace std;
int T,k,n,a,b,c,d;
int main(){
    scanf("%d",&T);
    while(T--){
        scanf("%d%d%d%d",&a,&b,&c,&d);n=a+b;
        int l=0,r=n+1,mid,A,B;k=(max(a,b)-1)/(min(a,b)+1)+1;;
        while(l<r){
            mid=(l+r)>>1;
            A=a-mid/(k+1)*k-mid%(k+1);B=b-mid/(k+1);
            if(B<=1ll*A*k)l=mid+1;else r=mid;
        }
        A=a-l/(k+1)*k-l%(k+1);B=b-l/(k+1);r=l+B-A*k+1;
        for(int i=c;i<=min(d,l);i++)putchar(i%(k+1)?'A':'B');
        for(int i=max(c,l+1);i<=d;i++)putchar((i-r)%(k+1)?'B':'A');
        puts("");
    }
    return 0;
}

Measured memory_bytes: 888
#include <iostream>
#include <cmath>
#include <vector>
#include <bitset>
#include <algorithm>
#include <stack>
#include <queue>
#include <map>
#include <climits>
#include <set>
#include <map>
#include <iomanip>
#include <cassert>
#include <functional>
#include <cstring>

using namespace std;

typedef pair<int, int> P;
#define mp make_pair
#define FOR(i, a, b) for(int (i)=a;(i)<(b);++(i))
#define rep(i, n)  FOR(i,0,n)
#define rrep(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define vsort(v) sort((v).begin(), (v).end());
#define rvsort(v) sort(v.begin(), v.end(),greater<int>());
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define all(c) (c).begin(),(c).end()
#define ll long long
#define vi vector<int>
#define vvi vector<vector<int>>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define vs vector<string>
#define vc vector<char>
#define vvc vector<vector<char>>
#define Print(p) cout<<(p)<<endl
#define F first
#define S second
#define pb push_back
#define mod 1000000007LL
#define INF 1050000000

const int maxn = 1e5 + 10;


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

	ll h, w;
	cin >> h >> w;



	rep(i,w+2)cout << '#';
	Print("");
	
	rep(i, h)
	{
		string s; cin >> s;
		cout << '#' << s << '#' << endl;
	}

	rep(i, w + 2)cout << '#';
	Print("");
	return 0;
	
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i = 1; i < (int)(n+1); i++)
const long long INF = 1LL << 60;
int main(){
    string S;
  cin>>S;
    int a=S.size();
    if(a==2){
        cout<<S<<endl;
    }
    else{
        cout<<S[2]<<S[1]<<S[0]<<endl;
    }
}


Measured memory_bytes: 3588
#include <iostream>
#include <vector>
#include <algorithm>
#include <climits>

using namespace std;

int main(void){
    int A, B, C, X, Y;
    int ans;
    
    cin >> A >> B >> C >> X >> Y;
    
    if(A + B <= 2 * C){
        ans = A * X + B * Y;
    }
    else{
        int a, b;
        a = max(X, Y);
        b = min(X, Y);
        
        if(X >= Y){
            ans = min(2 * C * a, 2 * C * b + A * (a - b));
        }
        else{
            ans = min(2 * C * a, 2 * C * b + B * (a - b));
        }
    }
    
    cout << ans << endl;
}

Measured memory_bytes: 256
(let* ((n (read))
       (l1 (loop repeat n
                 collect (read-line)))
       (m (read))
       (l2 (loop repeat m
                 collect (read-line))))

  (format t "~A~%"
          (max 0
               (loop for i in l1
                     maximize (- (count i l1 :test #'string=) (count i l2 :test #'string=))))))


Measured memory_bytes: 24384
#include<iostream>
using namespace std;
 
class Cube {
public:
  int f[6];
  Cube(){}
  void roll_z() {
    roll(1,2,4,3);
  }
  void roll_y() {
    roll(0,2,5,3);
  }
  void roll_x() {
    roll(0,1,5,4);
  }
  void roll(int i,int j,int k,int l) {
    int t = f[i];
    f[i] = f[j];
    f[j] = f[k];
    f[k] = f[l];
    f[l] = t;
  }
};
 
bool eq(Cube c1,Cube c2) {
  for (int i=0; i<6; i++) {
    if (c1.f[i]!=c2.f[i]) {
      return false;
    }
  }
  return true;
}
 
bool equal(Cube c1,Cube c2) {
  for (int i=0; i<6; i++) {
    for (int j=0; j<4; j++) {
      if (eq(c1,c2)) {
        return true;
      }
      c1.roll_z();
    }
    if (i%2==0) {
      c1.roll_y();
    } else {
      c1.roll_x();
    }
  }
  return false;
}
 
int main(void) {
  Cube c1, c2;
  for (int i=0; i<6; i++) {
    cin >> c1.f[i];
  }
  for (int i=0; i<6; i++) {
    cin >> c2.f[i];
  }
  if (equal(c1,c2)) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}

Measured memory_bytes: 3092
#ifndef LOCAL
#pragma GCC optimize ("O3")
#endif
#include <bits/stdc++.h>
using namespace std;
#define sim template < class c
#define ris return * this
#define mor > muu & operator << (
#define R22(r) sim > typename \
  enable_if<1 r sizeof dud<c>(0), muu&>::type operator<<(c g) {
sim > struct rge { c b, e; };
sim > rge<c> range(c h, c n) { return {h, n}; }
sim > auto dud(c* r) -> decltype(cerr << *r);
sim > char dud(...);
struct muu {
#ifdef LOCAL
stringstream a;
~muu() { cerr << a.str() << endl; }
R22(<) a << boolalpha << g; ris; }
R22(==) ris << range(begin(g), end(g)); }
sim, class b mor pair < b, c > r) { ris << "(" << r.first << ", " << r.second << ")"; }
sim mor rge<c> u) {
  a << "[";
  for (c i = u.b; i != u.e; ++i)
    *this << ", " + 2 * (i == u.b) << *i;
  ris << "]";
}
#else
sim mor const c&) { ris; }
#endif
muu & operator()() { ris; }
};
#define imie(r...) "[" #r ": " << (r) << "] "
#define imask(r...) "[" #r ": " << bitset<8 * sizeof(r)>(r) << "] "
#define arr(a, i) "[" #a imie(i) ": " << a[i] << "] "
#define arr2(a, i, j) "[" #a imie(i) imie(j) ": " << a[i][j] << "] "
#define debug (muu() << __FUNCTION__ << "#" << __LINE__ << ": ")

const int N = 3e3 + 7;
char s[N];
char t[N];
int dp[N][N];

int main() {
    scanf("%s", s + 1);
    scanf("%s", t + 1);
    int n = strlen(s + 1);
    int m = strlen(t + 1);
    
    for (int i = 1; i <= n; ++i) {
        for (int j = 1; j <= m; ++j) {
            dp[i][j] = max(dp[i][j - 1], dp[i - 1][j]);
            if (s[i] == t[j]) dp[i][j] = max(dp[i][j], 1 + dp[i - 1][j - 1]);
        }
    }
    
    vector <char> res;
    int i = n;
    int j = m;
    while (dp[i][j] > 0) {
        if (s[i] == t[j] && 1 + dp[i - 1][j - 1] == dp[i][j]) {
            res.push_back(s[i]);
            i--; j--;
        }
        else if (dp[i][j] == dp[i - 1][j]) i--;
        else j--;
    }
    
    reverse(res.begin(), res.end());
    for (char c : res) printf("%c", c);
    printf("\n");
    return 0;
}


Measured memory_bytes: 35456
#include <bits/stdc++.h>
#include <chrono>
#include <math.h>
using namespace std;
using ll = long long;
using ld = long double;
using namespace std::chrono; 
#define fo(i,z,n) for(int i = z;i<n;i++)
#define Fo(i,z,n) for(ll i = z;i<n;i++)
#define INT_BITS 32
#define mod 1000000007
#define vi vector<int>
#define vll vector<ll>
#define vvi vector<vector<int> >
#define vvl vector<vector<ll> > 
#define pb push_back
#define f first
// #define s second
#define int long long
#define float long double
#define all(c) (c).begin(), (c).end()
#define endl '\n'


int lcm(int a,int b){
	int x = a/ __gcd(a,b) *b;
	return x;
}
	


int32_t main()
{
 
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
     cout.tie(0);
   	
     // int t;
     // cin >> t;

     // while(t--){
	 	
 int n;
 cin >> n;
 int arr[n];
 fo(i,0,n)cin >> arr[i];
 int res = 0;
 fo(i,1,n){
 	int x = max(arr[i-1]-arr[i],0ll);
 	arr[i] += x;
 	res += x;
 }
 cout << res << endl;

     // }







return 0;
}




Measured memory_bytes: 5216
n,k=map(int,input().split())
a=[0]+list(map(int,input().split()))
already=[0]*(n+1)
already[1]=1
history=[1]
tmp=1
now=0
jump=1
while jump:
  now+=1
  tmp=a[tmp]
  history.append(tmp)
  if now==k:
    ans=tmp
    break
  elif already[tmp]==1:
    jump=0
    past=history.index(tmp)
    loop=now-past
    ans=history[past+(k-now)%loop]
    break
  else:
    already[tmp]=1

print(ans)

Measured memory_bytes: 32360
#include <bits/stdc++.h>
#ifdef __DEBUG__
    #define DBG(X) cout << #X << " = " << (X) << endl;
    #define SAY(X) cout << (X) << endl;
#else
    #define DBG(X)
    #define SAY(X)
#endif

using namespace std;

using ll = long long int;
using ull = unsigned long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

int dx[]={1, 0, -1, 0, 1,-1, 1,-1};
int dy[]={0, 1, 0, -1, 1, 1,-1,-1};
const int INT_INF = (int)(2e9);
const ll  LL_INF = (ll)(2e18);

inline void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); };
template<typename T, typename S> inline ostream& operator<<(ostream& os, const pair<T, S> p) { cout << "[" << p.first << ";" << p.second << "]"; return os; }
template<typename T, typename S> inline ostream& operator<<(ostream& os, const map<T, S> p) { for (auto el : p) cout << "[" << el.first << ";" << el.second << "]"; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const vector<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const deque<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const set<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline vector<T> fetch_vec(int sz) { vector<T> ret(sz); for (auto& elem : ret) cin >> elem; return ret; }

ll N,Q;
vector<ll> A,B,C;
void input(){
    fast_io();
    cin >> N;
    A = fetch_vec<ll>(N);
    cin >> Q;
    for (int i = 0; i < Q; i++)
    {
        ll b,c; cin >> b >> c;
        B.push_back(b);
        C.push_back(c);
    }
    
}

int solve(){
    map<ll,ll> cnt;
    for(ll a:A) cnt[a]++;
    ll ans = 0;
    ans = accumulate(A.begin(),A.end(),0LL);
    for (int i = 0; i < Q; i++)
    {
        ll b = B[i];
        ll c = C[i];
        ans -= b*cnt[b];
        ans += c*cnt[b];
        cnt[c]+=cnt[b];
        cnt[b]=0LL;
        cout << ans << endl;

    }    
    return 0;
}   

int main()
{
    input();
    solve();
    return 0;
}

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

int n, i, left, size;
char a[1010];

int main()
{
    scanf("%d", &n);
    scanf("%s", &a);
    i = 0;
    while (i < n)
    {
        if (a[i] == '(') size++;
        else
        {
            if (size == 0) left++;
                    else size--;
        }
        i++;
    }
    for (i = 1; i <= left; i++)
        printf("(");
    printf("%s", a);
    for (i = 1; i <= size; i++)
        printf(")");
    return 0;
} 

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define sz(a) int(a.size())
const int N=1e4+10;

int gi() {
	int x=0,o=1;char ch=getchar();
	while((ch<'0'||ch>'9')&&ch!='-') ch=getchar();
	if(ch=='-') o=-1,ch=getchar();
	while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
	return x*o;
}

int n,a[N],pri[N],tt;
bool vis[N];
vi ans;

int main() {
	cin>>n;int g=0;
	for(int i=n;~i;i--) a[i]=gi(),g=__gcd(g,abs(a[i]));
	for(int i=2;i*i<=g;i++)
		if(g%i==0) {
			if(i>=N) ans.pb(i);
			while(g%i==0) g/=i;
		}
	if(g>=N) ans.pb(g);
	for(int i=2;i<N;i++)
		if(!vis[i]) {
			for(int j=i+i;j<N;j+=i) vis[j]=1;
		}
	for(int i=2;i<N;i++) {
		if(vis[i]) continue;
		if(abs(a[0])%i!=0) continue;
		bool fl=1;
		for(int j=0;j<=i-2&&fl;j++) {
			int val=0;
			for(int k=j;k<=n;k+=i-1) val=(val+a[k])%i;
			if(val) fl=0;
		}
		if(fl) ans.pb(i);
	}
	sort(ans.begin(),ans.end());
	for(auto x:ans) cout<<x<<'\n';
	return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii =  pair<int, int>;
using pll =  pair<long long, long long>;
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
constexpr long long INF = 1000000009LL;
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
    string s, t, u; cin >> s;
    for(char c: s) if(c != 'x') t += c;
    u = t; reverse(all(u));

    if(t != u) cout << -1 << ln;
    else{
        vector<int> counter; int cnt = 0;
        rep(i, s.size()){
            if(s[i] != 'x'){
                counter.push_back(cnt);
                cnt = 0;
            }else{
                cnt++;
            }
        }
        counter.push_back(cnt);
        int res = 0;
        rep(i, counter.size()/2){
            res += abs(counter[i] - counter[counter.size()-1-i]);
        }
        cout << res << ln;
    }
}

Measured memory_bytes: 1148
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define PI 3.141592653589793
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;


int main(){
    ll H;
    cin >> H;
    ll count=0;
    ll countinc=0;
    while(floor(H/2)>=1){
        H = floor(H/2);
        countinc++;
    }
    if(countinc!=0){
        for(ll i=0; i<countinc; i++){
            count+=pow(2, i);

        }
    }

    count = count*2 +1;
    cout << count << endl;


}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  long long n;
  cin >> n;
  long long a[n],b[n];
  for(int i=0;i<n;i++){
    cin >> a[i];
    b[a[i]-1]=i+1;
  }
  for(int i=0;i<n;i++){
    cout << b[i] << ((i==n-1)?'\n':' ');
  }
  return 0;
}


Measured memory_bytes: 2432
#include <iostream>
#include <queue>
#include <algorithm>

using namespace std;

int n;
int adja[101][101];
int len[101];

void bfs() {
    queue<int> q;
    q.push(1);
    int d = 0;
    fill(len, &len[101], -1);
    while(!q.empty()) {
        for (int k = 0, size = q.size(); k < size; ++k) {
            int t = q.front();
            q.pop();
            if (len[t] > 0)
                continue;
            len[t] = d;
            for (int i = 1; i <= n; ++i) {
                if (adja[t][i] && len[i] < 0)
                    q.push(i);
            }
        }
        d++;
    }
}

int main() {
    int u, k, v;
    cin >> n;
    for (int i = 0; i < n; ++i) {
        cin >> u >> k;
        while (k--) {
            cin >> v;
            adja[u][v] = 1;
        }
    }
    bfs();
    for (int i = 1; i <= n; ++i) {
        cout << i << " " << len[i] << endl;
    }

    return 0;
}


Measured memory_bytes: 3144
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstring>
#include <string>
#include <math.h>
using namespace std;
typedef long long ll;
typedef double D;
typedef pair<ll,ll> P;
#define M 1000000007
#define F first
#define S second
#define PB push_back
#define INF 100000000000000000
ll n,a[100005],ans;
int main(void){
    cin>>n;
    for(int i=0;i<n;i++)cin>>a[i];
    sort(a,a+n);
    if(n%2==0){
        ll s=0;
        for(int i=0;i<n/2;i++)s-=a[i]*2;
        s+=a[n/2-1];
        for(int i=n/2;i<n;i++)s+=a[i]*2;
        s-=a[n/2];
        cout<<s<<endl;
    }else{
        ll s=0;
        for(int i=0;i<=n/2;i++)s-=a[i]*2;
        s+=a[n/2]+a[n/2-1];
        for(int i=n/2+1;i<n;i++)s+=a[i]*2;
        ans=s;
        s=0;
        for(int i=0;i<n/2;i++)s-=a[i]*2;
        for(int i=n/2;i<n;i++)s+=a[i]*2;
        s-=a[n/2];
        s-=a[n/2+1];
        ans=max(ans,s);
        cout<<ans<<endl;
    }
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
int main(){ 
    int n,k;
    cin>>n>>k;
    int b=1000000002;
    int c=0;
    vector<int> a(n);
    REP(i,n) cin>>a[i];
    sort(a.begin(),a.end());
    for(int i=0;i<n-k+1;i++){
    c=a[i+k-1]-a[i];
    b=min(b,c);
    }
    cout<<b;
    return 0;
}


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

int main() {
    int N;
    cin >> N;
    unordered_map<int, int> mp;
    for (int i = 0; i < N; i++) {
        int a;
        cin >> a;
        mp[a] = i+1;
    }
    for (int i = 0; i < N; i++) {
        cout << mp[i+1] << " ";
    }
    cout << endl;
}


Measured memory_bytes: 4900
def boxes_and_candies(N: int, x: int, A: list) -> int:
    count = 0
    for i in range(1, N):
        a1, a2 = A[i - 1], A[i]
        # print(a1, a2)

        if a1 + a2 <= x:
            # OK
            # print('--> OK')
            continue

        diff = (a1 + a2) - x
        count += diff
        # print('--> {}'.format(diff))

        if a2 > diff:
            A[i] -= diff
        else:
            A[i-1] -= diff - A[i]
            A[i] = 0

    return count


if __name__ == "__main__":
    N, x = map(int, input().split())
    A = [int(s) for s in input().split()]
    ans = boxes_and_candies(N, x, A)
    print(ans)


Measured memory_bytes: 14592
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mp make_pair
#define pb push_back
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)


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


  int n;
  cin >> n;
  string s;
  cin >> s;
  ll ans=0;
  rep(i,n-2){
    if(s[i]=='A'&&s[i+1]=='B' && s[i+2]=='C'){
      ans++;
    }
  }
  cout << ans << endl;

  
  return 0;
    

}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <string>
#include <sstream>
#include <algorithm>
#include <random>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cmath>
#include <cassert>
#include <climits>
#include <bitset>

#define FOR_LT(i, beg, end) for (int i = beg; i < end; i++)
#define FOR_LE(i, beg, end) for (int i = beg; i <= end; i++)
#define FOR_DW(i, beg, end) for (int i = beg; end <= i; i--)

using namespace std;

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

	int n; cin >> n;
	int count = 0;
	int ab_count = 0;
	int b_start = 0;
	int a_end = 0;

	FOR_LT(i, 0, n) {
		string s; cin >> s;
		bool is_b_start = false;
		bool is_a_end = false;

		if (s.front() == 'B') is_b_start = true;
		if (s.back() == 'A') is_a_end = true;


		if (is_b_start) b_start++;
		if (is_a_end) a_end++;
		if (is_b_start && is_a_end) ab_count++;

		FOR_LT(j, 0, s.size() - 1) {
			if (s[j] == 'A' && s[j + 1] == 'B') count++;
		}
	}

	int extra_count = min(a_end, b_start);
	if (a_end != 0 && a_end == b_start && a_end == ab_count) extra_count--;

	cout << (count + extra_count) << endl;

	return 0;
}

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

vector<vector<int>> to;
vector<int> color;

bool is_bipartite(int current, int now_color) {
	color[current] = now_color;
	for(auto&& next : to[current]) {
		if(color[next] == now_color) return false;
		else if(!color[next] && !is_bipartite(next, -now_color)) return false;
	}
	return true;
}

int main()
{
	long long n, m;
	cin >> n >> m;
	to = vector<vector<int>>(n);
	color = vector<int>(n);
	for(int i = 0; i < m; i++) {
		int a, b;
		cin >> a >> b;
		a--;
		b--;
		to[a].push_back(b);
		to[b].push_back(a);
	}
	bool frag = is_bipartite(0, 1);
	long long ans;
	if(frag) {
		long long b = count(color.begin(), color.end(), 1);
		long long w = count(color.begin(), color.end(), -1);
		ans = b * w - m;
	}
	else ans = n * (n - 1) / 2 - m;
	cout << ans << endl;
    return 0;
}


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

int main() {
    int H, N;
    cin >> H >> N;
    vector<int> dp(H + 1, 1e9);
    dp[0] = 0;
    for(int i = 0; i < N; ++i) {
        int a, b;
        cin >> a >> b;
        for(int h = 0; h < H; ++h) {
            int nh = min(h + a, H);
            dp[nh] = min(dp[nh], dp[h] + b);
        }
    }
    cout << dp[H] << '\n';
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
    char s1, s2, s3;
    int sum;
    int ret;

    ret = scanf("%c%c%c", &s1, &s2, &s3);

    sum = s1 + s2 + s3 - ('0' * 3);

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

    return 0;
}

Measured memory_bytes: 128
import math
k = int(input())
ans = 0
for i in range(1, k + 1):
    for j in range(1, k + 1):
        for m in range(1, k + 1):
            if math.gcd(i, j) == 1:
                ans += 1
            else:
                ans += math.gcd(m, math.gcd(i, j))
print(ans)

Measured memory_bytes: 67732
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<set>
#include<queue>
#include<cmath>
#include<map>
#include<stack>
#define ll long long
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
static const int MAXN = 100000;
static const int MAX = 1000000000;

int main(){
    ll N;
    string S;
    cin >> N >> S;
    ll r=0, g=0, b=0;
    rep(i,N){
        if(S[i] == 'R') r++;
        else if(S[i] == 'G')g++;
        else b++;
    }
    ll ans = r*g*b;
    for(int i = 1; i <= (N-1)/2; i++){
        for(int j = 0; j+2*i < N; j++){
            if(S[j] != S[j+i] && S[j+i] != S[j+2*i] && S[j] != S[j+2*i]){
                ans--;
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3192
#include<iostream>
#include<cstdio> //aojでは入力しないと怒られた

int main(){
    int a,b,d,r;
    double f;

    std::cin >> a >>b;
    d=a/b;
    r=a%b;
    f=(double)a/(double)b;

    printf("%d %d %f \n",d,r,f);

    return 0;
}



Measured memory_bytes: 3164
from collections import deque

H, W = [int(_) for _ in input().split()]
S = [input() for _ in range(H)]

move = ((1, 0), (-1, 0), (0, 1), (0, -1))
visited = [[False] * W for _ in range(H)]

def bfs(i, j):
    b, w = 0, 0
    visited[i][j] = True
    que = deque([(i, j)])

    while que:
        ci, cj = que.popleft()
        if S[ci][cj] == '#':
            b += 1
        else:
            w += 1

        for di, dj in move:
            ni, nj = ci + di, cj + dj
            if not (0 <= ni < H and 0 <= nj < W) or visited[ni][nj]:
                continue
            if S[ci][cj] != S[ni][nj]:
                visited[ni][nj] = True
                que.append((ni, nj))

    return b * w


result = 0
for i in range(H):
    for j in range(W):
        if visited[i][j]:
            continue
        result += bfs(i, j)
print(result)


Measured memory_bytes: 4844
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;cin>>n;
   double dp[n+1][n+1]={0};dp[0][0]=1;double prob[n+1];
   for(int i=1;i<=n;i++)cin>>prob[i];
   for(int i=1;i<=n;i++)
   {
       for(int j=0;j<=i;j++)
       {
           int heads=j,tails=i-j;
           if(heads)
           dp[heads][tails]+=dp[heads-1][tails]*prob[i];
           if(tails)
           dp[heads][tails]+=dp[heads][tails-1]*(1-prob[i]);
       }
   }
   int heads=n;int tails=0;double ans=0;
   while(heads>tails)
   {
       ans+=dp[heads][tails];heads--;tails++;
   }
    cout << fixed << setprecision(10) << ans;
}

Measured memory_bytes: 70528
use io::*;

fn main() {
    let input = read_string();
    let mut sc = Scanner::new(&input);
    let n: usize = sc.next();
    let m: usize = sc.next();
    let q: usize = sc.next();
    let mut tab: Vec<Vec<i64>> = vec![vec![0;n+1];n+1];
    for i in 0..m {
        let l: usize = sc.next();
        let r: usize = sc.next();
        tab[l][n] += 1;
        tab[l][r-1] -= 1;
    }
    for i in 0..n {
        tab[n-i-1][n] += tab[n-i][n];
        tab[n][n-i-1] += tab[n][n-i];
    }
    for i in 0..n {
        let x = n - i - 1;
        for j in 0..n {
            let y = n - j - 1;
            tab[x][y] += tab[x+1][y] + tab[x][y+1] - tab[x+1][y+1];
        }
    }
    for i in 0..q {
        let p: usize = sc.next();
        let q: usize = sc.next();
        println!("{}", tab[p][q]);
    }
}

pub mod io {
    use std;
    use std::str::FromStr;

    pub struct Scanner<'a> {
        iter: std::str::SplitWhitespace<'a>,
    }

    impl<'a> Scanner<'a> {
        pub fn new(s: &'a str) -> Scanner<'a> {
            Scanner {
                iter: s.split_whitespace(),
            }
        }

        pub fn next<T: FromStr>(&mut self) -> T {
            let s = self.iter.next().unwrap();
            if let Ok(v) = s.parse::<T>() {
                v
            } else {
                panic!("Parse error")
            }
        }

        pub fn next_vec_len<T: FromStr>(&mut self) -> Vec<T> {
            let n: usize = self.next();
            self.next_vec(n)
        }

        pub fn next_vec<T: FromStr>(&mut self, n: usize) -> Vec<T> {
            (0..n).map(|_| self.next()).collect()
        }

        pub fn next_mat<T: FromStr>(&mut self, w: usize, h: usize) -> Vec<Vec<T>> {
            (0..h).map(|_| self.next_vec(w)).collect()
        }

        pub fn next_vec_char(&mut self) -> Vec<char> {
            self.next::<String>().chars().collect()
        }

        pub fn next_mat_char(&mut self, n: usize) -> Vec<Vec<char>> {
            (0..n).map(|_| self.next_vec_char()).collect()
        }
    }

    pub fn read_string() -> String {
        use std::io::Read;

        let mut s = String::new();
        std::io::stdin().read_to_string(&mut s).unwrap();
        s
    }

    pub fn read_line() -> String {
        let mut s = String::new();
        std::io::stdin().read_line(&mut s).unwrap();
        s.trim_right().to_owned()
    }
}


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

using Int = long long;
const char newl = '\n';

template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
template<typename T> void drop(const T &x){cout<<x<<endl;exit(0);}
template<typename T=int>
vector<T> read(size_t n){
  vector<T> ts(n);
  for(size_t i=0;i<n;i++) cin>>ts[i];
  return ts;
}


template<typename TV, const int N> void read_tuple_impl(TV&) {}
template<typename TV, const int N, typename Head, typename... Tail>
void read_tuple_impl(TV& ts) {
  get<N>(ts).emplace_back(*(istream_iterator<Head>(cin)));
  read_tuple_impl<TV, N+1, Tail...>(ts);
}
template<typename... Ts> decltype(auto) read_tuple(size_t n) {
  tuple<vector<Ts>...> ts;
  for(size_t i=0;i<n;i++) read_tuple_impl<decltype(ts), 0, Ts...>(ts);
  return ts;
}

//INSERT ABOVE HERE
signed main(){
  cin.tie(0);
  ios::sync_with_stdio(0);

  int h,w,m;
  cin>>h>>w>>m;
  auto [ys,xs]=read_tuple<int, int>(m);

  using P = pair<int, int>;
  set<P> sp;
  for(int i=0;i<m;i++) sp.emplace(ys[i],xs[i]);

  map<int, int> cy,cx;
  for(int y:ys) cy[y]++;
  for(int x:xs) cx[x]++;

  int my=0,mx=0;
  for(auto [y,c]:cy) chmax(my,c);
  for(auto [x,d]:cx) chmax(mx,d);

  auto filter=[&](auto mp,int target){
    vector<int> vs;
    for(auto [key,val]:mp)
      if(val==target)
        vs.emplace_back(key);
    return vs;
  };

  auto yy=filter(cy,my);
  auto xx=filter(cx,mx);
  for(auto y:yy)
    for(auto x:xx)
      if(!sp.count(P(y,x)))
        drop(my+mx);

  cout<<my+mx-1<<newl;
  return 0;
}


Measured memory_bytes: 66028
data = [list(map(int,input().split())) for _ in range(3)]

N = int(input())
for _ in range(N):
    bn = int(input())
    for i in range(3):
        for j in range(3):
            if bn == data[i][j]:
                data[i][j] = 0
ans = "No"
for i in range(3):
    if data[i][0] == data[i][1] == data[i][2] == 0:ans = "Yes"
    if data[0][i] == data[1][i] == data[2][i] == 0:ans = "Yes"
if data[0][0] == data[1][1] == data[2][2]==0:ans ="Yes"
if data[0][2] == data[1][1] == data[2][0] == 0 :ans="Yes"
print(ans)

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

using namespace std;

const int md = int(1e9) + 7;

inline void add(int &a, int b) {
  a += b;
  if (a >= md) a -= md;
}

inline void sub(int &a, int b) {
  a -= b;
  if (a < 0) a += md;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  
  string k;
  int d;
  cin >> k >> d;

  vector< vector<int> > dp(d, vector<int>(2));
  dp[0][0] = 1;
  for (int i = 0; i < (int) k.length(); i++) {
    vector< vector<int> > new_dp(d, vector<int>(2));
    for (int j = 0; j < d; j++) {
      for (auto any : {false, true}) {
        for (int dig = 0; dig < 10; dig++) {
          if (!any && dig > k[i] - '0') {
            break;
          }
          add(new_dp[(j + dig) % d][any || dig < k[i] - '0'], dp[j][any]);
        }
      }
    }
    swap(dp, new_dp);
  }
  int ans = (dp[0][false] + dp[0][true]) % md;
  sub(ans, 1);
  cout << ans << '\n';
  return 0;
}

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

fn main() {
    let mut buf = String::new();
    let handle = std::io::stdin();

    let info: Vec<usize> = {
        handle.read_line(&mut buf).unwrap();
        let tmp = buf.trim().split_whitespace().map(|a| a.parse().unwrap()).collect();
        buf.clear();
        tmp
    };
    let n = info[0];
    let w = info[1];
    let mut memo = vec![w+1; n * 1000 + 1];
    memo[0] = 0;
    for i in 0..n {
        handle.read_line(&mut buf).unwrap();
        let i: Vec<usize> = buf.trim().split_whitespace().map(|a| a.parse().unwrap()).collect();
        for mut j in 0..n*1000+1 {
            j = n*1000+1 - j - 1; 
            if memo[j] + i[0] > w {
                continue;
            } else {
                memo[j + i[1]] = min(memo[j] + i[0], memo[j +i[1]]);
            }
        }
        buf.clear();
    }
    println!("{}", memo.into_iter().enumerate().filter(|&(a, b)| b <= w).max().unwrap().0);
}


Measured memory_bytes: 4352
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;
int main()
{
    char s[100100];
    while(~scanf("%s",s))
    {
        int a[30]={0};
        int len = strlen(s);
        for(int i=0;i<len;++i)
        {
            a[s[i]-'a']++;
        }
        int flag = 0;
        for(int i=0;i<26;++i)
        {
            if(a[i] == 0)
            {
                printf("%c\n",i+'a');
                flag = 1;
                break;
            }
        }
        if(flag == 0)
            printf("None\n");
    }
}

Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>

using namespace std;

int main()
{
	long long M[2], D[2], count = 0;
	cin >> M[0] >> D[0];
	cin >> M[1] >> D[1];

	if (M[1] != M[0] && D[1] == 1)
		count = 1;

	cout << count << endl;
}

Measured memory_bytes: 256
//
//AtCoder Beginner Contest 130
//C - Rectangle Cutting
//

#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <ctime>
#include <queue>
#include <map>
#include <set>
#include <tuple>
#include <functional>
#include <cassert>

using namespace std;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define SIZE(x) (int)(x).size()
#define SIZEL(x) (ll)(x).size()
#define MSG(a) cout << #a << " " << a << endl;

using ll = long long;
using ld = long double;

const double PI = 3.14159265358979323846;

ll gcd(ll x, ll y) { return (x % y)? gcd(y, x % y): y; }    //最大公約数
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }            //最小公倍数

int main()
{
    ll w,h,x,y;
    cin >> w >> h >> x >> y;

    int flag = 0;
    if (2*x==w && 2*y==h) flag = 1;
    cout << fixed;
    cout << setprecision(12) << ld(w)*ld(h)/2.0 << " " << flag << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define irep(i, n) for (int i = (n); i >= 0; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = 1 << 25;
const int MOD = 1e9+7;
 
int main() {
	string s,t;
	cin >> s >> t;
	int ls = s.size(), lt = t.size();
	if (ls < lt) {
		cout << "UNRESTORABLE" << endl;
		return 0;
	}

	vector<string> ans;
	for (int i = 0; i <= ls-lt; i++)
	{
		bool ok = true;
		for (int j = 0; j < lt; j++)
		{
			if (s[i+j] !='?' && s[i+j] != t[j]) ok = false;
		}
		if (ok) {
			string now = "";
			rep(k,i) {
				if (s[k]=='?') now+='a';
				else now += s[k];
			}
			now += t;
			for (int k = i+lt; k < ls; k++)
			{
				if (s[k]=='?') now+='a';
				else now+=s[k];
			}
			ans.push_back(now);
		}
	}
	if (ans.empty()) {
		cout << "UNRESTORABLE" << endl;
		return 0;
	}
	sort(ans.begin(), ans.end());
	cout << ans[0] << endl;
	
	return 0;
}

Measured memory_bytes: 3640
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int a = in.nextInt();
		int b = in.nextInt();

		if ( (a + b) % 2 == 1 ) {
			System.out.println("IMPOSSIBLE");
		} else {
			System.out.println((a + b) / 2);
		}

		in.close();
	}
}

Measured memory_bytes: 21584
import sys
import math
A,B = map(int,input().split(" "))

curr1 , curr2 = int(math.ceil(A/0.08)), int(math.floor(B/0.1))
low , high = min(curr1,curr2), max(curr1,curr2)

while low <= high:
    c1 ,c2= int(low*0.08), int(low*0.1)
    if c1 == A and c2 == B:
        print(low)
        sys.exit(0)
    low+=1
print(-1)

Measured memory_bytes: 3064
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <utility>
#include <cmath>
#include <climits>

#define ll long long int
#define pb push_back
#define mk make_pair
#define pq priority_queue

using namespace std;
typedef pair<int, int> P;
typedef pair<ll, int> Pl;
typedef pair<ll, ll> Pll;
const int inf = 1e9;
const ll linf = 1LL << 50;
const double EPS = 1e-10;

int main(int argc, char const* argv[])
{
  int k, t;
  cin >> k >> t;
  int maxi = 0;
  for(int i = 0; i < t; i++){
    int x;
    cin >> x;
    maxi = max(maxi, x);
  }
  if(maxi <= (k + 1) / 2)cout << 0 << endl;
  else {
    int rem = maxi - (k + 1) / 2;
    if(k % 2 == 0)cout << rem * 2 - 1 << endl;
    else cout << rem * 2 << endl;
  }
	return 0;
}


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

using namespace std;
using vi = vector<int>;

void ins() {}
template<class T,class... Rest>void ins(T& v,Rest&... rest){cin>>v;ins(rest...);}

#define rep(i,n) for(int i=0,_i=(n);i<_i;++i)

constexpr int INF = 1e9;
using Edge = vector<map<int, long long>>;


long long dfs(int s, int t, vi& level, Edge& cap, Edge& residual, long long flow = INF) {
  if (flow <= 0) return 0;
  if (s == t) return flow;
  long long total = 0;
  for (const auto& e:cap[s]) {
    int to = e.first; long long cost = e.second;
    if (level[to] != level[s] + 1)
      continue;
    long long f = dfs(to, t, level, cap, residual, min(cost, flow));
    flow -= f;
    total += f;
    cap[s][to] -= f;
    residual[to][s] += f;
  }
  for (const auto& e:residual[s]) {
    int from = e.first; long long cost = e.second;
    if (level[from] != level[s] + 1)
      continue;
    long long f = dfs(from, t, level, cap, residual, min(cost, flow));
    flow -= f;
    total += f;
    residual[s][from] -= f;
    cap[from][s] += f;
  }
  return total;
}

struct Graph {
  vector<map<int, long long>> edge;
  int N;
  Graph(int n = 0) : N(n) { resize(n); }
  void resize(int n) {
    N = n;
    edge.resize(n, map<int, long long>());
  }
  void addEdge(int from, int to, long long weight, bool directed = false) {
    edge[from][to] = weight;
    if (!directed)
      edge[to][from] = weight;
  }
  map<int, long long>& operator[](int from) { return edge[from]; }

  long long max_flow(int s, int t) {
    Edge cap(edge), residual(N);
    rep(from, N) {
      for (const auto& edge:cap[from]) {
        residual[edge.first][from] = 0;
      }
    }
    while (true) {
      vi level(N, INF); level[s] = 0;
      queue<int> q; q.push(s);
      while (!q.empty()) {
        int from = q.front(); q.pop();
        for (auto& e:cap[from]) {
          int to = e.first;
          long long cost = e.second;
          if (cost == 0 || level[to] != INF)
            continue;
          level[to] = level[from] + 1;
          q.push(to);
        }
        for (auto& e:residual[from]) {
          int to = e.first;
          long long cost = e.second;
          if (cost == 0 || level[to] != INF)
            continue;
          level[to] = level[from] + 1;
          q.push(to);
        }
      }
      if (level[t] == INF)
        break;
      dfs(s, t, level, cap, residual);
    }
    long long ans = 0;
    for (const auto& e:residual[t]) {
      ans += e.second;
    }
    return ans;
  }
};

int main() {
  int V, E;
  ins(V, E);

  Graph G(V);
  rep(i, E) {
    int a, b, w;
    ins(a, b, w);
    G.addEdge(a, b, w, true);
  }
  cout << G.max_flow(0, V-1) << endl;

  return 0;
}



Measured memory_bytes: 3304
#include <bits/stdc++.h>
#define reg register

using namespace std;

typedef long long ll;
const int maxn = 100005;

inline ll read() {
    reg ll s = 0, t = 0; reg char ch = getchar();
    while (!isdigit(ch)) t |= ch == '-', ch = getchar();
    while (isdigit(ch)) s = (s << 1) + (s << 3) + (ch ^ 48), ch = getchar();
    return t ? -s : s;
}

int n, d, tmp;
int a[12][12];

inline void check(int x, int y, int ans, int tot) {
    if (tot > d) {
        int res = sqrt(ans);
        if (res * res == ans) tmp++;
        return;
    }
    ans = ans + (a[x][tot] - a[y][tot]) * (a[x][tot] - a[y][tot]);
    check(x, y, ans, tot + 1);
}

int main() {
    n = read(), d = read();
    for (int i = 1; i <= n; i++)
        for (int j = 1; j <= d; j++) a[i][j] = read();
    for (int i = 1; i <= n; i++)
        for (int j = i + 1; j <= n; j++)
            check(i, j, 0, 1);
    cout << tmp << endl;
    return 0;
}


Measured memory_bytes: 256
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N, *A = map(int, read().split())

    m = A[0]
    ans = 0
    for a in A[1:]:
        if a < m:
            ans += m - a
        if m < a:
            m = a

    print(ans)
    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 99076
N = gets.to_i
A = gets.chomp.split(" ").map(&:to_i)

m, b, t = 1000, 0, true
(0..(N-2)).each{|i|
  if A[i] < A[i+1] && t then
    b += m/A[i]
    m = m % A[i]
    t = false
  elsif A[i] > A[i+1] && !t then
    m += b * A[i]
    b = 0
    t = true
  end
}

puts m + b*A[N-1]


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

#define loop(i,N) for(ll (i)=0; (i)<(N);++(i))
#define OMAZINAI cin.tie(0); ios::sync_with_stdio(false);
#define INF (1LL<<61)
typedef long long int ll;

int main() {
	int a, b, c;
	cin >> a >> b >> c;
	std::cout << std::max(a, std::max(b, c)) - std::min(a, std::min(b, c)) << std::endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<iomanip>
using namespace std;

int main(){
    string s;
    cin>>s;
    bool flag=true;
    for(int i=0;i<s.size();i++){
        if(i%2==0){
            if(s[i]=='L')flag=false;
        }else{
            if(s[i]=='R')flag=false;
        }
    }
    if(flag)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 3600
#!/usr/bin/env python
import sys
from io import StringIO

def guess(rl=sys.stdin.readline):
    n, m = [int(x) for x in rl().split(' ')]

    digits = [-1 for x in range(n)]
    for i in range(m):
        s, c = [int(x) for x in rl().split(' ')]
        if digits[s-1] >= 0 and digits[s-1] != c:
            return -1
        else:
            digits[s-1] = c

    if n == 1 and digits[0] < 0:
        return 0
    if n > 1 and digits[0] == 0:
        return -1

    for i in range(len(digits)):
        if digits[i] < 0:
            if i == 0:
                digits[i] = 1
            else:
                digits[i] = 0

    ans = 0
    for d in digits:
        ans = ans*10 + d
    return ans

print(guess())


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
    int n,k,num=0;
    cin>>n>>k;
    for(int i=1;i<=n;i++){
        int x;
        cin>>x;
        if(x>=k) num++;
    }
    cout<<num<<endl;
    
}  

Measured memory_bytes: 384
#include "bits/stdc++.h"
using namespace std;

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

	int N = 0;
	cin >> N;

	vector<int> A(N), B(N), C(N - 1);

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

	int manzoku = 0;
	for (int i = 0; i < N; i++)
	{
		manzoku += B[A[i] - 1];
		if (i < N - 1)
			if ((A[i + 1] - A[i]) == 1)
			{
				manzoku += C[A[i]-1];
			}
	}

	cout << manzoku;
	return 0;
}

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

int main(){
  int n;
  cin>>n;
  vector<int> a(n);
  int S;
  rep(i,n){
    cin>>a[i];
    if(i==0)S=a[i];
    else S=S^a[i];
  }
  rep(i,n){
    int ans=S^a[i];
    cout<<ans<<endl;
  }
}

Measured memory_bytes: 4056
N, M = map(int, input().split())

ac = [False] * N
wa = [0] * N
for _ in range(M):
   p, S = input().split()
   p = int(p) - 1
   if (S == 'AC'):
      ac[p] = True
   else:
      if not ac[p]:
         wa[p] += 1

a = 0
b = 0
for i in range(N):
   if ac[i]:
      a += 1
      b += wa[i]
print(*[a, b])


Measured memory_bytes: 4596
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <math.h>
#include <iomanip>

using namespace std;


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

    vector<int> x_(N);
    vector<int> y_(N);

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


    vector<int> towns(N);
    iota(towns.begin(), towns.end(), 0);


    vector<vector<int>> townsOrder {};
    do {
        townsOrder.push_back(towns);
    } while (next_permutation(towns.begin(), towns.end()));

    double townsOrderCount = static_cast<double>(townsOrder.size());
    double distance = 0.0;
    for (vector<int> order: townsOrder) {

        for (int i { 1 }; i < order.size(); ++i) {
            int prev { order[i - 1] };
            int prev_x = x_[prev];
            int prev_y = y_[prev];

            int current { order[i] };
            int current_x = x_[current];
            int current_y = y_[current];

            double diff_x = static_cast<double>(current_x - prev_x);
            double diff_y = static_cast<double>(current_y - prev_y);

            distance += sqrt(diff_x * diff_x + diff_y * diff_y);
        }
    }

    cout << setprecision(11) << (distance / townsOrderCount) << endl;

    return 0;
}


Measured memory_bytes: 4016