akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<vector>
using namespace std;

const int mod = 1e9 + 7;
int cnt(int mask)
{
  int ret = 0;
  while (mask)
  {
    ret += mask&1;
    mask >>= 1;
  }
  return ret;
}

bool set(int mask, int idx)
{
  return (mask >> idx) & 1;
}

void add(int& x, int y)
{
  long long res = x + y;
  if (res >= mod)
    res -= mod;
  x = res;
}


/*
int f(int idx, int mask)
{
  for (int j = 0; j < n; ++j) {
    if (match[idx][j] and !set(mask, j)) {
      ret += f(idx + 1, mask | (1 << j));
    }
  }
}

*/


int main()
{
  int n, k;
  cin >> n ;
  vector<vector<int>> dp(n + 1, vector<int>(1 << n));
  vector<vector<bool>> match(n, vector<bool>(n));
  bool x;
  for(int i = 0; i < n; ++i)
   for (int j = 0; j < n; ++j) {
     cin >> x;
     match[i][j] = x;
   }

  vector<vector<int>> masks(n + 1);
  for (int i = 0; i < (1 << n); ++i)
  {
    auto c = cnt(i);
    masks[c].push_back(i);
  }

    //cin >> match[i][j];
  dp[0][0] = 1;
  for (int i = 1; i <= n; ++i) {
   for (auto mask : masks[i-1])
   {
     for (int j = 0; j < n; ++j) {
       if (match[i-1][j] and !set(mask, j)) {
         add(dp[i][mask | 1 << j], dp[i-1][mask]);
       }
     }
   }
  }

   cout << dp[n][(1 << n) - 1] << '\n';


  return 0;
}


Measured memory_bytes: 195324
import java.util.Scanner;
public class Main{
	public static void main(String[] args) {
		Scanner scan=new Scanner(System.in);
		String a=scan.next();
		String b=scan.next();
		if(a.charAt(0)==b.charAt(2)&&a.charAt(1)==b.charAt(1)&&a.charAt(2)==b.charAt(0)) {
			System.out.println("YES");
		}
		else {
			System.out.println("NO");
		}
	}
}

Measured memory_bytes: 21716
package main

import (
	"fmt"
	"strconv"
	"strings"
)

func main() {
	var b string
	fmt.Scan(&b)

	numStrs := strings.Split(b, "")
	var sum int
	for _, numStr := range numStrs {
		num, _ := strconv.Atoi(numStr)
		sum += num
	}

	num, _ := strconv.Atoi(b)
	if num%sum == 0 {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}


Measured memory_bytes: 1840
// C++ implementation of above approach 
#include <bits/stdc++.h> 
using namespace std; 


const int MAX = 1000001; 

// structure to store queries 
struct Query 
{ 
	int l, r, idx; 
}; 

// cmp function to sort queries according to r 
bool cmp(Query x, Query y) 
{ 
	return x.r < y.r; 
} 

// updating the bit array 
void update(int idx, int val, int bit[], int n) 
{ 
	for (; idx <= n; idx += idx&-idx) 
		bit[idx] += val; 
} 

// querying the bit array 
int query(int idx, int bit[], int n) 
{ 
	int sum = 0; 
	for (; idx>0; idx-=idx&-idx) 
		sum += bit[idx]; 
	return sum; 
} 

void answeringQueries(int arr[], int n, Query queries[], int q) 
{ 
	// initialising bit array 
	int bit[n+1]; 
	memset(bit, 0, sizeof(bit)); 

	// holds the rightmost index of any number 
	// as numbers of a[i] are less than or equal to 10^6 
	int last_visit[MAX]; 
	memset(last_visit, -1, sizeof(last_visit)); 

	// answer for each query 
	int ans[q]; 
	int query_counter = 0; 
	for (int i=0; i<n; i++) 
	{ 
		// If last visit is not -1 update -1 at the 
		// idx equal to last_visit[arr[i]] 
		if (last_visit[arr[i]] !=-1) 
			update (last_visit[arr[i]] + 1, -1, bit, n); 

		// Setting last_visit[arr[i]] as i and updating 
		// the bit array accordingly 
		last_visit[arr[i]] = i; 
		update(i + 1, 1, bit, n); 

		// If i is equal to r of any query store answer 
		// for that query in ans[] 
		while (query_counter < q && queries[query_counter].r == i) 
		{ 
			ans[queries[query_counter].idx] = 
					query(queries[query_counter].r + 1, bit, n)- 
					query(queries[query_counter].l, bit, n); 
			query_counter++; 
		} 
	} 

	// print answer for each query 
	for (int i=0; i<q; i++) 
		cout << ans[i] << endl; 
} 
 
int main() 
{ 

	int n,q;
	cin>>n>>q;
	int arr[n];
	for(int i=0; i<n; ++i)
	cin>>arr[i];
Query queries[q];

for(int i=0; i<q; ++i)
{
	int a,b;
	cin>>a>>b;
	--a;
	--b;
	queries[i].idx=i;
	queries[i].l=a;
	queries[i].r=b;
}
	
sort(queries, queries+q, cmp); 
    answeringQueries(arr, n, queries, q); 
	return 0; 
} 


Measured memory_bytes: 19408
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
s = sum(a)
for i in range(n):
    c = min(a[i], b[i])
    a[i] -= c
    b[i] -= c
    a[i+1] = max(0, a[i+1]-b[i])
print(s - sum(a))

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

using namespace std;

const int MaxN = 100005;

int n, m;
vector<int> Adj[MaxN];
int f[MaxN];

void DFS(int u)
{
    f[u] = 0;
    for (auto v : Adj[u])
    {
        if (f[v] == -1)
        {
            DFS(v);
        }
        f[u] = max(f[u], f[v] + 1);
    }
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> n >> m;
    int u, v;
    for (int i = 1; i <= m; i++)
    {
        cin >> u >> v;
        Adj[u].push_back(v);
    }
    fill(f + 1, f + n + 1, -1);
    for (int i = 1; i <= n; i++)
    {
        if (f[i] == -1)
        {
            DFS(i);
        }
    }
    cout << *max_element(f + 1, f + n + 1);
    return 0;
}

Measured memory_bytes: 11448
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
vector<int> a[5];
int main(){
	ios::sync_with_stdio(false);
	for(int i=0;i<3;i++){
		int x,y;
		cin >> x >> y;
		a[x].push_back(y);
		a[y].push_back(x);
	}
	int x=0,y=0;
	for(int i=1;i<=4;i++)
		if(a[i].size()==1)x++;
		else if(a[i].size()==2)y++;
	if(x==2 and y==2)cout << "YES";
	else cout << "NO";
	return 0;
}

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

using namespace std;
typedef long long ll;

#define rep(i, N) for (int i = 0; i < (int)N; i++)
const ll MOD = pow(10,9)+7;
const ll LLINF = pow(2,61)-1;
const int INF = pow(2,29)-1;


int main() {
  int N; cin >> N;
  ll A[N]; rep(i,N) cin >> A[i];
  ll sum = 0; rep(i,N) sum += A[i];
  sum /= 2;
  for (int i=1; i<N; i+=2) sum -= A[i];
  ll result[N] = {};
  rep(i,N) {
    if (i==0) { result[i] = sum; continue; }
    result[i*2%N] = result[(i-1)*2%N];
    result[i*2%N] += A[i*2%N-1];
    result[i*2%N] -= A[(i-1)*2%N];
  }
  rep(i,N) result[i] *= 2;
  rep(i,N) cout << result[i] << " "; cout << endl;
  return 0;
}

Measured memory_bytes: 2816
import copy
N,x=map(int,input().split())

a=list(map(int,input().split()))

M=[i*x for i in range(N+1)]
M[0]=sum(a)
for i in range(1,N+1):
    b=copy.deepcopy(a)
    for j in range(N):
        b[j]=min(a[j],a[(j-1+N)%N])
    a=copy.deepcopy(b)
    M[i]+=sum(a)
print(min(M))

Measured memory_bytes: 57820
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
using namespace std;

unsigned long long int func(unsigned long long int n)
{
    int i = 0;
    while (n >= 10)
    {
        n = n / 10;
        ++i;
    }
    cout << i << endl;
    return i;
}

double func2(unsigned long long int n)
{
    int i = 0;
    while (n >= 10)
    {
        n = n / 10;
        ++i;
    }
    cout << n << endl;
    return n;
}

int main()
{

    int n;
    cin >> n;

    vector<unsigned long long int> v(n);

    unsigned long long int ans = 1LL;
    unsigned long long int pre_ans = 1LL;

    for (int i = 0; i < n; ++i)
    {
        cin >> v[i];
        if (v[i] == 0)
        {
            cout << 0 << endl;
            return 0;
        }
    }

    for (int i = 0; i < n; ++i)
    {

        ans *= v[i];
        if(ans<pre_ans){
            cout << -1 << endl;
            return 0;
        }
        if(ans>1000000000000000000){
                        cout << -1 << endl;
            return 0;

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


Measured memory_bytes: 3996
#include<bits/stdc++.h>
#define f(i,n) for(int i=0;i<n;i++)
#define F first
#define S second
#define mod 1000000007
#define P pair<int,int>
using namespace std;
double a[10];
string s[10];
signed main(){
	int n;
	double ans=0;
	cin>>n;
	f(i,n){
		cin>>a[i]>>s[i];
		if(s[i][0]=='B') ans+=a[i]*380000;
		else ans+=a[i];
	}
	printf("%.1000000lf",ans);
	return 0;
}


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

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    cin >> n;
    string s;
    cin >> s;
    int r = 0, b = 0;
    for (int i = 0; i < n; i++) {
        if (s[i] == 'B') {
            b++;
        } else {
            r++;
        }
    }
    if (r > b) {
        puts("Yes");
    } else {
        puts("No");
    }
    return 0;
}

Measured memory_bytes: 384
import math
#import numpy as np
import queue
from collections import deque,defaultdict
import heapq as hpq
from sys import stdin,setrecursionlimit
#from scipy.sparse.csgraph import dijkstra
#from scipy.sparse import csr_matrix
ipt = stdin.readline
setrecursionlimit(10**7)

def main():
    n,k = map(int,ipt().split())
    a = [int(i) for i in ipt().split()]
    a.sort()
    ra = sorted(a,reverse=True)
    mod = 10**9+7
    ans = 0

    #nCrをmodで割った余りを求める。Nに最大値を入れて使用。
    N = 10**5
    g1 = [1, 1] # 元テーブル
    g2 = [1, 1] #逆元テーブル
    inverse = [0, 1] #逆元テーブル計算用テーブル
    def cmb(n,r,mod):
        if r<0 or r>n :
            return 0
        r = min(r,n-r)
        return g1[n]*g2[r]*g2[n-r]%mod
    for i in range(2,N+1):
        g1.append((g1[-1]*i)%mod)
        inverse.append((-inverse[mod % i]*(mod//i))%mod)
        g2.append((g2[-1]*inverse[-1])%mod)

    for i,ai in enumerate(ra[:n-k+1:]):
        ans = (ans+ai*cmb(n-i-1,k-1,mod))%mod
    for i,ai in enumerate(a[:n-k+1:]):
        ans = (ans-ai*cmb(n-i-1,k-1,mod))%mod
    print(ans)

    return

if __name__ == '__main__':
    main()


Measured memory_bytes: 74404
#include <bits/stdc++.h>
using namespace std;
struct Edge {
    int to;     // 辺の行き先
    int weight; // 辺の重み
    Edge(int t, int w) : to(t), weight(w) { }
};
using Graph = vector<vector<Edge>>;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define reprep(i,j,h,w) rep(i,h)rep(j,w)
#define rrep(i,m, n) for(int i = m; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define aall(x,n) (x).begin(),(x).begin()+(n)
#define VEC(type,name,n) std::vector<type> name(n);rep(i,n)std::cin >> name[i];
#define pb push_back
#define pf push_front
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define sum accumulate
#define keta fixed<<setprecision
#define vvector(name,typ,m,n,a)vector<vector<typ> > name(m,vector<typ> (n,a))
#define vvvector(name,t,l,m,n,a) vector<vector<vector<t> > > name(l, vector<vector<t> >(m, vector<int>(n,a)));
typedef long long ll;
const int INF = 2000000000;
const long INF64 = 1000000000000000ll;
const ll MOD = 1000000007LL;
typedef unsigned int uint;
class Radix { //n進数に変換
private:
  const char* s;
  int a[100000];
public:
  Radix(const char* s = "0123456789ABCDEF") : s(s) {
    int i;    for(i = 0; s[i]; ++i)

      a[(int)s[i]] = i;
  }
  std::string to(long long p, int q) {
    int i;
    if(!p)
      return "a";
    char t[64000] = { };
    for(i = 62000; p; --i) {
      t[i] = s[p % q];
      p /= q;
    }
    return std::string(t + i + 1);
  }
  std::string to(const std::string& t, int p, int q) {
    return to(to(t, p), q);
  }
  long long to(const std::string& t, int p) {
    int i;
    long long sm = a[(int)t[0]];
    for(i = 1; i < (int)t.length(); ++i)
      sm = sm * p + a[(int)t[i]];
    return sm;
  }
};
int main(){
  ll n;
  std::cin >> n;
  ll c=0;
  for(int i=1;;i++){
    Radix r;
    string dum=r.to(i,3);
    
    if(stoll(dum)>n){
      std::cout << c << std::endl;
      exit(0);
    }
    
    ll rin=stoll(dum);
    string dumdum=dum;
    for(int j=dum.size();;j++){
      if(j!=dumdum.size())dum.insert(dum.begin(),'0');

      std::vector<ll> han(3,0);
      bool h=1;
      rep(k,dum.size()){
        if(dum[k]=='0'||dum[k]=='3'){
            han[0]++;
            dum[k]='3';
          }
        if(dum[k]=='1'||dum[k]=='5'){
            han[1]++;
            dum[k]='5';
          }
        if(dum[k]=='2'||dum[k]=='7'){
            han[2]++;
            dum[k]='7';
          }
      }
      if(stoll(dum)>n){
        break;
      }
      //std::cout << stoll(dum) << std::endl;
      rep(k,3)if(han[k]==0)h=0;
      if(h)c++;
    }
    
  }
}


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

#define rep(i, m, n) for(int(i) = (int)(m); i < (int)(n); ++i)
#define rep2(i, m, n) for(int(i) = (int)(n)-1; i >= (int)(m); --i)
#define REP(i, n) rep(i, 0, n)
#define REP2(i, n) rep2(i, 0, n)
#define all(hoge) (hoge).begin(), (hoge).end()
#define en '\n'
using ll = long long;
using ull = unsigned long long;
template <class T>
using vec = vector<T>;
template <class T>
using vvec = vector<vec<T>>;
typedef pair<ll, ll> P;
constexpr long long INF = 1LL << 60;
constexpr int INF_INT = 1 << 25;
constexpr long long MOD = (ll)1e9 + 7;
//constexpr long long MOD = 998244353LL;
using ld = long double;
static const ld pi = 3.141592653589793L;
typedef vector<ll> Array;
typedef vector<Array> Matrix;

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

struct Edge {
    ll to, rev;
    long double cap;
    Edge(ll _to, long double _cap, ll _rev) {
        to = _to;
        cap = _cap;
        rev = _rev;
    }
};
using Edges = vector<Edge>;
using Graph = vector<Edges>;

void add_edge(Graph &G, ll from, ll to, long double cap, bool revFlag,
              long double revCap) {
    G[from].push_back(Edge(to, cap, (ll)G[to].size()));
    if(revFlag)
        G[to].push_back(Edge(from, revCap, (ll)G[from].size() - 1));
}

void solve() {

    ll n, a, b;
    cin >> n >> a >> b;
    ll aa = 0, ab = 0, bb = 0;
    REP(i, n) {
        ll p;
        cin >> p;
        if(p <= a) {
            aa++;
        } else if(p <= b) {
            ab++;
        } else {
            bb++;
        }
    }
    cout << min({aa, ab, bb}) << en;
}

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

    solve();
    /*
    ll t;
    cin >> t;
    REP(i, t)
    solve();
    */

    return 0;
}


Measured memory_bytes: 3672
import sys
input = sys.stdin.readline
from collections import defaultdict
sys.setrecursionlimit(10 ** 9)

N = int(input())
d = defaultdict(int)
for _ in range(N):
    s = list(input().rstrip("\r\n"))
    s.sort()
    d["".join(s)] += 1
ans = 0
def count(v):
    if v == 0:
        return 0
    return v + count(v-1)
for k in d:
    ans += count(d[k]-1)
print(ans)

Measured memory_bytes: 101084
import bisect
import os
import sys

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7

N = int(sys.stdin.readline())
X = list(map(int, sys.stdin.readline().split()))
L = int(sys.stdin.readline())
Q = int(sys.stdin.readline())
AB = [list(map(int, sys.stdin.readline().split())) for _ in range(Q)]

N += 2
X = [X[0]] + X + [X[-1]]
X = np.array(X, dtype=int)
# dp[d][i]: i番のホテルから(2^d)日で何個右までいけるか
dp = np.zeros((N.bit_length() + 1, N), dtype=int)
dp[0] = np.searchsorted(X, X + L, side="right") - 1
for d in range(1, N.bit_length() + 1):
    dp[d] = dp[d - 1][dp[d - 1]]
dp = dp.T.tolist()


def solve(l, r):
    ret = 0
    while l + 1 < r:
        d = max(0, bisect.bisect_left(dp[l], r) - 1)
        ret += pow(2, d)
        l = dp[l][d]
    if l < r:
        ret += 1
    return ret


ans = []
for a, b in AB:
    ans.append(solve(min(a, b), max(a, b)))
print(*ans, sep='\n')


Measured memory_bytes: 131088
#include <bits/stdc++.h>
using namespace std;
int n,x;
void ask(int pos){
	cout<<pos<<endl;
	string s;
	cin>>s;
	if(s=="Male") x=0;
	else if(s=="Female") x=1;
	else exit(0);
}
int main(){
	ios_base::sync_with_stdio(0);
	cin>>n;
	int L=0,R=n-1,cL,cR;
	int mid=(L+R)/2;
	ask(L), cL=x;
	ask(R), cR=x;
	while(1){
		ask(mid);
		if(cL^x==(mid-L)%2) L=mid, cL=x;
		else R=mid, cR=x;
		mid=(L+R)/2;
	}
}


Measured memory_bytes: 852
#include<iostream>
#include<vector>
#include<cstdio>
#include<string>
#include<cmath>
#include<math.h>
#include<algorithm>
#include<string.h>
#include <iomanip>
#include <sstream>
using namespace std;

int main() {
  long long  N, K;
  long long ans = 1000000001;
  long long minh = 1000000001;
  long long maxh = 0;
  string s;

  cin >> N >> K;

  vector<long long> h(N);
  for(int i = 0; i < N; i++){
    cin >> h[i];
  }
  sort(h.begin(), h.end());
  
  for(int i = 0; i < N; i++){
    
    if(i >= (K-1)){
      ans = min(ans, h[i] - h[i-(K-1)]);
    }
  }

  cout << ans << endl;

}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i,n) for (ll i = 0; i < n; ++i)
#define ALL(c) (c).begin(), (c).end()
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end())
#define FORV(i, v) for (auto i = v.begin(); i != v.end(); i++)
using namespace std;

typedef long long ll;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
const ll INF = 1e9;
const long long INFL = 1LL<<60;

int main() {
  int n;
  cin >> n;
  vector<int> a(n, 0);
  vector<int> b(n-1);
  rep(i, n-1) {
    cin >> b[i];
  }

  a[0] = b[0];
  for (int i = 1; i < n-1; i++) {
    a[i] = min(b[i], b[i-1]);
  }
  a[n-1] = b[n-2];

  cout << SUM(a) << endl;
  return 0;
}


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

int main() {
    int n;
    cin >> n;
    vector<vector<int>> csf (n-1);
    for(int i=0; i<n-1; i++){
        int c,s,f;
        cin >> c >> s >> f;
        csf.at(i).push_back(c);
        csf.at(i).push_back(s);
        csf.at(i).push_back(f);
    }
    for(int x=-1; x<n-2; x++){
        int ans = 0;
        for(int i=x+1; i<n-1; i++){
            if(ans < csf.at(i).at(1)) ans = csf.at(i).at(1);
            if(ans % csf.at(i).at(2) != 0) ans +=  csf.at(i).at(2) - ans % csf.at(i).at(2);
            ans += csf.at(i).at(0);
        }
        cout << ans << endl;
    }
    cout << 0 << endl;
}

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

int main(){
    string S;
    cin >> S;
    if(S=="RRS"||S=="SRR"){
        cout << 2 << endl;
    }else if(S=="SSS"){
        cout << 0 << endl;
    }else if(S=="RRR"){
        cout << 3 << endl;
    }else{
        cout << 1 << endl;
    }
    system("pause");
    return 0;
}

Measured memory_bytes: 3636
#include <iostream>
#include <vector>
#include <queue>
#include <stack>
using namespace std;

struct Bridge {
    int to_;
    int time_;
    Bridge(int to, int time) 
        : to_(to), time_(time) {}
};

struct Island {
    int no_;
    int required_time_;
        Island(int no, int time) 
            : no_(no), required_time_(time) {}
};

int n;

auto isEnd(int to, int from, vector<vector<Bridge>> &bridges) -> bool {
    if (bridges[to].size() == 1 && bridges[to].front().to_ == from) {
        return true;
    }
    return false;
}

auto solve(int start, vector<vector<Bridge>> &bridges, vector<bool> &visited) -> int {
    stack<Island> st;
    st.push(Island(start, 0));
    visited[start] = true;
    int ans = 0;
    int max_cost = 0;

    while (!st.empty()) {
        Island land = st.top();
        st.pop();
        const int current_no = land.no_;
        const int current_required_time = land.required_time_;
        visited[current_no] = true;
        for (auto &e : bridges[current_no]) {
            const int to = e.to_;
            const int time = e.time_;
            if (visited[to]) continue;
            if (!isEnd(to, current_no, bridges)) {
                ans += time;
                max_cost = max(max_cost, current_required_time + time);
            }
            st.push(Island(to, time + current_required_time));
        }
    }
    return ans * 2 - max_cost;
}

auto main(int argc, char const *argv[]) -> int {
    
    while (cin>>n, n) {
        vector<vector<Bridge>> bridges(n+1);
        vector<bool> visited(n+1, false);
        for (int i = 0; i < n-1; ++i) {
            int a, b, t;
            cin>>a>>b>>t;
            bridges[a].push_back(Bridge(b, t));
            bridges[b].push_back(Bridge(a, t));
        }
        cout<<solve(1, bridges, visited)<<endl;
    }
    return 0;
}

Measured memory_bytes: 2984
#include <stdio.h>
#include <math.h>

const int Num = 200001; //defineよりいいらしい
int times; //how many times
    
long long int max_profit(int *price);

int main () {

    int price[Num];
    int i; 
    
    scanf ("%d",&times);
    
    for (i = 0;i < times;i ++) {
        scanf ("%d",&price[i]);
    }
    
    printf ("%lld\n",max_profit(price) );
    return 0;
}

long long int max_profit(int *price) {
    int i;
    long long int maxsa,min; //max初期化命 でも0やと事故る
    //max差　ただ最小値
    maxsa = -10000000000;
    
    /*ただただ差だけを考えないと事故る
      全走査しないと*/
    min = price[0];
    for (i = 1;i < times;i ++) {
        maxsa = (maxsa < price[i] - min) ? (price[i] - min) : maxsa;
        min = (min > price[i]) ? price[i] : min; 
    }
    return maxsa;
} 


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

using namespace std;

const long long int mod = 1e9 + 7;

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

  vector<vector<long long int>> dp(H, vector<long long int>(W, 0));
  dp[0][0] = 1;

  for(int i=0; i<H; i++) {
    for(int j=0; j<W; j++) {
      if(i <  H - 1) {
        if(a[i+1][j] == '.') {
          dp[i+1][j] += dp[i][j];
          dp[i+1][j] %= mod;
        }
      }
      if(j < W -1) {
        if(a[i][j+1] == '.') {
          dp[i][j+1] += dp[i][j];
          dp[i][j+1] %= mod;
        }
      }
    }
  }

  cout << dp[H-1][W-1]%mod << endl;

  return 0;
}

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

int main() {
  int A,B,C,D,E,a,b,c,d,e,z;
  cin >> A >> B >> C >> D >> E;

  a=A%10;
  b=B%10;
  c=C%10;
  d=D%10;
  e=E%10;
  
  z=0;
  
  if (a==0) a=10; z++;
  if (b==0) b=10; z++;
  if (c==0) c=10; z++;
  if (d==0) d=10; z++;
  if (e==0) e=10;
  
  if ((a<=b)&&(a<=c)&&(a<=d)&&(a<=e)) 
    cout << A+B+C+D+E+40-(b+c+d+e) << endl;
  else 
    if ((b<=a)&&(b<=c)&&(b<=d)&&(b<=e)) 
      cout << A+B+C+D+E+40-(a+c+d+e) << endl;
    else
      if ((c<=a)&&(c<=b)&&(c<=d)&&(c<=e)) 
        cout << A+B+C+D+E+40-(a+b+d+e) << endl;
      else
        if ((d<=a)&&(d<=b)&&(d<=c)&&(d<=e)) 
          cout << A+B+C+D+E+40-(a+b+c+e) << endl;
        else
          if ((e<=a)&&(e<=b)&&(e<=c)&&(e<=d)) 
            cout << A+B+C+D+E+40-(a+b+c+d) << endl;
        
}


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

int main() {
  int N;
  cin >> N;
  int count = 0;

  for (int i = 0; i < N; i++) {
    int l,r;
    cin >> l >> r;
    count += (r - l) + 1;
  }
  cout << count << endl;
}

Measured memory_bytes: 256
import sys

f = sys.stdin
N = int(f.readline()[:-1])
X = list(map(int, f.readline().split(' ')))


def cost(p):
    return sum((x - p)**2 for x in X)


P1 = sum(X) // N
P2 = P1 + 1
result1 = cost(P1)
result2 = cost(P2)
if result1 >= result2:
    print(result2)
else:
    print(result1)

Measured memory_bytes: 3064
n = gets.to_i
t, a = gets.split.map(&:to_i)
h = gets.split.map(&:to_i)

ans = 0
m = 10000000000
h.each_with_index do |h,i|
    diff = (a - (t - h * 0.006)).abs
    if m > diff
        m = diff
        ans = i + 1
    end
end

p ans

Measured memory_bytes: 1788
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<utility>
#include <functional>
#include <set>
#include <map>
#include <queue>
#include <cmath>
#include <stack>

using namespace std;


int main() {
	string s;
	cin >> s;
	int a[30];
	for (int i = 0; i < 30; i++) {
		a[i] = 0;
	}
	for (int i = 0; i < s.size(); i++) {
		int t = s[i] - 'a';
		a[t]++;
	}
	bool f = false;
	for (int i = 0; i < 30; i++) {
		if (a[i] % 2 != 0)f = true;
	}
	if (f)cout << "No";
	else cout << "Yes";
}

Measured memory_bytes: 256
#include<iostream>
#define _USE_MATH_DEFINES
#include<cmath>
#include<iomanip>

using namespace std;

int main(){

double A,B,H,M;
double h,m;
cin>>A>>B>>H>>M;

m=M*6.0000000000;
h=30.000000000*H+0.5000000000*M;


double omega = abs(h-m);

// if(omega>180){
//     omega=360-omega;
// }
double ans=sqrt(A*A+B*B-2*A*B*cos(omega*M_PI/180.0000));

cout<<fixed<<setprecision(20)<<ans<<endl;



    return 0;
}

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

#define	MOD 1000000007;
#define PI 3.14159265358979323846;
using namespace std;
typedef long long ll;
ll mod = 1000000007;

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

	set<char> D;
	for (int i = 0; i < K; i++)
	{
		char c;
		cin >> c;
		D.insert(c);
	}

	for (int i = N; i < 100000; i++)
	{
		string s = to_string(i);
		bool valid = true;
		for (int j = 0; j < s.size(); j++)
		{
			if (D.find(s[j]) != D.end())
			{
				valid = false;
				break;
			}
		}
		if (valid)
		{
			cout << i << endl;
			return 0;
		}
	}
	cout << 0 << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define all(V) V.begin(),V.end()
const ll MOD = 1000000007;

double dist(pair<double, double>&X, pair<double, double>&Y) {
	return sqrt(pow(X.first - Y.first, 2) + pow(X.second - Y.second, 2));
}

int main() {
	int N;
	cin >> N;
	vector<int> A(N), B(N);
	vector<pair<double, double>> P(N);
	for (int i = 0;i < N;i++) {
		cin >> P[i].first >> P[i].second;
		A[i] = B[i] = i;
	}
	double ans = 0;
	int cnt = 0;
	do {
		cnt++;
		next_permutation(all(A));
		for (int i = 1;i < N;i++) {
			ans += dist(P[A[i - 1]], P[A[i]]);
		}
	}while (A != B);
	printf("%.10f\n", ans / cnt);
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int ct, cx, cy;
        ct = cx = cy = 0;
        int t, x, y;
        boolean possible = true;
        for (int i = 0; i < n; i++) {
            t = sc.nextInt();
            x = sc.nextInt();
            y = sc.nextInt();
            int distance = Math.abs(x-cx) + Math.abs(y-cy);
            if (t-ct < distance || ((t-ct)-distance)%2 == 1) {
                possible = false;
                break;
            } 
            ct = t;
            cx = x;
            cy = y;
        }
        if (possible) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    }
}

Measured memory_bytes: 86980
import java.util.*;

public class Main{
  public static void main(String[]args){
    Scanner sc=new Scanner(System.in);
    int x=sc.nextInt();
    int y=sc.nextInt();
    int x2=sc.nextInt();
    int y2=sc.nextInt();
    int xx=x2-x;
    int yy=y2-y;
    int x3=x2-yy;
    int y3=y2+xx;
    int x4=x3-xx;
    int y4=y3-yy;

    System.out.println(x3+" "+y3+" "+x4+" "+y4);


    sc.close();

  }
}

Measured memory_bytes: 22612
#include <stdio.h>
//#include <stdlib.h>
//#include <string.h>
//#include <stdbool.h>
//#include <limits.h>
//#include <math.h>

int main() {
  int n;
  scanf("%d", &n);
  char s[n+5];
  scanf("%s", s);
  int cnt[3][n+1];
  cnt[0][n] = 0;
  cnt[1][n] = 0;
  cnt[2][n] = 0;
  for (int i=n-1; i>=0; i--) {
    cnt[0][i] = cnt[0][i+1] + (s[i] == 'R');
    cnt[1][i] = cnt[1][i+1] + (s[i] == 'G');
    cnt[2][i] = cnt[2][i+1] + (s[i] == 'B');
  }
  long ans = 0;
  for (int i=0; i<n-2; i++) {
    for (int j=i+1; j<n-1; j++) {
      if (s[i] == 'R') {
        if (s[j] == 'G') {
          ans += cnt[2][j+1];
          if (2*j-i < n && s[2*j-i] == 'B')
            ans--;
        } else if (s[j] == 'B') {
          ans += cnt[1][j+1];
          if (2*j-i < n && s[2*j-i] == 'G')
            ans--;
        }
      } else if (s[i] == 'G') {
        if (s[j] == 'B') {
          ans += cnt[0][j+1];
          if (2*j-i < n && s[2*j-i] == 'R')
            ans--;
        } else if (s[j] == 'R') {
          ans += cnt[2][j+1];
          if (2*j-i < n && s[2*j-i] == 'B')
            ans--;
        }
      } else {
        if (s[j] == 'R') {
          ans += cnt[1][j+1];
          if (2*j-i < n && s[2*j-i] == 'G')
            ans--;
        } else if (s[j] == 'G') {
          ans += cnt[0][j+1];
          if (2*j-i < n && s[2*j-i] == 'R')
            ans--;
        }
      }
    }
  }
  printf("%ld\n", ans);
  return 0;
}


Measured memory_bytes: 1736
/**
 * @copyright (c) 2020 Daisuke Hashimoto
 */

#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
using Pair = pair<int64_t, int64_t>;

// std::cout << std::setprecision(20) << 1.1 << endl;

const int64_t kMod = 1000000007LL;
// const int64_t kMod = 998244353LL;
struct Mint {
  int64_t value;
  Mint(int64_t value = 0LL) : value((value % kMod + kMod) % kMod) {}
  Mint operator-() const {
    return Mint(-value);
  }
  Mint &operator+=(const Mint rhs) {
    if ((value += rhs.value) >= kMod) {
      value -= kMod;
    }
    return *this;
  }
  Mint &operator-=(const Mint rhs) {
    if ((value += kMod - rhs.value) >= kMod) {
      value -= kMod;
    }
    return *this;
  }
  Mint &operator*=(const Mint rhs) {
    (value *= rhs.value) %= kMod;
    return *this;
  }
  Mint operator+(const Mint rhs) const {
    return Mint(*this) += rhs;
  }
  Mint operator-(const Mint rhs) const {
    return Mint(*this) -= rhs;
  }
  Mint operator*(const Mint rhs) const {
    return Mint(*this) *= rhs;
  }
  Mint Pow(int64_t p) const {
    if (p == 0LL) {
      return 1LL;
    } else if (p < 0LL) {
      return Pow(-p).Pow(kMod - 2LL);
    }
    Mint temp = Pow(p >> 1LL);
    temp *= temp;
    if (p & 1LL) {
      temp *= (*this);
    }
    return temp;
  }
  Mint Inv() const {
    return Pow(kMod - 2LL);
  }
  Mint &operator/=(const Mint a) {
    return *this *= a.Inv();
  }
  Mint operator/(const Mint a) const {
    return Mint(*this) /= a;
  }
};
std::ostream &operator<<(std::ostream &os, const Mint &a) {
  os << a.value;
  return os;
}

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

  int64_t N;
  cin >> N;
  // const int64_t L = static_cast<int64_t>(T.length());
  vector<int64_t> hist(N, 0);
  bool is_okay = true;
  for (int64_t i = 0; i < N; ++i) {
    int64_t a;
    cin >> a;
    ++hist[a];
  }
  for (int64_t i = 0; i < N; ++i) {
    if (i == 0) {
      if (N % 2 == 0) {
        if (hist[i] != 0) {
          is_okay = false;
        }
      } else {
        if (hist[i] != 1) {
          is_okay = false;
        }
      }
    } else {
      if (N % 2 == 0) {
        if (i % 2 == 0) {
          if (hist[i] != 0) {
            is_okay = false;
          }
        } else {
          if (hist[i] != 2) {
            is_okay = false;
          }
        }
      } else {
        if (i % 2 == 0) {
          if (hist[i] != 2) {
            is_okay = false;
          }
        } else {
          if (hist[i] != 0) {
            is_okay = false;
          }
        }
      }
    }
  }
  if (is_okay) {
    Mint result;
    if (N % 2 == 0) {
      result = Mint(2).Pow(N / 2);
    } else {
      result = Mint(2).Pow((N - 1) / 2);
    }
    cout << result.value << endl;
  } else {
    cout << 0 << endl;
  }
  return 0;
}


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

#define debug(x) cout<<#x<<": "<<x<<endl
#define rep(i,n) for (int i=0;i<(n);i++)
#define FOR(i,a,b) for (int i=(a);i<=(b);i++)
#define all(a) (a).begin(),(a).end()
using namespace std;
typedef vector<int> VI;
typedef vector<vector<int>> VVI;
typedef long long ll;


void solve() {
#ifdef _WIN32
	istream &cin = ifstream("input.txt");
#endif
	int n;
	string s;
	cin >> s;

	cout << ((int)s.find("AC") == -1 ? "No" : "Yes") << endl;
}



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

	solve();
#ifdef _WIN32
	system("PAUSE");
#endif
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
using Graph = vector<vector<ll>>;

int main(){
  ll x;cin>>x;
  ll ans = 0;
  for (ll i = 1; i <= 360; i++) {
    if ((i*360) % x == 0){
      ans = (i*360) / x;
      break;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 3504
while True:
    m, f, r = [int(i) for i in input().split()]
    
    if m == f == r == -1:
        break
    
    grade = None
    
    if m == -1 or f == -1:
        grade = 'F'
    elif m + f >= 80:
        grade = 'A'
    elif 65 <= m + f < 80:
        grade = 'B'
    elif 50 <= m + f < 65:
        grade = 'C'
    elif 30 <= m + f < 50:
        grade = 'D' if r < 50 else 'C'
    else:
        grade = 'F'
        
    print(grade)
        


Measured memory_bytes: 5604
#!/user/bin/env pypy3
import sys
from typing import List


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


def print_format(b: bool) -> str:
    return "YES" if b else "NO"


def solve(s: str, tokens: List[str], s_max: int) -> bool:
    dp = [False] * s_max
    dp[0] = True

    for s_ind in range(len(s)):
        if not dp[s_ind]:
            continue
        for token in tokens:
            if s[s_ind:s_ind + len(token)] == token:
                dp[s_ind + len(token)] = True
    return dp[len(s)]


def main():
    tokens = ["dream", "erase", "eraser", "dreamer"]
    s = fast_input()
    result = solve(s=s, tokens=tokens, s_max=len(s) + 6)
    print(print_format(result))


main()


Measured memory_bytes: 10652
#include<cstdio>
int W, H;
int x, y;
void solve()
{
	double S = (double)W*H/2.0;
	if(2*x == W && 2*y == H){
		printf("%0.9f 1\n", S);
	}	
	else{
		printf("%0.9f 0\n", S);
	}
}
int main()
{
	scanf("%d %d", &W, &H);
	scanf("%d %d", &x, &y);
	solve();
	return 0;
}


Measured memory_bytes: 128
#include<stdio.h>
int main()
{

    long long int N,s=0;
    scanf("%lld",&N);
    for(int i=1;i<=N;i++)
    {
        if(i%3!=0)
        {
            if(i%5!=0)
            {
                s=s+i;
            }
        }

    }
    printf("%lld\n",s);
    return 0;
}



Measured memory_bytes: 1680
#!/usr/bin/env perl

use strict;
use warnings;
use feature 'say';

chomp(my $str = <STDIN>);
my @nums = split(//, $str);
my $size = @nums;
my $result = 1000;
for my $i (0..($size - 3)){
    my $j = $nums[$i] . $nums[$i + 1] . $nums[$i + 2];
    $result = abs($j - 753) if (abs($j - 753) < $result);
}
say $result;


Measured memory_bytes: 768
#include <cstdint>
#include <iostream>
#include <vector>

using namespace std;

int main()
{
    int n;
    cin >> n;
    vector<uint64_t> vs(n);
    for (auto& v : vs)
    {
        cin >> v;
    }
    int64_t ans = 0;
    int right = 0;
    uint64_t accum = 0;

    for (int left = 0; left < n; accum -= vs[left], left++)
    {
        while (right < n && ((accum | vs[right]) == (accum + vs[right])))
        {
            accum += vs[right];
            right++;
        }
        ans += right - left;
    }
    cout << ans << endl;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);i++)
const int MOD=(int)1e9+7;
using namespace std;
int main(){
    int n,ans=1;
    cin>>n;
    for(int i=0;ans<=n;i++){
        ans*=2;
    }
    cout<<ans/2<<endl;
}

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

int main()
{
    int n,f=0;
    cin>>n;
    for(int i=0; i*4<=n; i++)
        for(int j=0; j*7+i*4<=n; j++)
            if(i*4+j*7==n)
            {
                f=1;
                break;
            }
    if(f)cout<<"Yes";
    else cout<<"No";
    return 0;
}


Measured memory_bytes: 256
public class Main {
  private static void solve() {
    int n = ni();
    int k = ni();
    
    long now = 1;
    for (int i = 0; i < n ; i++) {
      if (now < k) {
        now *= 2;
      } else {
        now += k;
      }
    }
    System.out.println(now);
  }

  public static void main(String[] args) {
    new Thread(null, new Runnable() {
      @Override
      public void run() {
        long start = System.currentTimeMillis();
        String debug = args.length > 0 ? args[0] : null;
        if (debug != null) {
          try {
            is = java.nio.file.Files.newInputStream(java.nio.file.Paths.get(debug));
          } catch (Exception e) {
            throw new RuntimeException(e);
          }
        }
        reader = new java.io.BufferedReader(new java.io.InputStreamReader(is), 32768);
        solve();
        out.flush();
        tr((System.currentTimeMillis() - start) + "ms");
      }
    }, "", 64000000).start();
  }

  private static java.io.InputStream is = System.in;
  private static java.io.PrintWriter out = new java.io.PrintWriter(System.out);
  private static java.util.StringTokenizer tokenizer = null;
  private static java.io.BufferedReader reader;

  public static String next() {
    while (tokenizer == null || !tokenizer.hasMoreTokens()) {
      try {
        tokenizer = new java.util.StringTokenizer(reader.readLine());
      } catch (Exception e) {
        throw new RuntimeException(e);
      }
    }
    return tokenizer.nextToken();
  }

  private static double nd() {
    return Double.parseDouble(next());
  }

  private static long nl() {
    return Long.parseLong(next());
  }

  private static int[] na(int n) {
    int[] a = new int[n];
    for (int i = 0; i < n; i++)
      a[i] = ni();
    return a;
  }

  private static char[] ns() {
    return next().toCharArray();
  }

  private static long[] nal(int n) {
    long[] a = new long[n];
    for (int i = 0; i < n; i++)
      a[i] = nl();
    return a;
  }

  private static int[][] ntable(int n, int m) {
    int[][] table = new int[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[i][j] = ni();
      }
    }
    return table;
  }

  private static int[][] nlist(int n, int m) {
    int[][] table = new int[m][n];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[j][i] = ni();
      }
    }
    return table;
  }

  private static int ni() {
    return Integer.parseInt(next());
  }

  private static void tr(Object... o) {
    if (is != System.in)
      System.out.println(java.util.Arrays.deepToString(o));
  }
}




Measured memory_bytes: 22996
n,m,c = map(int, input().split())
b = list(map(int,input().split()))

result = 0

for i in range(n):
  a = list(map(int,input().split()))
  sum_ab = 0
  for j in range(m):
    sum_ab += a[j]*b[j]
  if sum_ab+c > 0:
    result += 1

print(result)
    

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


int main()
{
    int n; ll L;
    cin >> n >> L;
    vector<ll> a(n);
    rep(i,n) scanf("%lld", &a[i]);

    int start = -1;
    rep(i,n-1) {
        if(a[i]+a[i+1] >= L) {
            start = i;
            break;
        }
    }

    if(start == -1) {printf("Impossible\n"); return 0;}

    printf("Possible\n");
    for(int i = 0; i < start; i++) printf("%d\n",i+1);
    for(int i = n-2; i >= start; --i) printf("%d\n",i+1);
    return 0;
}

Measured memory_bytes: 4032
import itertools
H, W, D = [int(_) for _ in input().split()]
A = [[int(_) for _ in input().split()] for _ in range(H)]
Q = int(input())
LR = [[int(_) for _ in input().split()] for _ in range(Q)]

G = [[0, 0]] * (H * W + 1)

for i, j in itertools.product(range(H), range(W)):
    G[A[i][j]] = [i, j]

S = [0] * (H * W + 1)

for i in range(D + 1, H * W + 1):
    x1, y1 = G[i]
    x2, y2 = G[i - D]
    S[i] += S[i - D] + abs(x1 - x2) + abs(y1 - y2)

for l, r in LR:
    print(S[r] - S[l])


Measured memory_bytes: 38432
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
long long int mod = (long long int)1000000007;
using namespace std;

void solve()
{
    ll i,j,k,n;
    std::cout.precision(10);
    int yes=0;
  string s,t;
  cin>>s>>t;
  for(i=0;i<s.size();i++)
  {
   	if(s[i]!=t[i])
    {
     	cout<<"No";
      	return;
    }
  }
  if(t.size()!=s.size()+1)
  {
   	cout<<"No";
    return;
  }
  cout<<"Yes";
}

int main()
{
    ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
    int i,j,k;
    int t;
    std::cout.precision(10);
    t=1;
    while(t--)
    {
        solve();
        cout<<"\n";
    }
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
#define step(i, s, n, d) for(int i=s; i<n; i+=d)
#define FOR(i,s,n) step(i,s,n,1)
#define rep(i,n) FOR(i,0,n)
#define ll long long
typedef pair<int, int> P;

int main(){
  int N;
  cin >> N;
  if (N % 2 == 0) {
    cout << pow(N/2, 2) << endl;
  }else{
    cout << (N/2)*(N/2+1) << endl;
  }
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <cstdio>

using namespace std;

struct Point {
  double x;
  double y;
};

double dot(Point a, Point b) {
  return a.x * b.x + a.y * b.y;
}

Point vector_sub(Point a, Point b) {
  Point c;
  c.x = b.x - a.x;
  c.y = b.y - a.y;
  return c;
}

double distance2(Point a, Point b) {
  return pow(a.x - b.x, 2) + pow(a.y - b.y, 2);
}

int main(void) {
  Point p0,p1,p2;
  int q;
  cin >> p1.x >> p1.y >> p2.x >> p2.y;
  cin >> q;

  for(int i = 0; i < q; i++) {
    cin >> p0.x >> p0.y;
    Point v10 = vector_sub(p1, p0);
    Point v12 = vector_sub(p1, p2);
    double aNorm2 = distance2(p1, p2);
    double k = dot(v10, v12) / aNorm2;
    printf("%.10lf %.10lf\n", p1.x + k * v12.x, p1.y + k * v12.y);
  }

}


Measured memory_bytes: 3292
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(k,i,n) for(ll i=k;i<n;++i)
int main(void){
    bool T[2]={false,false};
    string s;
    cin>>s;
    ll n[2]={atoi(s.substr(0,2).c_str()),atoi(s.substr(2,2).c_str())};
    rep(0,i,2){
        if(n[i]<=12 && n[i]!=0){
            T[i]=true;
        }else{
            T[i]=false;
        }
    }
    if(T[0]){
        if(T[1])cout<<"AMBIGUOUS";
        else cout<<"MMYY";
    }else{
        if(T[1])cout<<"YYMM";
        else cout<<"NA";
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mxn= 5e5+5;
#define mod 1000000007
#define endl '\n'
void rishabh(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
}
int cnt=0;
void shuffle(int a, int b, int c){
    if(a%2||b%2||c%2)return;
    cnt++;
    if(cnt>1000){cnt=-1;return ;}
    int x,y,z;
    x=(b+c)/2;
    y=(a+c)/2;
    z=(a+b)/2;
    shuffle(x,y,z);
}
int main(){
    int a,b,c;cin>>a>>b>>c;
    shuffle(a,b,c);
    cout<<cnt;
}



Measured memory_bytes: 3604
#include<bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
int main()
{
    int n,m;
    cin>>n>>m;
    vector<vector<int> > v(100000+3);

    vector<int>::iterator it;

    vector<pair<int,int> > vv;

    for(int i=1; i<=m; i++)
    {
        int a, b;
        cin>>a>>b;
        v[a].push_back(b);
        vv.push_back(make_pair(a,b));
    }

    for(int i=1; i<=n; i++)
    {
        sort(v[i].begin(),v[i].end());
    }
    int sz = vv.size();
    for(int i=0; i<sz; i++)
    {
        int x = vv[i].ff;
        int y = vv[i].ss;
        it = lower_bound(v[x].begin(),v[x].end(),y);

        int z = it-v[x].begin();
        printf("%06d%06d\n",x,z+1);
    }

    return 0;
}



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

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef vector<ld> vd;
typedef vector<ll> vll;
typedef vector<string> vstr;
typedef vector<vector<ll>> vvll;
typedef vector<pair<ll, ll>> vpll;
typedef priority_queue<ll, vector<ll>, greater<ll>> spqll;  // 小さい順に取り出し
typedef priority_queue<ll, vector<ll>, less<ll>> bpqll;     // 大きい順に取り出し

#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define FOR(i, a, b) for (ll i = (ll)a; i < (ll)b; i++)
#define IREP(i, v) for (auto i = (v).begin(); i != (v).end(); i++)
#define FI first
#define SE second
#define MP make_pair
#define MT make_tuple
#define PB push_back
#define TS to_string
#define NP next_permutation
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) (ll) x.size()
#define SP(x) setprecision((ll)x)


ll INF = 1e9;
ll NIL = -1;
ll MOD = 1000000007;
ll LINF = 1e18;
ld EPS = 1e-9;
ld PI = M_PI;
vll dx = {1, 0, -1, 0, 1, -1, -1, 1};
vll dy = {0, 1, 0, -1, 1, 1, -1, -1};
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a;} //最大公約数
ll lcm(ll a, ll b) { return a / gcd(a, b) * b;}     //最小公倍数

void yes(){ cout << "Yes" << endl;}
void no(){ cout << "No" << endl;}

//-----------------------------------------
ll h, w;
const ll H_MAX = 1000+10;
const ll W_MAX = 1000+10;
ll dp[H_MAX][W_MAX];
string grid[H_MAX];

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

    cin >> h >> w;



    REP(i,h){
        cin >> grid[i];
    }
    
    dp[0][0] = 1;
    for(ll i=1;i<h;i++){
        if(grid[i][0]=='#') dp[i][0] = 0;
        else dp[i][0] = dp[i-1][0];
    }
    for(ll j=1;j<w;j++){
        if(grid[0][j]=='#') dp[0][j] = 0;
        else dp[0][j] = dp[0][j-1];
    }
    for(ll i=1;i<h;i++){
        for(ll j=1;j<w;j++){
            if(grid[i][j]=='#') dp[i][j] = 0;
            else{
                dp[i][j] = dp[i-1][j] + dp[i][j-1];
                dp[i][j] %= MOD;
            }
        }
    }

    cout << dp[h-1][w-1] <<endl;

    
    return 0;
}



Measured memory_bytes: 12608
#include <stdio.h>
#include <limits.h>

int main(){

  int n;
  int G[105][105],d[105],pi[105],iro[105];
  int i,j,x,mincost,sum=0;

  scanf("%d",&n);

  for(i=0;i<n;i++){
    d[i]=INT_MAX;
    pi[i]=0;
    iro[i]=0;
    for(j=0;j<n;j++)scanf("%d",&G[i][j]);
  }

  d[0]=0;

  while(1){
    mincost=INT_MAX;
    for(i=0;i<n;i++){
      if(iro[i]!=1&&d[i]<mincost){
	mincost=d[i];
	x=i;
      }
    }
    if(mincost==INT_MAX)break;
    iro[x]=1;
    for(i=0;i<n;i++){
      if(G[x][i]!=-1&&iro[i]!=1&&G[x][i]<d[i]){
	pi[i]=x;
	d[i]=G[x][i];
      }
    }
  }

  for(i=0;i<n;i++)sum+=d[i];
  printf("%d\n",sum);
  
  return 0;
}



Measured memory_bytes: 2112