akhauriyash/Code-Regression huggingface dataset:
function main(arg) {
    var genbun = arg.split("\n")[1];
    var zure = arg.split("\n")[0];
    var arr1 = {A:1,B:2,C:3,D:4,E:5,F:6,G:7,H:8,I:9,J:10,K:11,L:12,M:13,N:14,O:15,P:16,Q:17,R:18,S:19,T:20,U:21,V:22,W:23,X:24,Y:25,Z:26};
    var arr2 = ["A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"];
    var kekka = "";
    for(i=0;i<genbun.length;i++){
        kekka = kekka + arr2[(arr1[genbun.charAt(i)]+parseInt(zure-1))%26];
    }
    console.log(kekka);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 7372
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

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

        final int A = sc.nextInt();
        final int B = sc.nextInt();
        final int K = sc.nextInt();

        List<Integer> l = new ArrayList<>();
        for (int i = 1; i <= Math.min(A, B); i++) {
            if (A % i == 0 && B % i == 0) {
                l.add(i);
            }
        }

        System.out.println(l.get(l.size()-K));
    }
}


Measured memory_bytes: 23636
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

using namespace std;
using ll = long long;
using vpii = vector<pair<int, int>>;
using vpll = vector<pair<ll, ll>>;

int		main(void)
{
	int N, R;
	cin >> N >> R;
	int x;
	if (N >= 10)
		x = R;
	else
		x = R + (100*(10-N));
	cout << x << endl;
}


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

ll L;

int main() { 
    cin >> L;
    ll a, b, c, out;
    a = L / 3;
    b = L / 3;
    c = L / 3;
    out = a * b * c;
    cout << fixed << setprecision(6) << out << endl;
    return 0;
}

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

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repc(i, n) for (int i = 0; i <= int(n); i++)
#define rrepc(i, n) for (int i = int(n); i >= 0; i--)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define repic(i, a, b) for (int i = int(a); i <= int(b); i++)
#define each(x, y) for (auto &x : y)
#define all(a) (a).begin(), (a).end()
#define bit(b) (1ll << (b))

using namespace std;

using i32 = int;
using i64 = long long;
using u64 = unsigned long long;
using f80 = long double;
using vi32 = vector<i32>;
using vi64 = vector<i64>;
using vu64 = vector<u64>;
using vf80 = vector<f80>;
using vstr = vector<string>;

inline void yes() { cout << "Yes" << '\n'; exit(0); }
inline void no() { cout << "No" << '\n'; exit(0); }
inline i64 gcd(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); if (a % b == 0) return b; return gcd(b, a % b); }
inline i64 lcm(i64 a, i64 b) { return a / gcd(a, b) * b; }
inline u64 xorshift() { static u64 x = 88172645463325252ull; x = x ^ (x << 7); return x = x ^ (x >> 9); }
void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); solve(); return 0; }
template <typename T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {};
template <typename T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {};
template <typename T> inline void amax(T &x, T y) { if (x < y) x = y; }
template <typename T> inline void amin(T &x, T y) { if (x > y) x = y; }
template <typename T> inline T power(T x, i64 n, T e = 1) { T r = e; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }
template <typename T> istream& operator>>(istream &is, vector<T> &v) { each(x, v) is >> x; return is; }
template <typename T> ostream& operator<<(ostream &os, vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } return os; }
template <typename T, typename S> istream& operator>>(istream &is, pair<T, S> &p) { is >> p.first >> p.second; return is; }
template <typename T, typename S> ostream& operator<<(ostream &os, pair<T, S> &p) { os << p.first << ' ' << p.second; return os; }

void solve() {
  int n; cin >> n;
  vi32 a(n + 1), b(n); cin >> a >> b;
  i64 ans = 0;
  rep(i, n) {
    if (b[i] >= a[i]) {
      b[i] -= a[i];
      i64 c = min(a[i + 1], b[i]);
      ans += c + a[i];
      a[i + 1] -= c;
    } else {
      ans += b[i];
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 1024
#include <iostream>
#include <cstdlib>
#include <vector>

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

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

const long long INF {1LL << 60};
const int max_index {110000};

int main()
{
  int n {0};
  int k {0};
  std::cin >> n >> k;
  long long h [max_index] {0};
  for (int i = 0; i < n; i++) {
    std::cin >> h[i];
  }
  
  long long dp [max_index] {0};
  for (int i = 0; i < max_index; i++) {
    dp[i] = INF;
  }
  dp[0] = 0;

  for ( int i = 0; i < n; i++ ) {
    for ( int j = 1; j <= k; j++ ) {
      chmin(dp[i+j], dp[i] + std::abs(h[i] - h[i+j]));
    }
  }
  std::cout << dp[n-1] << std::endl;
  return 0;
}


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

int main(){
    int a, b;
    char op;
    while(cin>>a >>op >>b){
        if(op=='?')break;
        if(op=='+'){
            cout<<a+b<<endl;
        }else if(op=='-'){
            cout<<a-b<<endl;
        }else if(op=='*'){
            cout<<a*b<<endl;
        }else{
            cout<<a/b<<endl;
        }
    }
    return 0;
}



Measured memory_bytes: 3096
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++)

using namespace std;
typedef long long int ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int, int> PI;
const ll mod = 1e9 + 7;

ll n;

string str(ll v) {
  stringstream ss;
  ss << v;
  return ss.str();
}

int ask(ll q) {
  if (n == 0) {
    // actual output
    cout << "? " << q << endl;
    char res;
    cin >> res;
    return res == 'Y';
  }
  return (q <= n) == (str(q) <= str(n));
}

void output(ll q) {
  if (n == 0) {
    cout << "! " << q << endl;
  } else {
    cout << n << " == " << q << endl;
  }
  exit(0);
}


int main(void) {
  n = 0;
#if 0
  cin >> n;
#endif
  if (ask(1e9)) {
    // 10...0
    ll cur = 1;
    while (true) {
      if (ask(cur + 1)) {
	output(cur);
      }
      cur *= 10;
    }
    assert (0);
  }
  // not 10...0
  ll cur = 1;
  while (true) {
    if (not ask(cur)) {
      break;
    }
    cur *= 10;
  }
  // cur / 10 < n < cur
  ll lo = cur / 10;
  ll hi = cur;
  while (hi - lo > 1) {
    ll mid = (hi + lo) / 2;
    if (ask(10 * mid)) {
      hi = mid;
    } else {
      lo = mid;
    }
  }
  output(hi);
}


Measured memory_bytes: 596
#include <bits/stdc++.h>
#include<iostream>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

typedef long long ll;
typedef pair<ll, ll> P;

const ll mod =  1000000007;  //出力は (ans % mod + mod) % mod  (負の剰余を正にする)
const int inf = 1e9;
const long long INF = 1LL << 60;   // INF = 1152921504606846976
const double PI = 3.1415926535897932;


const int MAX_N = 10010;
ll g[MAX_N][MAX_N];   //g[i][j] はすべてinfで初期化
ll d[MAX_N];
bool used[MAX_N];
int n;

void dijkstra(int s){
    fill(d,d+n,inf);
    fill(used,used+n,false);
    d[s] = 0;

    while(true){
        int v = -1;
        for(int u = 0; u < n; u++){
            if(!used[u] && (v == -1 || d[u] < d[v])){
                // 1番最小のd[u]となるuを、v = u　として保存
                // ループを抜けた後に、vを介して[u]を更新
                v = u;
            }
        }
        //　この時点でd[u]が最小となるuは決定されている。
        if(v == -1) break;
        used[v] = true;
        for(int u = 0; u < n; u++){
            d[u] = min(d[u],d[v] + g[v][u]);
        }
    }
}

int main()
{
    ll m; cin >> n >> m;
    rep(i,n) rep(j,n) g[i][j] = inf;
    vector<P> v;
    rep(i,m){
        ll a,b,c; cin >> a >> b >> c;
        a--; b--;
        g[a][b] = c;
        g[b][a] = c;
        v.push_back(make_pair(a,b));
    }
    ll ans = 0;
    rep(i,m){
        P p = v[i];
        ll a = p.first, b = p.second;
        ll cost = g[a][b];

        dijkstra(a);
        ll tmp = d[b];
        if(cost > tmp) ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 6528
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <set>
#include <string>
#include <map>
#define rep(i,n) for(int i = 0;i<n;i++)
using namespace std;
int main(){
    vector<string> s;
    map<string,int> mp;
    int max_s = 0;
    int n;
    cin >> n;
    rep(i,n){
        string ss;
        cin >> ss;
        mp[ss]++;
        max_s = max(max_s,mp[ss]);
        s.push_back(ss);
    }
    vector<string> ans;
    rep(i,s.size()){
        if(mp[s[i]]==max_s){
            ans.push_back(s[i]);
            mp[s[i]]=-1;
        }
    }
    sort(ans.begin(),ans.end());
    rep(i,ans.size()) cout << ans[i] << endl;
}

Measured memory_bytes: 28784
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define mp make_pair
#define pb push_back
#define ALL(A) A.begin(),A.end()
const long long mod=1000000007;
int main(){
    int a,b,c;
    cin>>a>>b>>c;
    cout<<a*b/2<<endl;
    return 0;
}

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

#define REP(i,n) for(int i = 0;i < n;++i)
#define PB(s) push_back(s)
#define ST(n) sort(n.begin(),n.end())

using namespace std;
typedef long long ll;

int main(){
	int H,W,h,w;

	cin >> H >> W >> h >> w;

		cout << (H-h)*(W-w) << endl;
}


Measured memory_bytes: 256
class Node:
    def __init__(self, id):
        self.id=id
        self.parent=self.left=self.right=None
        
    def insert(self, node):
        if node.id < self.id:
            if self.left is None:
                self.left=node
                node.parent=self
            else:
                self.left.insert(node)
        else:
            if self.right is None:
                self.right=node
                node.parent=self
            else:
                self.right.insert(node)
    
    def walk_inorder(self,result):
        if self.left:
            self.left.walk_inorder(result)
        result.append(self.id)
        if self.right:
            self.right.walk_inorder(result)
    
    def walk_preorder(self,result):
        result.append(self.id)
        if self.left:
            self.left.walk_preorder(result)
        if self.right:
            self.right.walk_preorder(result)
        

root=None
n=int(input())
for _ in range(n):
    cmd=input()
    if cmd[0]=='i':
        id=int(cmd.split()[1])
        node=Node(id)
        if root:
            root.insert(node)
        else:
            root=node
    else:
        if root:
            result=[]
            root.walk_inorder(result)
            print('',*result)
            result=[]
            root.walk_preorder(result)
            print('',*result)
            
            
            



Measured memory_bytes: 116564
#include<stdio.h>

int main(void){
   int w,h,x,y,r;
   scanf("%d%d%d%d%d",&w,&h,&x,&y,&r);
   if(0<=x-r && 0<=y-r && x+r<=w && y+r<=h)
      printf("Yes\n");
   else
      printf("No\n");
   return 0;
}



Measured memory_bytes: 2104
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        String S = sc.nextLine();
        String T = sc.nextLine();

        int ans = 0;
        for (int i = 0; i < S.length(); i++) {
            if (S.charAt(i) == T.charAt(i)) {
                ans++;
            }
        }
        System.out.println(ans);
    }
}


Measured memory_bytes: 24276
k = int(input())
 
def gcd(a, b):
    while True:
        r = a % b
        a, b = b, r
        if b == 0:
            return a
    
def gcds(a, b, c):
    d = gcd(a, b)
    return gcd(c, d)
 
ans = 0
for i in range(1, k+1):
    for j in range(i, k+1):
        for l in range(j, k+1):
            if (i == j) and (j == l):
                ans += gcds(i, j, l)
            elif (i != j) and(j != l) and (l != i):
                ans += 6*gcds(i, j, l)
            else:
                ans += 3*gcds(i, j, l)
print(ans)

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

using namespace std;


int main() {
    cin.tie(0);
    cout.tie(0);
    ios_base::sync_with_stdio(0);
    
    int k;
    string s, t = "...";
    cin >> k >> s;
    if(s.size() <= k)
        cout << s << '\n';
    else {
        for (int i = 0; i < k; ++i) {
            cout << s[i];

        }
        cout << t;
    }

}

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

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

int main()
{
  int n;
  while (cin >> n, n){
    int sum = 0;
    REP(i, n / 4){
      int tmp;
      cin >> tmp;
      sum += tmp;
    }
    cout << sum << endl;
  }
}

Measured memory_bytes: 1160
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		int k = sc.nextInt();
		List<Integer> S1 = prefixSum(n, sc, k);
		List<Integer> S2 = prefixSum(m, sc, k);
		// print(S1);
		// print(S2);
		n = S1.size();
		m = S2.size();
		int max = n + m;
		boolean found = false;

		int j = m - 1;
		int ans = 0;
		for (int i = 0; i < n; i++) {
			// S1 + S2 <= k
			while (S1.get(i) > k - S2.get(j)) {
				j--;
			}
			ans = Math.max(ans, i + j);
		}
		System.out.println(ans);
	}

	private static List<Integer> prefixSum(int n, Scanner sc, int k) {
		List<Integer> S = new ArrayList<>();
		S.add(0);
		for (int i = 1; i <= n; i++) {
			int t = sc.nextInt() + S.get(i - 1);
			if (t > k) {
				sc.nextLine();
				break;
			}
			S.add(t);
		}
		return S;
	}

	private static void print(List<Integer> list) {
		for (int i = 0; i < list.size(); i++) {
			System.out.print(list.get(i) + " ");
		}
		System.out.println();
	}

}


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

int main() {
	long long n, a, b; cin >> n >> a >> b;
	vector<long long> x(n);
	for (long long& i : x) {
		cin >> i;
	}
	vector<long long> cost(n, 0);
	for (int i = 1; i < n; i++) {
		cost.at(i) = cost.at(i - 1) + min(b, a * (x.at(i) - x.at(i - 1)));
	}
	cout << cost.at(n - 1) << endl;
	return 0;
}

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

using namespace std;

#define int long long
#define PB push_back
#define PPB pop_back
typedef pair<int, int> pii;
static const int INF = 1LL<<61;
static const int MAX_N = 200005;
static const int MOD = 1000000007;

int n, s[MAX_N];

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

    cin >> n;
    for (int i = 1; i <= n; ++i) {
        cin >> s[i];
    }

    for (int i = n; 0 < i; --i) {
        if (n % i != 0) continue;
        int end = n / i;
        for (int j = 1; j <= end; ++j) {
            int temp = s[j];

            for (int k = j; k <= n; k += end) {
                if (temp != s[k]) {
                    goto end;
                }
            }

        }

        cout << i << endl;
        return 0;

        end:;
    }

    return 0;
}

Measured memory_bytes: 2756
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define l long long
void frooty()
{
	l n;
	cin>>n;
	l sum=0;
	for(l i=1;i<=n;i++)
	{
		if(i%3!=0&&i%5!=0)
			sum+=i;
	}
	cout<<sum<<"\n";
}
int main()
{
	l t=1;
//	cin>>t;
	while(t--)
	{
		frooty();
	}
}

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

int main(int argc, char *argv[]){
  int a, b,imm;
  char op;
  for(;;){
    cin >> a >> op >> b;
    if(op == '?')break;
    switch(op){
    case '+':
      imm = a + b;
      cout << imm << endl;
      break;
    case '-':
      imm = a - b;
      cout << imm << endl;
      break;
    case '*':
      imm = a * b;
      cout << imm << endl;
      break;
    case '/':
      imm = a / b;
      cout << imm << endl;
      break;
    case '?':
      break;
    }
  }
  // cout << d << " " << r << " " << endl;
  return 0;
}

Measured memory_bytes: 1160
//#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>

using namespace std;


void solve() {
    int N; cin >> N;
    
    int mi = N, ans = 0;
    for (int i = 0; i < N; i++) {
        int p; cin >> p;
        if (p <= mi) {
            ans++;
            mi = p;
        }
    }

    cout << ans << endl;
}


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

Measured memory_bytes: 384
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <queue>
#include <cmath>

using namespace std;
typedef long long ll;


int main(){
  int x[100000],y[100000],x2[100000],y2[100000],n,ansx,ansy,w,h,l=0;
  ll sumx=0,sumy=0,ans=1000000000000000,sum;

  scanf("%d%d%d",&w,&h,&n);

  for(int i=0;i<n;i++){
    scanf("%d%d",&x[i],&y[i]);
    x2[i]=x[i];
    y2[i]=y[i];
  }

  sort(x,x+n);
  sort(y,y+n);

  for(int j=0;j<2;j++){
    for(int k=0;k<2;k++){
      sum=0;
      for(int i=0;i<n;i++){
	l=max(l,abs(x2[i]-x[(n+j+1)/2-1])+abs(y2[i]-y[(n+k+1)/2-1]));
	sum+=((ll)abs(x2[i]-x[(n+j+1)/2-1])+(ll)abs(y2[i]-y[(n+k+1)/2-1]))*2LL;
      }
      if(ans>sum-l){
	ans=sum-(ll)l;
	ansx=x[(n+j+1)/2-1];
	ansy=y[(n+k+1)/2-1];
      }
    }
  }
    
  printf("%lld\n%d %d\n",ans,ansx,ansy);
    
  return 0;
}

Measured memory_bytes: 2604
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef long long lint;
typedef pair<int,int> P;
const int    INF=(int)1e9;
const int    MOD=(int)1e9+7;
const double EPS=(double)1e-10;
const int    dx[]={-1,0,0,1};
const int    dy[]={0,-1,1,0};
struct Accelerate_Cin{
    Accelerate_Cin(){
        cin.tie(0);ios::sync_with_stdio(0);cout<<fixed<<setprecision(20);
    };
};

//幾何学テンプレート

#define equals(a,b) (fabs((a)-(b))<EPS)

//点
class Point{
public:
  double x,y;

  Point(double x = 0,double y = 0):x(x), y(y){};

  Point operator + (Point p) {return Point (x+p.x, y+p.y);}
  Point operator - (Point p) {return Point (x-p.x, y-p.y);}
  Point operator * (double a) {return Point(a*x, a*y);}
  Point operator / (double a) {return Point(x/a,y/a);}

  double abs(){return sqrt(norm());}
  double norm(){return x*x+y*y;}

  bool operator < (const Point &p)const{
    return x!=p.x ? x<p.x:y<p.y;
  }
  bool operator > (const Point &p)const{
    return x!=p.x ? x>p.x:y>p.y;
  }
  bool operator == (const Point &p)const{
    return fabs(x-p.x)<EPS && fabs(y-p.y)<EPS;
  }
};

//ベクトル
typedef Point Vector;

//内積
double dot(Vector a,Vector b){
  return a.x*b.x+a.y*b.y;
}

//外積
double cross(Vector a,Vector b){
  return a.x*b.y-a.y*b.x;
}

//線分
struct Segment{Point p1,p2;};

//直線
typedef Segment Line;

//円
class Circle{
public:
  Point c;   //中心
  double r;  //半径
  Circle(Point c=Point(),double r=0.0):c(c),r(r){}
};

//多角形
typedef vector<Point> Polygon;

//距離を求める。


//3点の位置関係を調べる。
static const int COUNTER_CLOCKWISE=1;
static const int CLOCKWISE=-1;
static const int ONLINE_BACK=2;
static const int ONLINE_FRONT=-2;
static const int ON_SEGMENT=0;

int ccw(Point p0,Point p1,Point p2){
  Vector a=p1-p0;
  Vector b=p2-p0;
  if(cross(a,b)>EPS)   return COUNTER_CLOCKWISE;
  if(cross(a,b)<-EPS)  return CLOCKWISE;
  if(dot(a,b)<-EPS)    return ONLINE_BACK;
  if(a.norm()<b.norm())return ONLINE_FRONT;

  return ON_SEGMENT;
}

//二つの線分の交差判定をする。
bool intersect(Point p1,Point p2,Point p3,Point p4){
  return (ccw(p1,p2,p3)*ccw(p1,p2,p4)<=0&&
          ccw(p3,p4,p1)*ccw(p3,p4,p2)<=0);
}

bool intersect(Segment s1,Segment s2){
  return intersect(s1.p1,s1.p2,s2.p1,s2.p2);
}

//点と点の距離
double getDistance(Point a, Point b){
  return (a-b).abs();
}

//点と直線の距離
double getDistanceLP(Line l, Point p){
  return abs(cross(l.p2-l.p1,p-l.p1)/(l.p2-l.p1).abs());
}

//点と線分の距離
double getDistanceSP(Segment s,Point p){
  if(dot(s.p2-s.p1,p-s.p1)<0.0) return (p-s.p1).abs();
  if(dot(s.p1-s.p2,p-s.p2)<0.0) return (p-s.p2).abs();
  return getDistanceLP(s,p);
}

//線分と線分の距離
double getDistance(Segment s1,Segment s2){
  if(intersect(s1,s2)) return 0.0;
  return min(min(getDistanceSP(s1,s2.p1),getDistanceSP(s1,s2.p2)),
             min(getDistanceSP(s2,s1.p1),getDistanceSP(s2,s1.p2)));
}


signed main(){
  int q;cin>>q;
  for(int i=0;i<q;i++){
    double x0,y0,x1,y1,x2,y2,x3,y3;cin>>x0>>y0>>x1>>y1>>x2>>y2>>x3>>y3;
    Segment s1={Point{x0,y0},Point{x1,y1}},s2={Point{x2,y2},Point{x3,y3}};
    cout<<fixed<<setprecision(15)<<getDistance(s1,s2)<<endl;
  }

  return 0;
}



Measured memory_bytes: 3300
#include<bits/stdc++.h>
using namespace std;
vector<int>x[200002];
int n,m,p,a,dist[200002];bool OK=true;
int main(){
	cin>>n>>m;
	for(int i=0;i<n;i++){
		cin>>p;for(int j=0;j<p;j++){cin>>a;a--;x[i].push_back(a+n);x[a+n].push_back(i);}
	}
	for(int i=0;i<200002;i++)dist[i]=1000000;dist[0]=1;queue<int>Q;Q.push(0);
	while(!Q.empty()){
		int a1=Q.front();Q.pop();
		for(int i=0;i<x[a1].size();i++){
			if(dist[x[a1][i]]==1000000){
				dist[x[a1][i]]=dist[a1]+1;
				Q.push(x[a1][i]);
			}
		}
	}
	for(int i=0;i<n;i++){if(dist[i]==1000000){cout<<"NO"<<endl;return 0;}}
	cout<<"YES"<<endl;
	return 0;
}

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

using namespace std;

#define x first
#define y second
#define mp make_pair
#define pb push_back
#define sqr(a) ((a) * (a))
#define sz(a) int(a.size())
#define all(a) a.begin(), a.end()
#define forn(i, n) for(int i = 0; i < int(n); i++) 
#define fore(i, l, r) for(int i = int(l); i < int(r); i++)

typedef long long li;
typedef long double ld;
typedef pair<int, int> pt;

template <class A, class B> ostream& operator << (ostream& out, const pair<A, B> &a) {
	return out << "(" << a.x << ", " << a.y << ")";
}

template <class A> ostream& operator << (ostream& out, const vector<A> &v) {
	out << "[";
	forn(i, sz(v)) {
		if(i) out << ", ";
		out << v[i];
	}
	return out << "]";
}

mt19937 rnd(time(NULL));

const int INF = int(1e9);
const li INF64 = li(1e18);
const int MOD = INF + 7;
const ld EPS = 1e-9;
const ld PI = acos(-1.0);

const int N = 200 * 1000 + 7;

int n, m, k;
pt a[N];

bool read () {
	if (scanf("%d%d%d", &n, &m, &k) != 3)
		return false;
	forn(i, k){
		scanf("%d%d", &a[i].x, &a[i].y);
		--a[i].x, --a[i].y;
	}
	return true;
}

int fact[N], rfact[N];

int add(int a, int b){
	a += b;
	if (a >= MOD)
		a -= MOD;
	if (a < 0)
		a += MOD;
	return a;
}

int mul(int a, int b){
	return (a * li(b)) % MOD;
}

int binpow(int a, int b){
	int res = 1;
	while (b){
		if (b & 1)
			res = mul(res, a);
		a = mul(a, a);
		b >>= 1;
	}
	return res;
}

int cnk(int n, int k){
	if (k < 0 || k > n) return 0;
	return mul(fact[n], mul(rfact[k], rfact[n - k]));
}

int dp[N];

void solve(){
	fact[0] = 1;
	fore(i, 1, N) fact[i] = mul(fact[i - 1], i);
	rfact[N - 1] = binpow(fact[N - 1], MOD - 2);
	for (int i = N - 2; i >= 0; --i) rfact[i] = mul(rfact[i + 1], i + 1);
	
	a[k++] = mp(n - 1, m - 1);
	sort(a, a + k);
	forn(i, k){
		dp[i] = cnk(a[i].x + a[i].y, a[i].x);
		forn(j, i) if (a[j].y <= a[i].y)
			dp[i] = add(dp[i], -mul(dp[j], cnk(a[i].x - a[j].x + a[i].y - a[j].y, a[i].x - a[j].x)));
	}
	
	printf("%d\n", dp[k - 1]);
}

int main() {
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);
	
	int tt = clock();
	
#endif
	
	cerr.precision(15);
	cout.precision(15);
	cerr << fixed;
	cout << fixed;

	while(read()) {	
		solve();
		
#ifdef _DEBUG
	cerr << "TIME = " << clock() - tt << endl;
	tt = clock();
#endif

	}
}

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

using namespace std;

#define rep(i,n) for(int i=0;i<(int)(n);i++)
void sort2array(double *a,long *b,long n){
    for(int i=0;i<n;i++){
        b[i]=i;
    }
    sort(b,b+n,[a](long i,long j)->bool {return a[i]<a[j];} );
}
int main(){
    int i;
    //入力
    int n;
    cin>>n;
    bool s=true;
    int a[n];
    rep(i,n){
        cin>>a[i];
        if(a[i]%2==0){
            if(a[i]%3!=0&&a[i]%5!=0)s=false;
        }
    }
    //処理
    //出力
    s?cout<<"APPROVED"<<endl:cout<<"DENIED"<<endl;
}

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

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)n; ++i)
#define REP(i, a, b) for (int i = (int)a; i < (int)b; ++i)
#define each(i,c) for(__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define all(v) v.begin(), v.end()
#define mset(a, n) memset(a, n, sizeof(a))

typedef long long ll;

const int INF = 1000000000;
const int MOD = 1000000007;

int main(int argc, char *argv[]) {
    // cin.tie(0);
    // ios::sync_with_stdio(false);
    int N; cin >> N;
    int Z = 0;
    deque<int> A, B;
    rep(i, N) {
        int a; cin >> a;
        if (a >= 0) A.push_back(a);
        else B.push_back(a);
        if (a == 0) Z++;
    }
    sort(all(A));
    sort(all(B));

    int x, y;
    vector<pair<int, int>> ope;
    if (A.empty()) {
        x = B[B.size()-1], y = B[0];
        ope.push_back(make_pair(x, y));
        B.pop_front();
        B.pop_back();
        A.push_back(x - y);
    }

    if (B.empty()) {
        x = A[0], y = A[A.size()-1];
        ope.push_back(make_pair(x, y));
        A.pop_front();
        A.pop_back();
        B.push_back(x - y);
    }

    while (A.size() + B.size() > 2) {
        if (B.size() == 1) {
            x = B[0], y = A[0];
            B.push_back(x - y);
            ope.push_back(make_pair(x, y));
        } else {
            x = A[0], y = B[0];
            A.push_back(x - y);
            ope.push_back(make_pair(x, y));
        }
        A.pop_front();
        B.pop_front();
    }

    x = A[0], y = B[0];
    ope.push_back(make_pair(x, y));
    cout << x - y << endl;
    if (Z == N) rep(i, N-1) cout << 0 << ' ' << 0 << endl;
    else rep(i, ope.size()) printf("%d %d\n", ope[i].first, ope[i].second);
    return 0;
}

Measured memory_bytes: 3192
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <deque>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <utility>
#include <iostream>
#include <algorithm>
#include <functional>

using namespace std;

#define INF (1 << 30)
#define INFL (1LL << 62)
#define MOD7 1000000007
#define MOD9 1000000009
#define EPS 1e-10

#define ll long long
#define ull unsigned long long
#define all(a) (a).begin(), (a).end()

int main() {
	int n;
	for (int i = 1; cin >> n && n != 0; ++i)
		cout << "Case " << i << ": " << n << endl;

	return 0;
}


Measured memory_bytes: 3016
n,m = map(int,input().split())
lis = [list(map(int,input().split())) for i in range(m)]
path = [[] for i in range(n)]

for a,b in lis:
    path[a-1].append(b-1)
    path[b-1].append(a-1)
gone = [0] * n
gone[0] = 1
ans = [-1] * n
now = {0}
for i in range(10 ** 5):
    next = set()
    while now:
        a = now.pop()
        for go in path[a]:
            if gone[go] == 0:
                gone[go] = 1
                ans[go] = a
                next.add(go)
    now = next
print("Yes")
for i in range(1,n):
    print(ans[i]+1)

Measured memory_bytes: 72800
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
int INF = 1LL << 30;
int MOD = 1e9+7;
main(){
    int N;
    cin >> N;
    vector<int> A(N+2,0);
    int sum = 0;
    for(int i = 1;i <= N;i++){
        scanf("%d",&A[i]);
        sum += abs(A[i] - A[i-1]);
    }
    sum += abs(A[N]);
    for(int i = 1;i <= N;i++){
        int a = abs(A[i-1] - A[i]) + abs(A[i] - A[i+1]);
        int b = abs(A[i-1] - A[i+1]);
        printf("%d\n",sum - a + b);
    }
}

Measured memory_bytes: 2172
#include <bits/stdc++.h>
#define LL long long
using namespace std;
int arr[100005];

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

    for(int i = 1; i <= n; i++) {
        cin >> arr[i];
    }
    int cnt = 0;
    for(int i = 2; i < n; i++) {
        if( (arr[i] > arr[i-1] and arr[i] < arr[i+1]) or (arr[i] < arr[i-1] and arr[i] > arr[i+1]) ) cnt++;
    }
    cout << cnt << "\n";
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define pb push_back
typedef long long ll;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<vector<int>> vvi;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
int main()
{
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    int n, m;
    // scanf("%d%d", &n, &m);
    cin >> n >> m;
    vector<vector<char>> A(n + 1, vector<char> (m + 1));
    for (int i = 1; i <= n; i++){
        string s;
        cin >> s;
        for (int j = 1; j <= m; j++) A[i][j] = s[j - 1];
    }
    const ll modu = 1e9 + 7;
    vvll dp(n + 1, vll(m + 1, 0));
    dp[1][1] = 1;
    for (int i = 1; i <= n; i++){
        for (int j = 1; j <= m; j++){
            if (A[i][j] == '#' || (i == 1 && j == 1)) {
                // cout << i << " LOL " << j << endl;
                continue;
            }
            dp[i][j] = (dp[i][j - 1] + dp[i - 1][j]) % modu;
            // cout << dp[i][j] << " ";
        }
        // cout << endl;
    }
    // for (int i = 1; i <= n; i++){
    //     for (int j = 1; j <= m; j++){
    //         // if (A[i][j] == '#' || (i == 1 && j == 1)) continue;
    //         // dp[i][j] = dp[i][j - 1] + dp[i - 1][j];
    //         cout << dp[i][j] << " ";
    //     }
    //     cout << endl;
    // }
    cout << dp[n][m] << endl;
    return 0;
}

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

"""
参考：https://img.atcoder.jp/exawizards2019/editorial.pdf
・二分探索
"""

import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

N,Q=MAP()
S=input()
TD=[input().split() for i in range(Q)]

# ある位置にいるゴーレムを動かして、左端から外に出ないか判定する
def calc1(m):
    idx=m
    s=S[idx]
    for i in range(Q):
        t,d=TD[i]
        if t==s:
            if d=='L':
                idx-=1
            elif d=='R':
                idx+=1
        if idx<0:
            return False
        if idx>=N:
            return True
        s=S[idx]
    return True

# ある位置にいるゴーレムを動かして、右端から外に出ないか判定する
def calc2(m):
    idx=m
    s=S[idx]
    for i in range(Q):
        t,d=TD[i]
        if t==s:
            if d=='L':
                idx-=1
            elif d=='R':
                idx+=1
        if idx>=N:
            return False
        if idx<0:
            return True
        s=S[idx]
    return True

low=-1
hi=N
while low+1<hi:
    mid=(hi+low)//2
    if calc1(mid):
        hi=mid
    else:
        low=mid
# 左端にたどり着かない(生き残る)ゴーレムのうち、初期位置が最も左のもの
lowest=hi

low=-1
hi=N
while low+1<hi:
    mid=(hi+low)//2
    if calc2(mid):
        low=mid
    else:
        hi=mid
# 右端にたどり着かない(生き残る)ゴーレムのうち、初期位置が最も右のもの
highest=low

print(max(highest-lowest+1, 0))


Measured memory_bytes: 83788
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
template<class T> using vc = vector<T>;
template<class T> using vvc = vector<vector<T>>;

const ll MOD = 1e9 + 7;
const ll INF = 1e14;
const ld EPS = 1e-11;
const ld PI = acos(-1.0L);
#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define repr(i, n) for (ll i = (n)-1; i >= 0; i--)
#define repe(i, l, r) for (ll i = (l); i < (r); i++)
#define reper(i, l, r) for (ll i = (r)-1; i >= (l); i--)

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; }

void init() {cin.tie(0);ios::sync_with_stdio(false);cout << fixed << setprecision(15);}
//--------------------------------------------------------------------------------//

int main() {
    init();
    ll N;
    cin >> N;
    vl A(N);
    rep(i, N) cin >> A[i];
    rep(i, N) A[i]--;
    ll ans = 0;
    
    rep(i,N){
        if (i == A[A[i]]) ans++;
    }
    cout << ans / 2 << endl;
} 

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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N,M,S,T;
int U[101010],V[101010],A[2][101010];
vector<pair<int,int>> E[101010];

ll D[2][101010];
ll ret[101010];

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N>>M>>S>>T;
	FOR(i,M) {
		cin>>U[i]>>V[i]>>A[0][i]>>A[1][i];
		E[U[i]-1].push_back({V[i]-1,i});
		E[V[i]-1].push_back({U[i]-1,i});
	}
	
	S--,T--;
	FOR(i,N) D[0][i]=D[1][i]=1LL<<60;
	FOR(i,2) {
		priority_queue<pair<ll,int>> PQ;
		if(i==0) {
			D[0][S]=0;
			PQ.push({0,S});
		}
		else {
			D[1][T]=0;
			PQ.push({0,T});
		}
		while(PQ.size()) {
			ll co=-PQ.top().first;
			int cur=PQ.top().second;
			PQ.pop();
			if(D[i][cur]!=co) continue;
			FORR(e,E[cur]) {
				ll nc=co+A[i][e.second];
				if(nc<D[i][e.first]) {
					D[i][e.first]=nc;
					PQ.push({-nc,e.first});
				}
			}
		}
	}
	
	ll mi=1LL<<60;
	for(i=N-1;i>=0;i--) {
		mi=min(mi,D[0][i]+D[1][i]);
		ret[i]=mi;
	}
	FOR(i,N) cout<<1000000000000000LL-ret[i]<<endl;
	
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


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

int main() {
    int n; cin >> n;
    vector<int> d(n);
    vector<int> s(n);
    int tot = 0;
    for(int i=0; i<n; i++){
        cin >> d[i];
        tot += d[i];
        s[i] = tot;
    }
    int ans = 0;
    for(int i=1; i<n; i++){
        ans += d[i] * s[i-1];
    }
    cout << ans << endl;
}

Measured memory_bytes: 3632
#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 req(i,n) for(int i = 1;i <=n;i++)
#define pai 3.14159265358979323846
const int INF = 1001001001;
typedef long long ll;
int A[3][3], N;
bool punched[3][3];
bool ok[3][3];
using Graph = vector<vector<int>>;
vector<vector<int>> field;
vector<bool> seen;

const int MOD = 1000000007;
typedef pair<int,int> P;

//最大公約数
int gcd(int a,int b){
	if (a%b == 0){
		return b;
	}
	else{
		return gcd(b,a%b);
	}

}

//最小公倍数
int lcm(int a,int b){
	return a /gcd(a,b) * b;
}

//素数判定
bool is_prime(long long N) {
    if (N == 1) return false;
    for (long long i = 2; i * i <= N; ++i) {
        if (N % i == 0) return false;
    }
    return true;
}




#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;


  




int main (){
  int a,b,c;
  cin >> a >> b >> c;
  ll ans = 0;
  bool ok = false;
  rep (i,100){
    ans += a;
    if (fmod(ans,b)==c){
      ok = true;
      break;
    }
  }
  if (ok) cout << "YES" << endl;
  else cout << "NO" << endl;
}

Measured memory_bytes: 3688
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
#include <memory>
#include <regex>
using namespace std;

int main()
{
    int n;
    cin >> n;
    vector<vector<int> > v(10, vector<int>(10, 0));
    for(int a=1; a<=n; ++a){
        string s = to_string(a);
        int i = s.front() - '0';
        int j = s.back() - '0';
        ++ v[i][j];
    }

    int ans = 0;
    for(int i=0; i<10; ++i){
        for(int j=0; j<10; ++j){
            ans += v[i][j] * v[j][i];
        }
    }
    cout << ans << endl;

    return 0;
}


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

int main()
{
	string s, temp;
	cin >> s;
	temp = s;
	reverse(temp.begin(), temp.end());

	if (temp != s) //not even a palindrome
	{
		cout << "No" << endl;
		return 0;
	}

	string a, b, tempa, tempb;
	a = s.substr(0, (s.length() - 1) / 2);
	tempa = a;
	b = s.substr((s.length() + 3) / 2 - 1);
	tempb = b;
	reverse(tempa.begin(), tempa.end());
	reverse(tempb.begin(), tempb.end());
	if (tempa != a || tempb != b) //not even a palindrome
	{
		cout << "No" << endl;
		return 0;
	}
	else
		cout << "Yes" << endl;
}

Measured memory_bytes: 256
//解説放送の実装
#include<iostream>
#include<string>
using namespace std;

int main(){
    string red[100],blue[100];
    int N,M;
    cin>>N;
    for(int i=0;i<N;i++) cin>>red[i];
    cin>>M;
    for(int i=0;i<M;i++) cin>>blue[i];
    int ans=0;
    for(int i=0;i<N;i++){
        int score=0;
        for(int j=0;j<N;j++) if(red[i]==red[j]) score++;
        for(int j=0;j<M;j++) if(red[i]==blue[j]) score--;
        ans =max(ans,score);
    }
    cout<<ans<<endl;
    return 0;
}

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

string s;

void input(){
    cin >> s;
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    input();
    map<char, int> cnt;
    for(int i=0;i<s.size();i++) cnt[s[i]]++;
    bool flg = false;
    if((cnt['S'] > 0 && cnt['N'] > 0) && (cnt['E'] > 0 && cnt['W'] > 0)) flg = true;
    if((cnt['S'] > 0 && cnt['N'] > 0) && !(cnt['E'] > 0 || cnt['W'] > 0)) flg = true;
    if(!(cnt['S'] > 0 || cnt['N'] > 0) && (cnt['E'] > 0 && cnt['W'] > 0)) flg = true;

    if(flg) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0; 
}

Measured memory_bytes: 256
# dfs
import sys
sys.setrecursionlimit(10**6)

C = ['dream', 'dreamer', 'erase', 'eraser']
S = input()
L = len(S)


def dfs(x, l):
    if l == L:
        return True
    elif l > L:
        return False

    match = S[l:l+7]
    for c in C:
        if match.find(c) == 0:
            if dfs(c, l+len(c)):
                return True
    return False


print('YES' if dfs('', 0) else 'NO')


Measured memory_bytes: 26008
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val a = (1..3).map {
        (1..3).map { sc.nextInt() }
    }
    val n = sc.nextInt()
    val b = (1..n).map {
        sc.nextInt()
    }

    println(abc157b(a, b))
}

private fun abc157b(a: List<List<Int>>, b: List<Int>): String {
    val bingo = mutableListOf<Boolean>()    
    for (i in 0..2) {
        for (j in 0..2) {
            if (b.contains(a.get(i).get(j))) {
                bingo.add(true)
            } else {
                bingo.add(false)
            }
        }
    }

    var hit = false
    if (bingo.get(0)) {
        if (bingo.get(1) && bingo.get(2)) hit = true
        if (bingo.get(3) && bingo.get(6)) hit = true
    }
    if (bingo.get(4)) {
        if (bingo.get(0) && bingo.get(8)) hit = true
        if (bingo.get(1) && bingo.get(7)) hit = true
        if (bingo.get(2) && bingo.get(6)) hit = true
        if (bingo.get(3) && bingo.get(5)) hit = true
    }
    if (bingo.get(8)) {
        if (bingo.get(2) && bingo.get(5)) hit = true
        if (bingo.get(6) && bingo.get(7)) hit = true
    }
    var ans = "No"
    if (hit) ans = "Yes"

    return ans
}

Measured memory_bytes: 29596
import math

def combinations(p, q):
    return math.factorial(p) // (math.factorial(p - q) * math.factorial(q))

n, k = map(int, input().split())

if n == k:
    print(1)
    for i in range(k-1):
        print(0)
elif k == 1:
    print(combinations(n-k+1, 1) % 1000000007)
else:
    for i in range(k-1):
        if i + 1 > n-k+1:
            print(0)
        else:
            print((combinations(n-k+1, i+1) * combinations(k-1, i)) % 1000000007)
    else:
        if k > n-k+1:
            print(0)
        else:
            print((combinations(n-k+1, k)) % 1000000007)

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

using namespace std;
typedef long long ll;
string n;
int dp[17][2];

int rec(int i, int tight) {

  
  if(i == n.size()) return 0;
    int res = 0;
   
    if(tight) {
      res = max(res,rec(i + 1,1) + (n[i] - '0'));
      if((n[i] - '0') > 0) {
	res = max(res,rec(i + 1,0) + (n[i] - '1'));
      }
    }
    else res = max(res,rec(i + 1,0) + 9);
   
    return res;
}

int main() {
  cin >> n;
  cout << rec(0,1) << endl;
}
  


Measured memory_bytes: 256
import math 
k = int(input())
ans = 0 
dic = {}
for x in range(1, k+1):
  for y in range(1, k+1):
    dic[(x, y)] = math.gcd(x, y)

for x in range(1, k+1):
  for y in range(1, k+1):
    for z in range(1, k+1):
      ans += dic[(x, dic[(y, z)])]
print(ans)

Measured memory_bytes: 73788
# include <bits/stdc++.h>
# define rep(i, n) for (ll i = 0; i < (n); i++)
# define reps(i, n) for (ll i = 1; i <= (n); i++)
# define foreps(i, m, n) for (ll i = (m); i < (n); i++)
# define len(x) ((int)(x).size())
# define all(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;
typedef long double ld;
const long long mod = 1e9 + 7;
const long long inf = 1e18;

int main() {
    ll X; cin >> X;
    ll Q = X / 100;
    ll R = X % 100;
    cout << (R <= Q * 5) << endl;
}

Measured memory_bytes: 3592
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int INF = 0x3f3f3f3f;
const int maxn = 2e5 + 10;
int N, K, C;
char s[maxn];
int dp[maxn], limit[maxn];
vector<int> v[maxn], ans;
int main()
{
    scanf("%d %d %d", &N, &K, &C);
    getchar();
    for(int i = 1; i <= N; i++)
        s[i] = getchar();
    for(int i = 1, mx = 0; i <= N; i++)
    {
        if(s[i] == 'o')
            dp[i] = mx + 1;
        else
            dp[i] = 0;
        if(i - C >= 1)
            mx = max(mx, dp[i - C]);
        v[dp[i]].push_back(i);
    }
    if(!v[K + 1].empty())
    {
        printf("\n");
        return 0;
    }
    if(v[K].size() == 1)
        ans.push_back(v[K][0]);
    limit[K] = v[K].size();
    for(int i = K; i >= 2; i--)
    {
        for(int j = 0; j < limit[i]; j++)
            limit[i-1] = max(limit[i-1], (int)(lower_bound(v[i-1].begin(), v[i-1].end(), v[i][j] - C) - v[i-1].begin()));
        if(limit[i-1] == 1)
            ans.push_back(v[i-1][0]);
    }
    for(int i = ans.size() - 1; i >= 0; i--)
        printf("%d\n", ans[i]);
	return 0;
}


Measured memory_bytes: 15096
#include <iostream>
#include <cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
using namespace std;
int main()
{
    long long n,m,ans;
    scanf("%lld%lld",&n,&m);
    if(n > m/2)
    {
        printf("%lld\n",m/2);
    }
    else
    {
        ans = n;
        m = m - n*2;
        ans += m/4;
        printf("%lld\n",ans);
    }
    return 0;
}


Measured memory_bytes: 256
while 1:
    r,a=raw_input().split()
    if r=='0' and a=='0': break
    h = b = 0
    for i in xrange(4):
        if r[i]==a[i]: h+=1
    for i in xrange(10):
        b += min(r.count(chr(ord('0')+i)),a.count(chr(ord('0')+i)))
    print h,b-h

Measured memory_bytes: 4216
n, ma, mb = map(int, input().split())

item = [tuple(map(int, input().split())) for _ in range(n)]

INF = 5000
dp = [[INF] * 444 for _ in range(444)]


dp[0][0] = 0

for i in range(n):
    next = [[INF] * 444 for _ in range(444)]
    for j in range(401):
        for k in range(401):
            a, b, c = item[i]
            next[j + a][k + b] = min(next
                                     [j + a][k + b], dp[j][k] + c)
            next[j][k] = min(next[j][k], dp[j][k])
    dp = next

ans = INF
for i in range(1, 401):
    for j in range(1, 401):  # i : j == ma : mb
        if ma * j == i * mb:
            ans = min(ans, dp[i][j])
print(ans if ans != INF else -1)


Measured memory_bytes: 89892
#include<bits/stdc++.h>
using namespace std;
#define rep(i,j,k) for(int i=j;i<k;i++)
#define MAX 500000
int cnt;
void merge(int A[],int n,int left,int mid,int right){
    int n1=mid-left;
    int n2=right-mid;
    int L[MAX/2+2],R[MAX/2+2];
    rep(i,0,n1)L[i]=A[left+i];
    rep(i,0,n2)R[i]=A[mid+i];
    L[n1]=2000000000;R[n2]=2000000000;
    int i=0,j=0;
    rep(k,left,right){
        cnt++;
        if(R[i]>=L[j]){
            A[k]=L[j];
            j++;
        }
        else{
            A[k]=R[i];
            i++;
        }
    }
}
void mergesort(int A[],int n,int left,int right){
    if(left+1<right){
        int mid=(left+right)/2;
        mergesort(A,n,left,mid);
        mergesort(A,n,mid,right);
        merge(A,n,left,mid,right);
    }
}
int main(){
    int n;cnt=0;cin>>n;
    int A[n];
    rep(i,0,n)cin>>A[i];
    mergesort(A,n,0,n);
    rep(i,0,n-1)cout<<A[i]<<" ";
    cout<<A[n-1]<<endl;
    cout<<cnt<<endl;
    return 0;
}


Measured memory_bytes: 6960
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#define MIN(a, b) (a<b?a:b)
#define MAX(a, b) (a>b?a:b)


int main()
{
    int n;
    int a[200000] = {0};
    scanf("%d", &n);
    for( int i=0; i<n-1; i++ )
    {
        int b;
        scanf("%d", &b);
        a[b-1]++;
    }
    for( int i=0; i<n; i++ )
    {
        printf("%d\n", a[i]);
    }

    return 0;
}



Measured memory_bytes: 2516
#include<bits/stdc++.h>
using namespace std;
int n,m,i,j,mod=1e9+7,a[100005],b[100005];
vector<pair<int,int> > v;
vector<int> all;
struct bit
{
	int lowbit(int x){return x&(-x);}
	int a[100005];
	void add(int x,int y)
	{
		int i;
		for (i=x;i<=100002;i+=(lowbit(i))) (a[i]+=y)%=mod;
	}
	int query(int x)
	{
		int s=0,i;
		for (i=x;i;i-=lowbit(i)) (s+=a[i])%=mod;
		return s;
	}
}c;
int main()
{
	cin>>n>>m;
	for (i=1;i<=n;i++)
	{
		cin>>a[i];
	}
	for (i=1;i<=m;i++)
	{
		cin>>b[i];
	}
	for (i=1;i<=n;i++)
	{
		int t=lower_bound(b+1,b+m+1,a[i])-b;
		if (t>=2&&t<=m)
		{
			v.push_back(make_pair(a[i]-b[t-1],-(b[t]-a[i])));
			all.push_back(b[t]-a[i]);
		}
	}
	c.add(1,1);
	sort(v.begin(),v.end());
	sort(all.begin(),all.end());
	all.resize(unique(all.begin(),all.end())-all.begin()); 
	for (i=0;i<v.size();i++)
	{
		if (!i||v[i]!=v[i-1])
		{
			int t=upper_bound(all.begin(),all.end(),-v[i].second)-all.begin();
			c.add(t+1,c.query(t));
		}
	}
	cout<<c.query(100002);
	return 0;
}

Measured memory_bytes: 2804
import java.util.Scanner;

class Main {

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

        String s=stdIn.next();
        char[] c=s.toCharArray();
        int count1=0;
        int count2=0;
        int count3=0;
        int All=0;

        //条件1
        for(int i=0; i<c.length/2; i++){
            if(c[i]==c[c.length-1-i]){
                count1++;
            }
        }
        if(count1==(c.length-1)/2){
            All++;
        }
        //条件2

        for(int i=0; i<(c.length-1)/4; i++){
            if(c[i]==c[((c.length-1)/2)-1-i]){
                count2++;
            }
        }
        if(count2==(c.length-1)/4){
            All++;
        }
        //条件3
        for(int i=0; i<(c.length+1-(c.length+3)/2)/2; i++){
            if(c[(c.length+3)/2+i-1]==c[c.length-1-i]){
                count3++;
            }
        }
        if(count3==(c.length+1-(c.length+3)/2)/2){
            All++;
        }
        
        if(All==3){
            System.out.println("Yes");
            
        }
        else{
            System.out.println("No");
            
        }
        
    }

}

Measured memory_bytes: 21844
#include<stdio.h>

int main(void){
  int n,x,i,j,k,count;

  while(1){
    count=0;
    scanf(" %d %d",&n,&x);
    if(x==0&&n==0)
      break;
    for(i=1;i<=n;i++)
      for(j=i+1;j<=n;j++)
	for(k=j+1;k<=n;k++)
	  if((i+j+k)==x)
	    count++;
    printf("%d\n",count);

  }

  return 0;
}

Measured memory_bytes: 1836