akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i,x,y) for(int i=x;i<=y;i++)

const int RLEN=1<<18|1;
inline char nc() {
	static char ibuf[RLEN],*ib,*ob;
	(ib==ob) && (ob=(ib=ibuf)+fread(ibuf,1,RLEN,stdin));
	return (ib==ob) ? -1 : *ib++;
}
inline int rd() {
	char ch=nc(); int i=0,f=1;
	while(!isdigit(ch)) {if(ch=='-')f=-1; ch=nc();}
	while(isdigit(ch)) {i=(i<<1)+(i<<3)+ch-'0'; ch=nc();}
	return i*f;
}

const int mod=1e9+7;
inline int add(int x,int y) {return (x+y>=mod) ? (x+y-mod) : (x+y);}
inline int dec(int x,int y) {return (x-y<0) ? (x-y+mod) : (x-y);}
inline int mul(int x,int y) {return (long long)x*y%mod;}
inline int power(int a,int b,int rs=1) {for(;b;b>>=1,a=mul(a,a)) if(b&1) rs=mul(rs,a); return rs;}

int n,m;
const int T1[3][3]={ {2,1,1},
					 {2,1,2},
					 {1,0,1} };
const int T2[3][3]={ {1,1,1},
					 {0,1,2},
					 {0,0,1} }; 
struct matrix {
	int a[3][3];
	matrix (int t=0) {memset(a,0,sizeof(a)); rep(i,0,2) a[i][i]=t;}
	friend inline matrix operator *(const matrix &a,const matrix &b) {
		matrix c(0);
		rep(i,0,2) rep(k,0,2) rep(j,0,2) c.a[i][j]=add(c.a[i][j],mul(a.a[i][k],b.a[k][j]));
		return c;
	}
	friend inline matrix operator ^(matrix a,int b) {
		matrix c(1);
		for(;b;b>>=1,a=a*a) if(b&1) c=c*a;
		return c;
	}
} A,tr1,tr2;

int main() {
	n=rd(), m=rd();
	A.a[0][0]=1;
	memcpy(tr1.a,T1,sizeof(T1));
	memcpy(tr2.a,T2,sizeof(T2));
	int lst=0;
	for(int i=1;i<=m;++i) {
		int nxt=rd();
		A=A*(tr1^(nxt-lst-1));
		A=A*tr2; lst=nxt;
	}
	A=A*(tr1^(n-lst)); 
	cout<<A.a[0][2]<<'\n';
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
int main(void){
    // Your code here!
    long long X,Y,Z,count;
    cin>>X;
    Y=100;
    Z=100;
    count=0;
    while(Z<X){
        Y=Y*1.01;
        Z=Y;
        count++;
    }
    cout<<count<<endl;
}

Measured memory_bytes: 3636
using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using System.Text;


class Program
{
    static void Main(string[] args)
    {
        // 入力
        //var s = Console.ReadLine();
        var n = long.Parse(Console.ReadLine());

        long[] ans = new long[n + 1];
        for (long i = 1; i <= n; i++)
        {
            for (long j = i; j <= n; j++)
            {
                for (long k = j; k <= n; k++)
                {
                    var tmp = i * i + j * j + k * k + i * j + j * k + i * k;
                    if (tmp <= n)
                    {
                        if (i != j && i != k && j != k) ans[tmp] += 6;
                        else if ((i == j && j != k) || (i == k && k != j) || (j == k && k != i)) ans[tmp] += 3;
                        else ans[tmp] += 1;
                    }
                    else
                    {
                        break;
                    }
                }
            }
        }

        // 出力
        for (long i = 1; i < n + 1; i++)
        {
            Console.WriteLine(ans[i]);
        }

    }
}

Measured memory_bytes: 27388
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
		String strA = bufferedReader.readLine();
		String strB = bufferedReader.readLine();

		String[] list = strA.split("");
		String reA = list[2] + list[1] + list[0];

		if(strB.equals(reA)) {
			System.out.println("YES");
		}else {
			System.out.println("NO");
		}
	}

}


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

using namespace std;

int a[105][2];
long long f[105][100005];

int main() {
	int n, w;
	scanf("%d %d", &n, &w);
	int sum = 0;
	for (int i = 0; i < n; i++) {
		scanf("%d %d", &a[i][0], &a[i][1]);
		sum += a[i][1];
	}
	for (int j = 1; j <= sum; j++) {
		f[0][j] = 1e9;
	}
	for (int i = 0; i <= n; i++) {
		f[i][0] = 0;
	}
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= sum; j++) {
			if (j - a[i - 1][1] >= 0) {
				f[i][j] = min(f[i - 1][j], a[i - 1][0] + f[i - 1][j - a[i - 1][1]]);
			} else {
				f[i][j] = f[i - 1][j];
			}
		}
	}
	int ans = 0;
	for (int j = 1; j <= sum; j++) {
		if (f[n][j] <= 1ll * w) {
			ans = max(ans, j);
		}
	}
	printf("%d\n", ans);
	return 0; 
}

Measured memory_bytes: 80128
#include<bits/stdc++.h>
using namespace std;
/**
******************* Author:Bisnu sarkar ****************************
**/
/*
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
*/
#define fRead(x)       freopen(x,"r",stdin)
#define fWrite(x)      freopen (x,"w",stdout)
#define ull            unsigned long long
#define ll             long long
#define pii            pair<int,int>
#define sit            set<int> :: iterator
#define vrit           vector<int> :: reverse iterator
#define ff             first
#define ss             second
#define endl           '\n';
#define sz(s)          (int)s.size()
#define all(s)         s.begin(),s.end()
#define IO             ios_base::sync_with_stdio(false),cin.tie(NULL);  
#define what_is(x)     cerr << #x << " is " << x << endl;
///*....Debugger....*///
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) {cout << endl;}
template<typename T, typename... Args> void err(istream_iterator<string> it, T a, Args... args) {
  cerr << *it << " = " << a << ", ";
  err(++it, args...);
}
///*....Input....*///
template <typename T> inline void Int(T &n) {
  n = 0; int f = 1; register int ch = getchar();
  for (; !isdigit(ch); ch = getchar()) if (ch == '-') f = -1;
  for (; isdigit(ch); ch = getchar()) n = (n << 3) + (n << 1) + ch - '0';
  n = n * f;
}
 
template <typename T, typename TT> inline void Int(T &n, TT &m) { Int(n); Int(m); }
template <typename T, typename TT, typename TTT> inline void Int(T &n, TT &m, TTT &l) { Int(n, m); Int(l);}
double ind(){double x; scanf("%lf",&x);return x;}

///*....Bitmask....*///
int set_1(int n,int pos){return n = (n | (1<<pos));}
int reset_0(int n,int pos){return n= n & ~(1<<pos);}
bool check_bit(int n,int pos){return n = n & (1<<pos);}

int dx[8]= {1,0,-1,0,-1,-1,1,1};
int dy[8]= {0,1,0,-1,-1,1,-1,1};

///*....Constraints....*///
const int N = (int) 1e6 + 5;
const int M = (int) 1e9 + 7;
const double pi=2* acos(0.0);
const double eps=1e-9;


int main()
{
    int t=1,te=0;
    //Int(t);
    while(t--){
      ll x;
      Int(x);

      ll k=26;

      string res="";
      while(x>0){
        res+= ((x%k==0?25:(x%k - 1)) +'a');
        if(x%k==0){
          x=x/26 - 1;
        }
        else{
          x=x/26;
        }
        
       // k*=26;
      }
      reverse(all(res));
      cout<<res<<endl;

        //printf("Case %d: ",++te);
    }
    return 0;
}






Measured memory_bytes: 3600
#include<stdio.h>

int main(){
    int x, y;
    for(int i = 0; i < 3000; i++){
        scanf("%d %d", &x, &y);
        if(x == 0 && y == 0) break;
        if(x >= y){
            printf("%d %d\n", y, x);
        }
        else{
            printf("%d %d\n", x, y);
        }
    }
}


Measured memory_bytes: 2012
// #define _GLIBCXX_DEBUG
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
using ll = long long; using ull = unsigned long long;
using pii = pair<int, int>; using vi = vector<int>; using vvi = vector<vi>; using puu = pair<uint, uint>; using vu = vector<uint>; using vvu = vector<vu>;
using pll = pair<ll, ll>; using vl = vector<ll>; using vvl = vector<vl>; // using pulul = pair<ull, ull>; using vul = vector<ull>; using vvul = vectro<vul>;
using vb = vector<bool>; using vvb = vector<vb>;
#define rep0(TMS) for (int CNT = 0; CNT < (int)(TMS); CNT++)
#define rep(CNT, GOAL) for (int CNT = 0; CNT < (int)(GOAL); CNT++)
#define rep2(CNT, START, GOAL) for (int CNT = (int)(START); CNT < (int)(GOAL); CNT++)
#define rep3(CNT, START, GOAL) for (int CNT = (int)(START); CNT > (int)(GOAL); CNT--)
#define all(CONT) begin(CONT), end(CONT)
template <typename T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template <typename T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; }
void prec(const int &DIG) { cout << fixed << setprecision(DIG); cerr << fixed << setprecision(DIG); }
template <typename T> void CERR(const T &ELEM) { cerr << ELEM; }
#define dbl(OBJ) cerr << #OBJ << ": "; CERR(OBJ); cerr << "\n"
template <typename T, typename ...Ts> void CERR(const T &FIRST, const Ts &...REST) { CERR(FIRST); cerr << ", "; CERR(REST...); }
#define dbs(...) cerr << "(" << #__VA_ARGS__ << "): ("; CERR(__VA_ARGS__); cerr << ")\n"
#define itrep(ITR, CONT) for (auto ITR = begin(CONT); ITR != end(CONT); ITR++)
template <typename T> void CERR(const vector<T> &VEC) { cerr << "{ "; itrep(ITR, VEC) { CERR(*ITR); cerr << ", "; } cerr << "}"; }
#define YN(FLG) cout << (FLG ? "YES" : "NO") << "\n"
#define Yn(FLG) cout << (FLG ? "Yes" : "No") << "\n"
#define yn(FLG) cout << (FLG ? "yes" : "no") << "\n"

#include <atcoder/all>

using namespace atcoder;

const ll INF = LONG_LONG_MAX;
// const int INF = INT_MAX;
// const ll MOD = 1000000007; // 998244353;

vector<pll> pf(ll x) {
	vector<pll> res;
	ll p = 2;
	while (p * p <= x) {
		if (x % p == 0) {
			ll d = 0;
			while (x % p == 0) {
				x /= p;
				d++;
			}
			res.push_back(pll(p, d));
		}
		p++;
	}
	if (x > 1) res.push_back(pll(x, 1));
	return res;
}

ll solve(int i, vl &m) {
	vl r; // 余り(0 or -1)
	rep(j, m.size()) {
		if (i & (1 << j)) {
			r.push_back(m[j] - 1);
		} else {
			r.push_back(0);
		}
	}
	// dbl(i); dbl(r);
	auto [res, M] = crt(r, m);
	// dbs(res, M);
	return res;
}

int main() {
	ll N; cin >> N;
	vector<pll> v = pf(N * 2); // 2Nの素因数分解
	int d = v.size(); // 2Nの異なる素因数の個数
	// rep(i, d) {
	// 	dbs(v[i].first, v[i].second);
	// }
	vl m; // 法
	rep(i, d) {
		ll t = 1;
		rep0(v[i].second) t *= v[i].first; // p^d
		m.push_back(t);
	}
	// dbl(m); // 法
	ll ans = INF;
	rep2(i, 1, 1 << d) { // 0以外の2^d-1通り試す
		chmin(ans, solve(i, m)); // i(に対応するベクトル),法
	}
	cout << ans << endl;
}

Measured memory_bytes: 3640
#include <stdio.h>
#define N 10

int main()
{
  int i,j;
  char str[N+1];
  while (scanf("%s",str)!=EOF){
    for (i=0;i<N;i++){
      for (j=0;j<N-i-1;j++){
        str[j]=((str[j]-'0')+(str[j+1]-'0'))%10+'0';
      }
    }
    printf("%d\n",str[0]-'0');
  }

  return 0;
}

Measured memory_bytes: 540
#include <iostream>
    #include <vector>
    #include <string>
    #include <algorithm>
    #include<set>
    #include <unordered_map> 
    #include <cmath>
    using namespace std;
   #define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main(void){

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

    string str;
    cin >> str;

    if(str=="ABC"){
        cout << "ARC";
    }else{
        cout << "ABC";
    }


    return 0;
}

Measured memory_bytes: 3648
N = int(input())
S = input()
Pin = ['{0:03d}'.format(a) for a in range(0,1000)]
cnt = 0
for i in Pin:
  S1 = S
  A1 = S1.find(i[0])
  if A1!=-1:
    S2 = S1[(A1+1):]
    A2 = S2.find(i[1])
    if A2!=-1:
      S3 = S2[(A2+1):]
      A3 = S3.find(i[2])
      if A3!=-1:
        cnt +=1
print(cnt)


Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std::literals::string_literals;
using i64 = long long;
using std::cout;
using std::endl;
using std::cin;

template<typename T>
std::vector<T> make_v(size_t a){return std::vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return std::vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

int main() {
	int n; scanf("%d", &n);
	auto A = make_v<int>(n, n);
	for(int i = 0; i < n; i++) for(int j = 0; j < n - 1; j++) {
		scanf("%d", &A[i][j]);
		A[i][j]--;
	}
	
	int tmp = 0;
	auto edge = make_v<int>(n, n);
	for(int i = 0; i < n; i++) for(int j = 0; j < n; j++) {
		edge[i][j] = edge[j][i] = tmp++;
	}

	std::vector<int> h(tmp, 0);
	std::vector<std::vector<int>> g(tmp);
	for(int i = 0; i < n; i++) {
		for(int j = 0; j < n - 2; j++) {
			int X = edge[i][A[i][j]];
			int Y = edge[i][A[i][j + 1]];
			g[X].push_back(Y);
			h[Y]++;
		}
	}

	std::vector<int> vec;
	std::vector<int> d(tmp, 1);
	[&vec, g, tmp, &h, &d] {
		std::queue<int> qu;
		for(int i = 0; i < tmp; i++) if(!h[i]) qu.push(i);
		while(!qu.empty()) {
			auto p = qu.front(); qu.pop();
			vec.push_back(p);

			for(auto e: g[p]) {
				h[e]--;
				
				d[e] = std::max(d[e], d[p] + 1);
				if(!h[e]) qu.push(e);
			}
		}
	}();

	if(vec.size() != tmp) {
		printf("-1\n");
		return 0;
	}

	int ans = 0;
	std::for_each(begin(d), end(d), [&ans](auto x) { ans = std::max(ans, x); });
	printf("%d\n", ans);
	return 0;
}


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

typedef long long LL;
typedef long double LD;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;
typedef pair<LD, LD> PDD;

#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
#define dbl(k, x) fixed << setprecision(k) << (x)

template <typename _T>
inline void _DBG(const char *s, _T x) {
  cerr << s << " = " << x << "\n";
}
template <typename _T, typename... args>
void _DBG(const char *s, _T x, args... a) {
  while (*s != ',') cerr << *s++;
  cerr << " = " << x << ',';
  _DBG(s + 1, a...);
}

#define _upgrade                \
  ios_base::sync_with_stdio(0); \
  cin.tie(0);                   \
  cout.tie(0);
#define DBG(...) _DBG(#__VA_ARGS__, __VA_ARGS__)

// ********************** CODE ********************** //

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

int main() {
  _upgrade;
  LL n, k;
  cin >> n >> k;
  n %= k;
  cout << min(n, abs(n - k)) << '\n';
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < int(n); i++)
using namespace std;
using ll = long long;
const int INF = (1<<30)-1;
const long long LINF = (1LL<<62)-1;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, x, t;
  cin >> n >> x >> t;
  cout << (n+x-1)/x*t << endl;
  return 0;
}

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

int main(void) {
    int h, w;
    cin >> h >> w;
    vector<int> dx = {1, 1, 0, -1, -1, -1, 0, 1};
    vector<int> dy = {0, 1, 1, 1, 0, -1, -1, -1};
    vector<string> board;
    for (int i = 0; i < h; i++) {
        string s;
        cin >> s;
        board.push_back(s);
    }
    for (int y = 0; y < h; y++) {
        for (int x = 0; x < w; x++) {
            if (board.at(y).at(x) == '#') continue;
            int n = 0;
            for (int di = 0; di < 8; di++) {
                if (x + dx.at(di) < 0 || w <= x + dx.at(di)) continue;
                if (y + dy.at(di) < 0 || h <= y + dy.at(di)) continue;
                if (board.at(y + dy.at(di)).at(x + dx.at(di)) == '#') {
                    n++;
                }
            }
            board.at(y).at(x) = '0' + n;
        }
    }
    for (auto &&i : board) {
        cout << i << endl;
    }
    return 0;
}

Measured memory_bytes: 3600
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD=1e9+7;
const int INF=1e9;

int m[100000][40];

int main(){
    string s,t;
    cin>>s>>t;
    int p[40];
    memset(m,-1,sizeof(m));
    memset(p,-1,sizeof(p));
    for(int i=s.size()-1;i>=0;i--){
        for(int j='a';j<='z';j++){
            m[i][j-'a']=p[j-'a'];
        }
        p[s[i]-'a']=i;
    }
    for(int i=s.size()-1;i>=0;i--){
        for(int j='a';j<='z';j++){
            m[i][j-'a']=p[j-'a'];
        }
        p[s[i]-'a']=i;
    }
    int prev=m[s.size()-1][t[0]-'a'];
    if(prev==-1){
        cout<<-1<<endl;
        return 0;
    }
    ll ans=prev+1;
    for(int i=1;i<t.size();i++){
        int n=m[prev][t[i]-'a'];
        if(n==-1){
            cout<<-1<<endl;
            return 0;
        }
        else if(n<=prev){
            ans+=s.size()-prev+n;
            prev=n;
        }
        else{
            ans+=n-prev;
            prev=n;
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 16256
#include<stdio.h>
#include<stdlib.h>

typedef struct{
	int h;
	int p;
	int q;
} amida;

int cmph(const void* a,const void* b){
	return ((amida*)b)->h - ((amida*)a)->h;
}

int main(){
	int n,m,a,i,tmp;
	amida line[1000];
	while(scanf("%d %d %d",&n,&m,&a)!=0 && (n!=0) && (m!=0) && (a!=0)){
		for(i=0;i<m;i++){
			scanf("%d %d %d",&(line[i].h),&(line[i].p),&(line[i].q));
		}
		qsort(line,m,sizeof(amida),cmph);
		for(i=0;i<m;i++){
			if(line[i].p==a){
				a=line[i].q;
			}else if(line[i].q==a){
				a=line[i].p;
			}
		}
		printf("%d\n",a);
	}
	return 0;
}
		

Measured memory_bytes: 672
s = [_ for _ in input()]
qn = int(input())
rev = False
prevs = ['']*200000
nexts = ['']*200000
previ = 0
nexti = 0

for _ in range(qn):
  q = [_ for _ in input().split()]
  if q[0] == '1':
    rev = not rev
  else:
    if (rev and q[1] == '2') or (not rev and q[1] == '1'):
      prevs[previ] = q[2]
      previ += 1
    else:
      nexts[nexti] = q[2]
      nexti += 1

prevs.reverse()
s = prevs + s + nexts
if rev:
  s.reverse()
print("".join(s))

Measured memory_bytes: 13348
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007 

int main() {
	ll n,cnt=0,MIN=INF,ans=0;
	cin>>n;
	for(int i=0;i<n;i++){
		ll z;
		cin>>z;
		if(z<0){
			cnt++;
		}
		z=abs(z);
		MIN=min(MIN,z);
		ans+=z;
	}
	if(cnt%2==1){
		ans-=2*MIN;
	}
	cout<<ans;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>
#include <fstream>
#include <bitset>
#include <time.h>
#include <tuple>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef complex<double> Point;

#define PI acos(-1.0)
#define EPS 1e-10
const ll INF = (1LL << 60) - 1;
const ll MOD = 1e9 + 7;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,N) for(int i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
#define EQV(a,b) ( EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()) )
#define fi first
#define se second
#define N_SIZE (1LL << 20)
#define NIL -1
#define MAX_N 100100 * 3

int a, b;

int main() {
	cin >> a >> b;
	if (a % 3 == 0 || b % 3 == 0 || (a + b) % 3 == 0)cout << "Possible" << endl;
	else cout << "Impossible" << endl;
}

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

#define MAX_N 100001

vector<pair<int, int> > adj[MAX_N];
int64_t dis[MAX_N];
bool vis[MAX_N];

void dfs(int v)
{
    vis[v] = true;
    for (int i = 0; i < adj[v].size(); i++) {
        int u = adj[v][i].first;
        int w = adj[v][i].second;
        if (!vis[u]) {
            dis[u] = dis[v] + w;
            dfs(u);
        }
    }
}

int main(void)
{
    int n, k, q;
    scanf("%d", &n);
    for (int i = 1; i < n; i++) {
        int a, b, c;
        scanf("%d%d%d", &a, &b, &c);
        adj[a].push_back(make_pair(b, c));
        adj[b].push_back(make_pair(a, c));
    }
    scanf("%d%d", &q, &k);
    dfs(k);
    while (q--) {
        int x, y;
        scanf("%d%d", &x, &y);
        printf("%lld\n", dis[x] + dis[y]);
    }
    return 0;
}

Measured memory_bytes: 12800
#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;
}

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

  Int n;
  cin>>n;
  auto as=read(n);
  Int ans=0,pre=0;
  for(Int a:as){
    chmax(pre,a);
    ans+=pre-a;
  }
  cout<<ans<<newl;
  return 0;
}


Measured memory_bytes: 4680
sx, sy, tx, ty = map(int, input().split())
for _ in range(ty-sy):
  print('U', end='')
for _ in range(tx-sx):
  print('R', end='')
for _ in range(ty-sy):
  print('D', end='')
for _ in range(tx-sx+1):
  print('L', end='')
for _ in range(ty-sy+1):
  print('U', end='')
for _ in range(tx-sx+1):
  print('R', end='')
print('DR',end='')
for _ in range(ty-sy+1):
  print('D', end='')
for _ in range(tx-sx+1):
  print('L', end='')
print('U')

Measured memory_bytes: 9308
import math
from functools import reduce
from collections import deque
import sys
sys.setrecursionlimit(10**7)

# スペース区切りの入力を読み込んで数値リストにして返します。
def get_nums_l():
    return [ int(s) for s in input().split(" ")]

# 改行区切りの入力をn行読み込んで数値リストにして返します。
def get_nums_n(n):
    return [ int(input()) for _ in range(n)]

# 改行またはスペース区切りの入力をすべて読み込んでイテレータを返します。
def get_all_int():
    return map(int, open(0).read().split())

def log(*args):
    print("DEBUG:", *args, file=sys.stderr)

n,k,c = get_nums_l()
s = input()

ox = [ c=="o" for c in s ]
work = [False] * (n)
count = 0
prev = -99999999999999
for i,o in enumerate(ox):
    if o:
        if i-prev > c:
            work[i] = True
            prev = i
            count += 1
            if count == k:
                break

# log("ox", ox)
# log("work", work)

kouho = None
last_work = 9999999999999
ans = []
for i in range(n-1, -1, -1):
    if work[i]:
        if kouho == None:
            # log(i, "req")
            ans.append(i+1)
            last_work = i
        else:
            # log(i, "change")
            last_work = kouho
            kouho = None

    if not kouho and ox[i] and last_work-i>c:
        # log(i, "kouho")
        kouho = i

print("\n".join(map(str, sorted(ans))))


Measured memory_bytes: 81488
n = int(input())
if n < 3:
  print(0)
  exit()
l = map(int,input().split())
l = sorted(l)
c = 0
for i in range(n-2):
  for j in range(i+1,n-1):
    for k in range(j+1,n):
      if l[i] + l[j] > l[k] and l[i] != l[j] and l[j] != l[k]:
        c += 1
print(c)


Measured memory_bytes: 9216
#include <iostream>
#include <vector>
#include <complex>

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

  std::vector<int> v(n);
  for (int &i : v) {
    std::cin >> i;
  }

  std::sort(v.begin(), v.end());
  int a = INT_MAX;
  for (int i = v.at(0); i <= v.at(v.size() - 1); ++i) {
    int sum = 0;
    for (const int j : v) {
      sum += std::pow(j - i, 2);
    }
    if (sum < a) {
      a = sum;
    }
  }

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


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

int main(void) {
	int a, b, k;
	cin >> a >> b >> k;
	set<int> st;
	for (int i = a; i < a + k; i++) {
		if (b < i)break;
		st.insert(i);
	}
	for (int i = b; i > b - k; i--) {
		if (i < a)break;
		st.insert(i);
	}
	for (auto x:st) {
		cout << x << endl;
	}
	return 0;
}


Measured memory_bytes: 256
using System;

class Atcoder88
{
    public static void Main()
    {
        string[] input = Console.ReadLine().Split(' ');
        int a = int.Parse(input[0]);
        int b = int.Parse(input[1]);

        if (a <= 8 && b <= 8)
            Console.WriteLine("Yay!");
        else
            Console.WriteLine(":(");
    }
}

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

namespace AtCoder
{
	class Program
	{
		static void Main(string[] args)
		{
			int n = int.Parse(Console.ReadLine());

			int[] arr = Console.ReadLine().Trim().Split(' ').Select(hogehoge => int.Parse(hogehoge)).ToArray<int>();

			Array.Sort(arr);

			decimal tmp = arr[0];


			for (int i = 0; i < n; i++)
			{
				tmp = (tmp + arr[i]) / 2;
			}

			Console.WriteLine(tmp);
		}
	}
}


Measured memory_bytes: 13396
#include <cstdio>
using namespace std;
int n,k;
int a[200005];
int main(){
	scanf("%d%d",&n,&k);
	for(int i=0;i<n;++i){
		scanf("%d",a+i);
		if(i>=k){
			if(a[i-k]<a[i]){
				printf("Yes\n");
			}else{
				printf("No\n");
			}
		}
	}
	return 0;
}

Measured memory_bytes: 2396
s=list(input())
t=list(reversed(s))
p=s[:(len(s) - 1) // 2]
q=list(reversed(p))
#r=s[(len(s) - 1) // 2:]
#u=list(reversed(r))
if s == t:
    if p == q:
        
        print("Yes")
        
    else:
        print("No")
    
else:
    print("No")

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

int main(){
	string s;
	int index;
	cin >> s;
	int start = 0;
	int count = 0;
	for(int i = 0; i < s.size(); i++){
		char t = s[i];
		switch(t){
			case 'A':
				index = 0;
				break;
			case 'B':
				index = 1;
				break;
			case 'C':
				index = 2;
				break;
			case 'D':
				index = 3;
				break;
			case 'E':
				index = 4;
				break;
			case 'F':
				index = 5;
				break;
			case 'G':
				index = 6;
				break;
			case 'H':
				index = 7;
				break;
			case 'I':
				index = 8;
				break;
			case 'J':
				index = 9;
				break;
			case 'K':
				index = 10;
				break;
			case 'L':
				index = 11;
				break;
			case 'M':
				index = 12;
				break;
			case 'N':
				index = 13;
				break;
			case 'O':
				index = 14;
				break;
			case 'P':
				index = 15;
				break;
			case 'Q':
				index = 16;
				break;
			case 'R':
				index = 17;
				break;
			case 'S':
				index = 18;
				break;
			case 'T':
				index = 19;
				break;
			case 'U':
				index = 20;
				break;
			case 'V':
				index = 21;
				break;
			case 'W':
				index = 22;
				break;
			case 'X':
				index = 23;
				break;
			case 'Y':
				index = 24;
				break;
			case 'Z':
				index = 25;
				break;
		}
		if(index <= start){
			count++;
		}
		start = index;
	}
	cout << count << endl;
}

Measured memory_bytes: 3164
#include <bits/stdc++.h>
using namespace std;
 
int main() {

  bool can=false;
  
  int64_t A,B,C;

  cin >> A >> B >> C ;

  int64_t ans=0;

  for(int i=1;i<=100000;i++){
    int64_t x=(int64_t)A*i;
    if(x%B==C){can=true; break;}
  }

  if(can) cout << "YES" << endl;
  else cout << "NO" << endl;
  
  return 0;
}

Measured memory_bytes: 256
n=int(input())
A=list(map(int,input().split()))
A=sorted(A)
B=list(map(int,input().split()))
B=sorted(B)
C=list(map(int,input().split()))
C=sorted(C)
def ais_ok(i,b):
    if i<-1: #all ng ok=-1
        return True
    if n<=i: #all ok ng=n
        return False
    return A[i]<b #okになる条件
def cis_ok(i,b):
    if i<-1: #all ok ng=-1
        return False
    if n<=i: #all ng ok=n
        return True
    return b<C[i]
ans=0
for i in range(n):
    b=B[i]
    ok_a,ng_a=-1,n
    ok_c,ng_c=n,-1
    while (ng_a-ok_a)>1:
        mid=(ok_a+ng_a)//2
        if ais_ok(mid,b):
            ok_a=mid
        else:
            ng_a=mid
    while (ok_c-ng_c)>1:
        mid=(ok_c+ng_c)//2
        if cis_ok(mid,b):
            ok_c=mid
        else:
            ng_c=mid
    ans+=(ok_a+1)*(n-(ng_c+1))
print(ans)

Measured memory_bytes: 107108
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>

using namespace std;

#define rep(i,j) REP((i), 0, (j))
#define REP(i,j,k) for(int i=(j);(i)<(k);++i)
#define BW(a,x,b) ((a)<=(x)&&(x)<=(b))
#define ALL(v) (v).begin(), (v).end()
#define LENGTHOF(x) (sizeof(x) / sizeof(*(x)))
#define AFILL(a, b) fill((int*)a, (int*)(a + LENGTHOF(a)), b)
#define SQ(x) ((x)*(x))
#define Mod(x, mod) (((x)+(mod)%(mod))
#define MP make_pair
#define PB push_back
#define Fi first
#define Se second
#define INF (1<<29)
#define EPS 1e-10
#define MOD 1000000007

typedef pair<int, int> pi;
typedef pair<int, pi> pii;
typedef vector<int> vi;
typedef queue<int> qi;
typedef long long ll;

ll N[8], S;


int main(){
  int D;
  scanf("%d", &D);
  rep(d, D){
    for(int i=0;i<8;i++) scanf("%llx", &N[i]);
    scanf("%llx", &S);
    ll res = 0;
    for(int i=0;i<32;i++){
      ll sum = 0; rep(j, 8) sum += (N[j]^res);

      if((sum&(1LL<<i)) != (S&(1LL<<i))) res |= (1LL<<i);
      //      cout << res << endl;      
    }
    printf("%llx\n", res);    
  }


  return 0;
}

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

#define INF 1001001001
#define LINF 1001001001001001001
#define MOD 1000000007
#define MOD2 998244353

template<class T,class U>bool chmax(T &a, const U &b){if(a<b){a=b;return 1;}return 0;}
template<class T,class U>bool chmin(T &a, const U &b){if(b<a){a=b;return 1;}return 0;}

#define rep(i,n) for(int i=0,_i=(n);i<_i;++i)
#define rep1(i,a,b) for(int a_=(a),b_=(b),i=a_;i<b_;++i)
#define repr(i,n) for(int _i=(n),i=_i;i>0;--i)

#define db(x) cerr<<#x<<" = "<<x<<" ";
#define db2(x,y) cerr<<"("<<#x<<", "<<#y<<") = ("<<x<<", "<<y<<") ";
#define db3(x,y,z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = ("<<x<<", "<<y<<", "<<z<<") ";
#define ln cout<<endl;

#define all(a)  (a).begin(),(a).end()
#define dig(n)  to_string(n).length()

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define se second
#define fi first

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<pii,pii> ppii;

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

int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

int main(){
    bool flag=true;
    ll ans=0,sum=0;

    ll n,m;
    string s,t;
    cin >>n>>m;
    cin>>s>>t;

    ll L=lcm(n,m);
    ll G=gcd(n,m);

    ll d=lcm(m/G,n/G);

    rep(i,G){
        ll li=i;
        //db2((m/G)*i,(n/G)*i);ln;
        //cout<<s[(n/G)*i] << t[(m/G)*i]<<endl;

        if(s[(n/G)*li] != t[(m/G)*li]){
            flag=false;
            break;
        }
    }


    //cout <<fixed<<setprecision(16)<< << endl;
    //cout<<ans<<endl;
    if(flag)cout << L <<endl;
    else cout << "-1" <<endl;
    
    return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
string a[26][26];
signed main(){
	int h,w,cnt=0;
	cin>>h>>w;
		rep(i,h){
			rep(j,w){
				cin>>a[i][j];
			}
		}
		rep(i,h){
			rep(j,w){
				if(a[i][j]=="snuke")cout<<char(j+'A')<<i+1<<endl;
			}
		}
}
		
		


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

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)
#define unless(p) if(!(p))
#define until(p) while(!(p))

using ll = std::int64_t;
using P = std::tuple<int,int>;

int M, D;

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

  std::cin >> M >> D;

  int res = 0;
  for(int i=1;i<=M;++i){
      for(int j=10;j<=D;++j){
          int j1 = j % 10, j10 = j / 10;

          if(j1 >= 2 && j10 >= 2 && j1 * j10 == i){
              res += 1;
          }
      }
  }

  std::cout << res << std::endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i = 0; i < (n); i++)
int main(){
  int K,A,B;
  cin >> K >> A >> B;
  for (int i = 1;i*K<=B;i++){
  	if (A<=i*K){
    	cout << "OK" << endl;
      return 0;
    }
  }
  	cout << "NG" << endl;
    
  
}

Measured memory_bytes: 3588
import sys
input = sys.stdin.buffer.readline

class Combination:
    def __init__(self, size, mod=10**9 + 7):
        self.size = size + 2
        self.mod = mod
        self.fact = [1, 1] + [0] * size
        self.factInv = [1, 1] + [0] * size
        self.inv = [0, 1] + [0] * size

        for i in range(2, self.size):
            self.fact[i] = self.fact[i - 1] * i % self.mod
            self.inv[i] = -self.inv[self.mod % i] * (self.mod // i) % self.mod
            self.factInv[i] = self.factInv[i - 1] * self.inv[i] % self.mod

    def npr(self, n, r):
        if n < r or n < 0 or r < 0:
            return 0
        return self.fact[n] * self.factInv[n - r] % self.mod

    def ncr(self, n, r):
        if n < r or n < 0 or r < 0:
            return 0
        return self.fact[n] * (self.factInv[r] * self.factInv[n - r] % self.mod) % self.mod

    def nhr(self, n, r):  # 重複組合せ
        return self.ncr(n + r - 1, n - 1)

    def factN(self, n):
        if n < 0:
            return 0
        return self.fact[n]

    def factInvN(self, n):
        if n < 0:
            return 0
        return self.factInv[n]

N = int(input())
MOD = 10**9 + 7
comb = Combination(N + 100)

edges = [[] for _ in range(N + 1)]
for _ in range(N - 1):
    fr, to = map(int, input().split())
    edges[fr].append(to)
    edges[to].append(fr)

order = []
parent = [0] * (N + 1)
st = [1]
while st:
    now = st.pop()
    order.append(now)
    for to in edges[now]:
        if to == parent[now]:
            continue
        st.append(to)
        parent[to] = now

size = [1] * (N + 1)
for v in order[::-1]:
    size[parent[v]] += size[v]

dpLeaf = [1] * (N + 1)
for v in order[:: -1]:
    pr = parent[v]
    dpLeaf[v] = dpLeaf[v] * comb.factN(size[v] - 1) % MOD
    dpLeaf[pr] = dpLeaf[pr] * dpLeaf[v] * comb.factInvN(size[v]) % MOD

ans = [0] * (N + 1)
ans[1] = dpLeaf[1]
for v in order[1:]:
    pr = parent[v]
    ans[v] = ans[pr] * comb.inv[N - size[v]] * size[v] % MOD

print(*(ans[1:]), sep='\n')

Measured memory_bytes: 86616
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
const int maxn = 2e5 + 7;
const double pi = acos(-1);

int main(){
	int n,p;
	scanf("%d %d",&n,&p);
	string s;
	cin >> s;
	ll ans = 0;
	if(p == 2){
		ll m = 0;
		for(int i = 0;i < s.size();i++){
			if(s[i]=='2'||s[i]=='0'||s[i]=='4'||s[i]=='6'||s[i]=='8'){
				m += (i+1);
			}
		}
		ans = m;
	}else if(p == 5){
		ll m = 0;
		for(int i = 0;i < s.size();i++){
			if(s[i]=='5'||s[i]=='0'){
				m += (i+1);
			}
		}
		ans = m;
	}else{
		map<ll,ll> mp;
		mp[0]++;
		ll num = 0;
		ll r = 1;
		for(int i = n-1;i >=0;i--){
			num += (s[i] - '0') * r;
			ll k = num % p;
			ans += mp[k];
			mp[k]++;
			r = r * 10 % p;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1028
import numpy as np
i4 = np.int32

nin = np.fromstring(open(0).read(), i4, sep=' ')
N = nin[0]
ab = nin[1:].reshape(-1, 2).T
a = np.sort(ab[0])
b = np.sort(ab[1])
i = N // 2
if N % 2:
    print(b[i] - a[i] + 1)
else:
    nmin = a[i - 1] + a[i]
    nmax = b[i - 1] + b[i]
    print(nmax - nmin + 1)


Measured memory_bytes: 34532
#include <bits/stdc++.h>
using namespace std;
int n, m, a[120], b[120], p = 1000000007;
int c[32777], d[32777], t[120];
long long f[2][32777], z;
int main() {
	scanf("%d%d", &n, &m);
	for (int i = t[0] = 1; i <= 105; i++) {
		t[i] = t[i - 1] * 2 % p;
	}
	for (int i = 0; i < m; i++) {
		scanf("%d%d", &a[i], &b[i]);
		a[i]--;
		b[i]--;
	}
	for (int i = 0; i < 1 << n; i++) {
		for (int j = 0; j < m; j++) {
			if ((i >> a[j] & 1) & (i >> b[j] & 1)) {
				c[i]++;
			}
			if ((i >> a[j] & 1) | (i >> b[j] & 1)) {
				d[i]++;
			}
		}
	}
	for (int i = 0; i < 2; i++) {
		for (int j = 0; j < 1 << n; j++) {
			if (~j >> i & 1) {
				continue;
			}
			f[i][j] = t[c[j]];
			for (int k = j; k > 0; k = (k - 1) & j) {
				f[i][j] = (f[i][j] + p - f[i][j - k] * t[c[k]]) % p;
			}
		}
	}
	for (int i = 0; i < 1 << n; i++) {
		for (int j = 0; j < 1 << n; j++) {
			if ((i & j) || c[i] + c[j] != c[i | j]) {
				continue;
			}
			z = (z + f[0][i] * f[1][j] % p * t[m - d[i | j]]) % p;
		}
	}
	printf("%d\n", (t[m] + p - z) % p);
}

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

int main() {
    string s, t, u;
    int a, b;
    map<string, int> m;
    cin >> s >> t >> a >> b;
    m[s] = a;
    m[t] = b;
    cin >> u;
    m[u] -= 1;
    cout << m[s] << " " << m[t] << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
using P = pair<int, int>;

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

  int N, M; cin >> N >> M;
  vector<P> v(M);
  for (int i = 0; i < M; i++) {
    int a, b; cin >> a >> b;
    v[i] = P(a, b);
  }
  sort(v.begin(), v.end(), [](P p1, P p2) {
    return p1.second < p2.second;
  });

  int ans = 0, bridge = 0;
  for (int i = 0; i < M; i++) {
    if (bridge < v[i].first) {
      bridge= v[i].second - 1;
      ans++;
    }
  }
  cout << ans << "\n";
}

Measured memory_bytes: 1024
use proconio::{input, fastout};
use proconio::marker::{Chars};
use proconio::marker::Usize1;
use std::cmp::*;
use std::mem::swap;

macro_rules! debug {
      ($($a:expr),*) => {
          eprintln!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

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

    p.push(0);
    let mut cnt = 0;
    let mut flag: Vec<bool> = vec![true;n+1];
    for i in 0..n+1 {
        if p[i]==i+1 {
            flag[i] = false;
        }
    }
    for i in 0..n {
        if flag[i]==false {
            p.swap(i,i+1);
            cnt += 1;
            if p[i+1]==i+2 {
                flag[i+1] = false;
            } else {
                flag[i+1] = true;
            }
        } 
    }
    println!("{}", cnt);
}


Measured memory_bytes: 3628
use std::io;
#[allow(dead_code)]
fn read<T: std::str::FromStr>() -> T {
    let mut n = String::new();
    io::stdin().read_line(&mut n).unwrap();
    n.trim().parse().ok().unwrap()
}
#[allow(dead_code)]
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    let mut n = String::new();
    io::stdin().read_line(&mut n).unwrap();
    n.trim()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

fn main() {
    let input: Vec<f64> = read_vec();
    let x1 = input[0];
    let y1 = input[1];
    let x2 = input[2];
    let y2 = input[3];
    println!("{}", ((x1 - x2).powi(2) + (y1 - y2).powi(2)).sqrt());
}



Measured memory_bytes: 5056
#include <bits/stdc++.h>
 
using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
template<class T> using V = vector<T>;
template<class T> using VV = V<V<T>>;
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n-1); }
 
template <class T> ostream& operator<<(ostream& os, const V<T>& v) {
    os << "[";
    for (auto d : v) os << d << ", ";
    return os << "]";
}
 
template <class T, class U>
ostream& operator<<(ostream& os, const pair<T, U>& p) {
    return os << "P(" << p.first << ", " << p.second << ")";
}
 
template <uint MD> struct ModInt {
    using M = ModInt;
    uint v;
    ModInt() : v(0) {}
    ModInt(ll _v) { set_v(_v % MD + MD); }
    M& set_v(uint _v) {
        v = (_v < MD) ? _v : _v - MD;
        return *this;
    }
    explicit operator bool() const { return v != 0; }
    M operator-() const { return M() - *this; }
    M operator+(const M& r) const { return M().set_v(v + r.v); }
    M operator-(const M& r) const { return M().set_v(v + MD - r.v); }
    M operator*(const M& r) const { return M().set_v(ull(v) * r.v % MD); }
    M operator/(const M& r) const { return *this * r.inv(); }
    M& operator+=(const M& r) { return *this = *this + r; }
    M& operator-=(const M& r) { return *this = *this - r; }
    M& operator*=(const M& r) { return *this = *this * r; }
    M& operator/=(const M& r) { return *this = *this / r; }
    M pow(ll n) const {
        M x = *this, r = 1;
        while (n) {
            if (n & 1) r *= x;
            x *= x;
            n >>= 1;
        }
        return r;
    }
    M inv() const { return pow(MD - 2); }
    friend ostream& operator<<(ostream& os, const M& r) { return os << r.v; }
};
using Mint = ModInt<TEN(9) + 7>;
 
const int MF = TEN(6) + TEN(5);
V<Mint> fact(MF + 1), iFac(MF + 1);
void first() {
    fact[0] = 1;
    for (int i = 1; i <= MF; i++) fact[i] = fact[i-1] * Mint(i);
    iFac[MF] = fact[MF].inv();
    for (int i = MF; i >= 1; i--) iFac[i-1] = iFac[i] * Mint(i);
    assert((fact[114] * iFac[114]).v == 1);
}
 
Mint C(int n, int k) {
    if (n < k || n < 0) return Mint(0);
    return fact[n] * iFac[k] * iFac[n - k];
}
 
const int MN = 21;
int n;
int g[MN][MN];
Mint dp[MN][1<<MN];
bool vis[MN][1<<MN];
Mint solve(int p, int f) {
    if (p == n) return Mint(1);
    if (vis[p][f]) return dp[p][f];
    vis[p][f] = true;
    Mint sm = 0;
    for (int a = 0; a < n; a++) {
        if (f & (1<<a)) continue;
        if (!g[p][a]) continue;
        sm += solve(p + 1, f | (1<<a));
    }
    return dp[p][f] = sm;
}
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cin >> n;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            cin >> g[i][j];
        }
    }
 
    cout << solve(0, 0) << endl;
 
    return 0;
}

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

#define For(i,a,b) for(int (i) = (a);(i) < (b);i++)
#define Rep(i,n) For((i),0,(n))
#define All(a) (a).begin(),(a).end()
#define sp " "
#define INF 1e18
#define INT_INF 1e9

typedef long long ll;
const ll MOD = 1000000007;
const ll MOD_9 = 998244353;


int H,W;
int Map[2][80][80];
vector<vector<vector<bool>>> dp(80,vector<vector<bool>>(80,vector<bool>(13000,0)));


int main(){
    cin >> H >> W;
    Rep(i,H){
        Rep(j,W){
            cin >> Map[0][i][j];
        }
    }
    Rep(i,H){
        Rep(j,W){
            cin >> Map[1][i][j];
        }
    }
    dp[0][0][abs(Map[0][0][0]-Map[1][0][0])] = true;
    For(i,1,H){
        int A = Map[0][i][0];
        int B = Map[1][i][0];
        int d = abs(A-B);
        Rep(x,12800){
            if(x - d >= 0) dp[i][0][x] = dp[i-1][0][x-d];
            if(x + d <= 12800 && dp[i-1][0][x+d] == true) dp[i][0][x] = true;
            if(d - x >= 0) dp[i][0][x] = (dp[i][0][x] || dp[i-1][0][d-x]);
        }        
    }
    For(i,1,W){
        int A = Map[0][0][i];
        int B = Map[1][0][i];
        int d = abs(A-B);
        Rep(x,12801){
            if(x - d >= 0) dp[0][i][x] = dp[0][i-1][x-d];
            if(x + d <= 12800 && dp[0][i-1][x+d] == true) dp[0][i][x] = true;
            if(d - x >= 0) dp[0][i][x] = (dp[0][i][x] || dp[0][i-1][d-x]);
        }        
    }
    Rep(i,H){
        Rep(j,W){
            if(i == 0 || j == 0)continue;
            int A = Map[0][i][j];
            int B = Map[1][i][j];
            int d = abs(A-B);
            Rep(x,12801){
                if(x - d >= 0) dp[i][j][x] = (dp[i][j-1][x-d] || dp[i-1][j][x-d]);
                if(x + d <= 12800) dp[i][j][x] = (dp[i][j][x] || (dp[i][j-1][x+d] || dp[i-1][j][x+d]));
                if(d - x >= 0) dp[i][j][x] = (dp[i][j][x] || (dp[i][j-1][d-x] || dp[i-1][j][d-x]));
                //if(dp[i][j][x] == true) cout << i+1 << sp << j+1 << sp << x << endl;
            } 
        }
    }
    Rep(i,12801){
        if(dp[H-1][W-1][i] == true){
            cout << i;
            break;
        }
    }
    //cin >> H;
}

Measured memory_bytes: 11008
import java.util.*;
public class Main {

    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        System.out.println(sc.nextInt()+sc.nextInt()>=sc.nextInt()?"Yes":"No");
//        Location[] points=new Location[5];
//        for(int i=0;i<5;i++){
//            points[i]=new Location(random(0,100),random(0,100));
//        }
//        Comp c=new Comp();
//        Arrays.sort(points,c);
//        for(int i=0;i<5;i++){
//            points[i].show();
//        }
        
    }
    static int random(int rangemin,int rangemax){
        if(rangemin>=rangemax){
            return 0;
        }else{
            return (int)(rangemin+Math.random()*(rangemax-rangemin));
        }
    }
}
class Comp implements Comparator{
    @Override
    public int compare(Object a1,Object a2){
        Location b1=(Location)a1;
        Location b2=(Location)b1;
        return b1.direction()>b2.direction()?1:-1;
    }
}
class Location{
    int x;
    int y;
    public Location(int x,int y){
        this.x=x;
        this.y=y;
    }
    double direction(){
        return Math.sqrt(x*x+y*y);
    }
    void show(){
        System.out.println("("+x+","+y+")"+this.direction());
    }
}


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

int main() {
  int A,B,C,D;
  cin >>A>>B>>C>>D;
  for(int i =0;i <100;i++){
    C -= B;
    if(C <= 0){
      cout << "Yes" << endl;
      break;
    }
    A -= D;
    if(A <= 0){
      cout << "No" << endl;
      break;
    }
  } 
}

Measured memory_bytes: 3632
#include <cstdio>
#include <algorithm>
using namespace std;
using ll = long long;
struct store {
    ll a,b;
};
bool cmp(store x, store y) {
    return x.a < y.a;
}
int main() {
    ll n,m;
    scanf("%lld%lld", &n,&m);
    store *st = new store[n];
    for (int i = 0; i < n; i++) {
        scanf("%lld%lld", &(st[i].a), &(st[i].b));
    }
    sort(st, st+n,cmp);
    ll cnt = 0;
    ll m0=m;
    int i = 0;
    while (m0>0) {
        if (st[i].b >= m0) {
            cnt += m0 * st[i].a;
            m0 = 0;
        }
        else {
            cnt += st[i].b * st[i].a;
            m0 -= st[i].b;
            i++;
        }
    }
    printf("%lld\n", cnt);
    return 0;
}


Measured memory_bytes: 1792
import java.util.*;

public class Main {

    public static void main(String[] args) throws Exception {
        Scanner reader = new Scanner(System.in);
        int n = reader.nextInt();
        int W = reader.nextInt();
        int[] w = new int[n];
        int[] v = new int[n];
        for (int i = 0; i < n; ++i) {
            w[i] = reader.nextInt();
            v[i] = reader.nextInt();
        }
        System.out.println(solve(w, v, W));
    }

    private static long solve(int[] w, int[] v, int W) {
        boolean[] taken = new boolean[w.length];
        long[][] dp = new long[w.length + 1][W + 1];
        for (int i = 0; i <= w.length; ++i)
            Arrays.fill(dp[i], -1);
//        long max = calcMax(-1, w, v, W, w.length, taken, dp);
//        System.out.println(Arrays.toString(dp));
//        return max;
//        return takeNext(w, v, W, w.length, taken, dp);
        return calcMax(0, w, v, W, dp);
    }

    private static long calcMax(int ind, int[] w, int[] v, int W, int n, boolean[] taken, long[][] dp) {
        if (ind >= 0 && dp[ind][W] >= 0)
            return dp[ind][W];
        long max = 0;
        for (int i = 0; i < taken.length; ++i) {
            if (!taken[i] && (W - w[i] >= 0)) {
                taken[i] = true;
                max = Math.max(calcMax(i, w, v, W - w[i], n - 1, taken, dp), max);
                dp[i][W] = max;
                taken[i] = false;
            }
        }
        long res = max;
        if (ind >= 0) {
            res += v[ind];
//            dp[ind] = res;
        }
        return res;
//        return res;
    }

    private static long takeNext(int[] w, int[] v, int W, int count, boolean[] taken, long [][] dp) {
        if (count == 0)
            return 0;
        long maxVal = 0;
        if (dp[count][W] >= 0)
            return dp[count][W];
        for (int i = 0; i < taken.length; ++i) {
            if (taken[i] || (W - w[i] < 0))
                continue;
            taken[i] = true;
            maxVal = Math.max(maxVal, v[i] + takeNext(w, v, W - w[i], count - 1, taken, dp));
            taken[i] = false;
        }
        System.out.println("count:" + count + " W:" + W + " " + maxVal);
        dp[count][W] = maxVal;
        return maxVal;
    }

    private static long calcMax(int curIndex, int[] w, int[] v, int W, long[][] dp) {
        if (curIndex >= w.length || W == 0) {
            return 0;
        }
        if (dp[curIndex][W] >= 0)
            return dp[curIndex][W];
        long profit1 = 0;
        if (w[curIndex] <= W)
            profit1 = v[curIndex] + calcMax(curIndex + 1, w, v, W - w[curIndex], dp);
        long profit2 = calcMax(curIndex + 1, w, v, W, dp);
        long res = Math.max(profit1, profit2);
        dp[curIndex][W] = res;
        return res;
    }
}


Measured memory_bytes: 129492