akhauriyash/Code-Regression huggingface dataset:
import itertools

N = int(input())
nums = {key: 0 for key in "MARCH"}

for _ in range(N):
    name = input()
    if name[0] in nums:
        nums[name[0]] += 1

result = 0
for combination in itertools.combinations("MARCH", 3):
    first, second, third = combination
    result += nums[first] * nums[second] * nums[third]

print(result)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int MOD = pow(10, 9) + 7;
//const int MOD = 998244353;
//const int MOD = ;
int mod(int A, int M) {return (A % M + M) % M;}
const int INF = 1LL << 60;
template <class T> bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template <class T> bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
int divCeil(int A, int B) {return (A + (B - 1)) / B;}
int myctoi(char C) {return C - 48;}
char myitoc(int N) {return '0' + N;}

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

  if ((A + B) % 2 == 0) cout << (A + B) / 2 << endl;
  else cout << "IMPOSSIBLE" << endl;
}

Measured memory_bytes: 256
//#include<bits/stdc++.h>
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
using namespace std;
using ll = long long;
int main(){
    int k;
    
    int x[5];
    for(int i=0;i<5;i++)cin >> x[i];
    cin >> k;
    bool frag = true;
    for(int i=0;i<5;i++){
        for(int j=0;j<5;j++){
            if(abs(x[i]-x[j]) > k){
                frag= false;
                break;
            }
        }
    }
    if(frag)cout << "Yay!" << endl;
    else cout << ":(" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
#include <climits>
#include <vector>
#include <numeric>
#include <complex>
#include <map>
#include <bitset>
#include <stack>
#include <queue>
#include <set>
using namespace std;

//#define __int64 long long
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
const int Vec = 4;
const int Vecy[Vec] = {0,-1,0,1};
const int Vecx[Vec] = {1,0,-1,0};
const int Modd = 1000000007;

int main(){
	string a[3];
	cin >> a[0] >> a[1] >> a[2];
	int player = 0;
	int save;
	
	while(true){
		if(a[player].length() == 0){
			cout << (char)(player + 'A') << endl;
			return 0;
		}
		save = a[player][0] - 'a';
		a[player].erase(a[player].begin());
		
		player = save;
	}
	
}

Measured memory_bytes: 256
S = input()
K = int(input())
if len(set(S)) == 1:
    print(len(S) * K // 2)
    exit()
def get_kyotsu(st):
    kyotsu = []
    tmp = 1
    for s1, s2 in zip(st[:-1], st[1:]):
        if s1 == s2:
            tmp += 1
        if s1 != s2 and tmp != 1:
            kyotsu.append(tmp)
            tmp = 1
    if tmp != 1:
        kyotsu.append(tmp)
    res = 0
    for k in kyotsu:
        res += k//2
    return res

sento = S[0]
for s1, s2 in zip(S[:-1], S[1:]):
    if s1 == s2:
        sento+=s2
    if s1 != s2:
        break
matsubi = S[-1]
for s1, s2 in zip(S[::-1][:-1], S[::-1][1:]):
    if s1 == s2:
        matsubi+=s2
    if s1 != s2:
        break

conn = matsubi + sento 

print(K * get_kyotsu(S) - (get_kyotsu(sento) + get_kyotsu(matsubi) - get_kyotsu(conn)) *(K-1))

Measured memory_bytes: 38256
#dp[x][i]=x日目に、場所iへ、行くときの幸福度の総和の最大値 連日iに行くことはできない縛りがある
#直前＝昨日にいった場所をjとすると、j!=iで表せる 
n=int(input())

dp=[[0 for i in range(3)]for j in range(n)]
happy=[]
for i in range(n):
    a,b,c=map(int,input().split())
    happy.append((a,b,c))
for i in range(3):
    dp[0][i]=happy[0][i]
for i in range(1,n):
    for t_place in range(3):
        for y_place in range(3):
            if t_place==y_place:
                continue
            dp[i][t_place]=max(dp[i][t_place],dp[i-1][y_place]+happy[i][t_place])#昨日来た場所と今日行く場所の幸福度の和
print(max(dp[n-1]))

Measured memory_bytes: 103444
N,X,Y = map(int,input().split())
answers = [0]*(N-1)
for i in range(N-1):
    for j in range(i+1,N):
        answers[min(j-i,abs(i-(X-1))+abs(j-(Y-1))+1)-1] += 1
for answer in answers:
    print(answer)

Measured memory_bytes: 45660
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <stack>
#include<algorithm>
#include<sstream>
#include<iomanip>
#include<deque>
#include<list>


using namespace std;

typedef long long ll;

typedef pair<int, int> pii;

const ll MOD_CONST = 1000000007;
const ll BIG_NUM = 1000000000000000000;
const int BIG_INT = 1000000000;



int main() {
	int a, b, c;
	cin >> a >> b >> c;
	
	int ans = 0;
	if (c <= b) {
		ans = c + b;
		c = 0;
	}
	else {
		ans = 2 * b;
		c -= b;
	}

	if (c > 0) {
		ans += min(a+1, c);
	}

	cout << ans << endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define ll long long
#define pii pair<int,int>
#define pll pair<ll int,ll int>
#define pb push_back
#define sbit __builtin_popcount
#define vec vector <int>
#define vecp vector <pii>
#define ub upper_bound
#define lb lower_bound
#define bs binary_search
#define bg begin()
#define en end()
#define endl "\n"
#define ff first
#define ss second
#define sz(a) (int)a.size()
#define min3(a,b,c) min(a,min(b,c))
#define max3(a,b,c) max(a,max(b,c))
#define sp(x) setprecision(x)
#define fill(a,b) memset(a,b,sizeof(a))
#define fr(i,n) for(int i=0;i<n;i++)
#define rp(i,a,b) for(int i=a;i<b;i++)
#define rr(i,a,b) for(int i=a;i>=b;i--)
#define ft(it,x) for(auto it : x)
#define dbg(x) cerr<<#x<<" "<<x<<endl;
#define dbga(arr,n) cerr<<#arr<<": "; rep(tt,0,n)cerr<<arr[tt]<<" "; cerr<<endl;
#define mapi map<int,int>
#define mapl map<ll int,ll int>
#define val_at(x) find_by_order(x)
#define idx_of(x) order_of_key(x)
#define scni(x) scanf("%d",&x)
#define prt(x) printf("%d\n",x)
#define test(t) int t;cin>>t;while(t--)
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
const int mod=1e9+7;
const int mex=1e6+1;
inline ll power(ll a,ll b)
{
    ll ans=1,temp=a;
    while(b!=0)
    {
        if(b&1)
        ans=ans*temp;
        ans=ans%mod;
        temp=temp*temp;
        temp=temp%mod;
        b/=2;
    }
    return ans;
}
int pr[mex];
vec prime;
inline void seive()
{
    rp(i,2,mex) pr[i]=1;
    for(int i=2;i*i<mex;i++)
    {
        if(pr[i])
        for(int j=i*i;j<mex;j+=i)
        pr[j]=0;
    }
    vec prime;
    rp(i,2,mex)
    {
        if(pr[i]) prime.pb(i);
    }
}
ll int xx,xy,d1;
void exeu(ll int a1,ll int b1)
{
    if(b1==0)
    {
        xx=1;
        xy=0;
        d1=a1;
    }
    else
    {
        exeu(b1,a1%b1);
        ll int temp=xx;
        xx=xy;
        xy=temp-(a1/b1)*xy;
    }
}
ll int modinv(ll int A,ll int M)
{
    exeu(A,M);
    return (xx%M+M)%M;
}
int main()
{
    fast
    ll int n,k;
    cin>>n>>k;
    double a[n],b[n];
    fr(i,n){ 
        cin>>a[i];
        b[i]=(a[i]+1)/2;
        if(i!=0)
        b[i]+=b[i-1];
    }
    double ans=b[k-1];
    rp(i,k,n)
    {
        ans=max(ans,b[i]-b[i-k]);
    }
    cout<<fixed<<setprecision(10)<<ans;
    
    return 0;
}


Measured memory_bytes: 3456
from sys import stdin
n = int(stdin.readline())
a = map(int,stdin.readline().split(' '))

res, l, r = 0, 0, 0
while r < n:
  l = r
  while r+1 < n and a[r+1] == a[l]:
    r += 1
  res += (r - l + 1) / 2
  r += 1
print res

Measured memory_bytes: 2568
package main

import (
        "fmt"
        "strconv"
)

// O(10^5)
func checkPIN(a []int, p []int) bool {
        var pos int

        for _, v := range a {
                if p[pos] == v {
                        pos++
                }

                if pos == len(p) {
                        return true
                }
        }
        return false
}

func main() {
        var n int
        fmt.Scanf("%d", &n)
        var s string
        fmt.Scanf("%s", &s)
        sn := make([]int, n)
        for i, r := range s {
                sn[i], _ = strconv.Atoi(string(r))
        }

        var count int
        for i1 := 0; i1 <= 9; i1++ {
                for i2 := 0; i2 <= 9; i2++ {
                        for i3 := 0; i3 <= 9; i3++ {
                                if checkPIN(sn, []int{i1, i2, i3}) {
                                        count++
                                }
                        }
                }
        }

        fmt.Println(count)
}

Measured memory_bytes: 1152
#include <iostream>
#include <atcoder/dsu>

using namespace std;

int main(){
    int N,Q;
    cin >> N >> Q;
    int query[Q][3];
    for(int i = 0; i < Q; i++){
        cin >> query[i][0]  >> query[i][1] >> query[i][2];
    }
    atcoder::dsu d(N);
    for(int i = 0; i < Q; i++){
        int u = query[i][1];
        int v = query[i][2];
        if(query[i][0] == 0){
            d.merge(u, v);
        }
        else{
            cout << d.same(u, v) << endl;
        }         
    }  
}

Measured memory_bytes: 5764
# ABC148 F
si = lambda: input()
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))
N, u, v = nm()
u -= 1
v -= 1
G = [[] for i in range(N)]
for i in range(N-1):
    A, B = nm()
    A -= 1
    B -= 1
    G[A].append(B)
    G[B].append(A)

dist_u = [-1]*N
dist_v = [-1]*N
dist_u[u] = 0
dist_v[v] = 0

from collections import deque

q = deque()
q.append(u)
while q:
    x = q.popleft()
    for nx in G[x]:
        if dist_u[nx] == -1:
            q.append(nx)
            dist_u[nx] = dist_u[x]+1

q = deque()
q.append(v)
while q:
    x = q.popleft()
    for nx in G[x]:
        if dist_v[nx] == -1:
            q.append(nx)
            dist_v[nx] = dist_v[x]+1

ans = 0
for i in range(N):
    if dist_u[i] < dist_v[i] and dist_v[i] >= ans:
        ans = dist_v[i]

print(ans-1)


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

#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("avx,avx2,fma")



using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin>>n;
    double a[n];
    for(int i=0;i<n;i++) cin>>a[i];
    double down=0;
    for(int i=0;i<n;i++)
        down+=(1/a[i]);
    cout<< (1/down) << '\n';
    return 0;
}


Measured memory_bytes: 256
n = int(input())
d = list(map(int,input().split()))
d.sort()
m = int(input())
t = list(map(int,input().split()))
t.sort()
now = 0
for x in t:
    if now == n:
        print("NO")
        exit()
    while d[now] != x:
        now += 1
        if now == n:
            print("NO")
            exit()
    now += 1

print("YES")

Measured memory_bytes: 122832
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll dp[5001][5001];
 
int main() {
  ll n,m,k,q,mod=1000000007;
  cin >> n >> m >> k >> q;
  dp[0][0]=1;
  for(int i=0; i<n; i++) {
    if(i/k%2==0) dp[1][i]=1;
  }
  ll x=n/k/2,N=k*2;
  for(int i=1; i<m; i++) {
    ll sum=0;
    for(int j=N-k; j<N; j++) sum+=dp[i][j];
    for(int j=0; j<n; j++) {
      sum-=dp[i][(j-k+N)%N];
      sum+=dp[i][j];
      dp[i+1][j]=sum*x;
      dp[i+1][j]%=mod;
    }
  }
  while(q--) {
    int a,b,c;
    cin >> a >> b >> c;
    cout << dp[b][(c-a+n)%n] << endl;
  }
  return 0;
}


Measured memory_bytes: 198456
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

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

  vector<int> list = {A, B, C};
  sort(list.rbegin(), list.rend());

  cout << list[0] * 10 + list[1] + list[2] << endl;
  return 0;
}

Measured memory_bytes: 256
n=int(input())
s=input()
nr=s.count('R')
ng=s.count('G')
nb=s.count('B')
ans=nr*ng*nb
for i in range(1,1+(n-1)//2):
      for j in range(n-2*i):
            if s[j]!=s[j+i] and s[j]!=s[2*i+j] and s[j+i]!=s[j+2*i]:
                  ans-=1
print(ans)

Measured memory_bytes: 9192
#include <bits/stdc++.h>
using namespace std;
 
#define MOD 1000000007
#define INF  2000000000
//#define int ll
#define ll long long
#define ld long double
#define vi vector<int>
#define pa pair<int, int>
#define fi first
#define se second
#define pb push_back
#define mp make_pair
 
#define INIT ios::sync_with_stdio(false);cin.tie(0);
#define VAR(type, ...)type __VA_ARGS__;MACRO_VAR_Scan(__VA_ARGS__);
template<typename T> void MACRO_VAR_Scan(T& t) { cin >> t; }
template<typename First, typename...Rest>void MACRO_VAR_Scan(First& first, Rest&...rest) { cin >> first; MACRO_VAR_Scan(rest...); }
#define VEC(type, c, n) vector<type> c(n);for(auto& i:c)cin>>i;
#define MAT(type, c, m, n) vector<vector<type>> c(m, vector<type>(n));for(auto& r:c)for(auto& i:r)cin>>i;
 
#define BR cout << "\n";
#define SP cout << " ";
#define ENDL cout<<endl;
#define OUT(d) cout<<(d);
#define OUTL(d) cout<<(d); BR;
#define YES OUTL("YES")
#define Yes OUTL("Yes")
#define NO OUTL("NO")
#define No OUTL("No")
#define RET return 0;
#define SUM(a, n) accumulate(a, a+n, 0)
#define VSUM(v) accumulate(ALL(v), 0);
 
#define REP(i, n) for(int i=0;i<(n);i++)
#define RREP(i, n) for(int i=n-1;i>=0;--i)
#define FOR(i, m, n) for(int i = m;i < n; i++)
#define RFOR(i, a, b) for(int i=(b)-1;i>=(a);--i)
#define AREP(a, n) for(auto (a):(n))
#define ALL(a) (a).begin(),(a).end()
#define IN(n, a, b) ((a)<=(n)&&(n)<(b))
 
signed main(){ INIT;
    VAR(int, a, b,c,d);
    a+=b;
    c+=d;
    if(a<c){OUTL("Right");}
    if(a==c){OUTL("Balanced");}
    if(a>c){ OUTL("Left");}
 
RET;}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

int main(){
    int n;
    cin >>n;
    vector<ll> h(n);
    rep(i,n) cin >>h[i];
    sort(all(h));

    ll ans = 1;
    int idx = 0;
    for(int i=1; i<=125; ++i){
        while(idx<n && h[idx]<i) ++idx;
        int num = n-idx;
        int add = min(num,i*4);
        ans += add;
    }
    rep(i,n){
        if(h[i]>125) ans += h[i]-125;
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 3104
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        
        
        
        
        Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		
		int a[] =new int[N];
		int b[] =new int[N];
		int m=0;
		
		
		for(int i=0;i<N;i++){
		    a[i]=sc.nextInt();
		    b[i]=a[i];
		}
		for(int i=0;i<N;i++){
		    b[i]-=1;
		}
		for(int i=0;i<N;i++){
		    m+=b[i];
		}
		
		System.out.println(m);
		
		
	}
}


Measured memory_bytes: 40712
S = input()
ans = len(S)
for i in range(26):
	c = chr(ord('a') + i)
	t = list(S)
	while not all(a==t[0] for a in t):
		u = []
		for a,b in zip(t,t[1:]):
			if a==c or b==c:
				u.append(c)
			else:
				u.append(a)
		t = u
	tmp = len(S) - len(t)
	ans = min(ans, tmp)
print(ans)

Measured memory_bytes: 9112
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.TreeSet;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author anand.oza
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        EStringsOfImpurity solver = new EStringsOfImpurity();
        solver.solve(1, in, out);
        out.close();
    }

    static class EStringsOfImpurity {
        static final public void solve(int testNumber, InputReader in, PrintWriter out) {
            char[] s = in.next().toCharArray();
            char[] t = in.next().toCharArray();

            TreeSet<Integer>[] index = new TreeSet['z' + 1];
            for (char i = 'a'; i <= 'z'; i++) {
                index[i] = new TreeSet<>();
            }

            for (int i = 0; i < s.length; i++) {
                index[s[i]].add(i);
            }

            int i = -1;
            int wraps = 0;
            for (char c : t) {
                if (index[c].isEmpty()) {
                    out.println(-1);
                    return;
                }

                Integer next = index[c].higher(i);
                if (next == null) {
                    wraps++;
                    next = index[c].first();
                }

                i = next;
            }

            long answer = ((long) s.length) * wraps + i + 1;

            out.println(answer);
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

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

    }
}



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

using namespace std;

int main() {
	int a, b, k;
	cin >> a >> b >> k;
	
	if((b - a)/2 < k){
	    while(a <= b){
	        cout << a << " ";
	        a++;
	    }
	}
	else{
	    for(int i = a; i < a+k; i++){
	        cout << i << " ";
	    }
	    for(int i = b - k + 1; i <= b; i++){
	        cout << i << " ";
	    }
	}
	
	cout << endl;
	return 0;
}


Measured memory_bytes: 256
n,m = map(int,input().split())
a = [0]*m
for i in range(m):
    a[i] = int(input())
s = 1
for i in range(m-1):
    if a[i+1] - a[i] == 1:
        s = 0
        break
if s == 0:
    print(0)
else:
    dp = [0]*(n+1)
    j = 0
    dp[0] = 1
    dp[1] = 1
    a = a + [-1]
    for i in range(n-1):
        if a[j] == i+1:
            dp[i+2] = dp[i]
        elif a[j] == i:
            dp[i+2] = dp[i+1]
            j += 1
        else:
            dp[i+2] = dp[i+1] + dp[i]
    print(dp[-1]%1000000007)

Measured memory_bytes: 460020
from fractions import gcd

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

forward = []
backward = [0 for x in range(n)]

if n == 2:
    print(max(a[0], a[1]))
    exit(0)

for i in range(n):
    if i == 0:
        forward.append(a[i])
    else:
        forward.append(gcd(forward[i - 1], a[i]))


for i in range(n - 1, -1, -1):
    if i == n - 1:
        backward[i] = a[i]
    else:
        backward[i] = gcd(backward[i + 1], a[i])


ans = 1

for i in range(n):
    if i == 0:
        ans = max(ans, backward[1])
    elif i == n - 1:
        ans = max(ans, forward[n - 2])
    else:
        ans = max(ans, gcd(forward[i - 1], backward[i + 1]))

print(ans)


Measured memory_bytes: 14160
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
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; }

const int INF = 1001001001;
int dp[1000005][2];

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    reverse(s.begin(), s.end());
    s += "0";
    int n = s.size();
    rep(i, n+1)rep(j,2) dp[i][j] = INF;
    dp[0][0] = 0;
    rep(i, n)rep(j, 2){
    	int x = s[i]-'0';
    	x += j;
    	rep(a, 10){
    		int ni = i+1, nj = 0;
    		int b = a - x;
    		if(b < 0){
    			nj = 1;
    			b += 10;
    		}
    		chmin(dp[ni][nj], dp[i][j]+a+b);
    	}
    }
    int ans = dp[n][0];
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 9116
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <utility>
#include <stack>
#include <queue>
#include <list>
#include <iterator>
#include <cmath>
#include <cstdio>

using namespace std;

int main() {
	int a, b; cin >> a >> b;
	if (a >= 13) cout << b;
	else if (6 <= a && a <= 12) cout << b / 2;
	else cout << 0;
	cout << endl;

	return 0;
}

Measured memory_bytes: 256
from sys import exit
INF = 10**21
N, L= [int(n) for n in input().split()]
apples = [L +i - 1 for i in range(1,N+1)]
ans = INF
val = INF
# print(apples)
for i in range(N):
    eat = apples[i]
    tmp = abs(eat)
    if tmp < val:
        ans = sum(apples) - eat
        val = tmp
print(ans)


Measured memory_bytes: 38768
#include <iostream>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;

int main(void) {
  int N;
  cin >> N;
  vector<string> S(2);
  cin >> S[0] >> S[1];

  const int64_t mod = 1e9 + 7;
  int64_t answer = 3;
  int start = 1;
  bool prev_same = true;
  if (S[0][0] != S[1][0]) {
    answer *= 2;
    start++;
    prev_same = false;
  }
  for (int i = start; i < N; ++i) {
    if (S[0][i] == S[1][i]) {
      if (prev_same) {
        // a b
        // a b
        answer = (answer * 2) % mod;
      } else {
        // aa c
        // bb c
        answer = answer;  // no choise
      }
      prev_same = true;
    } else {
      if (prev_same) {
        // a bb
        // a cc
        answer = (answer * 2) % mod;
      } else {
        // aa cc
        // bb dd
        answer = (answer * 3) % mod;
      }
      ++i;
      prev_same = false;
    }
  }
  cout << answer << endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string.h>

using namespace std;
const int inf = 1e7;
const int man = 5e2+10;
//int maze[man][man];
int vis[man],dis[man];
int c[15][15];
//int jishu[10];
int h,w;
/*
int dij(int u)
{
	memset(vis,0,sizeof(vis));
	for(int i =1 ;i <= 9 ;i++)
	{
		dis[i] = c[u][i];
	}
	vis[u] = 1;
	for(int i =1 ;i < 9;i++)//必须是小于9，不能等于，debug了好久。。。
	{
		int minn = inf ,v = -1;
		for(int j =1 ;j <= 9 ;j++)
		{
			if(!vis[j]&&dis[j]<minn)
			{
				v = j;
				minn = dis[j];
			}
		}
		vis[v] = 1;
		for(int j = 1; j <= 9 ;j++)
		{
			if(!vis[j])
			{
				dis[j] = min(dis[j],dis[v]+c[v][j]);
			}
		}
	}
	return dis[1];
}
*/

void floyd()
{
	for(int k = 1; k <= 9 ;k++)
	{
		for(int i = 1 ;i <= 9 ;i++)
		{
			for(int j =1;j<= 9 ;j++)
			{
				c[i][j] = min(c[i][j],c[i][k] + c[k][j]);
			}
		}
	}
}

void solve()
{
	cin >> h >> w;
	 for (int i = 0; i < 10; i++)
       for (int j = 0; j < 10; j++)
             cin>>c[i][j];
     for(int k=0;k<=9;k++)
         for(int i=0;i<=9;i++)
            for (int j = 0; j <=9; j++)
                c[i][j] = min(c[i][j],c[i][k]+c[k][j]);
     int ans = 0;
     for(int i=0;i<h;i++)
         for (int j = 0; j < w ; j++)
		 {
		 	int A;
             scanf("%d", &A);
            if (A >= 0)
                 ans += c[A][1];
         }
		//cout << dij(8) << endl;
		cout << ans << endl;
}

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



Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, K;
    cin >> N >> K;
    cout << N - K + 1 << endl;

    return 0;
}


Measured memory_bytes: 256
/* ---------- STL Libraries ---------- */

// IO library
#include <cstdio>
#include <iomanip>
#include <ios>
#include <iostream>

// algorithm library
#include <algorithm>
#include <cmath>
#include <numeric>

// container library
#include <deque>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>


/* ---------- Namespace ---------- */

using namespace std;


/* ---------- Type Abbreviation ---------- */

template <typename T>
using V = vector<T>;
template <typename T, typename U>
using P = pair<T, U>;

using ll = long long;
using PL = P<ll, ll>;
using PS = P<string, ll>;

using VI = V<int>;
using VVI = V<VI>;
using VL = V<ll>;
using VVL = V<VL>;
using VS = V<string>;
using VB = V<bool>;
using VVB = V<VB>;
using VPL = V<PL>;
using VPS = V<PS>;

#define fst first
#define snd second


/* ---------- conversion ---------- */

#define INT(c) static_cast<int>(c)
#define CHAR(n) static_cast<char>(n)
#define LL(n) static_cast<ll>(n)


/* ---------- container ---------- */

#define EACH(i, c) for (auto i = (c).begin(); i != (c).end(); i++)
#define ALL(c) (c).begin(), (c).end()
#define SORT(c) sort(ALL(c))
#define GSORT(c) sort(ALL(c), greater<decltype((c).front())>())
#define SZ(x) (LL((x).size()))


/* ---------- repetition ---------- */

#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define NREP(i, n) FOR(i, 1, n + 1)
#define RFOR(i, a, b) for (ll i = (a); i >= (b); i--)
#define RREP(i, n) RFOR(i, n, 0)
#define RNREP(i, n) RFOR(i, n, 1)

// Usual REP runs from 0 to n-1 (R: n to 0)
// Natural REP runs from 1 to n (R: n to 1)


/* ---------- Constants ---------- */

// const ll MOD = 1e9 + 7;
// const int INF = 1 << 25;
// const ll INF = 1LL << 50;
// const ll dx[4] = {0, -1, 1, 0};
// const ll dy[4] = {-1, 0, 0, 1};
// const ll dx[8] = {-1, 0, 1, -1, 1, -1, 0, 1};
// const ll dy[8] = {-1, -1, -1, 0, 0, 1, 1, 1};


/* ---------- Debug ---------- */
#define GET_VAR_NAME(variable) #variable

#define test(x) cout << GET_VAR_NAME(x) << " = " << x << endl;

template <typename T>

void testVector(T& v) {
  REP(i, SZ(v)) {
    cout << i << ":" << v << endl;
  }
}


/* ^^^^^^^^^^^^^^^ Settting Part ^^^^^^^^^^^^^^^ */

/* ---------- Variances ---------- */

ll N;
VL C(510), S(510), F(510);

/* ---------- Functions ---------- */


/* ---------- Main Function ---------- */

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

  cin >> N;
  REP(i, N - 1) {
    cin >> C[i] >> S[i] >> F[i];
  }

  REP(i, N) {
    ll time = 0;
    FOR(j, i, N - 1) {
      time = max(S[j], ((time - 1) / F[j] + 1) * F[j]);
      time += C[j];
    }
    cout << time << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using vi=vector<int>;
using vvi=vector<vi>;
using vs=vector<string>;
using msi=map<string,int>;
using mii=map<int,int>;
using pii=pair<int,int>;
using vlai=valarray<int>;
using ll=long long;
#define rep(i,n) for(int i=0;i<n;i++)
#define range(i,s,n) for(int i=s;i<n;i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define fs first
#define sc second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define INF 1e9
#define EPS 1e-9
 
using vd=vector<double>;
using vvd=vector<vd>;
 
 
int main(){
    int h,w;
    cin>>h>>w;
    vvi f(h+2,vi(w+2,1));
    vvi walk(h+2,vi(w+2,0));
    int gy,gx,y=0,x=0,v=0;
    range(i,1,h+1)range(j,1,w+1){
        char c;
        cin>>c;
        switch(c){
            case 'G': gy=i,gx=j,f[i][j]=0; break;
            case '.': f[i][j]=0;break;
            case '#': break;
            case '^': y=i,x=j,v=0,f[i][j]=0; break;
            case '>': y=i,x=j,v=1,f[i][j]=0; break;
            case 'v': y=i,x=j,v=2,f[i][j]=0; break;
            case '<': y=i,x=j,v=3,f[i][j]=0; break;
        }
    }
    walk[y][x]=1;
    rep(loop,(2600+2750)/2){
        vvi vec={{-1,0},{0,1},{1,0},{0,-1}};
        if(f[y+vec[(v+1)%4][0]][x+vec[(v+1)%4][1]]==0){ //右手が道なら右に曲がって前に進む
            //cout<<"hoge";
            v=(v+1)%4;
            y+=vec[v][0], x+=vec[v][1];
            walk[y][x]=1;
        }else if(f[y+vec[v][0]][x+vec[v][1]]==1){ //（右が壁で、）正面が壁なら左に回る
            //cout<<"fuga";
            v=(v+3)%4;
        }else{ //そうでないならまえに進む
            //cout<<"zako";
            y+=vec[v][0],x+=vec[v][1];
            walk[y][x]=1;
        }
        if(y==gy&&x==gx){
            break;
        }
        // cout<<y<<","<<x<<","<<v<<endl;
        // rep(i,h+2){
        //     rep(j,w+2){
        //         if(i==y&&j==x){
        //             cout<<"^>v<"[v];
        //         }else{
        //             cout<<".#"[f[i][j]];
        //         }
        //     }
        //     cout<<endl;
        // }
    }
    if(y==gy&&x==gx){
        int ans=0;
        rep(i,h+2)rep(j,w+2)ans+=walk[i][j];
        cout<<ans<<endl;
    }else cout<<-1<<endl;
    return 0;
}


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

int P[10010];

void init(int N){
  for(int i=0; i< N; ++i){
    P[i]= i;
  }
}

int root(int a){
  if(P[a]==a) return a;//aはroot
  return (P[a] = root(P[a]));//aの親のrootを求め,aの親とする
}
bool is_same_set(int a, int b){
  return root(a) == root(b);
}
void unite(int a, int b){
   P[root(a)] = root(b);
}


int main(){
  int n,q,d,x,y;
  cin >> n >> q;
  init(n);
  for(int i=0;i<q;i++){
    cin >> d;
    if(d==0){
      cin >> x >> y;
      unite(x,y);
    }
    if(d==1){
      cin >> x >> y;
      if(is_same_set(x,y)){
        cout << 1 << endl;
      }else{
        cout << 0 << endl;
      }
    }
  }
}

Measured memory_bytes: 1320
#pragma GCC optimize("Ofast")
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using ull = unsigned long long;
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; }
#define MOD7 1000000007
#define LL_INF 1LL << 60
#define LL_MINF -1LL << 60
#define INT_INF 2000000000
#define INT_MINF -2000000000
#define all(a) (a).begin(), (a).end()
#define fi first
#define se second
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const long double PI = (acos(-1));


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

    
    int N;
    cin >> N;
    vector<int> L(N);
    for(int i = 0; i < N; i++) cin >> L[i];
    ll count = 0;
    sort(all(L));
    for(int i = 0; i < N; i++){
        for(int j = i + 1; j < N; j++){
            for(int k = j + 1; k < N; k++){
                int a = L[i], b = L[j], c = L[k];
                if(a < b + c
                and b < a + c
                and c < a + b)count++;
                if(c >= a + b) break;
            }
        }
    }
    cout << count << endl;
}


Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
#define ll long long
typedef pair<int, int>P;
int main(){

    int N;
    cin>>N;
    vector<P>V(N), IDX(N);
    vector<P>W(N);
    vector<P>H(N);
    for(int i=0;i<N;i++){
        cin>>V[i].first>>V[i].second;
        W[i].first = V[i].first;
        W[i].second = i;
        H[i].first = V[i].second;
        H[i].second = i;
    }
    sort(W.begin(), W.end());
    sort(H.begin(), H.end());
    for(int i=0;i<N;i++){
        IDX[W[i].second].first = i;
        IDX[H[i].second].second = i;
    }
    priority_queue<P, vector<P>, greater<P> >Q;
    vector<int>flg(N, 0);
    ll ans = 0;
    Q.push(P(0, 0));
    while(!Q.empty()){
        P p = Q.top();
        Q.pop();
        if(flg[p.second])continue;
        ans+=p.first;
        flg[p.second]=1;
        int widx = IDX[p.second].first;
        int hidx = IDX[p.second].second;
        if(0<widx){
            if(flg[W[widx-1].second]==0){
                Q.push(P(W[widx].first - W[widx-1].first, W[widx-1].second));
            }
        }
        if(widx+1<N){
            if(flg[W[widx+1].second]==0){
                Q.push(P(W[widx+1].first - W[widx].first, W[widx+1].second));
            }
        }
        if(0<hidx){
            if(flg[H[hidx-1].second]==0){
                Q.push(P(H[hidx].first - H[hidx-1].first, H[hidx-1].second));
            }
        }
        if(hidx+1<N){
            if(flg[H[hidx+1].second]==0){
                Q.push(P(H[hidx+1].first - H[hidx].first, H[hidx+1].second ));
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 4984
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}
fn main(){
    let (n,t) = {
        let t = read_vec::<i64>();
        (t[0],t[1])
    };
    // let mut an = vec![];
    // for _ in 0..n{
    //     an.push(read_vec::<i64>());
    // }
    let an = read_vec2::<i64>(n as u32);
    if an.iter().filter(|x| x[1] <= t).count() == 0{
        println!("TLE");
    } else {
        let ans = an.iter().filter(|x| x[1] <= t).map(|x| x[0]).min().unwrap();
        println!("{}",ans);
    };
   
}

Measured memory_bytes: 4352
#!/usr/bin/env python3
import collections as cl
import sys


def II():
    return int(sys.stdin.readline())


def MI():
    return map(int, sys.stdin.readline().split())


def LI():
    return list(map(int, sys.stdin.readline().split()))


MOD = 10 ** 9 + 7


def main():
    N = II()
    targets = LI()

    colors = [0] * 3
    ans = 1

    for i in range(N):
        count = 0
        for k in range(3):
            if colors[k] == targets[i]:
                if count == 0:
                    colors[k] += 1
                count += 1
        ans *= count
        ans %= MOD

    print(ans)


main()


Measured memory_bytes: 84952
#define _CRT_SECURE_NO_WARNINGS

#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <cstring>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <list>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <unordered_set>
#include <unordered_map>
#include <array>
#include <cassert>
#include <bitset>
#include <cstdint>
using namespace std;
using LL = long long;

int M;

int main() {
	cin >> M;
	LL sum = 0,dig = 0;
	for (int i = 0; i < M; ++i) {
		LL d, c;
		cin >> d >> c;
		dig += c;
		sum += d * c;
	}
	LL ans = dig - 1 + (sum - 1) / 9;
	cout << ans << endl;
}

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

int main()
{
	long long n,A,B,C,D,E;
	cin>>n;
	cin>>A>>B>>C>>D>>E;
	A=min(A,min(B,min(C,min(D,E))));
	cout<<5+(n-1)/A;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
typedef long long ll;
typedef pair<int, int> pii;
const int INF = 1e9;
const int MOD = 1000000007;
const double PI = acos(-1);
int dx[4] = {0,1,0,-1};
int dy[4] = {1,0,-1,0};

void solve() {
  int n;
  cin >> n;
  vector<int> x(n), y(n);
  rep(i,n) cin >> x[i] >> y[i];
  vector<int> v(n);
  iota(ALL(v), 0);
  double ans = 0;
  int c = 0;
  do {
    c++;
    double temp = 0;
    rep(i,n-1) {
      double d = pow(x[v[i]]-x[v[i+1]], 2) + pow(y[v[i]]- y[v[i+1]], 2);
      temp += sqrt(d);
    }
    ans += temp;
  } while (next_permutation(ALL(v)));
  cout << setprecision(12) << ans / c << endl;
}

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

Measured memory_bytes: 3812
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cassert>
#include<cstring>
#include<climits>
#include<sstream>
#include<deque>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<bitset>

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

using namespace std;

typedef long long ll;

int main() {
  int a;
  cin >> a;
  if( a < 1200 ) puts("ABC");
  else puts("ARC");
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
int main()
{
  int n;
  std::cin >> n;
  std::string line;
  std::getline(std::cin, line);
  while (n--) {
    std::getline(std::cin, line);
    
    int i;
    while ((i = line.find("Hoshino")) != std::string::npos) {
      line.replace(i, 7, "Hoshina");
    }
    std::cout << line << std::endl;
  }
  return 0;
}

Measured memory_bytes: 1212
#include<iostream>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<queue>
#include<cstring>
#include<cmath>
#include<cstdio>
#include<cstdlib>
using namespace std;

int main() {
  int X, A;
  cin >> X >> A;
  if (X < A) {
    cout << 0 << endl;
  } else {
    cout << 10 << endl;
  }
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <set>
#include <vector>

using namespace std;

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

#define MOD 1000000007
#define REP(i, N) for (int i = 0; i < N; ++i)
#define REP1(i, N) for (int i = 1; i <= N; ++i)
#define RREP(i, N) for (int i = N - 1; i >= 0; --i)
#define ALL(a) a.begin(), a.end()

int main() {
  int n;
  cin >> n;
  int a[n];
  REP(i, n) cin >> a[i];
  multiset<int> st;
  REP(i, n) st.insert(a[i]);
  int ans = 0;
  while (st.size()) {
    ll p = *st.rbegin();
    st.erase(st.find(p));
    ll b = 1;
    while (b <= p) b *= 2;
    if (st.find(b - p) != st.end()) {
      ans++;
      st.erase(st.find(b - p));
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 10368
fun main(args: Array<String>) {
    val n = readLine()!!.toLong()

    for (x in Math.sqrt(n.toDouble()).toLong() downTo 1) {
        if (n % x == 0L) {
            val y = n / x
            val dist = x + y - 2
            println(dist)
            return
        }
    }
}

Measured memory_bytes: 33768
from heapq import heappush,heappop

import sys

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

def main():

    X,Y,A,B,C = list(map(int,input().split()))
    p = list(map(int,input().split()))
    q = list(map(int,input().split()))
    r = list(map(int,input().split()))

    p.sort(reverse=True)
    q.sort(reverse=True)
    r.sort(reverse=True)

    aq = []
    bq = []
    ans = 0
    for i in range(X):
        heappush(aq, p[i])
        ans += p[i]

    for i in range(Y):
        heappush(bq, q[i])
        ans += q[i]

    for rr in r:
        pp,qq = heappop(aq),heappop(bq)
        if pp < rr and qq < rr:
            if rr-pp >= rr-qq:
                heappush(aq,rr)
                heappush(bq,qq)
                ans += rr-pp
            else:
                heappush(aq,pp)
                heappush(bq,rr)
                ans += rr-qq
        elif pp<rr:
            heappush(aq,rr)
            heappush(bq,qq)
            ans += rr-pp
        elif qq<rr:
            heappush(aq,pp)
            heappush(bq,rr)
            ans += rr-qq
        else:
            break

    print(ans)


if __name__ == '__main__':
	main()

Measured memory_bytes: 107552
#include <bits/stdc++.h>
#define FOR(i, a, n) for(ll i = (ll)a; i < (ll)n; i++)
#define rep(i, n) FOR(i, 0, n)
#define ALL(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;

constexpr ll Mod = 998244353;
constexpr ll mod = 1e9 + 7;
constexpr ll inf = 1LL << 60;

template <typename T> constexpr bool chmax(T &a, const T b) {
    if(a >= b) return false;
    a = b;
    return true;
}
template <typename T> constexpr bool chmin(T &a, const T b) {
    if(a <= b) return false;
    a = b;
    return true;
}

/*-------------------------------------------*/

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

    ll n, x;
    cin >> n >> x;
    cout << 3 * (n - __gcd(n, x)) << endl;

    return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static  void main(String  args[]) {
        Scanner sc = new Scanner(System.in);
        while (true) {
            int a = sc.nextInt();
            int b = sc.nextInt();
            int c = sc.nextInt();
            if (a < 0 && b < 0 && c < 0) break;
            if (a < 0 || b < 0) {
                System.out.println("F");
            } else {
                int s = a + b;
                if (s >= 80) {
                    System.out.println("A");
                } else if (s >= 65) {
                    System.out.println("B");
                } else if (s >= 50) {
                    System.out.println("C");
                } else if (s >= 30) {
                    if (c >= 50) {
                        System.out.println("C");
                    } else {
                        System.out.println("D");
                    }
                } else {
                    System.out.println("F");
                }
            }
        }

    }
}

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

#define equals(a, b) (fabs((a)-(b)) < EPS)
const double EPS = (1e-10);

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(x*a, y*a);
    }
    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 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;
}

class Segment {
public:
    Point p1, p2;

    Segment(Point p1, Point p2): p1(p1), p2(p2) {}
};

Point project(Segment s, Point p) {
    Vector base = s.p2 - s.p1;
    Vector hypo = p - s.p1;
    double r = dot(hypo, base) / base.norm();
    return s.p1 + base*r;
}

Point reflect(Segment s, Point p) {
    return p + (project(s, p) - p)*2.0;
}

int main(void) {
    double x1, y1, x2, y2;
    cin >> x1 >> y1 >> x2 >> y2;
    Segment s(Point(x1, y1), Point(x2, y2));

    int q; cin >> q;
    double x, y;
    for (int i = 0; i < q; i++) {
        cin >> x >> y;
        Point ans = reflect(s, Point(x, y));
        printf("%.9f %.9f\n", ans.x, ans.y);
    }

    return 0;
}

Measured memory_bytes: 1240
#include <bits/stdc++.h>
using namespace std;
int a[100000];
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int n,k;
	cin>>n>>k;
	for(int i=0;i<n;i++) cin>>a[i];
	sort(a,a+n);
	int ans=0;
	for(int i=0;i<k;i++) ans+=a[i];
	cout<<ans;
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
#define ll long long
ll x,k,d;

int main(){
    cin >> x >> k >> d;
    if(x<0) x=-x;
    ll k1 = x/d;
    ll ans = 0;
    if(k1>=k){
        ans = x-k*d;
    }
    else{
        if((k-k1)%2==0){
            ans = abs(x-k1*d);
        }
        else{
            ans = abs(x-(k1+1)*d);
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 3592
from collections import Counter

n, m = map(int, input().split())
l = list(map(int, input().split()))

s = [0]
for i in range(n):
    s.append((s[-1]+l[i])%m)

c = Counter(s)

ans = 0
for x in c.values():
    ans += x*(x-1)//2

print(ans)

Measured memory_bytes: 16556
from copy import copy
n = int(input())
data = ["a"] * n
ans = ["".join(data)]

def print_str(ans, data, i):
    if i == n:
        return 
    ans.append("".join(data))
    mx = max(data[i] for i in range(n))
    while ord(data[i]) + 1 <= ord(mx) + 2:
        s = copy(data)
        ans.append("".join(data))
        print_str(ans, s, i + 1)
        data[i] = chr(ord(data[i]) + 1)
    data = ["a"] * n
    print_str(ans, data, i + 1)

print_str(ans, data, 1)
ans = sorted(set(ans))
for i in range(len(ans)):
    print(ans[i])

Measured memory_bytes: 39000
import sys
from itertools import combinations
import math


def I(): return int(sys.stdin.readline().rstrip())


def LI(): return list(map(int, sys.stdin.readline().rstrip().split()))


def S(): return sys.stdin.readline().rstrip()


def LS(): return list(sys.stdin.readline().rstrip().split())


n = I()
A = LI()
ans = 0
isEven = True
while 1:
    for a in A:
        if a % 2 == 1:
            isEven = False
    if isEven == False:
        break
    for a in range(len(A)):
        A[a] = A[a] // 2
    ans += 1
print(ans)


Measured memory_bytes: 38768
#include<iostream>
using namespace std;
int main()
{
	int n;
	cin>>n;
	int sum=0;
	for(int i=1;i<=n;i++){
		int a;
		cin>>a;
		if(a%2==1&&i%2==1){
			sum++;
		}
	}
	cout<<sum<<endl;
	return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
int main() {
  string s; cin >> s;
  string ans;
  vector<string> wez = vector<string>{"Sunny","Cloudy","Rainy"};
  for(int i=0; i<3; i++){
    if(wez[i] == s){
      if(i==2) ans = wez[0];
      else ans = wez[i+1];
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<algorithm>
#include<string.h>
using namespace std;
long long mod=1000000007;
char A[60];
char B[60];
char C[60];
long long dp[60][2];
int main(){
	while(1){
		scanf("%s",A);
		if(A[0]=='0')break;
		scanf("%s%s",B,C);
		for(int i=0;i<60;i++)dp[i][0]=dp[i][1]=0;
		int n=strlen(A);
		dp[n][0]=1;
		for(int i=n-1;i>=0;i--){
			int t11=0;
			int t12=0;
			int t21=0;
			int t22=0;
			for(int j=0;j<10;j++){
				if(i==0&&j==0)continue;
				if(A[i]!='?'&&j!=A[i]-'0')continue;
				for(int k=0;k<10;k++){
					if(i==0&&k==0)continue;
					if(B[i]!='?'&&k!=B[i]-'0')continue;
					if(C[i]!='?'&&(j+k)%10!=C[i]-'0')continue;
					if(j+k>=10)t12++;
					else t11++;
				}
			}
			for(int j=0;j<10;j++){
				if(i==0&&j==0)continue;
				if(A[i]!='?'&&j!=A[i]-'0')continue;
				for(int k=0;k<10;k++){
					if(i==0&&k==0)continue;
					if(B[i]!='?'&&k!=B[i]-'0')continue;
					if(C[i]!='?'&&(j+k+1)%10!=C[i]-'0')continue;
					if(j+k+1>=10)t22++;
					else t21++;
				}
			}
			dp[i][0]=(dp[i+1][0]*t11+dp[i+1][1]*t21)%mod;
			dp[i][1]=(dp[i+1][0]*t12+dp[i+1][1]*t22)%mod;
		//	printf("%d: %lld %lld\n",i,dp[i][0],dp[i][1]);
		}
		printf("%lld\n",dp[0][0]);
	}
}

Measured memory_bytes: 968
n = int(input())
D = [list(map(int,input().split())) for _ in range(n)] 
for i in range(n-2):
  if (D[i][0] == D[i][1]) and (D[i+1][0]==D[i+1][1]) and (D[i+2][0]==D[i+2][1]):
    print("Yes")
    break
  if i == n-3:
    print("No")

Measured memory_bytes: 9196
#include <iostream>
#include <cmath>
#include <string>
#include <typeinfo>
#include <climits>
#include <algorithm>
#include <cctype>
#include <cstring>
#include <stdio.h>
#include <cstdlib>
using namespace std;

int main(){
    int a;
    cin >> a;
    if(a<1200){
        cout << "ABC";
    }else{
        cout << "ARC";
    }
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
//Ninda Irvany

int main() {
    int x, y, z;
    cin >> x >> y;
    z = x*y;
    if(z>5) {
        cout << 1 << endl;
    }else if(z>2) {
        cout << 2 << endl;
    }else{
        cout << 3 << endl;
    }
    return 0;
}


Measured memory_bytes: 3608
using System;

class Program
{
    static void Main(string[] args)
    {
        string[] array = Console.ReadLine().Split(' ');
        int N = int.Parse(array[0]);
        int M = int.Parse(array[1]);
        int[] a = new int[M];
        int[] b = new int[M];
        bool[] brg = new bool[M];
        for (int i = 0; i < M; i++)
        {
            array = Console.ReadLine().Split(' ');
            a[i] = int.Parse(array[0]);
            b[i] = int.Parse(array[1]);
        }

        int bk = 0;
        int task = M;
        while (task != 0)
        {
            int min = N;
            for (int i = 0; i < M; i++)
            {
                if (b[i] <= min && brg[i] == false)
                {
                    min = b[i];
                }
            }
            for (int i = 0; i < M; i++)
            {
                if (a[i] < min && min <= b[i] && brg[i] == false)
                {
                    brg[i] = true;
                    task--;
                }
            }
            bk++;
        }
        Console.WriteLine(bk);
    }
}

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

using namespace std;

constexpr int MAXN = 200000;

int p[MAXN + 2];

int main() {
	int N, K;
	cin >> N >> K;
	for(int i = 0; i < N; i++) cin >> p[i];
	int sum = 0;
	for(int i = 0; i < K; i++) sum += p[i];
	int ans = sum;
	for(int i = K; i < N; i++) {
		sum += p[i];
		sum -= p[i - K];
		ans = max(ans, sum);
	}
	ans += K;
	cout << (ans >> 1) << '.' << ((ans & 1) ? '5' : '0') << '\n';
}


Measured memory_bytes: 1024