akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<vector>
using namespace std;
#define int long long int
void dfs(int src,vector<int> adj[],int p,bool isleaf[])
{
	int count=0;
	for(int x:adj[src])
	{
		if(x!=p)
		{
			dfs(x,adj,src,isleaf);
			count++;
		}
	}
	if(count==0)
	{
		isleaf[src]=true;
	}
}
void dfs(int src,vector<int> adj[],int p,int in[],bool isleaf[],int m)
{
	if(isleaf[src])
	{
		in[src]=1;
		return ;
	}
	else
	{
		for(int x:adj[src])
		{
			if(x!=p)
			{
				dfs(x,adj,src,in,isleaf,m);
			}
		}
		for(int x:adj[src])
		{
			if(x!=p)
			{
				in[src]*=(in[x]+1);
				in[src]%=m;
			}
		}
	}
}
void dfs(int src,vector<int> adj[],int p,int prev,int in[],int out[],bool isleaf[],int m)
{
	out[src]*=(prev+1);
	out[src]%=m;
	int next=prev+1;  // prev is for black only
	next%=m;
	if(isleaf[src])
	  return ;
	vector<int> vec;
	for(int x:adj[src])
	{
		if(x!=p)
		{
			vec.push_back(x);
		}
		
	}
	int n=vec.size();
	int prefix[n],suffix[n];
	prefix[0]=in[vec[0]]+1;
	int j;
	for(j=1;j<n;j++)
	{
		prefix[j]=prefix[j-1]*(in[vec[j]]+1);
		prefix[j]%=m;
	}
	suffix[n-1]=(in[vec[n-1]]+1);
	for(j=n-2;j>=0;j--)
	{
		suffix[j]=suffix[j+1]*(in[vec[j]]+1);
		suffix[j]%=m;
	}
	for(j=0;j<n;j++)
	{
		int here=1;
		if(j>=1)
		{
			here*=prefix[j-1];
		}
		if(j+1<n)
		{
			here*=suffix[j+1];
		}
		here%=m;
		int final=here*next;
		int x=vec[j];
		dfs(x,adj,src,final,in,out,isleaf,m);
	}
}
int32_t main()
{
	int n;
	cin>>n;
	int m;
	cin>>m;
	vector<int> adj[n+2];
	int j;
	for(j=1;j<n;j++)
	{
		int u,v;
		cin>>u>>v;
		adj[u].push_back(v);
		adj[v].push_back(u);
	}
	bool isleaf[n+2]={false};
	dfs(1,adj,-1,isleaf);
	int in[n+2],out[n+2];
	for(j=0;j<=n+1;j++)
	{
		in[j]=1;
		out[j]=1;
	}
	dfs(1,adj,-1,in,isleaf,m);
	dfs(1,adj,-1,0,in,out,isleaf,m);
	int answer[n+2];
	for(j=1;j<=n;j++)
	{
		answer[j]=in[j]*out[j];
		answer[j]%=m;
	}
	for(j=1;j<=n;j++)
	{
		cout<<answer[j]<<endl;
	}
	cout<<endl;
}


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

using namespace std;

int main (void) {
    int N;
    cin >> N;
    long long sum = 0;
    vector<long long> a(N);
    for ( int i=0; i<N; i++ ) {
        cin >> a.at(i);
        sum += a.at(i);
    }

    long long ans = LLONG_MAX;
    long long sunuke = 0;
    long long rascal;

    for ( int i=0; i<N-1; i++ ) {
        sunuke += a.at(i);
        rascal = sum - sunuke;
        ans = min(ans, abs(sunuke - rascal));
    }

    cout << ans << endl;
    return 0;
}


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

using ll = long long;
using pii  = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

const long long mod = 1000000007;
// auto mod int
struct mint {
    ll x; // typedef long long ll;
    mint(ll x=0):x((x%mod+mod)%mod){}
    mint operator-() const { return mint(-x);}
    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod-a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
    mint operator+(const mint a) const { return mint(*this) += a;}
    mint operator-(const mint a) const { return mint(*this) -= a;}
    mint operator*(const mint a) const { return mint(*this) *= a;}
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }

    // for prime mod
    mint inv() const { return pow(mod-2);}
    mint& operator/=(const mint a) { return *this *= a.inv();}
    mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, mint& a) { return is >> a.x; }
ostream& operator<<(ostream& os, const mint& a) { return os << a.x; }


int main(){
    int n, k;
    cin >> n >> k;
    vi a(n);
    rep(i, n) cin >> a[i];
    int p = 0, q = 0;
    rep(i, n) for (int j=i+1; j<n; ++j) {
        if (a[i] > a[j]) ++p;
    }
    rep(i, n) rep(j, n) {
        if (i == j) continue;
        if (a[j] > a[i]) ++q;
    }
    mint ans = (mint)p * k + (mint)q * k * (k-1) / 2;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3600
#include <bits/stdc++.h>
#include <array>
#define FOR(i,a,b) for(int i=(a);i<=(b);++i) 
#define RFOR(i,a,b) for(int i=(a);i>=(b);--i) 
#define REP(i,n) for(int i=0;i<(n);++i)
#define RREP(i,n) for(int i=(n);i>0;--i)
#define CI cin>> 
#define CO cout<<
#define EN <<endl 
#define all(x) (x).begin(),(x).end() 
using namespace std;
template <typename T> istream & operator >> (istream & is, vector<T> & vec) { for (T& x : vec) is >> x; 	return is; }
using ll = long long;
using VI = vector<int>;
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }


int main() {
	int a, b; CI a >> b;
	if (a < 6)CO 0 EN;
	else if (a >= 6 && a < 13)CO b / 2 EN;
	else CO b EN;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <stdio.h>
using namespace std;

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

    vector<int> li;
    li.push_back(a[0]);
    for (int i = 1; i < n; i++) {
        if (a[i] <= li[li.size()-1]) {
            li.push_back(a[i]);
        } else {
            for (int j = 0; j < li.size(); j++) {
                if (li[j] < a[i]) {
                    li[j] = a[i];
                    break;
                }
            }
        }
    }
    printf("%d\n", li.size());
}

Measured memory_bytes: 1276
#include <cstdio>
#include <random>
#include <cassert>
#include <algorithm>    
#include <iostream>
#include <chrono>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <iomanip>
#include <cstring>
#include <cmath>
#include <bitset>
#define pb push_back
#define mk make_pair
#define eb emplace_back
#define eps 1e-8
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
// #define int long long


using namespace std;
typedef long double ld;
typedef unsigned int ui;
typedef pair<int,int> pii;
typedef tuple<int, int, int> tiii;
typedef vector<int> vii;
typedef vector<long double> vd;
const int inf = 1e9;
const long long INF = 1e18;
const int M = 1e9 + 7;





signed main()
{
#ifndef ONLINE_JUDGE
    // freopen("in.txt", "r", stdin);
    // freopen("out.txt", "w", stdout);
#endif
    int x, k;
    cin >> k >> x;
    const int maxn = 1e5;
    for(int i = max(-maxn, x - k + 1); i <= min(maxn, x + k - 1); ++i) {
        cout << i << ' ';
    }




    
    return 0;
}

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


public class Program
{	
    public static void Main()
	{
	    char[] c = Console.ReadLine().ToCharArray();
	    int cnt = 0;
	    for(int i = 0 ; i < c.Length ; i++)
	    {
	        if(c[i] == '2')
	        {
	            cnt++;
	        }
	    }
	    Console.WriteLine(cnt);
	}

}

Measured memory_bytes: 13140
//#undef DEBUG
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Runtime.InteropServices;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using static System.Math;
using MethodImplAttribute = System.Runtime.CompilerServices.MethodImplAttribute;
using MethodImplOptions = System.Runtime.CompilerServices.MethodImplOptions;

public static class P
{
    public static void Main()
    {
        ulong n = ulong.Parse(Console.ReadLine()) - 1;
        ulong valid = 0;
        ulong invalid = (ulong)1e18;
        while (invalid - valid > 1)
        {
            var mid = (valid + invalid) / 2;
            if (GetLengthUntil(mid) <= n) valid = mid;
            else invalid = mid;
        }
        var curInd = GetLengthUntil(valid);
        string s = "";
        for (ulong i = valid + 1; i < valid + 20; i++)
        {
            if (i % 3 == 0) s += "Fizz";
            if (i % 5 == 0) s += "Buzz";
            if (i % 3 != 0 && i % 5 != 0) s += i;
        }
        Console.WriteLine(s.Substring((int)(n - curInd), 20));
    }
    static ulong GetLengthUntil(ulong n)
    {
        ulong res = 0;
        for (ulong Base = 1, digit = 1; Base <= n; Base *= 10, digit++)
        {
            var lowerBound = Base - 1;
            var upperBound = Min(Base * 10 - 1, n);
            var fizzBuzzCount = upperBound / 15 - lowerBound / 15;
            var fizzCount = upperBound / 3 - lowerBound / 3 - fizzBuzzCount;
            var buzzCount = upperBound / 5 - lowerBound / 5 - fizzBuzzCount;
            var numCount = upperBound - lowerBound - (fizzBuzzCount + fizzCount + buzzCount);
            res += numCount * digit + fizzCount * 4 + buzzCount * 4 + fizzBuzzCount * 8;
        }
        return res;
    }
}



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

int main() {
  int a, b, c;
  cin >> a >> b >> c;
  int is_poor = 0;
  if (a == b && b != c) {
    is_poor = 1;
  } else if (b == c && c != a) {
    is_poor = 1;
  } else if (c == a && a != b) {
    is_poor = 1;
  }
  if (is_poor == 1) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#pragma region RegionDefs
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#include "boost/multi_array.hpp"
#define rep(i,n) for(int i=0,i##_len=(n);i<i##_len;++i)
#define reps(i,j,n) for(int i=(j),i##_len=(n);i<i##_len;++i)
#define repr(i,n) for(int i=(n);i>=0;--i)
#define all(x) (x).begin(),(x).end()
using namespace std;
template<class T=int> using P  = pair<T, T>;
template<class T=int> using V  = vector<T>;
template<class T=int> using PQ = priority_queue<T>;
template<class T=int> using PQG = priority_queue<T, V<T>, greater<T>>;
typedef long long ll;
const int INF = 1e9;
const ll MOD = 1000000007LL;
void in() {}
template<class Head, class... Tail>
void in(Head&& head, Tail&&... tail)
{
    cin >> head;
    in(move(tail)...);
}
#define IN(...) int __VA_ARGS__; in(__VA_ARGS__)
#define VIN(T, v, n) V<T> v(n); for(auto& _elem:v)cin>>_elem
struct UnionFind
{
    V<int> par;
    V<int> siz;
    UnionFind(int n) : par(n), siz(n, 1)
    {
        rep(i, n) par[i] = i;
    }
    int root(int x)
    {
        while (par[x] != x) x = par[x] = par[par[x]];
        return x;
    }
    bool unite(int x, int y)
    {
        int rx = root(x);
        int ry = root(y);
        if (rx == ry) false;
        if (siz[rx] < siz[ry]) swap(rx, ry);
        siz[rx] += siz[ry];
        par[ry] = rx;
        return true;
    }
    int same(int x, int y)
    {
        return root(x) == root(y);
    }
};

#pragma endregion RegionDefs

void solve()
{
    IN(n);
    string s; cin >> s;
    char c = s[0];
    int ans = 1;
    rep(i, n)
    {
        if (c != s[i])
        {
            ans++;
            c = s[i];
        }
    }
    cout << ans << endl;
}

int main()
{
    cin.tie(0); cout.tie(0);
    ios::sync_with_stdio(false);
    cout << setprecision(numeric_limits<double>::max_digits10);

    solve();

    return 0;
}

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

using namespace std;

const int maxn = 2e5 + 5;
int n, cnt[maxn][2];
char s[maxn];

int main()
{
    scanf("%d", &n);
    scanf("%s", s + 1);
    int p = 0;
    for(int i = 1; i <= n; ++i) cnt[i][0] = cnt[i - 1][0] + (s[i] == 'W');
    cnt[n][1] = s[n] == 'R';
    for(int i = n - 1; i; --i) cnt[i][1] = cnt[i + 1][1] + (s[i] == 'R');
    int ans = n + 1;
    for(int i = 0; i <= n; ++i)
    {
        ans = min(ans, cnt[i][0] + cnt[i + 1][1] - min(cnt[i][0], cnt[i + 1][1]));
    }
    printf("%d", ans);
    return 0;
}

Measured memory_bytes: 5508
import std.algorithm;
import std.stdio;

bool solve (long n, long a, long b, long c, long d)
{
	foreach (i; 0..n)
	{
		long pos = a + c * i - d * (n - 1 - i);
		long right = pos + (d - c) * (n - 1);
		debug {writeln (pos, " ", right);}
		if (pos <= b && b <= right)
		{
			return true;
		}
	}
	return false;
}

void main ()
{
	long n, a, b, c, d;
	while (readf (" %s %s %s %s %s", &n, &a, &b, &c, &d) > 0)
	{
		writeln (solve (n, a, b, c, d) ? "YES" : "NO");
	}
}


Measured memory_bytes: 256
import sys


def input():
    return sys.stdin.readline()[:-1]


def main():
    n, l = map(int, input().split())
    a = [i for i in range(l, l+n)]
    if l < 0 and abs(l) < n:
        print(sum(a))

    elif l < 0 and abs(l) >= n:
        print(sum(a)-max(a))
    else:
        print(sum(a)-min(a))


if __name__ == "__main__":
    main()


Measured memory_bytes: 38384
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<cmath>
#include<utility>
#include<set>
#include<complex>
#define vi vector<int>
#define vvi vector<vector<int> >
#define ll long long int
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<string>
#define ld long double
#define INF 1e9
#define EPS 0.0000000001
#define rep(i,n) for(int i=0;i<n;i++)
#define CC puts("-------ok--------");
#define all(in) in.begin(), in.end()
#define bv vector<bool>
using namespace std;
typedef pair<int, int> PI;
#define MAX 99999999
int main(){
    int n;
    while(cin>>n,n){
    char array[10000]; rep(i,10000)array[i]=i;
    rep(i,n){
        char c,d; cin>>c>>d;
        array[(int)c]=d;
    }
        int m;
    cin>>m; vc v(m);
    rep(i,m)cin>>v[i];
    rep(i,m){
        if(array[v[i]]==v[i])cout<<v[i];
        else cout<<array[v[i]];
    }cout<<endl;
    }
}

Measured memory_bytes: 3112
#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
long long a[100];
int n;
void uradi()
{
    long long maxx = 0;int pok = 0;
    for (int i=1;i<=n;i++)
        if (maxx<a[i])maxx=a[i],pok=i;
    for (int i=1;i<=n;i++)if (pok==i)a[i]-=n*1LL;else a[i]++;
}
int main()
{
    long long k;
    scanf("%lld",&k);
    n = 50;
    long long p = k/50;
    for (int i=1;i<=n;i++)a[i] = 50LL+p;
    p = k%50;
    p = 50-p;
    for (int i = 1;i<=p;i++)uradi();
    cout<<n<<endl;
    for (int i=1;i<=n;i++)cout<<a[i]<<" ";
    return 0;
}


Measured memory_bytes: 256
import itertools

N,D=map(int,input().split())
lst=[list(map(int,input().split())) for i in range(N)]

_result = 0
_sum = 0
for i in itertools.combinations(range(N),2):
    for j in range(D):
        _result += abs(lst[(i[0])][j] - lst[(i[1])][j])**2
    if (_result ** 0.5).is_integer():
        _sum += 1
    _result = 0
print(_sum)

Measured memory_bytes: 3316
#include <bits/stdc++.h>
#define speed                                                                  \
  ios_base::sync_with_stdio(0);                                                \
  cin.tie(0);                                                                  \
  cout.tie(0);
#define oprecision                                                             \
  cout.precision(30);                                                          \
  cerr.precision(7);
#define bb bool
#define ii int
#define ll long long
#define ff float
#define dd double
#define cc char
#define ss string
#define forn(sz) for (int i = 1; i <= sz; i++)
#define forni(i, sz) for (int i = 1; i <= sz; i++)
#define fornid(i, m, sz) for (int i = m; i <= sz; i++)
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define vii vector<ii>
#define vii64 vector<ll>
#define vb vector<bb>
using namespace std;
ii a;
ii main() {
  speed;
  oprecision;
  /*#ifndef ONLINE_JUDGE
    freopen("outd.txt", "rt", stdin);
  #endif*/
  // code
  cin >> a;
  cout << (int)pow(a, 3);
  // endl
#ifndef ONLINE_JUDGE
  cerr << "\nTime elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
  return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define ll long long int
#define pb push_back
#define mp make_pair
const int mod=1e9+7;

void solve()
{
  int x,y,z;
  cin>>x>>y>>z;
  int temp;
  temp=y;
  y=x;
  x=temp;
  temp=z;
  z=x;
  x=temp;
  cout<<x<<" "<<y<<" "<<z;
}

int main()
{
  fastio
  solve();
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int ctoi(char);
int main(){
  int n;
  cin >> n;
  for(int I=0;I<n;I++){
    vector<char> ha(2);
    int c=0;
    int ac=0;
    vector<char> ya(8);
    for(int i=0;i<2;i++){
      cin >> ha[i];
      if(ha[i]=='A'){
	ac++;
      }
      c+=ctoi(ha[i]);
    }
    for(int i=0;i<8;i++){
      cin >> ya[i];
    }
    int i=0;
    while(1){
      if(i==0&&c==11&&ac){
	cout << "blackjack" << endl;
	break;
      }
      int c2=-1;
      if(ac&&c+10<=21)c2=c+10;
      if((c<=16&&c2<=16)||(c==7&&ac)){
	c+=ctoi(ya[i]);
	if(ya[i]=='A'){
	  ac++;
	}
	i++;
      }
      else{
	if(c>21){
	  cout << "bust" << endl;
	  break;
	}
	else {
	  cout << max(c,c2) << endl;
	  break;
	}
      }
    }
  }
  return 0;
}

int ctoi(char x){
  if(x>='0'&&x<='9'){
    return x-'0';
  }
  if(x=='A')return 1;
  return 10;
}

Measured memory_bytes: 3016
let () = Scanf.scanf "%d\n%s\n" @@ fun n s ->
  Array.init n (String.get s)
  |> Array.fold_left (fun (minimum, h) -> function
    | '(' -> (minimum, h + 1)
    | ')' -> (min minimum (h - 1), h - 1)) (0, 0)
  |> (fun (minimum, h) ->
      let d = max 0 (~- minimum) in
      Printf.printf "%s%s%s\n" (String.make d '(') s (String.make (max 0 (d + h)) ')'))




Measured memory_bytes: 384
#include<stdio.h>
#include<math.h>
#include<stdlib.h>
int a[100005];
int main()
{
    int n,i,s=0,t;
    scanf("%d",&n);
    for(i=1;i<=n;i++)
        scanf("%d",&a[i]);
        a[0]=0;
        a[n+1]=0;
   for(i=1;i<=n+1;i++)
     s+=abs(a[i]-a[i-1]);
   for(i=1;i<=n;i++)
   {
        t=s-abs(a[i]-a[i-1])-abs(a[i+1]-a[i])+abs(a[i+1]-a[i-1]);
         printf("%d\n",t);
   }


    return 0;
}

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

int main(int argc, const char * argv[]) {
    long long int n,x;
    cin >> n >> x;
    vector<int> a(n);
    for (int i=0; i<n; i++) {
        cin >> a[i];
    }
    long long int count = 0;
    for(int i=0;i<n-1;i++){
        if(a[i]+a[i+1] > x){
            long long int decAmount = a[i]+a[i+1] - x;
            if(a[i+1] - decAmount >= 0) {
                a[i+1] -= decAmount;
                count += decAmount;
            }else{
                a[i+1] = 0;
                a[i] -= (decAmount-a[i+1]);
                count += decAmount-a[i+1];
            }
        }
    }
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 640
#include <algorithm>
#include <iostream>
#include <map>
#include <cstdio>
#include <bits/stdc++.h>
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define REP(i,n) for(int i=0;i<n;i++)
#define FORq(i, m, n) for(int i = m;i <= n;i++)
#define SCD(n) scanf("%d",&n)
#define SCD2(m,n) scanf("%d%d",&m,&n)
#define PRINTD(n) printf("%d\n",n)
#define DEBUG printf("%s\n","debug")
using namespace std;
 /////////////////////////////////////////////////////
int main() {
	int N,W;
	int v[1010] = {};
	int w[10100] = {};
	static int dp[1010][10100];
	SCD2(N,W);
	
	FORq(i,1,N){
		SCD2(v[i],w[i]);
	}
	
	FORq(i,0,W){
		dp[0][i] = 0;
	}
	
	FORq(i,1,N){
		FORq(j,0,W){
			if (j < w[i]){
				dp[i][j] = dp[i-1][j];
			}else{
				dp[i][j] = max(dp[i-1][j],dp[i-1][j-w[i]] + v[i]);
			}
			
		}
		
	}
	
	PRINTD(dp[N][W]);
	return 0;
}
 


Measured memory_bytes: 7252
#include <bits/stdc++.h>
using namespace std;
vector<vector<int> >A(5009);
int main(){
  int sum=0,n,m,a,b,c;
  for(int i=0;i<5009;i++){
    A[i].assign(i+7,0);
  }
  cin>>n>>m;
  while(m--){
    cin>>a>>b>>c;
    A[a][b]++;
    A[a][b+1]--;
    A[a+c+1][b]--;
    A[a+c+1][b+c+2]++;
    A[a+c+2][b+1]++;
    A[a+c+2][b+c+2]--;
  }
  for(int i=0;i<=n+3;i++){
    for(int j=0;j<i+2;j++){
      if(j) A[i][j]+=A[i][j-1];
    }
  }
  for(int i=0;i<=n+3;i++){
    for(int j=0;j<=i+3;j++){
      if(i) A[i][j]+=A[i-1][j];
    }
  }
  for(int i=0;i<=n+3;i++){
    for(int j=0;j<=i+3;j++){
      if(i&&j) A[i][j]+=A[i-1][j-1];
    }
  }
  for(int i=0;i<=n+3;i++){
    for(int j=0;j<=i+5;j++){
      if(A[i][j]>0) sum++;
    }
  }
  cout<<sum<<endl;
}


Measured memory_bytes: 52044
//g++ -std=gnu++14 a.cpp

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <iostream>
#include <istream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <tuple>
#include <iomanip>
#include <random>
#include <math.h>
//#include <ostream>


using namespace std;

#define ll long long
#define rep(i, n) for(ll i = 0; i < (n); i++)
ll MOD = 1e9 + 7;
int INF = 1 << 30;
ll INFL = 1LL << 60;

int main(){
  string s;
  cin >> s;
  bool hantei = true;
  if(s.at(0)=='B'&&s.at(1)=='B'&&s.at(2)=='B')hantei=false;
  if(s.at(0)=='A'&&s.at(1)=='A'&&s.at(2)=='A')hantei=false;

  if(hantei){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }


}


Measured memory_bytes: 256
def agc024_b():
    n = int(input())
    P = [int(input())-1 for _ in range(n)]  # 0 .. n-1 にしておく
    if n == 1: return print(0)

    A = [0]*n  # 登場するindex
    for i, p in enumerate(P):
        A[p] = i

    cnt = 0  # iの登場順がi-1より後ろが連続する回数
    cmax = 0
    for i in range(1, n):
        if A[i-1] < A[i]:
            cnt += 1
        else:
            cmax = max(cmax, cnt)
            cnt = 0
    else:
        cmax = max(cmax, cnt)

    ans = n - (cmax + 1)
    print(ans)

if __name__ == '__main__':
    agc024_b()

Measured memory_bytes: 24888
#include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<time.h>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double EPS=1e-10;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
int main(){
	vector<int>in(2);
	rep(i,2){
		rep(j,4){
			int a;cin>>a;
			in[i]+=a;
		}
	}
	cout<<max(in[0],in[1])<<endl;
}

Measured memory_bytes: 1192
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <vector>
#include <queue>
#include <utility>

using namespace std;
typedef long long ll;
const int LEN = 100000;

struct fastio{
  int it,len;
  char s[LEN + 5];
  fastio(){
    it = len = 0;
  }
  char get(){
    if(it < len) return s[it++];
    it = 0, len = fread(s,1,LEN,stdin);
    return len ? s[it++] : EOF;
  }
  bool notend(){
    char c;
    for(c = get();c == ' ' || c == '\n';c = get());
    if(it) it--;
    return c != EOF;
  }
  void put(char c){
    if(it == LEN) fwrite(s,1,LEN,stdout), it = 0;
    s[it++] = c;
  }
  void flush(){
    fwrite(s,1,it,stdout);
  }
}buff,bufo;
inline int getint(){
  char c; int res = 0, sig = 1;
  for(c = buff.get();c < '0' || c > '9';c = buff.get()) if(c == '-') sig = -1;
  for(;c >= '0' && c <= '9';c = buff.get()) res = res * 10 + (c - '0');
  return sig * res;
}
inline ll getll(){
  char c; ll res = 0, sig = 1;
  for(c = buff.get();c < '0' || c > '9';c = buff.get()) if(c == '-') sig = -1;
  for(;c >= '0' && c <= '9';c = buff.get()) res = res * 10 + (c - '0');
  return sig * res;
}
inline void putint(int x,char suf){
  if(!x) bufo.put('0');
  else{
    if(x < 0) bufo.put('-'), x = -x;
    int k = 0; char s[15];
    while(x){
      s[++k] = x % 10 + '0';
      x /= 10;
    }
    for(;k;k--) bufo.put(s[k]);
  }
  bufo.put(suf);
}
inline void putll(ll x,char suf){
  if(!x) bufo.put('0');
  else{
    if(x < 0) bufo.put('-'), x = -x;
    int k = 0; char s[25];
    while(x){
      s[++k] = x % 10 + '0';
      x /= 10;
    }
    for(;k;k--) bufo.put(s[k]);
  }
  bufo.put(suf);
}
inline char get_char(){
  char c;
  for(c = buff.get();c == ' ' || c == '\n';c = buff.get());
  return c;
}
vector <int> p,q,a;
int main(){
  int n = getint();
  for(int i = 1;i <= n;i++){
    int x = getint();
    p.push_back(x);
  }
  for(int i = 1;i <= n;i++){
    int x = getint();
    q.push_back(x);
  }
  for(int i = 1;i <= n;i++) a.push_back(i);
  int kp = -1, kq = -1, k = 0;
  do{
    k++;
    if(p == a) kp = k;
    if(q == a) kq = k;
    if(~kp && ~kq){
      putint(abs(kp - kq),'\n');
      break;
    }
  }while(next_permutation(a.begin(),a.end()));
  bufo.flush();
  return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""
input:
4 5
0 1 2
0 2 1
1 2 1
1 3 1
2 3 2

output:
3
"""

import sys
from collections import deque


def bfs(source, target, parent):
    queue = deque()
    queue.appendleft(source)
    visited = [False] * v_num
    visited[source] = True

    while queue:
        current = queue.popleft()
        for adj, cp in adj_table[current].items():
            if cp and not visited[adj]:
                queue.append(adj)
                visited[adj] = True
                parent[adj] = current

    return True if visited[target] else False


def graph_FordFulkerson(source, sink):
    parent = [-1] * v_num
    max_flow = 0

    while bfs(source, sink, parent):
        path_flow = float('inf')

        bk_1 = sink
        while bk_1 != source:
            parent_bk_1 = parent[bk_1]
            assert parent_bk_1 != -1
            path_flow = min(path_flow, adj_table[parent_bk_1][bk_1])
            bk_1 = parent[bk_1]

        max_flow += path_flow

        bk_2 = sink
        while bk_2 != source:
            parent_bk_2 = parent[bk_2]
            assert parent_bk_2 != -1
            adj_table[bk_2].setdefault(parent_bk_2, 0)

            adj_table[parent_bk_2][bk_2] -= path_flow
            adj_table[bk_2][parent_bk_2] += path_flow
            bk_2 = parent[bk_2]

    return max_flow


if __name__ == '__main__':
    _input = sys.stdin.readlines()
    v_num, e_num = map(int, _input[0].split())
    edges = map(lambda x: x.split(), _input[1:])

    adj_table = tuple(dict() for _ in range(v_num))
    for edge in edges:
        s, t, c = map(int, edge)
        adj_table[s][t] = c

    print(graph_FordFulkerson(source=0, sink=v_num - 1))

Measured memory_bytes: 8140
k = gets.chomp.to_i
a, b = gets.chomp.split(" ").map {|i| i.to_i}

base = a / k
if a % k == 0
  puts "OK"
elsif b % k == 0
  puts "OK"
elsif base*k + k < b
  puts "OK"
else
  puts "NG"
end

Measured memory_bytes: 14324
import math

n = int(input())

check = {}
ans = 0

for _ in range(n):
    word = sorted(input())
    new_word = ''.join(list(word))
    check.setdefault(new_word, 0)
    check[new_word] += 1

for k in check:
    if check[k] >= 2:
        ans += int(math.factorial(check[k])/(math.factorial(check[k]-2)*2))

print(ans)

Measured memory_bytes: 17932
#include <stdio.h>

int main(void) {
	int n, x;
	scanf("%d%d", &n, &x);

	int i, cur = 0;
	for (i = 0; i <= n && cur <= x; i++) {
		int l;
		scanf("%d", &l);
		cur += l;
	}
	printf("%d\n", i);
}


Measured memory_bytes: 128
#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 ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef long double ld;
int main()
{
  int a,b,c;
  cin >> a >> b >> c;

  cout << min(b/a,c) << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


#define NUM 50
#define MAX_TURN 5005

enum Type{
	turn_A,
	turn_B,
};

int num_room;
int dp[2][MAX_TURN][NUM][NUM];
vector<int> G[NUM];

int recursive(Type type,int num_turn,int loc_A,int loc_B){

	if(dp[type][num_turn][loc_A][loc_B] != -1)return dp[type][num_turn][loc_A][loc_B];

	if(loc_A == loc_B){
		return dp[type][num_turn][loc_A][loc_B] = num_turn;
	}

	if(num_turn == num_room){
		return dp[type][num_turn][loc_A][loc_B] = BIG_NUM;
	}

	int ret;

	if(type == turn_A){

		int maximum = max(0,recursive(turn_B,num_turn,loc_A,loc_B));

		for(int i = 0; i < G[loc_A].size(); i++){
			maximum = max(maximum,recursive(turn_B,num_turn,G[loc_A][i],loc_B));
		}

		ret = maximum;

	}else{

		int minimum = min(BIG_NUM,recursive(turn_A,num_turn+1,loc_A,loc_B));

		for(int i = 0; i < G[loc_B].size(); i++){
			minimum = min(minimum,recursive(turn_A,num_turn+1,loc_A,G[loc_B][i]));
		}

		ret = minimum;
	}

	return dp[type][num_turn][loc_A][loc_B] = ret;
}

void func(){

	scanf("%d",&num_room);

	for(int i = 0; i < num_room; i++)G[i].clear();

	int tmp;

	for(int from = 0; from < num_room; from++){
		for(int to = 0; to < num_room; to++){
			scanf("%d",&tmp);
			if(tmp == 0)continue;
			G[from].push_back(to);
		}
	}

	for(int i = 0; i < MAX_TURN; i++){
		for(int a = 0; a < num_room; a++){
			for(int b = 0; b < num_room; b++){
				dp[turn_A][i][a][b] = -1;
				dp[turn_B][i][a][b] = -1;
			}
		}
	}

	int loc_A,loc_B;

	scanf("%d %d",&loc_A,&loc_B);

	int ans = recursive(turn_A,0,loc_A,loc_B);

	if(ans == BIG_NUM){
		printf("infinity\n");
	}else{
		printf("%d\n",ans);
	}
}

int main(){

	int num_case;

	scanf("%d",&num_case);

	for(int loop = 0; loop < num_case; loop++){
		func();
	}

	return 0;
}



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

using namespace std;

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

const ld pi = 3.141592653589793;

ll n, a[81], m = 1000, s = 0;
int b[81];

int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  if (n == 2) {
    if (a[0] < a[1]) {
      ll ns = m / a[0];
      m -= a[0] * ns;
      m += ns * a[1];
    }
    cout << m << endl;
    return 0;
  }

  if (a[0] < a[1]) {
    b[0] = 1;
  }
  if (a[0] > a[1]) {
    b[0] = 2;
  }

  for (int i = 1; i < (n - 1); i++) {
    if (a[i - 1] >= a[i] && a[i] <= a[i + 1]) {
      b[i] = 1;
    }
    if (a[i - 1] <= a[i] && a[i] >= a[i + 1]) {
      b[i] = 2;
    }
  }

  if (a[n - 2] > a[n - 1]) {
    b[n - 1] = 1;
  }
  if (a[n - 2] < a[n - 1]) {
    b[n - 1] = 2;
  }

  for (int i = (n - 1); i >= 0; i--) {
    if (b[i] == 1) {
      b[i] = 0;
      break;
    }
    if (b[i] == 2) {
      break;
    }
  }

  for (int i = 0; i < n; i++) {
    if (b[i] == 1) {
      ll ns = m / a[i];
      m -= a[i] * ns;
      s += ns;
    }
    if (b[i] == 2) {
      m += s * a[i];
      s = 0;
    }
  }

  cout << m << endl;
}

Measured memory_bytes: 3588
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define REP(i, n) rep(i, 0, n)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define int long long
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef pair<int, int> P;
const int mod = 1LL << 32;
const int INF = 1e12;

signed main(){
	int t;
	cin >> t;
	rep(ij, 0, t){
		int a[9] = {}, b[8] = {}, k = 0, sum = 0;
		rep(i, 0, 9){
			scanf("%x", &a[i]);
		}
		rep(i, 0, 32){
			int tmp = 0;
			rep(j, 0, 8){
				if(a[j] & (1LL << i)) tmp++;
			}
			// cout << tmp % 2 << " " << !!(a[8] & (1LL << i)) << endl;
			int now = !!(a[8] & (1LL << i));
			if(sum & (1LL << i)) now = (now + 1) % 2;
			if(tmp % 2 == now){
				sum += tmp * (1LL << i);
				sum %= mod;
				//a[8] = (a[8] - tmp * (1LL << i) % mod + mod) % mod;
			}else{
				sum += (8 - tmp) * (1LL << i);
				sum %= mod;
				//a[8] = (a[8] - (8 - tmp) * (1LL << i) % mod + mod) % mod;
				k += (1LL << i);
			}
		}
		printf("%x\n", k);
	}
}


Measured memory_bytes: 3140
from itertools import permutations
import math

N = int(input())
P = tuple(int(x) for x in input().split(" "))
Q = tuple(int(x) for x in input().split(" "))

orders = dict()
i = 1
for perms in sorted(permutations(range(1, N+1))):
    orders[perms] = i
    i += 1

print(int(math.fabs(orders[P] - orders[Q])))


Measured memory_bytes: 48496
import copy

def partition(p, r):
    i = p
    for j in range(p, r):
        if A[r][1] >= A[j][1]:
            A[i], A[j] = A[j], A[i]
            i += 1
    A[r], A[i] = A[i], A[r]
    return i

def quick_sort(p, r):
    if p < r:
        q = partition(p, r)
        quick_sort(p, q-1)
        quick_sort(q+1, r)

def is_stable():
    for i in range(N-1):
        if A[i][1] == A[i+1][1]:
            small_idx, large_idx = 0, 0
            for j in range(N):
                if A[i] == orig_list[j]:
                    small_idx = j
                elif A[i+1] == orig_list[j]:
                    large_idx = j
            if small_idx > large_idx:
                return False
    return True


N = int(input())
A = []
for _ in range(N):
    suit, num = input().split()
    num = int(num)
    A.append([suit, num])
orig_list = copy.deepcopy(A)

quick_sort(0, N-1)

is_stable = is_stable()
if is_stable:
    print("Stable")
else:
    print("Not stable")

for card in A:
    print("%s %d" % (card[0], card[1]))


Measured memory_bytes: 39512
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
#define fi first
#define se second
using namespace std;
ll AL,BL,d[50][50][50],i,B[50][50][50],te,n,has;
char a[50],b[50];
string SA,SB;
ll depe(ll aa,ll bb,ll cc)
{
	if(cc==n+1&&aa==AL&&bb==BL)
		return 1;
	else
	if(B[aa][bb][cc]!=te)
	{
		B[aa][bb][cc]=te;
		d[aa][bb][cc]=0;
		if(aa<AL&&SA[aa]==b[cc])
			d[aa][bb][cc]+=depe(aa+1,bb,cc+1);
		if(bb<BL&&SB[bb]==b[cc])
			d[aa][bb][cc]+=depe(aa,bb+1,cc+1);
	}
	return d[aa][bb][cc];
}
ll hey(ll cc,string aa,string bb)
{
	if(cc==n+1)
	{
		SA=aa;
		SB=bb;
		AL=aa.length();
		BL=bb.length();
		te++;
		has+=depe(0,0,1);
	}
	else
	{
		hey(cc+1,aa+a[cc],bb);
		hey(cc+1,aa,bb+a[cc]);
	}
}
int main()
{
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	cin>>n;
	for(i=1;i<=n;i++)
		cin>>a[i];
	for(i=n;i>=1;i--)
		cin>>b[i];
	hey(1,"","");
	cout<<has<<"\n";
}

Measured memory_bytes: 512
// https://atcoder.jp/contests/abc175/tasks/abc175_b

#include "algorithm"
#include "bitset"
#include "cmath"
#include "functional"
#include "iomanip"
#include "iostream"
#include "map"
#include "numeric"
#include "queue"
#include "set"
#include "string"
#include "vector"
#define rep(i, to) for (ll i = 0; i < (to); ++i)
#define rep1(i, to) for (ll i = 1; i <= (to); ++i)
#define repf(i, from, to) for (ll i = from; i < (to); ++i)
#define repr(i, from) for (ll i = from - 1; i >= 0; --i)
#define all(vec) vec.begin(), vec.end()
#define unless(cond) if (!(cond))
#define fi first
#define se second
using namespace std;
using ll = long long;
using ld = long double;
template <typename T>
using V = vector<T>;
using VL = V<ll>;
template <typename T>
using VV = V<V<T>>;
using VVL = VV<ll>;
template <typename T>
using VVV = VV<V<T>>;
template <typename T, typename U>
using P = pair<T, U>;
using PL = P<ll, ll>;
using VPL = V<PL>;
template <typename T>
using asc_pq = priority_queue<T, V<T>, greater<T>>;

template <typename T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}

template <typename T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

template <typename T>
inline ll len(V<T> arr) {
  return arr.size();
}

struct exit_exception : public std::exception {
  const char* what() const throw() { return "Exited"; }
};

template <typename T>
void drop(T res) {
  cout << res << endl;
  throw exit_exception();
}

const ll INF = 1e18;

void solve();

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

  try {
    solve();
  } catch (exit_exception& e) {
  }

  return 0;
}
#endif

void solve() {
  ll N;
  cin >> N;

  VL ls(N);
  rep(i, N) cin >> ls[i];

  sort(all(ls));

  ll res = 0;
  rep(i3, N) rep(i2, i3) rep(i1, i2) {
    ll l1 = ls[i1];
    ll l2 = ls[i2];
    ll l3 = ls[i3];
    unless(l1 != l2 && l2 != l3) continue;
    unless(l1 + l2 > l3) continue;
    res++;
  }

  cout << res << "\n";
}


Measured memory_bytes: 3612
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <cstring>
#include <utility>
#include <numeric>

using namespace std;

int main(){

    int H, W, K;
    cin >> H >> W >> K;
    vector<string> s(H);
    for(int i = 0; i < H; i++){
        cin >> s[i];
    }

    vector<vector<int>> ans(H, vector<int>(W, 0));
    int k = 0;
    int temp = 0;
    int upper = 100000;
    int lower = -10000;
    for(int i = 0; i < H; i++){
        for(int j = 0; j < W; j++){
            if(s[i][j] == '#'){
                k++;
                temp = k;
                upper = min(upper, i);
                lower = max(lower, i);
            }
            ans[i][j] = temp;
        }
        temp = 0;
    }

    temp = 0;
    for(int i = 0; i < H; i++){
        for(int j = W - 1; j >= 0; j--){
            if(ans[i][j] == 0){
                ans[i][j] = temp;
            }
            else{
                temp = ans[i][j];
            }
        }
        temp = 0;
    }

    for(int i = upper - 1; i >= 0; i--){
        for(int j = 0; j < W; j++){
            if(ans[i][j] == 0){
                ans[i][j] = ans[i + 1][j];
            }
        }
    }

    for(int i = upper + 1; i < H; i++){
        for(int j = 0; j < W; j++){
            if(ans[i][j] == 0){
                ans[i][j] = ans[i - 1][j];
            }
        }
    }

    for(int i = 0; i < H; i++){
        for(int j = 0; j < W; j++){
            cout << ans[i][j];
            if(j != W - 1){
                cout << " ";
            }
            else{
                cout << endl;
            }
        }
    }

    return 0;
}

Measured memory_bytes: 1280
#template
def inputlist(): return [int(k) for k in input().split()]
#template
N,M = inputlist()
switch = [0]*M
k = [0]*M
for i in range(M):
    li = inputlist()
    k[i] = li[0]
    switch[i] = li[1:]
p = inputlist()

ans = 0

for i in range(2**N):
    s = bin(i)
    s = s[2:]
    if len(s) < N:
        for y in range(N-len(s)):
            s = '0'+s
    co = 0
    for j in range(M):
        count = 0
        for t in range(k[j]):
            if s[switch[j][t] - 1] == '1':
                count +=1
        if count % 2 == p[j]:
            co +=1
    if co == M:
        ans +=1

print(ans)

Measured memory_bytes: 42992
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N=sc.nextInt();
		int a[] = new int[N];
		int b[] = new int[N];
		int c[] = new int[N];
		
		for(int i=0;i<N;i++) {
			a[i]=sc.nextInt();
			b[i]=sc.nextInt();
			c[i]=sc.nextInt();
		}
		
		int happy[][] = new int[N][3];
		
		for(int j=0;j<3;j++) {
			if(j==0) {
				happy[0][j]=a[0];
			}else if(j==1) {
				happy[0][j]=b[0];
			}else if(j==2) {
				happy[0][j]=c[0];
			}
		}
		
		for(int i=1;i<N;i++) {
			int value[] = new int[3];
			value[0]=a[i];
			value[1]=b[i];
			value[2]=c[i];
			for(int j=0;j<3;j++) {
				happy[i][j]=Math.max(happy[i-1][(j+1)%3]+value[j], happy[i-1][(j+2)%3]+value[j]);
			}
		}
		int max = 0;
		max = Math.max(happy[N-1][0], Math.max(happy[N-1][1], happy[N-1][2]));
		System.out.println(max);
	}

}


Measured memory_bytes: 97600
#include <bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;
#define int long long
typedef pair<int,int>P;
#define F first
#define S second
 
signed main(){
  int r,d,x;
  cin>>r>>d>>x;
  r(i,10){
    x=r*x-d;
    cout<<x<<endl;
  }
}

Measured memory_bytes: 256
package main

import (
	"fmt"
	"math"
)

func main() {
	var x1, y1, x2, y2 float64
	fmt.Scan(&x1, &y1, &x2, &y2)
	fmt.Println(math.Sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2)))
}



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

struct Range{
    int l, r; // [l, r)
    Range(int l, int r) : l(l), r(r) {}
};

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

    Range a((A*25+(2-1))/2, (((A+1)*25)+(2-1))/2);
    Range b(B*10, (B+1)*10);

    Range result(max(a.l, b.l), min(a.r, b.r));
    if (result.r <= result.l)
        cout << "-1\n";
    else
        cout << result.l << 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);
		String strN = sc.next();
		int N = Integer.parseInt(strN);

		boolean isHigh = false;
		boolean isLow = false;
		boolean isFirst = true;

		int count = 1;
		int b = Integer.parseInt(sc.next());

		for (int i = 1; i < N; i++) {
			int a = Integer.parseInt(sc.next());
			if (b == a) {
				continue;
			}

			if (b < a) {
				b = a;
				if (!isLow) {
					isFirst = false;
					isHigh = true;
					continue;
				}
			} else {
				b = a;
				if (!isHigh) {
					isFirst = false;
					isLow = true;
					continue;
				}
			}
			count++;

			if (!isFirst) {
				isHigh = false;
				isLow = false;
				isFirst = true;
			}

		}
		System.out.println(count);

	}

}


Measured memory_bytes: 46628
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=ll(a);i<ll(b);++i)
#define SIZE 3005
#define INF 1000000005LL
//#define INF 1e18
#define MOD 998244353

using namespace std;
typedef long long int ll;
typedef pair <int,int> P;

ll n;
ll s;
ll a[SIZE];
ll dp[SIZE][SIZE];
ll t[SIZE];

void init(){
  t[0] = 1;
  rep(i,1,SIZE){
    t[i] = t[i-1]*2;
    t[i] %= MOD;
  }
}


int main(){
  cin >> n >> s;
  init();
  rep(i,0,n){
    cin >> a[i+1];
  }
  rep(i,1,n+1){
    rep(j,1,s+1){
      dp[i][j] += dp[i-1][j]*2;
      dp[i][j] %= MOD;

      if(j-a[i] >= 0) dp[i][j] += dp[i-1][j-a[i]];
      dp[i][j] %= MOD;

      if(a[i] == j){
        dp[i][j] += t[i-1];
        dp[i][j] %= MOD;
      }
    }
  }
  cout << dp[n][s] << endl;

  return 0;
}


Measured memory_bytes: 74068
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define pi 3.1415926536
#define pb push_back
#define N 1000000007
#define M 998244353
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define nrep(i,a,b) for(int i=a;i>=b;i--)
int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    ll t,i,j,k,q,x,y,l,r,z,n,m;
    cin>>k>>n;
    ll a[n+5];
    rep(i,1,n){
    	cin>>a[i];
	}
	x = a[1] + (k- a[2]);
	y = a[n] - a[1];
	ll ans;
	ans = min(x, y);
	rep(i,2,n-1){
		x = a[i] + (k- a[i+1]);
	    y  = k - a[i] + a[i-1];
		ans =  min(ans, min(y,x));
	}
		cout<<ans<<endl;
}

Measured memory_bytes: 1792
#include <iostream>
#include <algorithm>
#include <vector>
#include <iostream>
#include <set>
#include <deque>
#include <utility>
#include <numeric>
#include <map>
#include <math.h>
#define MAX 100000
#define inf (1LL << 62)
#define se second
#define fi first
#define pb push_back
#define m1 998244353
#define epi 1e-15d
#define NO "IMPOSSIBLE"
#define Ans(i, n) cout << "Case #" << i << ": " << n << endl;
using namespace std;
typedef long long ll;
typedef long double ld;
using namespace std;
int A[100000];
int B[100002];
vector<pair<int, int>> C(100000);
int pos = 0;

int cmp(pair<int, int> A, pair<int, int> B){
    return A.se > B.se;
}

int main(){
    fill(B, B+100002, 0);
    int n, m;
    cin >> n >> m;
    for(int i=0;i<n;i++){
        cin >> A[i];
    }
    for(int i=0;i<m;i++){
        int v1, v2;
        cin >> v1 >> v2;
        C.pb(pair<int, int>{v1, v2});
    }
    sort(A, A+n);
    sort(C.begin(), C.end(), cmp);
    int j = 0;
    while(pos < n && j < m){
        while(C[j].fi-- > 0 && pos < n){
            B[pos++] = C[j].se;
        }
        j++;
    }
    ll ans = 0;
    for(int i=0;i<n;i++){
        ans += max(A[i], B[i]);
    }
    cout << ans;
}


Measured memory_bytes: 2672
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws Exception {
		// BufferedReader br = new BufferedReader(new
		// InputStreamReader(System.in));
		// String line = br.readLine();
		Scanner scan = new Scanner(System.in);

		int a = scan.nextInt();
		int b = scan.nextInt();

		if(a-b<=0)
			System.out.println("0");
		else
			System.out.println(a-b);

	}
}

Measured memory_bytes: 23764
#include <algorithm>
#include <cassert>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;

#define rep(i, n) for(ll i = 0; i < n; i++)
#define REP(i, n) for(ll i = 1; i < n + 1; i++)
#define PI 3.14159265359
#define EPS 0.0000000001
#define MOD 1000000007
//cout << std::fixed << std::setprecision(15) << y << endl;


int main(){
    ll N, K;
    cin >> N >> K;

    ll l[N];
    rep(i, N){
        cin >> l[i];
    }
    sort(l, l + N, greater<ll>());

    ll ans = 0;
    rep(i, K){
        ans += l[i];
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3644
#include <stdio.h>

int main(int argc, const char * argv[]) {
    // insert code here...
    int a, b, c, d, e, f;
    while(scanf("%d", &a) != 0){
        if(a==0){break;}
        b = 0;
        c = 0;
        d = 0;
        while(b!=a){
            b++;
            scanf("%d %d",&e, &f);
            if(e>f){
                c=c+e+f;
            }
            else if(e<f){
                d=d+e+f;
            }
            else if(e==f){
                c=c+e;
                d=d+f;
            }
        }
        printf("%d %d\n", c, d);
    }
    
    return 0;
}

Measured memory_bytes: 600
#include <iostream>
#include <vector>
#include <string>
#include <cstdio>
#include <complex>
#include <cmath>
#include <cstdlib>
using namespace std;

#define FOR(i,x) for(int i=0;i<x;i++)

const double EPS = 1e-7;
typedef complex<double> P; /* _ */
struct L { P p, q; L(P p, P q) : p(p), q(q) {} }; /* üª */

// complexÉå¬ÖWªKvÈê
namespace std{
	bool operator < (const P &a, const P &b){ return make_pair(real(a),imag(a)) < make_pair(real(b),imag(b)); }
}

// àÏEOÏEpx(xNga,bÌZ)
double dot(P a, P b) { return real(conj(a)*b); }
double cross(P a, P b) { return imag(conj(a)*b); }
double angle(P a, P b) { return arg(conj(a)*b); }

// _p©ç¼ülÉºëµ½üÌ«
P footPerp(L l, P p) {
	return l.p + (l.q-l.p)*( dot(l.q-l.p, p-l.p) / (abs(l.q-l.p)*abs(l.q-l.p)));
}

// ¼ülÉÎ·é_pÌ
P lineShadow(L l, P p) {
	return footPerp(l, p)+footPerp(l, p)-p;
}

int main(){
	string in;
	while(cin>>in){
		//double x1,y1,x2,y2,xq,yq;
		//sscanf(in.c_str(), "%f,%f,%f,%f,%f,%f", &x1,&y1,&x2,&y2,&xq,&yq);
		double x1 = atof(in.substr(0, in.find(',')).c_str());
		in = in.substr(in.find(',')+1);
		double y1 = atof(in.substr(0, in.find(',')).c_str());
		in = in.substr(in.find(',')+1);
		double x2 = atof(in.substr(0, in.find(',')).c_str());
		in = in.substr(in.find(',')+1);
		double y2 = atof(in.substr(0, in.find(',')).c_str());
		in = in.substr(in.find(',')+1);
		double xq = atof(in.substr(0, in.find(',')).c_str());
		in = in.substr(in.find(',')+1);
		double yq = atof(in.substr(0, in.find(',')).c_str());
		in = in.substr(in.find(',')+1);

		L l = L(P(x1,y1), P(x2,y2));
		P q = P(xq, yq);

		P r = lineShadow(l, q);

		printf("%.7f %.7f\n", real(r), imag(r));
	}
	return 0;
}

Measured memory_bytes: 0
#include <iostream>
using namespace std;
long long S[100001], key;
long n;

bool binarySearch(){
    long left, right, mid;
    left=0;
    right=n;
    while(left<right){
        mid = (left+right)/2;
        if(S[mid]==key) return true;
        else if(key < S[mid])   right = mid;
        else    left = mid+1;
    }
    return false;
}

int main(void){
    long q, count=0;
    long long T[50001];
    cin >> n;
    for(int i=0; i<n; i++){
        cin >> S[i];
    }
    cin >> q;
    for(int i=0; i<q; i++){
        cin >> T[i];
    }
    for(int i=0; i<q; i++){
        key = T[i];
        if(binarySearch())   count++;
    }
    cout << count << endl;
    return 0;
}


Measured memory_bytes: 4204