akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define fi first
#define se second
#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define rrep(i, n) for (int (i) = 1; (i) <= (n); (i++))
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define pb push_back
#define eb emplace_back
#define yn {puts("Yes");}else {puts("No");}
#define printd(x) printf("%.12f\n", ans);
template<class T> bool chmin(T& a, const T& b) {if (a > b) {a = b; return 1;} return 0;}
template<class T> bool chmax(T& a, const T& b) {if (a < b) {a = b; return 1;} return 0;}
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main(void) {
  string s;
  cin >> s;

  reverse(rng(s));

  vector<string> S4 = {"dream", "dreamer", "erase", "eraser"};
  rep (i, 4) reverse(rng(S4[i]));

  int sz = s.size();
  for (int i = 0; i < s.size(); i++) {
    if (sz - i <= 4) {
      cout << "NO" << endl;
      return 0;
    }
    if (s.substr(i, 5) == S4[0] || s.substr(i, 5) == S4[2]) {
      i += 4;
      continue;
    }
    if (sz - i >= 6) if (s.substr(i, 6) == S4[3]) {
      i += 5;
      continue;
    }
    if (sz - i >= 7) if (s.substr(i, 7) == S4[1]) {
      i += 6;
      continue;
    }
    cout << "NO" << endl;
    return 0;
  }

  cout << "YES" << endl;
  return 0;
}

Measured memory_bytes: 512
def solve():
    K,N = [int(i) for i in input().split()]
    A = [int(i) for i in input().split()]
    ans = max_delta = 0
    for i in range(N):
        if i == N-1:
            delta = K - A[i] + A[0]
        else:
            delta = A[i+1] - A[i]
        ans += delta
        max_delta = max(delta, max_delta)
    else:
        ans -= max_delta
    print(ans)

if __name__ == "__main__":
    solve()

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

const long long INF = 1LL << 60;

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

long long N, K, H[100010];
long long DP[100010];

int main() {
	cin >> N >> K;
	for(int i = 0; i < N; i++) {
		cin >> H[i];
	}
	for(int i = 0; i < sizeof(DP) / sizeof(long long); i++) {
		DP[i] = INF;
	}
	
	DP[0] = 0;
	for(int i = 1; i < N; i++) {
		for(int j = 1; j < K+1; j++) {
			if(i - j < 0) {
				break;
			}
			long long tmp = abs(H[i-j] - H[i]);
			chmin(DP[i], DP[i-j] + tmp);
		}
	}
	cout << DP[N-1] << endl;
}


Measured memory_bytes: 1792
#include <bit>
#include <bitset>
#include <assert.h>
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <sstream>
#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <math.h>
#include <stdlib.h>
#include <queue>
#include <stack>


typedef long double ld;
typedef long long ll;

using namespace std;

ll MOD = ((ll)1e9 + 7);

struct mod {
	ll x;

	mod(ll tx = 0) {
		x = tx;
	}
	
	mod& operator=(const ll & tx) {
		x = tx;
		return *this;
	}
	
	mod& operator=(const mod & m2) {
		x = m2.x;
		return *this;
	}

	mod operator+(const mod& m2) const {
		return (x + m2.x) % MOD;
	}

	mod& operator+=(const mod& m2) {
		x += m2.x;
		x %= MOD;
		return *this;
	}

	mod operator-(const mod & m2) const {
		return (x - m2.x + MOD) % MOD;
	}

	mod& operator-=(const mod & m2) {
		x -= m2.x;
		x = (x + MOD) % MOD;
		return *this;
	}

	mod operator*(const mod & m2) const {
		return (x * m2.x) % MOD;
	}

	mod& operator*=(const mod & m2) {
		x *= m2.x;
		x %= MOD;
		return *this;
	}

	mod mypow(ll k) const {
		mod ret = 1;
		mod cur = x;
		while (k) {
			if (k & 1) {
				ret *= cur;
			}
			cur *= cur;
			k >>= 1;
		}
		return ret;
	}

	mod inv() const {
		return mypow(MOD - 2);
	}

	mod operator/(const mod & m2) const {
		return mod(((*this).x * (*this).inv().x) % MOD);
	}

	mod& operator/=(const mod & m2) {
		x *= m2.inv().x;
		x %= MOD;
		return *this;
	}

	bool operator<(const mod & m2) const {
		return x < m2.x;
	}
};

ostream &operator<<(ostream & os, const mod & m) {
	return os << m.x;
}

/* TEMPLATE ENDS HERE */

#define MAXN (1 << 11)
#define N (1001)

int a[MAXN]; 
ll cnt[MAXN];

int main() {
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		cnt[a[i]]++;
	}
	ll ret = 0;
	for (int i = 1; i < N; i++) {
		for (int j = i + 1; j < N; j++) {
			for (int k = j + 1; k < N; k++) {
				if ((i >= j + k) || (j >= i + k) || (k >= i + j)) {
					continue;
				}
				ret += cnt[i] * cnt[j] * cnt[k];
			}
		}
	}
	for (int i = 1; i < N; i++) {
		if (cnt[i] > 2) {
			ret += (cnt[i] * (cnt[i] - 1) * (cnt[i] - 2)) / 6;
		}
	}
	for (int i = 1; i < N; i++) {
		for (int j = 1; j < N; j++) {
			if ((i == j) || (j >= 2 * i)) {
				continue;
			}
			if (cnt[i] >= 2) {
				ret += ((cnt[i] * (cnt[i] - 1)) / 2) * cnt[j];
			}
		}
	}
	cout << ret << endl;
	return 0;
}


Measured memory_bytes: 3656
#include <stdio.h>

int main()
{
    int w, a, b, ans;
    scanf("%d%d%d", &w, &a, &b);
    if (a == b) {
        ans = 0;
    } else if (a < b) {
        if (a + w >= b) {
            ans = 0;
        } else {
            ans = b - (a + w);
        }
    } else {
        if (b + w >= a) {
            ans = 0;
        } else {
            ans = a - (b + w);
        }
    }
    printf("%d\n", ans);
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  
  cin >> N;
  
  if (N % 1000 % 111 == 0 || N / 10 % 111 == 0)
    cout << "Yes" << endl;
  
  else 
    cout << "No" << endl;
  

}

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

int main() {
  string s;
  cin>>s;
  if(s=="Sunny")
    cout<<"Cloudy"<<endl;
  else if(s=="Cloudy")
    cout<<"Rainy"<<endl;
  else if(s=="Rainy")
    cout<<"Sunny"<<endl;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
#define nil -1

struct node{
	int p,l,r;
};

node A[27];
int n;

void pre(int root){
	cout <<" "<<root;
	if(A[root].l!=nil){
		pre(A[root].l);
	}
	if(A[root].r!=nil){
		pre(A[root].r);
	}
}

void ino(int root){
	if(A[root].l!=nil){
		ino(A[root].l);
	}
	cout<<" "<<root;
	if(A[root].r!=nil){
		ino(A[root].r);
	}
}

void pos(int root){
	if(A[root].l!=nil){
		pos(A[root].l);
	}
	if(A[root].r!=nil){
		pos(A[root].r);
	}
	cout<<" "<<root;
}

int main() {
	int v,L,R;
	cin>>n;
	for(int i=0;i<n;i++){
		A[i].p=A[i].l=A[i].r=nil;
	}
	for(int i=0;i<n;i++){
		cin>>v>>L>>R;
		A[v].l=L;A[v].r=R;
		if(L!=nil){
			A[L].p=v;
		}
		if(R!=nil){
			A[R].p=v;
		}
	}
	int root;
	for(int i=0;i<n;i++){
		if(A[i].p==nil){
			root=i;
		}
	}
	cout<<"Preorder"<<endl;
	pre(root);cout<<endl;
	cout<<"Inorder"<<endl;
	ino(root);cout<<endl;
	cout<<"Postorder"<<endl;
	pos(root);cout<<endl;
	return 0;
}


Measured memory_bytes: 3116
#include <stdio.h>

double BMI(double weight, double length);

int main(int argc, const char *argv[])
{
	int num;
	double w, l;
	
	while(scanf("%d,%lf,%lf", &num, &w, &l)!=EOF){
		if(BMI(w, l)>=25) printf("%d\n", num); 
	}

	return 0;
}

double BMI(double weight, double length)
{
	return weight/length/length;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimization_level 3
using ll = long long;
constexpr ll INF = 1'010'000'000'000'000'017LL;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()

int main(){
	ll a,b;
	cin>>a>>b;
	ll ra;
	ll rb;

	for (size_t i = 0; i < 1250; i++)
	{
		ra = i*0.08;
		rb = i*0.10;

		if (ra==a && rb==b)
		{
			cout<<i;
			return 0;
		}
		
	}

	cout<<-1;
	
}


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

int main(){
    int N, M, X, count1=0,count2=0;
    cin >> N >> M >> X;
    vector<int> vec(M);
    for(int i = 0;i<M;i++){
        cin >> vec.at(i);
        if(vec.at(i)>X)
            count1++;
        
        else
            count2++;  
    }
    cout << min(count1,count2) << endl;   
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<limits>
#include<iomanip>
#include<cmath>
#include<climits>

using namespace std;

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

typedef long long ll;

const int mod=1e9+7;
const int INF=INT_MAX;

int main(){
    int a,p,sump;
    cin >> a >> p;
    sump=p+a*3;
    cout << sump/2 << endl;
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <string>
using namespace std;
int main(){
    int n;
    string s;
    cin >> n >> s;
    bool flag = 1;
    int i=0;
    if(n==1){
        cout << 1 << endl;
        return 0;
    }
    while(flag){
        while(s[i]==s[i+1]){
            s.erase(i,1);
            if(s.size() == i+1){
                flag=0;
                break;
                }
            }
        i++;
        if(s.size() == i+1)break;
    }
    
    cout<<s.size()<<endl; 


}

Measured memory_bytes: 512
#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
int main()
{
	int N;
	scanf("%d", &N);
	if (N % 2 == 0)
		printf("%d\n", N / 2 - 1);
	else
		printf("%d\n", N / 2);
	return 0;
}

Measured memory_bytes: 256
from math import atan2, degrees
A, B, X = map(int, input().split())
S = X / A


if S >= A * B / 2:
    h = (2 * (A * B - S)) / A
    print(degrees(atan2(h, A)))

else:
    w = (2 * S) / B
    print(degrees(atan2(B, w)))

Measured memory_bytes: 3060
#include <bits/stdc++.h>
typedef long long LL;
#define SORT(c) sort((c).begin(),(c).end())

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

using namespace std;
int w,h;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
vector<bool> reach[50][50][50];
vector<string> lroom,rroom;
bool flag;
queue<tuple<int,int,int,int> > sa;
// h w h w
bool outrange(int v,int l,int r){
  return v<l || r<=v;
}
void bfs(tuple<int,int,int,int> pos){
  int ly,lx,ry,rx;
  tie(ly,lx,ry,rx)=pos;
  if(lroom[ly][lx]=='%' && rroom[ry][rx]=='%'){
    flag=true;
    return;
  }
  if(lroom[ly][lx]=='%' || rroom[ry][rx]=='%') return;
  if(reach[ly][lx][ry][rx]) return;
  reach[ly][lx][ry][rx]=true;
  REP(i,4){
    int nly=ly+dy[i],nlx=lx+dx[i],nry=ry+dy[i],nrx=rx-dx[i];
    if(outrange(nly,0,h) ||
       outrange(nlx,0,w) ||
       lroom[nly][nlx] == '#')
      nly=ly,nlx=lx;
    if(outrange(nry,0,h) ||
       outrange(nrx,0,w) ||
       rroom[nry][nrx] == '#')
      nry=ry,nrx=rx;
    sa.push(make_tuple(nly,nlx,nry,nrx));
  }
}
int main(void)
{
  for(;;){
    cin >> w >> h;
    if(!w && !h) return 0;
    REP(i,h) REP(j,w) REP(k,h) reach[i][j][k].assign(w,false);
    lroom.resize(h);
    rroom.resize(h);
    REP(i,h) cin >> lroom[i] >> rroom[i];
    while(!sa.empty()) sa.pop();
    flag=false;
    int ly,lx,ry,rx;
    REP(i,h) REP(j,w) if(lroom[i][j]=='L') ly=i,lx=j;
    REP(i,h) REP(j,w) if(rroom[i][j]=='R') ry=i,rx=j;
    sa.push(make_tuple(ly,lx,ry,rx));
    while(!sa.empty()){
      auto pos=sa.front();
      sa.pop();
      bfs(pos);
    }

    if(flag) cout << "Yes" << endl;
    else cout << "No" << endl;
  }
}

Measured memory_bytes: 15304
package main

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

var sc *bufio.Scanner

func init() {
	// 100MB
	bufsize := 100 * 1024 * 1024
	sc = bufio.NewScanner(os.Stdin)
	sc.Buffer(make([]byte, bufio.MaxScanTokenSize), bufsize)
	sc.Split(bufio.ScanWords)
}
func readInt() int              { return readIntArray(1)[0] }
func readInt2() (int, int)      { a := readIntArray(2); return a[0], a[1] }
func readInt3() (int, int, int) { a := readIntArray(3); return a[0], a[1], a[2] }
func readIntArray(n int) []int {
	s := readStringArray(n)
	a := make([]int, n)
	for i := range a {
		a[i], _ = strconv.Atoi(s[i])
	}
	return a
}
func readString() string            { return readStringArray(1)[0] }
func readString2() (string, string) { a := readStringArray(2); return a[0], a[1] }
func readStringArray(n int) []string {
	a := make([]string, n)
	for i := 0; i < n; i++ {
		sc.Scan()
		a[i] = sc.Text()
	}
	return a
}
func max(ns ...int) int {
	max := ns[0]
	for _, n := range ns {
		if n > max {
			max = n
		}
	}
	return max
}
func min(ns ...int) int {
	min := ns[0]
	for _, n := range ns {
		if n < min {
			min = n
		}
	}
	return min
}
func abs(x int) int {
	if x < 0 {
		return -x
	}
	return x
}

func main() {
	N, K := readInt2()
	r := N % K
	if r == 0 {
		fmt.Println(0)
		return
	}
	if r < K-r {
		fmt.Println(r)
		return
	} else {
		fmt.Println(K - r)
		return
	}
}


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

typedef long long ll;

int main() {
    ll X, K, D;
    cin >> X >> K >> D;
    X = abs(X);
    ll q = X / D;
    if (K <= q) {
        cout << X - D * K << "\n";
        return 0;
    }
    ll r = X % D;
    if ((K - q) % 2) r = D - r;
    cout << r << "\n";
}

Measured memory_bytes: 3672
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>

int main()
{
	std::string s;
	std::cin >> s;
	int a = 0;
	for (int i = 0; i < s.size(); i++)
	{
		if (s[i] == '+')
			a++;
		else
			a--;
	}

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

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

int a, b, c;

int main() {
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> a >> b >> c;
	cout << min(b+c, min(a+b+1, c) + b) << endl;
}

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

  //ll t;
  //cin>>t;
  //while(t--)
  {
 string s1,s2,s3;
 cin>>s1>>s2;
 ll a,b;
 cin>>a>>b;
 cin>>s3;
 if(s3==s1)
    cout<<a-1<<endl<<b<<endl;
 else
    cout<<a<<endl<<b-1<<endl;
  }
return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define pb push_back

using namespace std;
int main()
{
  ios_base :: sync_with_stdio(false) , cin.tie(0), cout.tie(0);

  int  a, b, c,ans=0 , t=0;
  cin>>a>>b>>c;

  cout<<((c)/a)*b<<endl;
}


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

// ------------------------

void solve() {
    int N; cin >> N;
    vector<ll> a(3*N); rep(i, 3*N) cin >> a[i];

    sort(a.begin(), a.end());
    
    ll ans = 0;

    for(int i = N; i < 3*N; i+=2){
        ans +=a[i];
    }
    cout << ans << "\n";
}

signed main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    solve();
    return 0;
}

Measured memory_bytes: 2560
n = int(input())
dp = [[0, 0, 0] for i in range(n+1)]
for i in range(n):
  a, b, c = map(int, input().split())
  dp[i+1][0] = max(dp[i][1]+a, dp[i][2]+a)
  dp[i+1][1] = max(dp[i][0]+b, dp[i][2]+b)
  dp[i+1][2] = max(dp[i][0]+c, dp[i][1]+c)
print(max(dp[-1]))

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

int main()
{
	string s; cin >> s;
	char x = s[0];
	bool ans = true;
	for (int i = 1; i < 3; i++) {
		if (s[i] != x) {
			ans = false;
		}
	}
	if (ans) {

	cout << "No" << endl;
	}
	else {
		cout << "Yes" << endl;
	}
	return 0;
}


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

int main() {
    int N;
    cin >> N;
    vector<int> W;
    int right = 0;
    for (int i = 0; i < N; i++) {
        int a;
        cin >> a;
        W.push_back(a);
        right += W[i];
    }

    int left = 0;
    int dif = 99;
    int minP = 99;
    for (int j = 0; j < N; j++) {
        left += W[j];
        right -= W[j];
        dif = abs(right - left);
        minP = min(minP, dif);
    }
    cout << minP << endl;
}

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

int getNum(string str) {
  static string hand[15] = {
    "Rock", "Fire", "Scissors", "Snake", "Human",
    "Tree", "Wolf", "Sponge", "Paper", "Air", "Water",
    "Dragon", "Devil", "Lightning", "Gun"
  };
  for(int i = 0; i < 15; i++) {
    if(str == hand[i]) return i;
  }
  return -1;
}

main() {
  while(1) {
    int N;
    cin >> N;
    if(N == 0) break;
    string player[N];

    for(int i = 0; i < N; i++) {
      cin >> player[i];
    }

    int maxi = -99999;
    bool flag = false;
    for(int i = 0; i < N; i++) {
      bool win = false;
      bool lose = false;
      for(int j = 0; j < N; j++) {
	int tmp = getNum(player[j]) - getNum(player[i]);
	if(tmp < 0) tmp += 15;
	if(tmp >= 1 && tmp <= 7) {
	  win = true;
	}
	if(tmp >= 8 && tmp <= 14) {
	  lose = true;
	  break;
	}
      }
      if(win && !lose) {
	cout << player[i] << endl;
	flag = true;
	break;
      }
    }

    if(!flag) cout << "Draw" << endl;
  }
}

Measured memory_bytes: 952
n,m = map(int,input().split())
ac_list = [0] * (n + 1)
wa_list = [0] * (n + 1)

for i in range(m):
    q_no_tmp,anser = input().split()
    q_no = int(q_no_tmp)
    if anser == "AC":
        ac_list[q_no] = 1
    else:
        if ac_list[q_no] != 1:
            wa_list[q_no] = wa_list[q_no] + 1 

wa_num = 0
ac_num = 0
for i in range(n + 1):
    if ac_list[i] != 1:
        wa_list[i] = 0
    else:
        ac_num = ac_num + 1
    wa_num = wa_num + wa_list[i]

print(ac_num,wa_num)


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

//Packet Transportation
public class Main{

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		boolean[][] f = new boolean[n+1][n+1];
		for(int i=0;i<n;i++){
			int b = sc.nextInt();
			int k = sc.nextInt();
			for(int j=0;j<k;j++){
				f[b][sc.nextInt()] = true;
			}
		}
		int p = sc.nextInt();
		while(p--!=0){
			int s = sc.nextInt();
			int t = sc.nextInt();
			int ttl = sc.nextInt();
			boolean[] u = new boolean[n+1];
			u[s] = true;
			int step = 1;
			List<Integer> l = new ArrayList<Integer>();
			l.add(s);
			String ans = "NA";
			while(!l.isEmpty()&&step<=ttl){
				List<Integer> next = new ArrayList<Integer>();
				for(int a:l){
					if(a==t){
						ans = step+"";
						next.clear();
						break;
					}
					for(int i=1;i<=n;i++){
						if(f[a][i]&&!u[i]){
							u[i] = true;
							next.add(i);
						}
					}
				}
				l = next;
				step++;
			}
			System.out.println(ans);
		}
	}
}

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

long long N;

void recursive(long long now,int bits_flag,long long &ans)
{
    if(now > N) return;
    if(bits_flag == 0b111) ans++;
    recursive(now * 10 + 3, bits_flag | 0b001, ans);
    recursive(now * 10 + 5, bits_flag | 0b010, ans);
    recursive(now * 10 + 7, bits_flag | 0b100, ans);
}

void calculate(){
    cin >> N;
    long long ans = 0;
    recursive(0,0,ans);
    cout << ans << '\n';
}

int main(int, char**) {
    calculate();
    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <queue>
#include <vector>
using namespace std;
typedef long long ll;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
#define MAX_V 101
#define INF 1000000000

int main(){
    int h,w;cin>>h>>w;
    vector<vector<int> > b(h+2,vector<int>(w+2,INF));
    vector<vector<char> > m(h+2,vector<char>(w+2));
    queue<pair<int,int> > q;
    b[1][1]=1;
    for(int i=0;i<h+2;i++){
        m[i][0]='#';
        m[i][w+1]='#';
    }
    for(int i=0;i<w+2;i++){
        m[0][i]='#';
        m[h+1][i]='#';
    }
    int ans=0;
    for(int i=1;i<h+1;i++){
        for(int j=1;j<w+1;j++){
            cin>>m[i][j];
            if(m[i][j]=='.') ans++;
        }
    }
    q.push(make_pair(1,1));
    while(!q.empty()){
        int x=q.front().first;int y=q.front().second;q.pop();
        for(int A=0;A<4;A++){
            int check_x=x+dx[A];
            int check_y=y+dy[A];
            if(m[check_x][check_y]=='.'&&b[check_x][check_y]==INF){
                b[check_x][check_y]=b[x][y]+1;
                q.push(make_pair(check_x,check_y));
            }
        }
    }
    if(b[h][w]==INF) cout<<-1<<endl;
    else cout<<ans-b[h][w]<<endl;
}

Measured memory_bytes: 256
import fractions
import math

def is_prime(n):
    if n == 1: return False

    for k in range(2, int(math.sqrt(n)) + 1):
        if n % k == 0:
            return False

    return True
    
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    return divisors
    
A, B = map(int, input().split())

ans = 1
tmp = make_divisors(fractions.gcd(A ,B))
for x in tmp:
    if is_prime(x):
        ans += 1

print(ans)


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

int main()
{
    int n, a[100];

    cin >> n;

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

    for (int i = n - 1; i >= 0; i--) {
        if (i == 0) {
            cout << a[i];
        } else {
            cout << a[i] << ' ';
        }
    }
    cout << endl;

    return 0;
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
#define faster  ios :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long
#define ull unsigned long long
using namespace std;

int main()
{
    faster
    int w,h,n;
    cin>>w>>h>>n;

    int xx,yy,aa;

    int a1=0,a2=w,a3=0,a4=h;
    int hp1=0,hp2=0,hp3=0,hp4=0;

    for(int i=0; i<n; i++)
    {
        cin>>xx>>yy>>aa;

        if(aa==1)
        {
            if(hp1==0)
            {
                a1=xx;
                hp1=1;
            }
            else
            {
                if(xx>a1)
                    a1=xx;
            }

        }
        else if(aa==2)
        {
            if(hp2==0)
            {
                a2=xx;
                hp2=1;
            }
            else
            {
                if(xx<a2)
                    a2=xx;
            }

        }
        else if(aa==3)
        {
            if(hp3==0)
            {
                a3=yy;
                hp3=1;
            }
            else
            {
                if(yy>a3)
                    a3=yy;
            }

        }
        else if(aa==4)
        {
            if(hp4==0)
            {
                a4=yy;
                hp4=1;
            }
            else
            {
                if(yy<a4)
                    a4=yy;
            }
        }
    }


    //cout<<a1<<" "<<a2<<" "<<a3<<" "<<a4<<endl;


    if(a1>=a2)
    {
        w=0;
    }
    else
    {
        w=a2-a1;
    }

    if(a3>=a4)
    {
        h=0;
    }
    else
    {
        h=a4-a3;
    }

    //cout<<w<<" "<<h<<endl;

    cout<<w*h<<endl;




    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <vector>

using namespace std;

int main(){
    
    long a = 0;
    long goal;
    long sum = 0;
    
    cin >> goal;
    
    a = (goal/11)*2;
    sum = goal - goal%11;
    
    while ( sum < goal)
    {
        a++;
        sum += 6;
    
        if(sum < goal){
            a++;
            sum += 5;
        }
    }
    
    cout << a << endl;
//    while( sum >= goal){
//    switch (a) {
//        case (a = 1):
//            statements
//            break;
//            
//        case a =
//            
//        default:
//            break;
//    }
//    }
}

Measured memory_bytes: 256
// All Heil Fire Lord Zuko

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

#define all(x) x.begin() , x.end()

#define _sz(x) (int)x.size()
#define F first
#define S second
#define PB push_back

#define debug(x) cerr << #x << " = " << "\n"

typedef long long ll ;
typedef long double ld ;
typedef pair<ll , ll> pll ;

const int N = 5 * 1000 + 19 ;
const int inf = 1e9 + 19 ;
const ll INF = 1e18 + 19 ;

int n ;
string s , t ;

int main() {
      ios::sync_with_stdio(false) , cin.tie(0) , cout.tie(0) ;
      cin >> n ;
      cin >> s ;
      for (int i = 0 ; i < n / 2 ; i ++)
              t += s[i] ;
      if (t + t == s)
              cout << "Yes\n" ;
      else
              cout << "No\n" ;
      return 0;
}

/* THINGS TO CHECK */

// Runtime -> Checked
// Overflows -> Checked
// Time Complexity -> n + m
// Memory Complexity -> OK

/* READ PROBLEM STATEMENT CAREFULLY */


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

bool b[200][200];
int main() {
	int n; cin >> n;
	int cnt = 0;
	rep(i, n)for (int j = i + 1; j < n; j++) {
		if (cnt == n - 1)break;
		string s(n, '0'); s[i] = '1'; s[j] = '1';
		cout << "? " << s << endl;
		int res; cin >> res;
		if (res == 1) {
			b[i][j] = 1;
		}
	}
	cout << "!";
	rep(i, n)for (int j = i + 1; j < n; j++) {
		if (b[i][j]) {
			cout << " ";
			cout << "(" << i  << "," << j << ")";
		}
	}
	cout << endl;
}

Measured memory_bytes: 852
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    int n;
    cin>>n;
    for(int i=0;i<=50000;i++)
    {
        if(i*108>=n*100&&i*108<=n*100+99)
        {
            cout<<i<<'\n';
            return 0;
        }
    }
    cout<<":(";
}


Measured memory_bytes: 256
MOD = 1000000007


def gcd(a, b):
    while b != 0:
        a, b = b, a % b
    return a


def normalize(a, b):
    if a == 0 and b == 0:
        return 0, 0
    elif a != 0 and b == 0:
        return 1, 0
    elif a == 0 and b != 0:
        return 0, 1
    else:
        g = gcd(abs(a), abs(b))
        a //= g
        b //= g
        if a < 0:
            a *= -1
            b *= -1
        return a, b


def rotate(a, b):
    if b > 0:
        return b, -a
    else:
        return -b, a


n = int(input())
dv = {}
for _ in range(n):
    a, b = map(int, input().split())
    a, b = normalize(a, b)
    dv[(a, b)] = dv.get((a, b), 0) + 1


counted = {k: False for k in dv.keys()}
nc = 1
for k, v in dv.items():
    if not counted[k]:
        if k != (0, 0):
            a0, b0 = k
            a1, b1 = rotate(a0, b0)
            w = dv.get((a1, b1), 0)

            nc *= 1 + (pow(2, v, MOD) - 1) + (pow(2, w, MOD)- 1)
            nc %= MOD

            # counted[(a0, b0)] = True
            counted[(a1, b1)] = True


nc += dv.get((0, 0), 0)

nc -= 1
nc %= MOD
print(nc)


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

int main() {
  ll W, H;
  cin >> W >> H;
  vector<pair<ll, int>> pq(W + H);
  for (int i = 0; i < W; i++) {
    int p;
    cin >> p;
    pq[i] = make_pair(p, 0);
  }
  for (int i = 0; i < H; i++) {
    int q;
    cin >> q;
    pq[W + i] = make_pair(q, 1);
  }
  sort(pq.begin(), pq.end());

  ll cnt0 = 0, cnt1 = 0;
  ll ans = 0;
  for (int i = 0; i < H + W; i++) {
    if (pq[i].second == 0) {
      cnt0++;
      ans += (H + 1 - cnt1) * pq[i].first;
    } else {
      cnt1++;
      ans += (W + 1 - cnt0) * pq[i].first;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 3328
using System;

namespace AtCoder2
{
    class Program
    {
        public static int Add(int A, int B)
        {
            int i;
            i = (A * B) - (A + B - 1);
            return i;
        }
        static void Main(string[] args)
        {
            int R = int.Parse(Console.ReadLine());

            if(R < 1200)
            {
                Console.WriteLine("ABC");
            }
            else if(R < 2800)
            {
                Console.WriteLine("ARC");
            }
            else
            {
                Console.WriteLine("AGC");
            }
        }
    }
}

Measured memory_bytes: 13140
#include <stdio.h>
#include <algorithm>

int gcd(int, int);

int main(){
  int x, y, z;
  scanf("%d %d", &x, &y);
  z = gcd(x, y);

  printf("%d\n", z);
 
return 0;
}

int gcd(int x,int y){
    int r;  

    while (y > 0){
        r = x % y;
        x = y;
        y = r;
    }
    return x;
    
}

Measured memory_bytes: 2692
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let n: i32 = read();
    let mut vec: Vec<i32> = vec![];
    for _ in 0..n {
        vec.push(read());
    }
    let mut sunuke_balls = vec![0; vec.len()];
    let mut m = 0;
    let mut ans = vec![];
    for (i_1, _) in vec.iter().enumerate().rev() {
        let i = i_1 + 1;
        let mut sum = 0;
        for j in 1..((vec.len() / i) + 1) {
            sum += sunuke_balls[(i * j) - 1];
        }
        if sum % 2 == vec[i_1] {
            sunuke_balls[i_1] = 0;
        } else {
            sunuke_balls[i_1] = 1;
            ans.push(i);
            m += 1;
        }
    }
    println!("{}", m);
    println!(
        "{}",
        ans.iter()
            .map(|i| i.to_string())
            .collect::<Vec<String>>()
            .join(" ")
    );
}


Measured memory_bytes: 13308
#include <algorithm>  // sort, 二分探索(lower_bound)など
#include <cmath>      // pow, logなど
#include <complex>    // 複素数
#include <deque>      // 両端アクセスのキュー
#include <iostream>   // 入出力
#include <iterator>
#include <map>
#include <numeric>  // iota(整数列の生成), gcd, lcm
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>  // 順序保持しないmap
#include <unordered_set>  // 順序保持しないset
#include <utility>        // pair
#include <vector>

#define REP(i, a, b) for (int i = (a); i < (b); i++)
#define REPR(i, a, b) for (int i = (a); i >= (b); i--)
#define ALL(container) (container).begin(), (container).end()
#define MAX(x) *max_element(ALL(x))  // 最大値を求める
#define MIN(x) *min_element(ALL(x))  // 最小値を求める

using namespace std;
typedef long long ll;

constexpr int INF      = 1e9;
constexpr int MOD      = 1000000007;
constexpr size_t MAX_N = 110000;

int memo[MAX_N] = { -1 };

size_t rec(size_t n) {
  if (n == 0) return 0;
  if (memo[n] != -1) return memo[n];

  size_t res = n;  // 全て1円で引き出す
  for (size_t pow6 = 1; pow6 <= n; pow6 *= 6) {
    res = min(res, rec(n - pow6) + 1);
  }
  for (size_t pow9 = 1; pow9 <= n; pow9 *= 9) {
    res = min(res, rec(n - pow9) + 1);
  }

  return memo[n] = res;
}

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

  for (int& v : memo) {
    v = -1;
  }

  cout << rec(N) << endl;

  return 0;
}


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

int main() {int c=0,k=0,e=0;
    char S[5];
    for(int i=0;i<4;i++){
        cin>>S[i];
    }
    char b[4];
    char a=S[0];
    for(int i=0;i<4;i++){
        if(a==S[i]){
            c++;
        }
        else
        {
            b[k]=S[i];
            k++;
        }
    }
    char l=b[0];
    for(int i=0;i<4-c;i++){
        if(l==b[i]){
            e++;
        }
    }
    if((c==1&&e==3)||(c==2&&e==2)||(c==3&&e==1))
        cout<<"Yes";
    else
        cout<<"No";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define frst first
#define sec second
#define fast cin.tie(0) , ios_base :: sync_with_stdio(0)
#define db double
#define mod 1000000007
void online_judge()
{
#ifndef ONLINE_JUDGE
	freopen("Input.txt", "r", stdin);
	freopen("Output.txt", "w", stdout);
#endif
}


ll dp[200001];

ll dfs(vector<ll> g[] , ll strt , bool* vis)
{
	vis[strt] = 1;
	ll ans = 1;
	for (auto x : g[strt])
	{
		if (!vis[x]) {
			ans = max(ans , 1 + dfs(g , x , vis));
		}
		else {
			ans = max(ans , 1 + dp[x]);
		}
	}
	///cout << ans << " ";
	return dp[strt] = ans;
}


db cal(db a[] , ll n)
{
	db dp[n + 1][n + 1];
	for (int i = 0; i < n + 1; ++i)
	{
		for (int j = 0; j < n + 1; ++j)dp[i][j] = 0.0;
	}
	for (int i = 0; i <= n; ++i)
	{
		for (int j = 0; j <= n; ++j)
		{
			if (i == 0 && j == 0) {
				dp[i][j] = 1;
				continue;
			}
			if (i > 0 && j > 0)
				dp[i][j] = dp[i - 1][j - 1] * (a[i - 1]);
			if (i > 0)dp[i][j] += dp[i - 1][j] * (1 - a[i - 1]);
		}
	}
	db ans = 0;
	for (int i = 0; i <= n; ++i)
	{
		if (i > n - i) {
			ans += dp[n][i];
		}
	}
	return ans;
}


void go() {
	ll n;
	cin >> n;
	db a[n];
	for (int i = 0 ; i < n; ++i)cin >> a[i];
	cout << fixed << setprecision(10) << cal(a , n);
}


int main() {
	fast;
	//online_judge();
	//cout << 2332;
	go();
}

Measured memory_bytes: 70656
#include<iostream>
#include<math.h>
#include<string.h>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<deque>
using namespace std;

int main(){

	long long n,k;
	cin >> n >> k;
	
	long long ans=0;
	if(k%2==1){
		ans=n/k;
		ans=ans*ans*ans;
	}
	
	if(k%2==0){
		long long a,b;
		
		a=n/(k/2);
		a-=n/k;
		a=a*a*a;
		
		b=n/k;
		b=b*b*b;
		
		ans=a+b;
	}
	
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(4100000)
import math
import itertools
INF = float('inf')
from heapq import heapify, heappop, heappush
import collections
import bisect

def main():
    n,m = map(int, input().split())
    AB = [list(map(int, input().split())) for _ in range(n)]
    CD = [list(map(int, input().split())) for _ in range(m)]

    for i in range(n):
        dist = []
        for j in range(m):
            dist.append(abs(AB[i][0]-CD[j][0]) + abs(AB[i][1] - CD[j][1]))
        dist_min = min(dist)
        for k in range(len(dist)):
            if dist[k] == dist_min:
                print(k+1)
                break


if __name__ == '__main__':
    main()


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

int main() {
	string S; cin >> S;
	int cnt_N= 0, cnt_E = 0,cnt_S=0,cnt_W=0;
	for (int i = 0; i < S.size(); i++) {
		if (S[i] == 'N') cnt_N++;
		if (S[i] == 'E') cnt_E++;
		if (S[i] == 'S') cnt_S++;
		if (S[i] == 'W') cnt_W++;
	}
	if ((cnt_N != 0 && cnt_S == 0) || (cnt_N == 0 && cnt_S != 0)) {
		cout << "No" << endl;
		return 0;
	}
	if ((cnt_E != 0 && cnt_W == 0) || (cnt_E == 0 && cnt_W != 0)) {
		cout << "No" << endl;
		return 0;
	}
	cout << "Yes" << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long int
#define ld long double
#define pb push_back
#define pf push_front
#define ft first
#define sc second
#define all(v) v.begin(), v.end()
using namespace std;
const int maxn = 201001;
int cnt[maxn];
signed main() {
    ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    int n;
    cin >> n;
    vector<int> mas(n, 0);
    for (int d = 0; d < n; d++) {
        cin >> mas[d];
        cnt[mas[d]]++;
    }
    int ans = 0;
    for (int d = 0; d < maxn; d++) {
        ans += (cnt[d] * (cnt[d] - 1)) / 2;
    }
    for (int d = 0; d < n; d++) {
        cout << ans - (cnt[mas[d]] - 1) << "\n";
    }
}


Measured memory_bytes: 4736
#include <stdio.h>
int Partition(int ,int);
int n,A[100000],i;
int main(void){
  int element;
  scanf("%d",&n);
  for(i=0;i<n;i++)
    scanf("%d",&A[i]);
  element=Partition(0,n-1);
  for(i=0;i<n;i++){
    if(i!=element)printf("%d",A[i]);
    else printf("[%d]",A[i]);
    if(i!=n-1)printf(" ");
  }
  printf("\n");
  return 0;
}
int Partition(int pre,int last){
  int x=A[last],temp;
  for(i=pre;i<last;i++){
    if(A[i]<=x){
      temp=A[pre];
      A[pre++]=A[i];
      A[i]=temp;
    }
  }
  temp=A[last];
  A[last]=A[pre];
  A[pre]=temp;
  return pre;
}


Measured memory_bytes: 2104
# B - 81
# https://atcoder.jp/contests/abc144/tasks/abc144_b

n = int(input())

multi_table = []

for i in range(1,10):
    for j in range(1,10):
        multi_table.append(i*j)

if n in multi_table:
    print("Yes")
else :
    print("No")    


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

int main(void){
	int a[4];
	int b[4];
	int h,br;
	
	while(cin >> a[0] >> a[1] >> a[2] >> a[3]>> b[0] >> b[1] >> b[2] >> b[3]){
		
		h=0;
		br=0;
		
		for(int k=0;k<4;k++){
			for(int l=0;l<4;l++){
				if(a[k]==b[l]){
					if(k==l) h++;
					else br++;
				}
			}
		}
		
		cout << h << ' '<< br << endl;
	}
}

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

using namespace std;
typedef long long int ll;
typedef long double ld;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for (ll i = (ll)(n) - 1; i >= 0; i--)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007
#define INF (1LL << 62)

#define PI (acos(-1))
#define print(x) cout << x << endl
 
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; }
typedef pair <ll,ll> P;

template <typename T> 
ostream& operator<<(ostream& os, const vector<T>& v) 
{ 
    for (int i = 0; i < (int)v.size(); ++i) { 
        os << v[i]; 
        if (i != (int)v.size() - 1) 
            os << " "; 
    } 
    return os; 
} 

int main()
{
    ll N;
    string S;
    cin >> N >> S;
    if (N % 2 != 0) {
        cout << "No" << endl;
        return 0;
    }
    if (S.substr(0, N/2) == S.substr(N/2, N)) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
use std::io::*;

fn dijkstra(start: usize, graph: &Vec<Vec<(usize, i64)>>) -> Vec<i64> {
    let mut dist = vec![std::i64::MAX; graph.len()];
    dist[start] = 0;
    let mut bh = std::collections::BinaryHeap::new();
    bh.push((0i64, start));
    while let Some((cost, v)) = bh.pop() {
        if dist[v] < -cost {
            continue;
        }
        for e in graph[v].iter() {
            let nv = e.0;
            let nc = e.1;
            if dist[nv] > -cost + nc {
                dist[nv] = -cost + nc;
                bh.push((-dist[nv], nv));
            }
        }
    }
    dist
}

fn main() {
    let mut s: String = String::new();
    std::io::stdin().read_to_string(&mut s).ok();
    let mut itr = s.trim().split_whitespace();
    let n: usize = itr.next().unwrap().parse().unwrap();

    let mut graph: Vec<Vec<(usize, i64)>> = vec![Vec::new(); n];
    for _ in 0..n - 1 {
        let a: usize = itr.next().unwrap().parse::<usize>().unwrap() - 1;
        let b: usize = itr.next().unwrap().parse::<usize>().unwrap() - 1;
        let c: i64 = itr.next().unwrap().parse().unwrap();
        graph[a].push((b, c));
        graph[b].push((a, c));
    }
    let q: usize = itr.next().unwrap().parse().unwrap();
    let k: usize = itr.next().unwrap().parse().unwrap();
    let dist = dijkstra(k - 1, &graph);
    let mut out = Vec::new();
    for _ in 0..q {
        let x: usize = itr.next().unwrap().parse::<usize>().unwrap() - 1;
        let y: usize = itr.next().unwrap().parse::<usize>().unwrap() - 1;
        writeln!(out, "{}", dist[x] + dist[y]).ok();
    }
    stdout().write_all(&out).unwrap();
}


Measured memory_bytes: 24756
#include<stdio.h>

int main()
{
        int N, K;
        int x = 1;
        int i;

        scanf("%d %d", &N, &K);

        for(i=0; i<N; i++)
        {
                if(x*2 > x+K)x=x+K;
                else x *= 2;
        }

        printf("%d", x);

        return 0;
}





Measured memory_bytes: 128
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)n; i++)
#define REPvec(itr, mp) for (auto itr = mp.begin(); itr != mp.end(); itr++)
#define all(x) x.begin(), x.end()
#define MOD 1000000007  // 1e9+7
using namespace std;
typedef long long int ll;
typedef vector<int> vecint;
typedef vector<ll> vecll;
typedef vector<string> vecstr;
typedef vector<bool> vecbool;
typedef vector<vector<int>> vec2int;
typedef pair<int, int> P;
////////////////////////////////////////////////
void init() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
}
int n, m, q;
// struct edge {
//   int a;
//   int b;
//   int c;
//   int d;
// };
// vector<edge> G;
// vecbool seen;
// int dfs(int i, int s) {}
////////////////////////////////////////////////
int main() {
  init();
  cin >> n >> m >> q;

  vecint w(q), x(q), y(q), z(q);
  REP(i, q) {
    cin >> w[i] >> x[i] >> y[i] >> z[i];
    w[i]--;
    x[i]--;
  }
  // cout << w[0] << x[0] << y[0] << z[0] << endl;
  int ans = 0;
  int a = 1;
  for (int b = a; b <= m; b++) {
    for (int c = b; c <= m; c++) {
      for (int d = c; d <= m; d++) {
        for (int e = d; e <= m; e++) {
          for (int f = e; f <= m; f++) {
            for (int g = f; g <= m; g++) {
              for (int h = g; h <= m; h++) {
                for (int i = h; i <= m; i++) {
                  for (int j = i; j <= m; j++) {
                    int tmp = 0;
                    vecint pos = {a, b, c, d, e, f, g, h, i, j};
                    REP(k, q) {
                      if (pos[w[k]] + y[k] == pos[x[k]]) {
                        tmp += z[k];
                      }
                    }
                    ans = max(tmp, ans);
                  }
                }
              }
            }
          }
        }
      }
    }
  }

  cout << ans << endl;
}

Measured memory_bytes: 3664
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(n) begin(n), end(n)
using ll = long long;
using namespace std;

int main(){
	int n;
	cin >> n;
	string s;
	cin >> s;
	vector<int> wh(n, 0);
	rrep(i, n){
		if(i != n-1) wh.at(i) = wh.at(i+1);
		if(s[i] == '.') wh.at(i)++;
	}
	vector<int> bk(n, 0);
	rep(i, n){
		if(i != 0) bk.at(i) = bk.at(i-1);
		if(s[i] == '#') bk.at(i)++;
	}
	int ans = n;
	rep(i, n + 1){
		int add = 0;
		if(i < n) add += wh.at(i);
		if(i != 0) add += bk.at(i-1);
		ans = min(ans, add);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 2180
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

int main(){
        string s,t;
        int i,j,sn,ts;
        bool che = false;
        cin >> s >> t;
        //cout << s.size()-1 << endl;
        for(i=s.size()-1;i>=t.size()-1;i--){
                sn = i;
                //cout << sn << endl;
                for(j=t.size()-1;j>-1;j--){
                        /*if(sn == i+t.size()-1) {
                                che = true;
                                break;
                        }*/
                        if(s[sn] == t[j] || s[sn] == '?')sn--;
                        else break;
                        if(j==0)che=true;
                }
                if(che == true)break;
        }
        if(che==false){
                cout << "UNRESTORABLE" << endl;
                return 0;
        }
        for(j=t.size()-1;j>-1;j--){
                s[i] = t[j];
                i--;
                //cout << s << endl;
        }
        for(i=0;i<s.size();i++){
                if(s[i]=='?')s[i]='a';
        }
        cout << s << endl;
        return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, a, n) for(int i=a; i<n; i++)
#define RREP(i, a, n) for(int i=n-1; i>=a; i--)
#define CK(n, a, b) (a <= n && n < b)
#define MP(a, b) make_pair(a, b)
typedef long long ll;
const ll mod =1e9+7;
const int inf =1e9;
using namespace std;


string s;
int main() {
    cin>>s;

    bool hi=true;
    if(s.size()%2==0){
        REP(i, 0, s.size()/2){
            if(s[i*2]!='h'){
                hi=false;
            }
            if(s[i*2+1]!='i'){
                hi=false;
            }
        }
    } else{
        hi=false;
    }
    if(hi) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long int ll;
#define pb push_back
#define FOR(i, a, b) for (ll i = (signed)(a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define EREP(i, n) for (int i = (n)-1; i >= 0; --i)
using namespace std;

string s;
int main() {
  cin >> s;
  ll itr = 0, cnt = 0; // g
  for (auto &a : s) {
    ll f = (a == 'g') + itr;
    cnt += (f == 2);
    cnt -= (f == 0);
    itr = 1 - itr;
  }
  printf("%lld\n", cnt);
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
typedef long long int ll;
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) \
  for (int i = static_cast<int>(a); i < static_cast<int>(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, ) (__VA_ARGS__)  // NOLINT

using namespace std;

ll N;
ll col[300000];
ll sz[300000];
ll d[300000];
vector<ll> edges[300000];
vector<ll> vertices[300000];
vector<ll> children[300000];

ll occur[300000];

void dfs(ll cur, ll par) {
  ll tmp;
  if (par >= 1) {
    tmp = occur[col[par]];
    occur[col[par]] = cur;
  }
  ll s = 1;
  vertices[col[cur]].push_back(cur);
  for (auto c : edges[cur]) {
    if (c == par) continue;
    children[col[cur]].push_back(c);
    dfs(c, cur);
    s += sz[c];
  }
  sz[cur] = s;
  if (occur[col[cur]] >= 1) {
    d[occur[col[cur]]] += sz[cur];
  }
  if (par >= 0) {
    occur[col[par]] = tmp;
  }
}

signed main() {
  cin >> N;
  for (int i=1; i<=N; i++)
    cin >> col[i];
  rep(i,N-1) {
    ll a, b;
    cin >> a >> b;
    edges[a].push_back(b);
    edges[b].push_back(a);
  }
  dfs(1, -1);
  // for (int i=1; i<=N; i++) {
  //   printf("i=%d col=%d sz=%d d=%d\n", i, col[i], sz[i], d[i]);
  // }
  for (int k=1; k<=N; k++) {
    ll ans = 0, n = 0;
    // cout << "block for " << k << endl;
    for (auto cur : vertices[k]) {
      n++;
    }
    for (auto c : children[k]) {
      ans += (sz[c]-d[c]+1) * (sz[c]-d[c]) / 2;
      n += sz[c] - d[c];
      // cout << (sz[c] - d[c]) << endl;
    }
    ans += (N - n + 1) * (N - n) / 2;
    ans = (N+1) * N /2 - ans;
    cout << ans << endl;
  }
  return 0;
}


Measured memory_bytes: 64292
S = input()
smax = 0
for i in range(len(S)):
    for j in range(i, len(S)):
        contFlg = True
        for k in S[i:j + 1]:
            if 'ACGT'.count(k) != 1:
                contFlg = False
                break
        if contFlg:
            smax = max(smax, len(S[i:j + 1]))

print(smax)


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

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

typedef long long ll;

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

int main() {
  ll a, b;
  cin >> a >> b;
  cout << lcm(a, b);
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
long long n,k,r,s,p,ans;
//rock,scissors,paper
string t;
bool used[200001];
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin>>n>>k>>r>>s>>p>>t;
    for (int i=0;i<k;i++){
        if (t[i]=='r') ans+=p;
        else if (t[i]=='s') ans+=r;
        else ans+=s;
        used[i]=true;
    }
    for (int i=k;i<n;i++){
        if (t[i]==t[i-k] && used[i-k]){
            used[i]=false;
            continue;
        }
        if (t[i]=='r') ans+=p;
        else if (t[i]=='s') ans+=r;
        else ans+=s;
        used[i]=true;
    }
    cout<<ans;
}

Measured memory_bytes: 592
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#include <numeric>
typedef long long Int;
#define rep(i,a,b) for(Int i=a;i<b;++i)
#define rrep(i,a,b) for(Int i=a;i>=b;--i)
using namespace std;

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

  	int a, b; cin >> a >> b;
    cout << (a+b+1)/2 << endl;
}


Measured memory_bytes: 256
import java.io.*;
import java.util.*;
 
class Main
{
  public static void main (String[] arg)
  {
    Scanner scan = new Scanner(System.in);
    
    int[][] bingo = new int[3][3];
    
    int i = 0;
    int j = 0;
    
    for(i = 0;i < 3;i++){
    bingo[i][j] = Integer.parseInt(scan.next()); //数入れる
      
      for(j = 1;j < 3;j++){
        bingo[i][j] = Integer.parseInt(scan.next()); //数入れる
      }
      j = 0;
    }
    
    int n = Integer.parseInt(scan.next()); //数入れる
    
    boolean[][] bingo_pint = new boolean[3][3];
    
    for(int s = 0;s < n;s++){
      
      //nを入れる
      int num_in = Integer.parseInt(scan.next()); //数入れる
      
      //i列
      for(i = 0;i < 3;i++){
        
        if(num_in == bingo[i][j]){
          bingo_pint[i][j] = true;
        }
        //j行
        for(j = 1;j < 3;j++){
          
          if(num_in == bingo[i][j]){
            bingo_pint[i][j] = true;
          }
        }
        j = 0;
        //j行
      }
      i = 0;
      //i行
    }
    
    if(
      //横
      (bingo_pint[0][0]&&bingo_pint[0][1]&&bingo_pint[0][2])||
      (bingo_pint[1][0]&&bingo_pint[1][1]&&bingo_pint[1][2])||
      (bingo_pint[2][0]&&bingo_pint[2][1]&&bingo_pint[2][2])||
      //縦
      (bingo_pint[0][0]&&bingo_pint[1][0]&&bingo_pint[2][0])||
      (bingo_pint[0][1]&&bingo_pint[1][1]&&bingo_pint[2][1])||
      (bingo_pint[0][2]&&bingo_pint[1][2]&&bingo_pint[2][2])||
      
      //斜め
      (bingo_pint[0][0]&&bingo_pint[1][1]&&bingo_pint[2][2])||
      (bingo_pint[0][2]&&bingo_pint[1][1]&&bingo_pint[2][0])
      )
    {      
      System.out.println("Yes");
    }
    else{
      System.out.println("No");
    }
  }
}

Measured memory_bytes: 23124