akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef int64_t i6;

#define rep(i, n) for (ll i = 0; i < n; ++i)
#define rep2(i, n) for (ll i = 1; i <= n; ++i)
#define Sort(x) sort(x.begin(), x.end())
#define Sort_rev(x) sort(x.begin(), x.end(), greater<int>())
#define ALL(v) (v).begin(), (v).end()

// π M_PI
// deg = rad*180/M_PI

int main() {
    string s;
    cin >> s;
    ll q;
    cin >> q;
    ll num[q];
    ll f[q];
    char c[q];

    rep(i, q) {
        cin >> num[i];
        if ( num[i] == 2 ) {
            cin >> f[i] >> c[i];
        }
    }
    ll top = 0;
    rep(i, q) {
        if ( num[i] == 1 ) {
            top = !top;
        } else {
            if (top) {
                if ( f[i] == 1 ) {
                    s.insert(s.end(), c[i]);
                } else {
                    s.insert(s.begin(), c[i]);
                }
            } else {
                if ( f[i] == 1 ) {
                    s.insert(s.begin(), c[i]);
                } else {
                    s.insert(s.end(), c[i]);
                }
            }
        }
    }

    if (top) {
        reverse(ALL(s));
    }
    cout << s << endl;
    return 0;
}


Measured memory_bytes: 4228
function Main(input) {
  input = input.split("\n");
  var n = parseInt(input[0].split(" ")[0]);
  var k = parseInt(input[0].split(" ")[1]);
  x = new Array(n).fill(0);
  tmp = input[1].split(" ");
  var plus=0;
  var minus=0;
  for(i=0;i<n;i++){
    x[i]=parseInt(tmp[i]);
    if(x[i]>0){
      plus++;
    }else if(x[i]<0){
      minus++;
    }
  }
  var ans=Math.pow(10,9)+7;
  if(x.indexOf(0)!=-1){
    n-=1;
    k-=1;
    x.splice(x.indexOf(0),1);
  }
  if(x.length==0){
    ans=0;
  }else{
    for(i=0;i<n-k+1;i++){
      if(x[i]<0&&x[i+k-1]>0){
        ans=Math.min(ans,Math.abs(x[i])*2+x[i+k-1],Math.abs(x[i])+x[i+k-1]*2);
      }else if(i==minus-k){
        ans=Math.min(ans,Math.abs(x[i]));
      }else if(i==minus){
        ans=Math.min(ans,x[i+k-1]);
      }
    }
  }
  console.log('%s', ans);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 21064
#include <bits/stdc++.h>
#define rep(i, start, end) for (long long i = start; i < end; ++i)
#define repreverse(i, start, end) for (long long i = start; i >= end; --i)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define len(x) ((long long)(x).size())
#define lcm(a, b) ((a) / __gcd((a), (b)) * (b))
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using vllvll = vector<vll>;
using vc = vector<char>;
using pll = pair<ll, ll>;
template<class T>void print1d(T x,ll n=-1){if(n==-1)n=x.size();rep(i,0,n){cout<<x[i]<<' ';}cout<<'\n';}
template<class T>void print2d(T x,ll r=-1,ll c=-1){if(r==-1)r=x.size();if(c==-1)c=x[0].size();rep(i,0,r)print1d(x[i],c);}
template<class T, class U>bool haskey(T mp, U key) { return mp.find(key) != mp.end(); }
template<class T, class U>bool isin(T el, U container) { return find(all(container), el) != container.end(); }
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
template<class T>bool even(T n) { return ! (n & 1); }
template<class T>bool odd(T n) { return n & 1; }
template<class T>ld deg2rad(T deg) { return M_PI * deg / 180.0; }
template<class T>ld rad2deg(T rad) { return 180.0 * rad / M_PI; }
ll intpow(ll a,ll n){ll p=1;while(n){if(n&1)p*=a;a*=a;n>>=1;}return p;} 
const long double pi = M_PI;
const long long big = 1LL << 50;
const long long inf = 1LL << 60;
const long long mod = 1e9 + 7;



int main()
{
        ll N, H, W;
        cin >> N >> H >> W;
        cout << (N-H+1) * (N-W+1) << endl;
}


Measured memory_bytes: 3644
#include<algorithm>
#include<climits>
#include<cmath>
#include<iomanip>
#include<iostream>
#include<list>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<utility>
#include<vector>
 
#define lint long long
#define REP(i, x, n) for(int i = x ; i < n ; i++)
#define rep(i, n) REP(i, 0, n)
#define repr(i, n) for(int i = n - 1 ; i >= 0 ; i--)
#define SORT(c) sort((c).begin(), (c).end())
#define SORT_INV(c) sort((c).begin(), (c).end(), greater<int>())
#define IINF INT_MAX
#define LLINF LLONG_MAX

using namespace std;

int main(){
    int n;
    cin >> n;
    vector<lint> a(n);
    rep(i, n){
        cin >> a[i];
    }
    vector<lint> s1(n+1), s2(n+2);
    s1[0] = 0;
    s2[0] = 0;
    lint ans = LLINF, cnt = 0;
    bool flag = true;
    rep(i, n){
        s1[i+1] = s1[i] + a[i];
        if(flag){
            if(s1[i+1] <= 0){
                cnt += (abs(s1[i+1]) + 1);
                s1[i+1] = 1;
            }
        }else{
            if(s1[i+1] >= 0){
                cnt += (abs(s1[i+1]) + 1);
                s1[i+1] = -1;
            }
        }
        flag = !flag;
    }
    ans = min(ans, cnt);
    cnt = 0;
    flag = false;
    rep(i, n){
        s2[i+1] = s2[i] + a[i];
        if(flag){
            if(s2[i+1] <= 0){
                cnt += (abs(s2[i+1]) + 1);
                s2[i+1] = 1;
            }
        }else{
            if(s2[i+1] >= 0){
                cnt += (abs(s2[i+1]) + 1);
                s2[i+1] = -1;
            }
        }
        flag = !flag;
    }
    ans = min(ans, cnt);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 2560
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <cassert>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <algorithm>
#include <numeric>
#include <complex>
#include <stack>
#include <queue>
#include <list>
#include <set>
#include <map>
#include <bitset>
#include <functional>
#include <iterator>

using namespace std;

#define dump(n) cout<<"# "<<#n<<"="<<(n)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define peri(i,a,b) for(int i=int(b);i-->int(a);)
#define rep(i,n) repi(i,0,n)
#define per(i,n) peri(i,0,n)
#define iter(c) __typeof__((c).begin())
#define foreach(i,c) for(iter(c) i=(c).begin();i!=(c).end();++i)
#define all(c) (c).begin(),(c).end()
#define mp make_pair

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<string> vs;
typedef pair<int,int> pii;

const int INFTY=1<<29;
const double EPS=1e-9;

template<typename T1,typename T2>
ostream& operator<<(ostream& os,const pair<T1,T2>& p){
	return os<<'('<<p.first<<','<<p.second<<')';
}
template<typename T>
ostream& operator<<(ostream& os,const vector<T>& a){
	os<<'[';
	rep(i,a.size()) os<<(i?" ":"")<<a[i];
	return os<<']';
}

void solve(vs grid)
{
	int h=grid.size(),w=grid[0].size();
	char dir[]="ENWS";
	int di[]={0,-1,0,1},dj[]={1,0,-1,0};
	
	for(int t=0;t<=180;t++){
		bool escaped=true;
		rep(i,h) rep(j,w)
			escaped&=!strchr(dir,grid[i][j]);
		if(escaped){
			cout<<t<<endl;
			return;
		}
		
		rep(i,h) rep(j,w) if(strchr(dir,grid[i][j])){
			int cd=strchr(dir,grid[i][j])-dir;
			rep(k,4){
				int nd=(cd+3+k)%4;
				int ni=i+di[nd],nj=j+dj[nd];
				if(ni<0 || h<=ni || nj<0 || w<=nj || !(grid[ni][nj]=='.' || grid[ni][nj]=='X'))
					continue;
				grid[i][j]=dir[nd];
				break;
			}
		}
		
		vs grid2=grid;
		rep(i,h) rep(j,w) if(grid[i][j]=='.' || grid[i][j]=='X'){
			rep(k,4){
				int pi=i+di[k],pj=j+dj[k];
				if(pi<0 || h<=pi || pj<0 || w<=pj || grid[pi][pj]!=dir[(k+2)%4])
					continue;
				if(grid[i][j]=='.')
					grid2[i][j]=grid[pi][pj];
				grid2[pi][pj]='.';
				break;
			}
		}
		grid=grid2;
	}
	cout<<"NA"<<endl;
}

int main()
{
	for(int w,h;cin>>w>>h,w|h;){
		vs grid(h);
		rep(i,h) cin>>grid[i];
		
		solve(grid);
	}
	
	return 0;
}

Measured memory_bytes: 1220
/**
 *    author:  otera    
**/
#include<iostream>
#include<string>
#include<cstdio>
#include<cstring>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<deque>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
using namespace std;

typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
typedef long double ld;
const int inf=1e9+7;
const ll INF=1LL<<60 ;
const ll mod=1e9+7 ;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<int, int> P;
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
#define pb push_back
#define debug(x)  cerr << #x << " = " << (x) << endl;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
//#define int long long

void solve() {
	int h, a; cin >> h >> a;
    cout << (h + a - 1) / a << endl;
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(10);
	//int t; cin >> t; rep(i, t)solve();
	solve();
    return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const ll MOD = 1000000007LL;
int main() {
	ll N;
	ll A, B;
	cin >> N >> A >> B;
	if (A + B - 1 > N || N > A*B) {
		cout << -1 << endl;
		return 0;
	}
	vector<ll> v;
	int cnt = N - (A + B - 1);
	for (int i = 1; i <= A; i++) v.push_back(A*(B - 1) + i);
	for (int i = B - 2; i >= 0; i--) {
		v.push_back(A*i + 1);
		for (int j = 2; j <= A; j++) {
			if (cnt == 0) break;
			v.push_back(A*i + j);
			cnt--;
		}
	}
	vector <ll> s = v;
	sort(s.begin(), s.end());
	for (int i = 0; i < v.size(); i++) v[i] = lower_bound(s.begin(), s.end(), v[i]) - s.begin() + 1;
	cout << v[0];
	for (int i = 1; i < v.size(); i++) cout << " " << v[i];
	cout << endl;
}

Measured memory_bytes: 8300
#include<cstdio>
#include<algorithm>
using namespace std;
const int N=100005,inf=1047483647;
struct node { int y,next; } a[N<<1];
int z[N],l[N],r[N],head[N],i,j,k,n,m,x;
bool h[N],p[N],F,F1,F2;
char c;

inline char getc()
{
	#define VV 10000000
	static char s[VV],*l=s,*r=s;
	if (l==r)
		l=s,r=s+fread(s,1,VV,stdin);
	return l==r?0:*l++;
}

int read(){ int z=0; do c=getc(); while (c<'0'||c>'9'); while (c>='0'&&c<='9') z*=10,z+=c-'0',c=getc(); return z; }

void jb(int x,int y)
{
	a[++k]=(node){y,head[x]},head[x]=k,
	a[++k]=(node){x,head[y]},head[y]=k;
}

void dfs1(int w,int sp)
{
	if (p[w])
		if (F1)
		{
			if ((h[w]^(l[w]&1))!=F2)
				F=0;
		}
		else
			F1=1,F2=h[w]^(l[w]&1);
	for (register int j=head[w];j;j=a[j].next)
		if ((j^1)!=sp)
		{
			int c=a[j].y;
			h[c]=h[w]^1,dfs1(c,j),
			l[w]=max(l[w],l[c]-1),
			r[w]=min(r[w],r[c]+1);
			if (l[w]>r[w])
				F=0;
		}
}

void dfs2(int w,int sp)
{
	for (register int j=head[w];j;j=a[j].next)
		if ((j^1)!=sp)
		{
			int c=a[j].y;
			if (z[w]-1>=l[c])
				z[c]=z[w]-1;
			else
				z[c]=z[w]+1;
			dfs2(c,j);
		}
}

int main()
{
	n=read(),F=k=1;
	for (i=1;i<n;++i) jb(read(),read());
	for (i=1;i<=n;++i) l[i]=-inf,r[i]=inf;
	m=read();
	while (m--)
		p[x=read()]=1,l[x]=r[x]=read();
	dfs1(1,0);
	if (!F)
		puts("No");
	else
	{
		puts("Yes");
		z[1]=l[1],dfs2(1,0);
		for (i=1;i<=n;++i) printf("%d\n",z[i]);
	}
	return 0;
}

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


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);


    int n, m;
    cin >> n >> m;

    vector<int> h;
    rep(i, n) {
        int buf;
        cin >> buf;
        h.push_back(buf);
    }

    vector<bool> g;
    rep(i, n) {
        g.push_back(true);
    }
    rep(i, m) {
        int a, b;
        cin >> a >> b;
        if (h[a-1] == h[b-1]) {
            g[a-1] = false;
            g[b-1] = false;
        } else if (h[a-1] < h[b-1]) {
            g[a-1] = false;
        } else {
            g[b-1] = false;
        }
    }

    int c = 0;
    rep(i, n) {
        if (g[i] == true) c++;
    }

    cout << c << endl;


    return 0;
}



Measured memory_bytes: 3892
let calc (l, s) = function
  | x when x > l && x < s -> (x, x)
  | x when x > l -> (x, s)
  | x when x < s -> (l, x)
  | _ -> (l, s)

let () =
  let n = read_int () in
  let li = Array.init n (fun _ -> Scanf.scanf " %d" (fun x -> x)) in
  (* let () = Array.iter (Printf.printf "%d ") li in *)
  let l, s = Array.fold_left calc (1, 1000000000) li in
  print_int (l - s) ;
  print_newline ()


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

int main()
{
  string str;
  int sum;
  int array[1000];
  int j=0;

  while(true)
    {
      cin >> str;
      if(str=="0")
	break;
      sum=0;
      for(int i=0;i<str.size();i++)
	sum+=str.at(i)-'0';
      array[j]=sum;
      j++;
    }

  for(int i=0;i<j;i++)
    cout << array[i] << endl;


  return 0;
}

Measured memory_bytes: 1192
#include <iostream>
#include <algorithm>
#include <cstdio>
using namespace std;

int main(){
    string St;
    cin>>St;
    int n = St.length();
    int k = n;
    k /= 2;
    int result= 0;
    for (int i = 0; i < k ;i++){
        if (St[i] != St[ n - i -1]){
            result ++;
        }
    }
    cout<<result<<endl;
    return 0;
}


Measured memory_bytes: 256
import math
K = int(input())
total = 0
for i in range(1,K+1):
  for j in range(i,K+1):
    for k in range(j,K+1):
      if(i==j and j==k):
        total += math.gcd(i, math.gcd(j,k))
      elif(i==j or j==k):
        total += 3 * math.gcd(i, math.gcd(j,k))
      else:
        total += 6 * math.gcd(i, math.gcd(j,k))
print(total)

Measured memory_bytes: 9200
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     @hamayanhamayan0
　　　　／　　　＼　 　  |　|
　　　 /　　 /￣￣￣￣/　　|
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿
　 　　　＼/＿＿＿＿/　（u　⊃
---------------------------------------------------------------------------------------------------*/














int N, M, K, A[201010], B[201010];
ll Atot[201010], Btot[201010];
//---------------------------------------------------------------------------------------------------
void _main() {
	cin >> N >> M >> K;
	rep(i, 0, N) cin >> A[i];
	rep(i, 0, M) cin >> B[i];

	Atot[0] = 0;
	rep(i, 0, N) Atot[i + 1] = Atot[i] + A[i];
	Btot[0] = 0;
	rep(i, 0, M) Btot[i + 1] = Btot[i] + B[i];

	int ans = 0;
	int ok = M;
	rep(a, 0, N + 1) {
		while (0 <= ok && K < Atot[a] + Btot[ok]) ok--;
		if(0 <= ok) chmax(ans, a + ok);
	}
	cout << ans << endl;
}







Measured memory_bytes: 8352
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main() {
  int n, k; cin >> n >> k;
  char c[n];
  for (int i = 0; i < n; i++) {cin >> c[i];}
  for (int i = 0; i < n; i++) {
    if (i == k-1 && c[i] == 'A') {cout << 'a';}
    else if (i == k-1 && c[i] == 'B') {cout << 'b';}
    else if (i == k-1 && c[i] == 'C') {cout << 'c';}
    else {cout << c[i];}
  }
  cout << endl;
}
    

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll N = 1e7 + 5;
const ll MOD = 1e9 + 7;
#define all(x) x.begin(),x.end()
#define pii pair<int,int>
#define pis pair<ll,string>
#define F first
#define S second
#define LCM(a,b) ((a*b)/__gcd(a,b))
#define inf 1e10
#define test ll cse;cin>>cse;for(ll _i=1;_i<=cse;_i++)
#define PI 3.14159265
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
const double EPS = 1E-9;
typedef vector< vector<double> > matrix;
typedef vector<int> vi;


int prime[N];

int Exp(ll x, ll n){
    ll ans = 1, X =x,N= n;
    while(N > 0){
        if(N&1) ans = (ans*X);
        X = (X*X);
        N >>= 1;
    }
    return ans;
}
ll solve(ll num){

    unordered_map< int, int> mapp;
    while(num > 1){
        mapp[prime[num]]++;
        num /= prime[num];
    }
    // number of factors
    ll res = 1;
    for(auto ele: mapp) res *= (ele.S + 1);

    // sum of divisors/factors
    // ll ans = 1;
    // for(auto ele: mapp){
    //     ll ai = ele.F;
    //     ll pi = ele.S;

    //     ans *= (Exp(ai,pi+1)-1)/(ai-1);
    // }
    return res;
}

void sieve(int n){
    memset(prime,0,sizeof(prime));
    prime[0] = prime[1] = 1;

    for(int i = 2; i <= n; i++){
        if(prime[i]==0){
            for(int j=i; j <= N;j+=i) prime[j] = i;
        }
    }
}
int main() {
    fast;

    ll n; cin >> n;
    sieve(n);

    ll ans = 0;
    for(ll i = 1; i <= n; i++) {
        ll noOfDivisors = solve(i);
        ans += (i * noOfDivisors);
    }

    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 42656
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#define MAXN 1000
//const double INF=;
using namespace std;
double sx,sy,tx,ty;
struct Circle
{
	double x,y,r;
}C[MAXN+5];
bool vis[MAXN+5];
double G[MAXN+5][MAXN+5];
void Init()
{
	for(int i=0;i<=MAXN+3;i++)
		for(int j=0;j<=MAXN+3;j++)
			G[i][j]=-1.0;
}
double Getlen(double x1,double y1,double x2,double y2)
{
	return sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
}
bool Intersect(int a,int b)
{
	double len=Getlen(C[a].x,C[a].y,C[b].x,C[b].y);
	double totr=C[a].r+C[b].r;
	if(len<=totr)
		return true;
	return false;
}
int n;
double dist[MAXN+5];
double Dijkstra(int s)
{
	memset(vis,0,sizeof(vis));
	for(int i=0;i<=MAXN+3;i++)
		dist[i]=-1;
	dist[s]=0;
	vis[s]=true;
	int u=s,nu,cnt=1;
	for(int i=1;i<=n+2;i++)
	{
		double mindist=-1;
		for(int v=0;v<=n;v++)
		{
			if(G[u][v]==-1)
				continue;
			if(dist[v]>dist[u]+G[u][v]||dist[v]==-1)
				dist[v]=dist[u]+G[u][v];
			if((mindist==-1||dist[v]<mindist)&&vis[v]==false)
			{
				mindist=dist[v];
				nu=v;
			}
		}
		vis[nu]=true;
		u=nu;
	}
	return dist[n];
}
int main()
{
	Init();
	scanf("%lf %lf %lf %lf",&sx,&sy,&tx,&ty);
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		scanf("%lf %lf %lf",&C[i].x,&C[i].y,&C[i].r);
	for(int i=1;i<=n;i++)
		for(int j=1;j<=n;j++)
		{
			double len=max(Getlen(C[i].x,C[i].y,C[j].x,C[j].y)-C[i].r-C[j].r,0.0);
			if(G[i][j]==-1||len<G[i][j])
				G[i][j]=len;
		}
	for(int i=1;i<=n;i++)
	{
		double len=max(Getlen(sx,sy,C[i].x,C[i].y)-C[i].r,0.0);
		if(G[i][0]==-1||len<G[0][i])
			G[i][0]=G[0][i]=len;
		len=max(Getlen(tx,ty,C[i].x,C[i].y)-C[i].r,0.0);
		if(G[i][n+1]==-1||len<G[i][n+1])
			G[i][n+1]=G[n+1][i]=len;
	}
	n++;
	G[0][n]=G[n][0]=Getlen(sx,sy,tx,ty);
	double ans=Dijkstra(0);
	printf("%.10lf\n",ans);
	return 0;
}

Measured memory_bytes: 8064
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a,b;
  cin >> a >> b;
  int hash[4] = {0};
  hash[a] = 1 , hash[b] = 1;
  for(int i=1;i<=3;i++)
  {
  	if(!hash[i])
    {
    	cout << i;
    }
  }
}

Measured memory_bytes: 256
import java.util.*;

class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);

		int S = in.nextInt();
		int h = S / 60 / 60;
		int m = (S / 60) % 60;
		int s = S % 60;

		System.out.println(String.format("%d:%d:%d", h, m, s));
	}
}

Measured memory_bytes: 17360
#include<iostream>
#include<cstdio>
using namespace std;
const int maxn=100100;
int n,a[maxn],ans,cnt; 
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		scanf("%d",&a[i]);
	cnt=ans=0;
	for(int i=1;i<=n;i++)
		if(a[i]==i) cnt++;
		else
		{
			ans+=(cnt+1)/2;
			cnt=0;
		}	
	ans+=(cnt+1)/2;		
	printf("%d",ans);		
	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define N 1000005
#define ll long long int 	
#define MP make_pair
#define pb push_back
#define ppb pop_back
#define sp " "
#define endl "\n"
#define fi first
#define se second
#define ii pair<int,int>
#define lli pair<ll,ll>
#define fast cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(false)
#define fast2 freopen ("badhair.gir","r",stdin);freopen ("badhair.cik","w",stdout);
#define mod 1000000007
#define fs(x,y) for(ll i=1;i<=y;i++) cin>>x[i]
#define fo(i,x,y) for(ll i=x;i<=y;i++)
#define INF 1000000000005
#define ull unsigned long long int
using namespace std;

ll n,m,ar[N],sum,t;

int main()
{
	fast;
	cin>>n>>m;
	fs(ar,n);
	ll x=0;
	fo(i,1,n)
	x=__gcd(x,ar[i]);
	sort(ar+1,ar+n+1);
	if(ar[n]<m || m%x!=0)
		return cout<<"IMPOSSIBLE"<<endl,0;
	cout<<"POSSIBLE";

}



Measured memory_bytes: 4364
#include <bits/stdc++.h>
using namespace std;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ll long long
#define ld long double
#define all(a) (a).begin(),(a).end()
#define mk make_pair
ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;



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


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <queue>
#include <string>
#define int long long
#define P pair<int,int>
#define V vector<int>
#define rep(i,n) for(int i=0;i<n;++i)
#define vsort(vec) sort(vec.begin(),vec.end())
#define end system("PAUSE");return 0
using namespace std;
char a[10] = { 'm','m','m','m','m','m','a','a','a','r' };
char b[10] = { 'a','a','a','r','r','c','r','r','c','c' };
char c[10] = { 'r','c','h','c','h','h','c','h','h','h' };
signed main() {
	int n, ans = 0;
	map<char, int> mp;
	cin >> n;
	rep(i, n) {
		string s;
		cin >> s;
		mp[s[0]]++;
	}
	rep(i, 10) {
		ans += mp[a[i] - 'a' + 'A'] * mp[b[i] - 'a' + 'A'] * mp[c[i] - 'a' + 'A'];
	}
	cout << ans << endl;
	end;
}


Measured memory_bytes: 504
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <vector>

using namespace std;
using LLONG = long long;

int main()
{
    int N;
    cin >> N;
    vector<LLONG> monsters(N + 1), canKills(N);
    for (int i = 0; i < N + 1; ++i) cin >> monsters[i];
    for (int i = 0; i < N; ++i) cin >> canKills[i];
    LLONG kill = 0;
    for (int i = 0; i < N; ++i)
    {
        if (canKills[i] >= monsters[i])
        {
            kill += monsters[i];
            canKills[i] -= monsters[i];
        }
        else
        {
            kill += canKills[i];
            canKills[i] = 0;
        }

        if (canKills[i] >= monsters[i + 1])
        {
            kill += monsters[i + 1];
            monsters[i + 1] = 0;
        }
        else
        {
            kill += canKills[i];
            monsters[i + 1] -= canKills[i];
        }
    }
    cout << kill << endl;
}


Measured memory_bytes: 1792
import java.util.Scanner;
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int data[][] = new int[n][n];
        for(int i = 0 ; i < n ; i++){
            for(int j = 0 ; j < n ; j++)
                data[i][j] = 0;
        }
        for(int i = 0 ; i < n ; i++){
            int nul = sc.nextInt();
            int k = sc.nextInt();
            for(int v = 0 ; v < k ; v++)
                data[i][sc.nextInt()-1]++;
        }
        for(int i = 0 ; i < n ; i++){
            for(int j = 0 ; j < n-1 ; j++)
                System.out.print(data[i][j] + " ");
            System.out.println(data[i][n-1]);
        }
    }
}


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

	public static void main(String[] args){

		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		long A[]=new long[n];
		for(int i=0;i<n;i++) {
			A[i]=sc.nextLong();
		}
		
		long dp[]=new long[n];
		for(int i=n-2;i>=0;i--){
			if(A[i]>=A[i+1]){
				dp[i]=dp[i+1]+1;
			}
			else dp[i]=0;
		}
//		for(int i=0;i<n;i++) {
//			System.out.println(dp[i]+" ");
//		}
		long max=0;
		for(int i=0;i<n;i++){
			if(max<dp[i]){
				max=dp[i];
			}
		}

		System.out.println(max);
	}


}

Measured memory_bytes: 50704
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<map>
#include<set>
#include<queue>
#include<cstdio>
#include<climits>
#include<cmath>
#include<cstring>
#include<string>
#include<sstream>
#include<numeric>
#include<cassert>

#define f first
#define s second
#define mp make_pair

#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define rep(i,s,n) for(int i=(s); i<(int)(n); i++)
#define FOR(i,c) for(__typeof((c).begin()) i=(c).begin(); i!=(c).end(); i++)
#define ALL(c) (c).begin(), (c).end()
#define IN(x,s,g) ((x) >= (s) && (x) < (g))
#define ISIN(x,y,w,h) (IN((x),0,(w)) && IN((y),0,(h)))
#define print(x) printf("%d\n",x)

using namespace std;

typedef unsigned int uint;
typedef long long ll;

const int _dx[] = {0,1,0,-1};
const int _dy[] = {-1,0,1,0};

int getInt(){
  int ret = 0,c;
  c = getchar();
  while(!isdigit(c)) c = getchar();
  while(isdigit(c)){
    ret *= 10;
    ret += c - '0';
    c = getchar();
  }
  return ret;
}

int memo[100];
bool chk[100];
int sd[50][100];
int dd[100][100];

int main(){
  int s,d;
  while((s = getInt()) + (d = getInt())){
    REP(i,s) REP(j,d) sd[i][j] = getInt();
    REP(i,d) REP(j,d-i-1) dd[i][i+j+1] = dd[i+j+1][i] = getInt();
    REP(i,d){
      memo[i] = INT_MAX;
      chk[i] = false;
    }

    //puts("sd"); REP(i,s){ REP(j,d) printf("%d ",sd[i][j]); puts("");}
    //puts("dd"); REP(i,d){ REP(j,d) printf("%d ",dd[i][j]); puts("");}

    typedef pair<int,int> data;
    priority_queue<data,vector<data>,greater<data> > pq;
    REP(i,d){
      int pp = INT_MAX;
      REP(j,s) if(sd[j][i])
        pp = min(pp, sd[j][i]);
      pq.push(mp(pp,i));
      memo[i] = pp;
    }

    int cnt = 0;
    int ans = 0;
    while(cnt < d){
      data dt = pq.top();
      int  cost = dt.f;
      int  pos  = dt.s;
      pq.pop();

      if(chk[pos]) continue;
      chk[pos] = true;
      cnt++;
      ans += cost;

      REP(i,d) if(i != pos && !chk[i]){
        int cc = dd[i][pos];
        if(cc && cc < memo[i]){
          memo[i] = cc;
          pq.push(mp(cc, i));
        }
      }
    }
    print(ans);
  }
  return 0;
}

Measured memory_bytes: 0
# -*- coding: utf-8 -*-

## Library

import sys
from fractions import gcd
import math
from math import ceil,floor
import collections
from collections import Counter
import itertools

## input

# n=int(input())
# A,B,C,D=map(int, input().split())
# string = input()
# yoko = list(map(int, input().split()))
# tate = [int(input()) for _ in range(N)]
# N, M = map(int,input().split()) 
#    P = [list(map(int,input().split())) for i in range(M)]

N = int(input())
P = list(map(int, input().split()))
Q = list(map(int, input().split()))

Ptuple = tuple(P)
Qtuple = tuple(Q)

tmp = []
for i in range(1,N+1):
    tmp.append(i)

count = 0
num = 1
tmp1 = 0
tmp2 = 0

for j in itertools.permutations(tmp):
    if j == Ptuple:
        tmp1 = num
        count += 1
    if j == Qtuple:
        tmp2 = num
        count += 1
    if count == 2:
        print(abs(tmp1-tmp2))
        sys.exit()
    num += 1


Measured memory_bytes: 64364
#include<iostream>
#include<cstdio>
#include<vector>
using namespace std;
const int N=200005;
const int MOD=998244353;
int n;
vector<int>G[N];
int s,t;
int Max,p;
int dep[N];
int fa[N];
void dfs(int u,int father)
{
	fa[u]=father;
	dep[u]=dep[father]+1;
	if(dep[u]>Max) Max=dep[u],p=u;
	for(int v:G[u])
	{
		if(v==father) continue;
		dfs(v,u);
	}
	return;
}
vector<int>pos;
int len;
long long f[N][3][3];
long long g[3][3];
void DP(int u,int father,int d)
{
	if(d==len/2) f[u][1][1]=1;
	else f[u][0][0]=1;
	for(int v:G[u])
	{
		if(v==father) continue;
		DP(v,u,d+1);
		for(int i=0;i<=2;i++)
			for(int j=0;j<=2;j++)
				for(int x=0;x<=2;x++)
					for(int y=0;y<=2;y++)
						for(int k=-1;k<=1;k++)
						{
							int p=min(2,i+x*(k==-1)),q=min(2,j+y*(k==1));
							g[p][q]=(g[p][q]+f[u][i][j]*f[v][x][y]%MOD)%MOD;
						}
		for(int i=0;i<3;i++)
			for(int j=0;j<3;j++)
				f[u][i][j]=g[i][j],g[i][j]=0;
	}
	return;
}
long long ksm(long long a,long long b)
{
	long long res=1;
	while(b)
	{
		if(b&1) res=res*a%MOD;
		a=a*a%MOD,b>>=1;
	}
	return res;
}
int main()
{
	scanf("%d",&n);
	for(int i=1;i<n;i++)
	{
		int x,y;
		scanf("%d%d",&x,&y);
		G[x].push_back(y);
		G[y].push_back(x);
	}
	dfs(1,0);
	s=p;
	Max=0;
	dfs(s,0);
	t=p;
	for(int u=t;u!=s;u=fa[u])
		pos.push_back(u);
	pos.push_back(s);
	len=pos.size()-1;
	if(len%2==0)
	{
		int x=pos[len/2];
		DP(x,0,0);
		printf("%lld",f[x][1][1]*ksm(2,MOD-2)%MOD);
	}
	else
	{
		int x=pos[(len-1)/2],y=pos[(len+1)/2];
		DP(x,y,0);
		DP(y,x,0);
		long long fx=(f[x][1][0]+f[x][1][1]+f[x][1][2])%MOD,fy=(f[y][0][1]+f[y][1][1]+f[y][2][1])%MOD;
		printf("%lld",fx*fy%MOD);
	}
	return 0;
}

Measured memory_bytes: 37492
#include <cstdio>

#define iter(i, n) forw(i, 1, n)
#define forw(i, a, b) for (int i = a; i <= b; ++i)
#define down(i, a, b) for (int i = b; i >= a; --i)

const int mod = 1e9 + 7;

const int NR = 2010;

int pr(int a, int z) {
	int s = 1;
	while (z > 0) {
		if (z % 2 == 1) s = 1ll * s * a % mod;
		a = 1ll * a * a % mod;
		z /= 2;
	}
	return s;
}

int n, K, f[NR][NR], sum[NR][NR], fac[NR], inv[NR];

int binom(int n, int k) {
	return n < k ? 0 : 1ll * fac[n] * inv[k] % mod * inv[n - k] % mod;
}

int main() {
	scanf("%d%d", &n, &K);
	if (n == 1) {
		puts("1");
		return 0;
	}

	fac[0] = inv[0] = 1;
	iter(i, n) {
		fac[i] = 1ll * fac[i - 1] * i % mod;
		inv[i] = pr(fac[i], mod - 2);
	}

	int ans = binom(n - 2, K - 1);

	f[n + 1][0] = 1;
	forw(i, 0, K) sum[n + 1][i] = 1;
	down(i, n - K + 2, n) {
		forw(j, 0, K) {
			/*
				choice:
					-1
					+X
			*/

			f[i][j] = (f[i + 1][j + 1] + sum[i + 1][j]) % mod;
			sum[i][j] = f[i][j];
			if (j) sum[i][j] = (sum[i][j] + sum[i][j - 1]) % mod;

			if (!j) {
				if (i - 3 >= 0 && K - (n - i + 1) - 1 - j >= 0) {
				
					ans = (ans + 1ll * binom(i - 3, K - (n - i + 1) - 1) * f[i][j]) % mod;
			//		printf("0!%d %d => %lld\n", i, j, 1ll * binom(i - 3, K - (n - i + 1) - 1) * f[i][j]);
				}
			} else {

				if (i - 3 >= 0 && K - (n - i + 1) - 1 - j >= 0) {
				
					ans = (ans + 1ll * binom(i - 3, K - (n - i + 1) - 1) * f[i][j]) % mod;
		//			printf("0!%d %d => %lld\n", i, j, 1ll * binom(i - 3, K - (n - i + 1) - 1) * f[i][j]);
				}                                                
			}
		
//			printf("f[%d][%d]=%d\n", i, j, f[i][j]);
		}

	}
	
	if (n == K) printf("%d\n", f[2][0]); 
	else {
		//printf("ans=%d\n", ans);

		iter(i, n - K - 1) ans = ans * 2 % mod;
		printf("%d\n", ans);
	}
	return 0;
}

Measured memory_bytes: 31616
//write：Sakura
//id：
//problem：
//note：

#include <cstdio>
#include <cstring>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <queue>
#include <stack>
#include <map>
#include <set>
using namespace std;

typedef long long ll;

int n,a,b;
int ans1=0,ans2=0;
int x=0;

int main(){
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	scanf("%d %d %d",&n,&a,&b);
	ans1=n*a;
	ans2=b;
	x=min(ans1,ans2);
	printf("%d\n",x);
	return 0;
}


Measured memory_bytes: 256
def get_int
  gets.chop.to_i
end

def get_ints
  gets.chop.split.map(&:to_i)
end

def get_double
  gets.chop.to_f
end

def is_prime(x)
  if x == 2 or x == 3
    return true
  end
  if x % 2 == 0
    return false
  end
  3.step(Math.sqrt(x).to_i + 1, 2) do |i|
    if x % i == 0
      return false
    end
  end
  return true
end

def main
  x = get_int
  while true
    if is_prime(x)
      puts x
      exit 0
    end
    x += 1
  end
end

if __FILE__ == $0
  main
end

Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
typedef long long int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define MOD (1000000007)
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

int n;
vector<ll> a;

void input(){
    cin >> n;
    a.resize(n);
    for(int i=0;i<n;i++) cin >> a[i]; 
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    input();
    int cnt = 0;
    for(int i=0;i<n;i++){
        if(a[i] % 2 == 1) cnt++;
    }
    if(cnt % 2 == 0) cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0; 
}

Measured memory_bytes: 1024
#include <cmath>
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<set>
#include<tuple>
#include<bitset>
#include<iomanip>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
ll inf = 1000000007;
ll box[100005] = {};
ll red[100005] = {};
int main() {
	int n, m;
	cin >> n >> m;
	int x, y;
	ll count = 0;
	for (int i = 0; i < n; i++) {
		box[i] = 1;
	}
	red[0] = 1;
	for (int i = 0; i < m; i++) {
		cin >> x >> y;
		x--; y--;
		box[x]--;
		box[y]++;
		if (red[x] != 0) {
			red[y] = 1;
			if (box[x] == 0) {
				red[x] = 0;
			}
		}
	}
	for (int i = 0; i < n; i++) {
		if (box[i] > 0&&red[i]>0) {
			count++;
		}
	}
	cout << count << endl;
	return 0;
}

Measured memory_bytes: 5144
#include <iostream>
#include <string>
#include <sstream>  // istringstream
#include <vector>

using namespace std;

class Line {
public:
	Line()
		: a_(0)
		, b_(0)
		, inspected_(false)
	{};
	Line(int a, int b)
		: a_(a)
		, b_(b)
		, inspected_(false)
	{};

public:
	int a_;
	int b_;
	bool inspected_;
};


void SeekConnected(int node, std::vector<Line>& vctLine, std::vector<bool>& vctNode)
{
	vctNode[node] = true;
	for (auto& elem : vctLine){
		if (elem.inspected_){
			continue;
		}
		if (elem.a_ == node){
			elem.inspected_ = true;
			SeekConnected(elem.b_, vctLine, vctNode);
		}
		else if (elem.b_ == node){
			elem.inspected_ = true;
			SeekConnected(elem.a_, vctLine, vctNode);
		}
	}
}
bool IsBridge(int index, const std::vector<Line>& vctLine, std::vector<bool>& vctNode)
{
	std::vector<Line> tmpVctLine(vctLine);
	tmpVctLine.erase(tmpVctLine.begin() + index);
	vctNode.assign(vctNode.size(), false);

	SeekConnected(tmpVctLine[0].a_, tmpVctLine, vctNode);
	SeekConnected(tmpVctLine[0].b_, tmpVctLine, vctNode);

#if 0
	for(std::vector<bool>::iterator it = vctNode.begin(); it != vctNode.end(); ++it){
		if (it)
	}
#else
	for (const auto& elem : vctNode){
		if (elem == false){
			return true;;
		}
	}
#endif
	return false;
}

int main()
{
	int N = 0, M = 0;
	//std::string lineBuf;

	cin >> N >> M;

	std::vector<Line> vctLine(M);
	std::vector<bool> vctNode(N, false);

	for (auto& elem : vctLine){
		int a = 0, b = 0;
		cin >> a >> b;
		elem = Line(a - 1, b - 1);
	}

	int count = 0;
	for (int i = 0; i < M; ++i){
		if (IsBridge(i, vctLine, vctNode)){
			++count;
		}
	}

	cout << count;

	return 0;
}

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

typedef long long ll;
const int mod = 1000000007;

// 0:Tor未定, 1:C, 2:G, 3:A
// dp[i][j][k][l]   i桁目まで決めたとき、i桁目がkで、(i-1)桁目がjで、(i-2)桁目がlである場合の数
// 条件を満たさない場合は、0
ll dp[105][4][4][4];

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int n;
    cin >> n;
    
    // 場合の数を考えるときのdpテーブルの初期化
    dp[0][0][0][0] = 1;
    
    // dpテーブルを埋める
    for(int i = 0; i < n; ++i){
        // (i+1)桁目をTにする
        for(int j = 0; j < 4; ++j){
            for(int k = 0; k < 4; ++k){
                for(int l = 0; l < 4; ++l){
                    dp[i+1][0][j][k] = (dp[i+1][0][j][k] + dp[i][j][k][l]) % mod;
                }
            }
        }
        
        // (i+1)桁目をCにする(Cを入れられないのは、直前の並びが(AG, GA, AxG, AGx)のとき)
        for(int j = 0; j < 4; ++j){
            for(int k = 0; k < 4; ++k){
                // AG or GA
                if((j == 2 && k == 3) || (j == 3 && k == 2))    continue;
                for(int l = 0; l < 4; ++l){
                    // AxG or AGx
                    if((k == 2 && l == 3) || (j == 2 && l == 3))    continue;
                    dp[i+1][1][j][k] = (dp[i+1][1][j][k] + dp[i][j][k][l]) % mod;
                }
            }
        }
        
        // (i+1)桁目をGにする(Gを入れられないのは、直前の並びが(AC)のとき)
        for(int j = 0; j < 4; ++j){
            for(int k = 0; k < 4; ++k){
                if(j == 1 && k == 3)    continue;
                for(int l = 0; l < 4; ++l){
                    dp[i+1][2][j][k] = (dp[i+1][2][j][k] + dp[i][j][k][l]) % mod;
                }
            }
        }
        
        // (i+1)桁目をAにする
        for(int j = 0; j < 4; ++j){
            for(int k = 0; k < 4; ++k){
                for(int l = 0; l < 4; ++l){
                    dp[i+1][3][j][k] = (dp[i+1][3][j][k] + dp[i][j][k][l]) % mod;
                }
            }
        }
    }
    
    // デバッグ用
    // for(int i = 0; i <= n; ++i){
    //     for(int j = 0; j < 4; ++j){
    //         for(int k = 0; k < 4; ++k){
    //             for(int l = 0; l < 4; ++l){
    //                 cerr << dp[i][j][k][l] << " ";
    //             }
    //             cerr << " ";
    //         }
    //         cerr << " ";
    //     }
    //     cerr << endl;
    // }
    
    ll res = 0;
    for(int i = 0; i < 4; ++i){
        for(int j = 0; j < 4; ++j){
            for(int k = 0; k < 4; ++k){
                res = (res + dp[n][i][j][k]) % mod;
            }
        }
    }
    
    cout << res << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll MOD = 1e9+7;
ll add(ll a, ll b)
{
    return (a+b) % MOD;
}
int main()
{
    ll n, m;
    cin >> n >> m;
    vector<ll> x(n);
    vector<ll> y(m);
    for(int i = 0; i < n; i++)
    {
        cin >> x[i];
    }
    for(int i = 0; i < m; i++)
    {
        cin >> y[i];
    }

    vector<ll> sx(n);
    vector<ll> gx(n);
    sx[0] = 0;
    gx[0] = 0;
    for(int i = 1; i < n; i++)
    {
        ll cand = x[i] - x[i-1];
        gx[i] = add(gx[i-1], i * cand % MOD);
        sx[i] = add(sx[i-1], gx[i]);
    }
    vector<ll> sy(m);
    vector<ll> gy(m);
    sy[0] = 0;
    gy[0] = 0;
    for(int i = 1; i < m; i++)
    {
        ll cand = y[i] - y[i-1];
        gy[i] = add(gy[i-1], i * cand % MOD);
        sy[i] = add(sy[i-1], gy[i]);
    }

    cout << sx[n-1] * sy[m-1] % MOD << endl;
}


Measured memory_bytes: 4992
n = gets.chomp.to_i
btns = readlines.map(&:chomp).map(&:to_i)

cnt = - 1
next_btn = btns[0]
1.upto(n - 1) do |i|
    if next_btn == 2
        cnt = i
        break
    end
    next_btn = btns[next_btn - 1]
end

puts(cnt)

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

int main(){

  long long N, A=0, B=0, C=0, E=0, ans, num;
  string S;
  cin >> N;
  cin >> S;
  int D[N], F[N], T[N-1];

  for(int i=0; i<N; i++){
    if(S[i]=='#'){
      C++;
      D[i]=C;
    }else{
      D[i]=C;
    }
  }


  for(int i=(N-1); i>=0; --i){
    if(S[i]=='.'){
      E++;
      F[i]=E;
    }else{
      F[i]=E;
    }
  }


  for(int i=0; i<N; i++){
    if(S[i]=='#') A++;
  }
  for(int i=0; i<N; i++){
    if(S[i]=='.') B++;
  }

  for(int i=0; i<N-1; i++){
    T[i] = D[i] + F[i+1];
  }


  sort(T, T+(N-1));

  num = T[0];

  ans = min(A, B);
  ans = min(ans, num);


  cout << ans << endl;

  return 0;
}


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

int main() {
    int w, n;
    cin >> w >> n;
    vector<int> v(w);
    iota(v.begin(), v.end(), 1);
    while(n--) {
        int an, bn;
        char c;
        cin >> an >> c >> bn;
        
        int a = v[an-1];
        int b = v[bn-1];
        v[an-1] = b;
        v[bn-1] = a;
    }
    for(int i=0; i<w; i++) {
        cout << v[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 3084
#include <iostream>
using namespace std;
int main(){
    int p, q, r;
    cin >> p >> q >> r;
    if(p >= q && p >= r){
        cout << q+r << endl;
    }else if(q >= p && q >= r){
        cout << p+r << endl;
    }else{
        cout << p+q << endl;
    }
    return 0;
}


Measured memory_bytes: 256
function Main(input) {
  [a, b] = input.split(' ');
  a = parseInt(a);
  b = parseInt(b);
  console.log(a * b + ' ' + 2 * (a + b));
}

function debug() {
  var x = document.getElementById('id1').value;
  var y = document.getElementById('id2').value;
  Main(x + ' ' + y);
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));



Measured memory_bytes: 15396
n = gets.to_i
m = gets.split.map(&:to_i)
b = gets.split.map(&:to_i)

ans = 0
n.times do |i|
    if m[i] >= b[i]
        ans += b[i]
    else
        ans += m[i]
        y = b[i] - m[i]
        y = m[i+1] if m[i+1] < y
        ans += y
        m[i+1] -= y
        # p ans
    end
end

puts ans

Measured memory_bytes: 15388
use std::io::stdin;
use std::io::Error;
use std::io::Read;

#[derive(Debug)]
struct Input {
    n: u32,
    k: u32,
}

fn handle_input(input_str: String) -> Result<Input, Error> {
    let mut iter = input_str.split_whitespace();
    let n: u32 = iter.next().unwrap().parse().unwrap();
    let k: u32 = iter.next().unwrap().parse().unwrap();
    let input = Input { n: n, k: k };
    Ok(input)
}

fn handle_output(input: Input) -> Result<String, Error> {
    let mut sum = 0_f64;
    for i in 1..input.n + 1 {
        if i >= input.k {
            sum += 1_f64 / input.n as f64;
            continue;
        }
        let cast = (((input.k - 1) / i) as f64).log2() as i32 + 1;
        sum += 0.5_f64.powi(cast) / input.n as f64;
    }
    Ok(format!("{}", sum))
}

fn main() {
    let mut input_str = String::new();
    stdin().read_to_string(&mut input_str).unwrap();
    let input = handle_input(input_str).unwrap();
    let output = handle_output(input).unwrap();
    println!("{}", output);
}

Measured memory_bytes: 4352
X, N = map(int, input().split())
P = list(map(int, input().split()))
P_set = set(P)

ans = X
for i in range(101):
    a = X + i
    b = X - i
    if a not in P_set:
        ans = a
        if b not in P_set:
            ans = b
        break
    if b not in P_set:
        ans = b
        break
print(ans)

Measured memory_bytes: 9120
from itertools import combinations_with_replacement, accumulate

n, m, q = map(int, input().split())
queries = []
for _ in range(q):
    a, b, c, d = map(int, input().split())
    a -= 1
    b -= 1
    queries.append((a, b, c, d))

ans = 0
for adds in combinations_with_replacement(range(n + 1), m - 1):
    arr = [0] * (n + 1)
    for i in adds:
        arr[i] += 1
    arr = list(accumulate(arr))
    score = 0
    for a, b, c, d in queries:
        if arr[b] - arr[a] == c:
            score += d
    ans = max(ans, score)

print(ans)


Measured memory_bytes: 9224
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func out(x ...interface{}) {
	fmt.Println(x...)
}

var sc = bufio.NewScanner(os.Stdin)

func getInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func getString() string {
	sc.Scan()
	return sc.Text()
}

func min(a, b int) int {
	if a > b {
		return b
	}
	return a
}

func main() {
	sc.Split(bufio.ScanWords)
	sc.Buffer([]byte{}, 200200)
	_ = getInt()
	s := getString()

	wr := 0
	br := 0
	for _, v := range s {
		if v == '#' {
			br++
		} else {
			wr++
		}
	}
	wl := 0
	bl := 0
	m := wr
	for _, v := range s {
		if v == '#' {
			bl++
			br--
		} else {
			wl++
			wr--
		}
		if bl+wr < m {
			m = bl + wr
		}
	}

	out(m)
}


Measured memory_bytes: 1280
N = gets.to_i
B = gets.split.map(&:to_i)

ans = []

N.downto(1) do |n|
  updated = false

  (n - 1).downto(0) do |j|
    if B[j] == j + 1
      ans << j + 1
      B.delete_at(j)
      updated = true
      break
    end
  end

  if !updated
    puts -1
    exit
  end
end

puts ans.reverse


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

using ll = long long;
using P = pair<int, int>;

const int mod = 998244353;
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, const mint &a) { return is >> a.x; }
ostream &operator<<(ostream &os, const mint &a) { return os << a.x; }

mint combination(int a, int b) {
    mint ans = 1;
    if (a-b > b) {
        b = a-b;
    }
    for (int i=a; i>b; i--) {
        ans *= i;
    }
    for (int i=a-b; i>0; i--) {
        ans /= i;
    }
    return ans;
}

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

    mint ans = 0;
    mint mm = m;
    mint mm1 = m - 1;
    mint p = mm * mm1.pow(n-1-k);
    mint c = combination(n-1,k);
    for (int i=k; i>=0; i--) {
        ans += p * c;
        p *= mm1;
        c *= i; c /= (n-1-i+1);
    }

    cout << ans << endl;
}


Measured memory_bytes: 3624
/**
 *      ABC 90 C
 *      author  : kyomukyomupurin
 *      created : 2018-09-01 02:18:37
**/

#include <bits/stdc++.h>
using namespace std;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    long long N, M; cin >> N >> M;
    if (N == 1 && M == 1){
        cout << 1 << endl;
    }
    else if (N < 2 || M < 2){
        cout << max(N, M) - 2 << endl;
    }
    else {
        cout << (N - 2) * (M - 2) << endl;
    }
    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin >> N;
  long long mod = 1000000007;
  vector<int> A(N);
  for (int i = 0; i < N; i++){
    cin >> A[i];
    A[i]++;
  }
  bool flg = false;
  vector<int> a(N + 1), b(N + 1), c(N + 1);
  for (int i = 1; i <= N; i++){
    a[i] = a[i - 1];
    b[i] = b[i - 1];
    c[i] = c[i - 1];
    if (A[i - 1] == a[i] + 1){
      a[i]++;
    } else if (A[i - 1] == b[i] + 1){
      b[i]++;
    } else if (A[i - 1] == c[i] + 1){
      c[i]++;
    } else {
      flg = true;
      break;
    }
  }
  if (flg){
    cout << 0;
  } else {
    long long res = 1;
    for (int i = 0; i < N; i++){
      if (a[i] == c[i]){
        //A 000 -> 100
        res = res * 3 % mod;
      } else if (a[i] == b[i]){
        if (c[i] != c[i + 1]){
          //B1 110 -> 111
          res = res;
        } else {
          //C1 110 -> 210
          res = res * 2  % mod;
        }
      } else if (b[i] == c[i]){
        if (a[i] != a[i + 1]){
          //B2 100 -> 200
          res = res;
        } else {
          //C2 100 -> 110
          res = res * 2 % mod;
        }
      } else {
        //D 210 -> 211
        res = res;
      }
    }
    cout << res % mod;
  }
}

Measured memory_bytes: 1792
n=int(input())
ans=[]
for i in range(1,n+1):
  for j in range(i+1,n+1):
    if i+j != n+int(n%2==0):
      ans.append((i,j))
print(len(ans))
for p in ans:
  x,y=p
  print(x,y)

Measured memory_bytes: 3956
fun main(args: Array<String>) {
    val pw = java.io.PrintWriter(System.out)
    Problem.solve(java.util.Scanner(System.`in`), pw)
    pw.flush()
}

object Problem {
    fun solve(sc: java.util.Scanner, pw: java.io.PrintWriter) {
        val A = sc.next().toCharArray().map { it.toInt() - '0'.toInt() }
        val ans = CharArray(4)
        for (i in 0 until 8) {
            var sum = A[0]
            val ans = StringBuilder()
            ans.append(A[0])
            for (j in 0..2) {
                if ((i shr j) and 1 != 0) {
                    sum += A[j + 1]
                    ans.append('+')
                } else {
                    sum -= A[j + 1]
                    ans.append('-')
                }
                ans.append(A[j + 1])
            }
            if (sum == 7) {
                pw.println("$ans=7")
                return
            }
        }
    }
}


Measured memory_bytes: 31384