akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<vector>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#include<deque>
#include<map>
#include<bitset>
using namespace std;
typedef long long ll;

#define rep(i, n) for(int i = 0;i < (n);i++)
#define repr(i, n) for(int i = (n);i >= 0;i--)
#define repf(i, m, n) for(int i = (m);i < (n);i++)

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1;} return 0;}
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1;} return 0;}
int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};
//////////////////////////////////////////////////

const ll mod = 1e9+7;

// combination c;
// c(n, k); => nCk
struct combination {
    const int max = 10000000;
    vector<long long> fact, ifact, inv;
    combination() {
        fact.resize(max);   // i!
        ifact.resize(max);  // (i!)^(mod-2)
        inv.resize(max);    // i^(mod-2)
        fact[0] = fact[1] = 1;
        ifact[0] = ifact[1] = 1;
        inv[1] = 1;
        for (int i = 2; i < max; i++) {
            fact[i] = fact[i-1] * i % mod;
            inv[i] = mod - inv[mod%i] * (mod/i) % mod;
            ifact[i] = ifact[i-1] * inv[i] % mod;
        }
    }

    long long operator()(int n, int k) {
        if (n < k) return 0;
        if (k < 0 || k > n) return 0;
        return fact[n]*ifact[k]%mod*ifact[n-k]%mod;
    }
};

int main() {
    int r1,c1,r2,c2;
    cin >> r1 >> c1 >> r2 >> c2;
    combination c;

    ll s1, s2, s3, s4;
    // ans = s1 - s3 - s4 + s2
    s1 = c(c2+r2+2,c2+1);
    s2 = c(c1+r1,c1);
    s3 = c(c1+r2+1, c1);
    s4 = c(c2+r1+1, c2+1);
    ll ans = s1 + s2 - s3 - s4;
    ans %= mod;
    ans += mod;
    ans %= mod;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 234624
#include <iostream>
#include <sstream>
#include <vector>
#include <algorithm>
#include <string>
#include <functional>
#include <numeric>
#include <ctype.h>
#include <cstdlib>
#include <string.h>
#include <cmath>
#include <cstdio>





using namespace std;


int main()
{
	string input, str;

	cin >> input;

	for (auto a : input)
	{
		str.insert(str.begin(), a);
	}

	cout << str << endl;
}

Measured memory_bytes: 3132
import java.util.Arrays;
import java.util.Scanner;

class Main {
	public static void main(String[] $) {
		Scanner sc = new Scanner(System.in);
		int n=sc.nextInt(),k=sc.nextInt(),min=Integer.MAX_VALUE,count=0;
		int[] a=new int[n];
		for(int i=0;i<n;i++) a[i]=sc.nextInt();
		Arrays.sort(a);
		for(int i=0;i<n;i++) {
			count++;
			if(count>=k) {
				min=Math.min(min, a[i]-a[i-k+1]);
			}
		}
		System.out.println(min);
	}
}



Measured memory_bytes: 50616
#include <stdio.h>

int main() {
    
    char c[300];
    int m, h, i, j, k, num=0, tmp;
    while(1) {
        scanf("%s", c);
        if(c[0]=='-') {
            break;
        }
        
        for (num=0; num<300; num++) {
            if (c[num] == '\0') {
                break;
            }
        }
        scanf("%d",&m);
        
        for (i=0; i<m; i++) {
            scanf("%d", &h);
            for (j=0; j<h; j++) {
                tmp = c[0];
                for (k=0; k<num; k++) {
                    c[k] = c[k+1];
                }
                c[num-1]=tmp;
            }
        }
        printf("%s\n",c);
    }
    return 0;
}



Measured memory_bytes: 2032
// #include {{{
#include <iostream>
#include <cassert>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <ctime>
#include <queue>
#include <set>
#include <map>
#include <stack>
#include <string>
#include <bitset>
#include <vector>
#include <complex>
#include <algorithm>
using namespace std;
// }}}
// #define {{{
typedef long long ll;
typedef double db;
typedef pair<int,int> pii;
typedef vector<int> vi;
#define de(x) cout << #x << "=" << x << endl
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define per(i,a,b) for(int i=(b)-1;i>=(a);--i)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define fi first
#define se second
// }}}

const int N = 2e5 + 10;
typedef tuple<int,int,int> tr;
priority_queue<tr> Q;
int n,a[N],b[N],Mn[20][N],lg[N];

int getMin(int l,int r){
    int i=lg[r-l+1];
    return min(Mn[i][l],Mn[i][r+1-(1<<i)]);
}
tr get(int l,int r){
    return tr(-getMin(l,r),l,r);
}

int main(){
    scanf("%d",&n);
    rep(i,2,n+1) lg[i]=lg[i>>1]+1;
    rep(i,0,n) scanf("%d",a+i),Mn[1][i]=a[i],b[a[i]]=i;
    rep(i,2,lg[n]+1) rep(j,0,n-(1<<i)+2) Mn[i][j]=min(Mn[i-1][j],Mn[i-1][j+(1<<i>>1)]);
    Q.push(get(0,n-1));
    vi ans;
    while(sz(Q)) {
        int x,l,r;
        tie(x,l,r)=Q.top();Q.pop();
        x=-x;
        int y=getMin(b[x]+1,r+1);
        ans.pb(x);ans.pb(y);
        if(b[x]!=l) Q.push(get(l,b[x]-1));
        if(b[x]+1!=b[y]) Q.push(get(b[x]+1,b[y]-1));
        if(b[y]!=r) Q.push(get(b[y]+1,r));
    }
    rep(i,0,sz(ans)) printf("%d%c",ans[i]," \n"[i+1==sz(ans)]);
    return 0;
}


Measured memory_bytes: 20108
package main

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

var (
	sc = bufio.NewScanner(os.Stdin)

/*	sc = bufio.NewScanner(strings.NewReader(
		`8 5 22
100 3 7 5 3 1
164 4 5 2 7 8
334 7 2 7 2 9
234 4 7 2 8 2
541 5 4 3 3 6
235 4 8 6 9 7
394 3 6 1 6 2
872 8 4 3 7 2`))*/

	n int
	m int
	x int
)

func main() {
	intArray := readIntArray()
	n, m, x = intArray[0], intArray[1], intArray[2]

	books := make([][]int, n)
	for i := range books {
		books[i] = readIntArray()
	}

	combination := make([]int, 1<<n)
	for i := range combination {
		combination[i] = i
	}

	minPrice := math.MaxInt32
	for _, comb := range combination {
		price := 0

		understanding := make([]int, m)
		for mask := 0; mask < n; mask++ {
			if (comb>>mask)&1 == 1 {
				price += books[mask][0]

				for i := range understanding {
					understanding[i] += books[mask][i+1]
				}
			}
		}

		minUnderstanding := math.MaxInt32
		for _, n := range understanding {
			if minUnderstanding > n {
				minUnderstanding = n
			}
		}

		if minUnderstanding >= x && minPrice > price {
			minPrice = price
		}
	}

	if minPrice == math.MaxInt32 {
		fmt.Println(-1)
		return
	}

	fmt.Println(minPrice)
}

func readLine() string {
	if sc.Scan() {
		return sc.Text()
	}
	return "error"
}

func readStringArray() []string {
	return strings.Split(readLine(), " ")
}

func readIntArray() []int {
	a := readStringArray()
	ints := make([]int, len(a))
	for i, s := range a {
		n, err := strconv.Atoi(s)
		if err != nil {
			panic(err)
		}
		ints[i] = n
	}
	return ints
}

func readInt() int {
	n, err := strconv.Atoi(readLine())
	if err != nil {
		panic(err)
	}
	return n
}


Measured memory_bytes: 2208
//package atcoder;

import java.util.*;

public class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
			int N = sc.nextInt();
			String A[] = new String[N];
			for(int i=0;i<N;i++) {
				char B[] = new char[10];
				B = sc.next().toCharArray();
				Arrays.sort(B);
				A[i] = new String(B);
				//System.out.println(A[i]);
			}
			HashMap<String,Integer>map = new HashMap<String,Integer>();
			long ans = 0;
			//System.out.println(map.get(A[0]));
			for(int i=0;i<N;i++) {
				if(map.containsKey(A[i])) {
					map.put(A[i],map.get(A[i])+1);
					//System.out.println(map.get(A[i]));
				}else {
					map.put(A[i],1);
				}
			}
		for(String key : map.keySet()) {
				long tmp = map.get(key);
				if(tmp>1) {
					ans += (tmp*(tmp-1)/2);
				}
			}
			System.out.println(ans);
	}
	
}

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

typedef long long ll;

int main()
{
    int sx, sy, tx, ty;
    cin >> sx >> sy >> tx >> ty;
    int h = tx - sx;
    int v = ty - sy;
    string s;
    rep(i, v) s+='U';
    rep(i, h) s+='R';
    s+='D';
    rep(i, h - 1) s+='L';
    rep(i, v - 1) s+='D';
    s+="LL";
    rep(i, v + 1) s+='U';
    rep(i, h + 1) s+='R';
    s+= "DRDD";
    rep(i, h - 1) s+= 'L';
    rep(i, v - 1) s+= 'D';
    s += "LLU";
    cout << s << endl;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#define SIZE 100000

int main(){
  char s[SIZE];
  int i;

  scanf("%s",s);

  for(i = 0; s[i] != '\0'; i++){
    if(i % 2 == 0){
      printf("%c",s[i]);
    }
  }
  return 0;
}

Measured memory_bytes: 256
import java.io.*;
import java.util.*;

class Main
{
    public static void main(String[] args)
    {
        Scanner sc = new Scanner(System.in);
        
        int n = sc.nextInt();
        int m = sc.nextInt();
        int l = sc.nextInt();
        
        int[][] A = new int[n][m];
        int[][] B = new int[m][l];
        
        for (int i = 0; i < n ; i++) {
            for (int j = 0; j < m; j++) {
                A[i][j] = sc.nextInt();
            }
        }
        
        for (int i = 0; i < m; i++) {
            for (int j = 0; j < l; j++) {
                B[i][j] = sc.nextInt();    
            }
        }
        
        long[][] result = new long[n][l];
        
        
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < l; j++) {
                for (int k = 0; k < m; k++) {
                    result[i][j] += A[i][k] * B[k][j];
                }
            }
        }
        
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < l; j++) {
                if (j != l - 1) {
                    System.out.printf("%d ", result[i][j]);
                }
                else {
                    System.out.printf("%d\n", result[i][j]);
                }
            }
        }
    }
}

Measured memory_bytes: 74204
n, p = gets.split(" ").map(&:to_i)
a = gets.chomp.chars.map{|x| x.to_i }.reverse

if p == 2 or p == 5
  ans = 0
  n.times do |i|
    if a[i] % p == 0
      ans += (n - i)
    end
  end
  puts ans
  exit
end


sums = []
sum = 0
base = 1
x = [0] * p
x[0] = 1
n.times do |i|
  sum = (sum + a[i] * base) % p
  base = base * 10 % p
  sums[i] = sum
  x[sum] += 1
end

ans = 0
x.each do |y|
    ans += (y + 1) * y / 2
end
puts ans - n - 1


Measured memory_bytes: 17740
def calc_total_D(stats, D, color):
    total = 0
    for i in range(3):
        y = color[i]
        for x in range(len(stats[i])):
            total += stats[i][x] * D[x][y]
    return total


def main():
    N, C = map(int, input().split())
    D = [list(map(int, input().split())) for _ in range(C)]
    c = [list(map(int, input().split())) for _ in range(N)]

    # color -= 1
    stats = [[0] * C for _ in range(3)]

    for i in range(N):
        for j in range(N):
            stats[(i+j) % 3][c[i][j]-1] += 1

    retval = float("inf")
    for c1 in range(C):
        for c2 in range(C):
            if c1 == c2:
                continue
            for c3 in range(C):
                if c1 == c3 or c2 == c3:
                    continue
                retval = min(retval, calc_total_D(stats, D, [c1, c2, c3]))
    print(retval)


if __name__ == "__main__":
    main()


Measured memory_bytes: 5620
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc= new Scanner(System.in);
int a = sc.nextInt();
int b = sc.nextInt();
int c = sc.nextInt();
if(a<b && b<c) {
System.out.println("Yes");}
else{
System.out.println("No");}
}
}

Measured memory_bytes: 26024
#include <algorithm>
#include <complex>
#include <cstdlib>
#include <ctime>
#include <time.h>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <numeric>
#include <limits>
#include <type_traits>
#include <locale>

using namespace std;
#define SAY_YES cout << "YES" << endl;
#define SAY_Yes cout << "Yes" << endl;
#define SAY_NO cout << "NO" << endl;
#define SAY_No cout << "No" << endl;
#define IFYES(TRUE_OR_FALSE)   \
    if (TRUE_OR_FALSE)         \
    {                          \
        cout << "YES" << endl; \
    }                          \
    else                       \
    {                          \
        cout << "NO" << endl;  \
    }
#define IFYes(TRUE_OR_FALSE)   \
    if (TRUE_OR_FALSE)         \
    {                          \
        cout << "Yes" << endl; \
    }                          \
    else                       \
    {                          \
        cout << "No" << endl;  \
    }
#define IFyes(TRUE_OR_FALSE)   \
    if (TRUE_OR_FALSE)         \
    {                          \
        cout << "yes" << endl; \
    }                          \
    else                       \
    {                          \
        cout << "no" << endl;  \
    }
#define DEBUG_OUTPUT_ARRAY(XXX, ONE)                            \
    for (int i = 0; i < (ONE); i++)                             \
    {                                                           \
        cout << "DEBUG: i = " << i << " -> " << XXX[i] << endl; \
    }
#define DEBUG_OUTPUT_ARRAY2(XXX, ONE, TWO)                             \
    for (int i = 0; i < (ONE); i++)                                    \
    {                                                                  \
        cout << "<<< i = " << i << " >>>" << endl;                     \
        for (int j = 0; j < (TWO); j++)                                \
        {                                                              \
            cout << "DEBUG: j = " << j << " -> " << XXX[i][j] << endl; \
        }                                                              \
    }
#define DEBUG_OUTPUT_ARRAY2_BOX(XXX, ONE, TWO) \
    for (int i = 0; i < (ONE); i++)            \
    {                                          \
        cout << i << "  ";                     \
        for (int j = 0; j < (TWO); j++)        \
        {                                      \
            cout << XXX[i][j] << " ";          \
        }                                      \
        cout << endl;                          \
    }

typedef pair<long long int, long long int> pll;
typedef pair<long long int, pll> lpll;


const long long int mod = 998244353;
const long long int INF = 1e18;
const long double PI=3.14159265358979323; 

long long int N,M;

int main(){
    cout << fixed << setprecision(18);
    cin>>N>>M;
    cout<<N*(N-1)/2+M*(M-1)/2<<endl;
}




Measured memory_bytes: 256
/*dismint|jjc*/
#include <bits/stdc++.h>
using namespace std;
#define forl(V, S, E) for(int V = S; V < E; V++)
#define ford(V, S, E) for(int V = S; V >= E; V--)
#define fore(E, X) for(auto &E:X)
#define println(X) cout << X << endl
#define printe(X) for(auto &E:X) cout << E << " "; cout << endl
typedef unordered_map<int, unordered_set<int>> graph;
typedef long long ll;

int main() {
	ios_base::sync_with_stdio(false); cin.tie(NULL);
	int n; cin >> n;
	unordered_set<int> check; forl(i, 0, n) { int a; cin >> a; check.insert(a); }
	if(check.size() != n) println("NO");
	else println("YES");
}


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

int main() {
  int X;
  
  int f_X = 0;
  //int n = 0;
  cin >> X;
  int t = X;

  while (t > 0) {
    f_X += t % 10;
    t /= 10;
  }
  
  if (X % f_X == 0) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int x,y,z,w;
  cin>>x>>y>>z>>w;
  if(x+y>z+w) cout<<"Left"<<endl;
  else if(x+y==z+w) cout<<"Balanced"<<endl;
  else if(x+y<z+w) cout<<"Right"<<endl;
}

Measured memory_bytes: 3604
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#include <vector>
#include <set>
#include <cstdlib>
#include <deque>
#include <stack>

using namespace std;
const long long P = 1000000007;

vector<long long> vc;

int main() {
  int d,n;
  cin >> d >> n;
  if(n != 100) {
    cout << pow(100,d)*n << endl;
  }else {
    printf("%.0lf\n",pow(100,d)*(n + 1));
  }
  return 0;
}


Measured memory_bytes: 256
A = []
hole = []
for i in range(3):
    A.append(list(input().split()))
    hole.append(["","",""])
# print(A)
# print(hole)
N = int(input())
B = []
for j in range(N):
    B.append(input())

for m in range(3):
    for n in range(3):
#         print(A[m][n])
        if str(A[m][n]) in B:
#             print("match")
            hole[m][n] = "#"
# print(hole)
ans = "No"

if hole[0][0] == "#" and hole[1][1] == "#" and hole[2][2]== "#":
    ans = "Yes"
elif hole[0][0] == "#" and hole[0][1] == "#" and hole[0][2]== "#":
    ans = "Yes"
elif hole[1][0] == "#" and hole[1][1] == "#" and hole[1][2]== "#":
    ans = "Yes"
elif hole[2][0] == "#" and hole[2][1] == "#" and hole[2][2]== "#":
    ans = "Yes"
elif hole[0][0] == "#" and hole[1][0] == "#" and hole[2][0]== "#":
    ans = "Yes"
elif hole[0][1] == "#" and hole[1][1] == "#" and hole[2][1]== "#":
    ans = "Yes"
elif hole[0][2] == "#" and hole[1][2] == "#" and hole[2][2]== "#":
    ans = "Yes"
elif hole[0][2] == "#" and hole[1][1] == "#" and hole[2][0]== "#":
    ans = "Yes"

print(ans)

Measured memory_bytes: 3188
def bellmanford(num, start, goal, edges):
    cost = [float('inf')] * num
    cost[start] = 0
    for _ in range(num):
        updated = False
        for a, b, c in edges:
            if cost[b] > cost[a] + c:
                cost[b] = cost[a] + c
                updated = True
        if not updated:
            break
    else:
        return (-1,cost)
    return (1,cost[goal])

def main():
    N, M = LI()
    v = []
    for _ in range(M):
        x, y, z = map(int, input().split())
        v.append((x - 1, y - 1, -z))
#    print(v)
#    print(bellmanford(N, 0, N-1, v))
    cur, d = bellmanford(N, 0, N - 1, v)
    if cur == -1:
        # Nまでの道の途中に負閉路があるか
        inf_flag = [False] * N
        for _ in range(N):
            for f, t, c in v:
                if d[f] == inf: continue
                if inf_flag[f] == True:
                    inf_flag[t] = True
                # 更新が終わっていない→負閉路
                if d[t] > d[f] + c:
                    d[t] = d[f] + c
                    inf_flag[t] = True
        print("inf" if inf_flag[N - 1] else -d[N - 1])
    else:
        print(-d)
    return

import sys,copy,bisect,itertools,heapq,math
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LFI(): return list(map(float,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,mod2,inf,alphabet
mod = 10**9 + 7
mod2 = 998244353
inf = 10**18
alphabet = [chr(ord('a') + i) for i in range(26)]

if __name__ == '__main__':
    main()

"""
3 3
1 2 4
2 3 3
1 3 5
"""

Measured memory_bytes: 47704
#include<bits/stdc++.h>
#define int long long
#define ll long long
#define fi first
#define se second
#define pb push_back
#define pii pair<int,int>
#define vi vector<int>
using namespace std;
string s,t;
const int N = 1e5+5;
vi adj[N];
bool vis[N];
vi path;
void dfs(int v) {
    vis[v] = 1;
    for (int i : adj[v])
        if (!vis[i])dfs(i);
    path.pb(v);

}
int dp[N];
main() {
    ios::sync_with_stdio(0);
    int n,m;
    cin >> n >> m;
    for (int i = 0,a,b; i < m; i++) {
        cin >> a >> b;
        adj[a].pb(b);
    }
    for (int i =1 ; i <= n; i++) {
            if (!vis[i])
            dfs(i);
    }
    reverse(path.begin(),path.end());
    for (int i:path) {
        for (int j : adj[i])
            dp[j] = max(dp[j],dp[i] + 1);
    }
    cout << *max_element(dp,dp+n+1);
}


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

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

    int res10000 = -1, res5000 = -1, res1000 = -1;
    for (int i = 0; i <= n; i++)
    {
        for (int j = 0; j <= n - i; j++)
        {
            int k = n - i - j;
            if (i * 1000 + j * 5000 + k * 10000 == y)
            {
                res10000 = k;
                res5000 = j;
                res1000 = i;
            }
        }
    }
    cout << res10000 << ' ' << res5000 << ' ' << res1000 << endl;

}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int maxn=3e5+10;
int a[maxn],b[maxn],n;
priority_queue<pair<int,int>> s;
long long ans;

int main(){
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        scanf("%d",&a[i]);
    }
    for(int i=0;i<n;i++){
        scanf("%d",&b[i]);
        s.push({b[i],i});
    }
    int l,r;
    while(!s.empty()){
        auto it=s.top();
        if(it.first==a[it.second]){
            s.pop();
            continue;
        }
        int l=((it.second)-1);
        if(l<0)l=n-1;
        int r=(l+2);
        if(r>=n)r-=n;
        int sum=(b[l]+b[r]);
        if(b[it.second]<sum||b[it.second]-sum<a[it.second]){
            return !printf("-1");
        }
        if(a[it.second]>sum){
            if((b[it.second]-a[it.second])%sum)
                return !printf("-1");
            ans+=(b[it.second]-a[it.second])/sum;
            b[it.second]=a[it.second];
            s.pop();continue;
        }
        ///find the first number that is in form of
        ///b-sum*k<=sum sum*(k+1)>=b
        int cur=b[it.second]/sum-(b[it.second]%sum==0?1:0);
        b[it.second]-=sum*cur;
        ans+=cur;
        s.pop();
        s.push({b[it.second],it.second});
    }
    printf("%lld\n",ans);
}
/*
    Good Luck
        -Lucina
*/


Measured memory_bytes: 3700
#include <algorithm>
#include <cmath>
#include <iostream>
#include <numeric>
#include <vector>

using namespace std;

int main() {
  int a, b;

  cin >> a >> b;

  if((a<=8)and(b<=8)){
  cout <<"Yay!" << endl;
  }else{
    cout << ":(" << endl;
  }
}


Measured memory_bytes: 256
import sys
#from me.io import dup_file_stdin

#@dup_file_stdin
def solve():
    while True:
        m = []
        h,w = map(int,sys.stdin.readline().split(" "))
        if h==0 and w==0:
            break
        for r in range(h):
            m.append(list(sys.stdin.readline()[:-1]))
        r=0
        c=0
        while m[r][c]!='*':
            if m[r][c]=='>':
                m[r][c]='*'
                c+=1
            elif m[r][c]=='<':
                m[r][c]='*'
                c-=1
            elif m[r][c]=='v':
                m[r][c]='*'
                r+=1
            elif m[r][c]=='^':
                m[r][c]='*'
                r-=1
            elif m[r][c]=='.':
                break
        if m[r][c]=='*':
            print("LOOP")
        else:
            print("{} {}".format(c,r))
solve()

Measured memory_bytes: 7796
package main

import (
	"bufio"
	"fmt"
	"io"
	"math"
	"os"
	"strconv"
	"strings"

)


func main() {
	solve(os.Stdin, os.Stdout)
}

type ReaderEx struct {
	baseScanner *bufio.Scanner
	words       []string
	nextWordIdx func() int
	initWordIdx func(int)
}

func NewScannerEx(stdin io.Reader) *ReaderEx {
	var this ReaderEx
	var idx int
	var wordsCnt int
	this.baseScanner = bufio.NewScanner(stdin)
	this.baseScanner.Buffer(make([]byte, 0), 1E+11)
	this.nextWordIdx = func() int {
		cur := idx
		idx = (idx + 1) % wordsCnt
		return cur
	}
	this.initWordIdx = func(wc int) {
		idx = 0
		wordsCnt = wc
	}
	return &this
}

func (me *ReaderEx) Scan(doSplit bool) (isScanned bool) {
	isScanned = me.baseScanner.Scan()
	if doSplit {
		me.words = strings.Fields(me.baseScanner.Text())
	} else {
		me.words = []string{me.baseScanner.Text()}
	}
	me.initWordIdx(len(me.words))
	return
}

func (me *ReaderEx) nextBytes() []byte {
	return []byte(me.words[me.nextWordIdx()])
}
func (me *ReaderEx) nextString() string {
	return me.words[me.nextWordIdx()]
}

type StringArray []string

func (me *ReaderEx) nextStringArray() StringArray {
	return me.words[me.nextWordIdx():]
}

func (me StringArray) toStrings() []string {
	return me
}

func (me StringArray) toInts() []int {
	strValues := me.toStrings()
	values := make([]int, len(strValues))
	for i, v := range strValues {
		n, err := strconv.Atoi(v)
		if err != nil {
			panic(err)
		}
		values[i] = n
	}
	return values
}
func (me *ReaderEx) nextInt() int {
	n, err := strconv.Atoi(me.words[me.nextWordIdx()])

	defer func() {
		if err != nil {
			panic(fmt.Sprintf("getInt(%d)", n))
		}
	}()
	return n
}

func pow(x, y, mod int) (ans int) {

	ans = 1
	for bit := 1 << uint(math.Floor(math.Log2(float64(y)))); ; bit >>= 1 {
		if y&bit != 0 {
			ans *= x
			if mod > 0 {
				ans %= mod
			}
		}
		if bit <= 1 {
			return
		}
		ans *= ans
		if mod > 0 {
			ans %= mod
		}
	}
}

type factType struct {
	prime int
	count int
}

func fact(n int) (facts []*factType) {

	for i := 2; i*i <= n; i++ {
		if n%i == 0 {
			fa := factType{prime: i}
			for n%fa.prime == 0 {
				n /= fa.prime
				fa.count++
			}
			facts = append(facts, &fa)
		}
	}
	if n > 1 {
		facts = append(facts, &factType{prime: n, count: 1})
	}
	return facts
}
func dec2bin(n int) (ret []bool) {
	for bit := 1 << uint(math.Floor(math.Log2(float64(n)))); ; bit >>= 1 {
		ret = append(ret, n&bit != 0)

		if bit <= 1 {
			return
		}
	}

}

func abs(v int) int {
	if v < 0 {
		v = -v
	}
	return v
}

func b2i(b bool) (i int) {
	if b {
		i = 1
	} else {
		i = 0
	}
	return
}

func solve(stdin io.Reader, stdout io.Writer) {

	r := NewScannerEx(stdin)
	r.Scan(false)
	s := r.nextString()
	r.Scan(false)
	t := r.nextString()

	ans := 0
	for i := 0; i < len(s); i++ {
		if s[i] != t[i] {
			ans++
		}
	}
	fmt.Fprintln(stdout, ans)
}


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

using namespace std;

int main() {

//	string s;
//	cin >> s;

	long long n;
	cin >> n ;

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

	long long counter,minn;
	counter = 0;
	minn = 10000000;

	for(int i=0;i<=100;i++){
		counter = 0;
		for (int j = 0; j < n; j++) {
			counter+=(x[j]-i)*(x[j]-i);
		}
		minn = min(minn, counter);
	}

	cout << minn << endl;
	
	return 0;

}

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

int main(void){
	string S, T;
	cin >> S >> T;
	int count = 0;
	
	rep(i, S.size()){
		if (S[i] != T[i]) count++;
	}

	cout << count << endl;

return 0;
}


Measured memory_bytes: 3828
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
#include <math.h>
#include <stdio.h>
#include <set>
#include <list>

using namespace std;


int main() {
    int n, flag{1}, count{0};
    cin >> n;
    int A[n];
    for(int i=0; i<n;i++){
        cin >> A[i];
    }

    while (flag) {
        flag = 0;
        for (int i = n - 1; i > 0; i--) {
            if (A[i] < A[i - 1]) {
                swap(A[i], A[i - 1]);
                flag = 1;
                count++;
            }
        }
    }

    for(int i=0; i<n;i++){
        cout << A[i];
        if (i==n-1) cout << endl;
        else cout << " ";
    }
    cout << count << endl;
}


Measured memory_bytes: 3096
package main

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

var sc = bufio.NewScanner(os.Stdin)

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

func nextFloat64() float64 {
	sc.Scan()
	i, e := strconv.ParseFloat(sc.Text(), 64)
	if e != nil {
		panic(e)
	}
	return i
}

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

func sum(x, n int) int {
	ans := 0
	for i := 0; i < n; i++ {
		ans += (x - i)
	}
	return ans
}

func main() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(nil, 100000000)

	s := nextString()
	n := len(s)

	ss := make([]int, n)

	rc := 0
	lc := 0
	for i, v := range s {
		if v == 'B' {
			ss[i] = 1 // Black
			rc++
			lc += i + 1
		} else {
			ss[i] = 0 // White
		}
	}

	fmt.Println(sum(n, rc) - lc)
}


Measured memory_bytes: 4112
#include <iostream>
#include <algorithm>

#define SIZE 100000
#define INF  10000000000

typedef long long ll;

ll N;
ll A[SIZE];

ll solve() {
    ll n = N;
    std::sort(A, A+N);
    while (n > 1) {
        ll m = n;
        for (int i=1; i<m; ++i) {
            if (A[i] % A[0] == 0) {
                A[i] = INF;
                --n;
            } else {
                A[i] = A[i] % A[0];
            }
        }
        std::sort(A, A+m);
    }
    return A[0];
}

int main() {
    std::cin >> N;
    for (ll i=0; i<N; ++i) std::cin >> A[i];
    std::cout << solve() << std::endl;
    return 0;
}

Measured memory_bytes: 1024
#include <iostream>

using namespace std;
using llong = long long;

llong n;
llong a, b, c, d;

int main() {
    cin >> a >> b >> c >> d;
    cin >> n;

    c = min(4 * a, c);
    c = min(2 * b, c);
    d = min(2 * c, d);

    cout << (n / 2) * d + (n % 2) * c << endl;
    
    return 0;
}


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

long long N, K;
long long a[2001];
long long sa[2001];

const int M = int(1e9) + 7;

int main(){
	cin >> N >> K;
	for(int i = 0; i < N; i++){
		cin >> a[i];
		sa[i] = a[i];
	}
	//
	sort(sa, sa+N);
	//
	long long ans = 0;
	for(int i = 0; i < N; i++){
		long long subans = 0;
		for(int j = i + 1; j < N; j++){
			subans += ( a[i] > a[j] );
		}
		ans += (subans*K);
		ans %= M;
		//
		for(int j = 0; j < N; j++){
			if( sa[j] == a[i] ){
				ans += ((K-1)*(K)/2 % M *(j) % M);
				ans %= M;
				break;
			}
		}
	}
	//
	cout << ans;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N=305;
char s[N];
int dp[N][N][N],K;
int main(){
	scanf("%s%d",s,&K);
	int n=strlen(s);
	for (int i=0;i<n;i++)
		for (int k=0;k<=K;k++)dp[i][i][k]=1;
	for (int l=1;l<n;l++)
		for (int i=0;i+l<n;i++){
			int j=i+l;
			for (int k=0;k<=K;k++){
				dp[i][j][k]=max(dp[i+1][j][k],dp[i][j-1][k]);
				if (k>0)dp[i][j][k]=max(dp[i+1][j-1][k-1]+2,dp[i][j][k]);
				if (s[i]==s[j])dp[i][j][k]=max(dp[i+1][j-1][k]+2,dp[i][j][k]);
	        }
	    }
	printf("%d\n",dp[0][n-1][K]);
}

Measured memory_bytes: 110848
#define  _CRT_SECURE_NO_WARNINGS
#pragma comment (linker, "/STACK:526000000")

#include "bits/stdc++.h"

using namespace std;
typedef string::const_iterator State;
#define eps 1e-11L
#define MAX_MOD 1000000007LL
#define GYAKU 500000004LL

#define MOD 998244353LL
#define seg_size 262144 * 4LL
#define pb push_back
#define mp make_pair
typedef long long ll;
#define REP(a,b) for(long long (a) = 0;(a) < (b);++(a))
#define ALL(x) (x).begin(),(x).end()

unsigned long xor128() {
	static unsigned long x = 123456789, y = 362436069, z = 521288629, w = time(NULL);
	unsigned long t = (x ^ (x << 11));
	x = y; y = z; z = w;
	return (w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)));
}
void init() {
	iostream::sync_with_stdio(false);
	cout << fixed << setprecision(20);
}

#define int ll

void solve(){
	while (true) {
		int n, d;
		cin >> n >> d;
		if (n == 0) return;
		vector<vector<int>> inputs;
		int summing[2000] = {};
		REP(i, n) {
			int a;
			cin >> a;
			vector<int> tmp;
			REP(q, a) {
				int b;
				cin >> b;
				tmp.push_back(b);
				summing[i] += b;
			}
			inputs.push_back(tmp);
		}
		int ok = 1;
		REP(te, 10000) {
			int now = -1;
			REP(q, n) {
				if (summing[q] == 0) continue;
				int now_max = 0;
				int now_min = 1e18;
				summing[q] -= inputs[q].back();
				REP(j, n) {
					now_max = max(now_max, summing[j]);
					now_min = min(now_min, summing[j]);
				}
				summing[q] += inputs[q].back();
				if (now_max - now_min <= d) {
					now = q;
					break;
				}
			}
			if (now == -1) {
				REP(j, n) {
					if (summing[j] != 0) ok = 0;
				}
				break;
			}
			summing[now] -= inputs[now].back();
			inputs[now].pop_back();
			if (inputs[now].empty() == true) {
				break;
			}
		}

		string ans[2] = { "No","Yes" };
		cout << ans[ok] << endl;
		continue;
	}
}

#undef int

int main() {
	init();
	solve();
}


Measured memory_bytes: 3196
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <utility>
#include <map>

#include <stdio.h>

#define rep(i, n) for (int i = 0; i < (n); i++)
#define irep(i, k, n) for (int i = (k); i < (n); i++)
#define rrep(i, k, n) for (int i = (k); i >= (n); i++)
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define vec vector

typedef long long ll;

const ll inf = 1LL << 60;
const int mod = 1e9 + 7;

using namespace std;

/* Input variables. */
string s;

/* Solve! */
void solve() {
  int res = 0;
  irep(i, 1, s.length()) {
    if (s[i] == s[i - 1]) {
      s[i] = s[i] == '0' ? '1' : '0';
      res++;
    }
  }
  cout << res << endl;
}

int main() {
  /* Input handling. */
  cin >> s;

  solve();
  return 0;
}

Measured memory_bytes: 888
#include<stdio.h>
#include<string.h>

int main()
{
	int M1, M2, D1, D2;
	
	scanf("%d %d", &M1, &D1);
	scanf("%d %d", &M2, &D2);
	
	if(M1 == M2) printf("0");
	else printf("1");
	
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define maxn 200005
using namespace std;
map<string,int> M;
string arr[maxn];
map<string,bool> V;
vector<string> ansans;
int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	for ( int i=0; i<n; ++i ) {
		cin >> arr[i];
		M[arr[i]]++;
	}
	int idx = 0;
	for ( int i=1; i<n; ++i ) {
		if ( M[arr[i]] > M[arr[idx]] ) {
			idx = i;
		}
	}
	int ans = M[arr[idx]];
	for ( int i=0; i<n; ++i ) {
		if ( V[arr[i]] )	continue;
		if ( M[arr[i]] == ans ) {
			V[arr[i]] = true;
			ansans.emplace_back(arr[i]);
		}
	}
	sort(ansans.begin(), ansans.end());
	for ( string i : ansans )
		cout << i << '\n';

	return 0;
}

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

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    int a[n];
    for (int i = 0; i < n; i++) cin >> a[i];
    int b[n];
    for (int i = 0; i < n; i++) cin >> b[i];
    int c[n];
    for (int i = 0; i < n; i++) cin >> c[i];
    sort(a, a + n);
    sort(b, b + n);
    sort(c, c + n);
    long long x[n], y[n + 1];
    for (int i = 0; i < n; i++) {
        y[i] = c + n - upper_bound(c, c + n, b[i]);
    }
    y[n] = 0;
    for (int i = n - 1; i >= 0; i--) y[i] += y[i + 1];
    for (int i = 0; i < n; i++) {
        int t = upper_bound(b, b + n, a[i]) - b;
        x[i] = y[t];
    }
    long long res = accumulate(x, x + n, 0LL);
    cout << res << "\n";
    return 0;
}

Measured memory_bytes: 2944
#include <iostream>
#include <string>
#include <map>
#include <math.h>
using namespace std;

int main(void)
{
    int A, B;
    cin >> A >> B;
    if(A>8 || B>8){
        cout << ":(" << endl;
        return 0;
    }

    int diff;
    if(A>B) diff = A-B;
    else diff = B-A;
    
    int limit = int((16-diff)/2)+1;
    if(diff<=limit) cout << "Yay!" << endl;
    else cout << ":(" << endl;
    
    return 0;
    

}

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

long long ans=1LL;
vector<bool> visit;
vector<vector<int>> e;
int n,k;

long long p(int n, int r, long long now){
  if(r==0)return now;
  return p(n-1, r-1, n*now%1000000007);
}

int main(){
  cin>>n>>k;
  e.resize(n);
  for(int i=0; i<n-1; ++i){
    int a,b; cin>>a>>b;
    e[a-1].push_back(b-1);
    e[b-1].push_back(a-1);
  }
  
  visit.resize(n);
  for(int i=0; i<n; ++i)visit[i]=false;
  set<int> dfs;
  ans=p(k-1, e[0].size(), k)%1000000007;
  visit[0]=true;
  for(int x:e[0])dfs.insert(x);
  
  while(!dfs.empty()){
    for(int x:dfs){
      visit[x]=true;
      dfs.erase(x);
      int nodes=e[x].size();
      ans=ans*p(k-2, nodes-1, 1)%1000000007;
      for(int y:e[x])if(!visit[y])dfs.insert(y);
    }
  }

  cout<<ans<<endl;
}


Measured memory_bytes: 10744
#include <cmath>
#include <cassert>
#include <iostream>
#include <iomanip>
#include <map>
#include <set>
#include <vector>
#include <algorithm>
#include <queue>
#include <cstring>

using namespace std;

#define forsn(i,s,n) for (int i = (s);i < (int)(n);i++)
#define forn(i,n) forsn(i,0,n)
#define dforsn(i,s,n) for (int i = (n-1);i >= (int)(s);i--)
#define dforn(i,n) dforsn(i,0,n)
#define all(v) (v).begin(), (v).end()
#define F first
#define S second

bool could[100010];
int balls[100010];

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

	memset(could, 0, sizeof(could));
	
	int n, m; cin >> n >> m;
	forn(i,n) { could[i + 1] = 0, balls[i + 1] = 1; }
	could[1] = 1;
	
	while (m--) {
		int x, y; cin >> x >> y;
		
		could[y] |= could[x];
		balls[y]++;
		balls[x]--;
		could[x] &= (bool)(balls[x]);
	}
	
	int res = 0;
	forn(i, n) res += could[i + 1];
	
	cout << res << endl;
}


Measured memory_bytes: 768
n,m,x=map(int,input().split())
a=list(map(int,input().split()))
cnt1=0
cnt2=0
for i in range(0,x+1):
    if i in a:
        cnt1+=1
for j in range(x,n+1):
    if j in a:
        cnt2+=1
print(min(cnt1,cnt2))

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

//https://qiita.com/tubo28/items/e6076e9040da57368845
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")
}

//https://qiita.com/maguro_tuna/items/fab200fdc1efde1612e7
macro_rules! min {
    // 引数が 1 個だけの場合は、そのまま返す
    ($a:expr ) => {
        $a
    };
    // 引数が 2 個の場合は、std::cmp::minを使用して小さい方を返す
    ($a:expr, $b:expr) => {
        std::cmp::min($a, $b)
    };
    // 引数が 3 個以上ある場合は、再帰的に min! マクロを呼び出す
    ($a:expr, $($rest:expr),+ ) => {
        std::cmp::min($a, min!($($rest),+)) // 第2引数以降の部分に対して再帰呼び出し
    };
}

macro_rules! chmin {
    ($base:expr, $($cmps:expr),+) => {
        // 第2引数以降の部分に関して、min! を使用して最小値を求める
        let cmp_min = min!($($cmps),+);
        // それが第1引数より小さかったら、更新して true を返す
        if $base > cmp_min{
            $base = cmp_min;
            true
        }else{
            // 更新が不要なので、false を返す
            false
        }
    };
}

//https://drken1215.hatenablog.com/entry/2020/03/22/154300
fn main() {
    //方向ベクトル
    let dx = vec![1, 0];
    let dy = vec![0, 1];
    //入力処理
    let h: usize = read();
    let w: usize = read();
    let mut fi: Vec<Vec<char>> = vec![vec![' '; w]; h];
    for i in 0..h {
        fi[i] = read::<String>().chars().collect();
    }

    //dpテーブル初期化
    let mut dp: Vec<Vec<u64>> = vec![vec![std::u64::MAX; w]; h];
    //dp初期値セット
    if fi[0][0] == '#' {
        dp[0][0] = 1;
    } else {
        dp[0][0] = 0
    }

    //dp更新
    for i in 0..h {
        for j in 0..w {
            for dir in 0..2 {
                let ni = i + dx[dir];
                let nj = j + dy[dir];
                //場外の場合は処理しない
                if ni >= h || nj >= w {
                    continue;
                }
                let mut add = 0;
                //通路から壁へ移動する時はコスト１増加
                if fi[ni][nj] == '#' && fi[i][j] == '.' {
                    add = 1;
                }
                //dpテーブルを最小値で更新する
                chmin!(dp[ni][nj], dp[i][j] + add);
            }
        }
    }
    //println!("{:?}", dp);
    println!("{}", dp[h-1][w-1]);
}


Measured memory_bytes: 2292
#include<iostream>

using namespace std;

int main(int argc, char const *argv[])
{
    int A, B, C;
    cin >> A >> B >> C;
    if(A+B+C>=22){
        cout << "bust" << endl;
    }else
    {
        cout << "win" << endl;
    }
    
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define mp make_pair
#define PI pair<int,int>
#define poly vector<ll>
#define For(i,l,r) for(int i=(int)(l);i<=(int)(r);i++)
#define Rep(i,r,l) for(int i=(int)(r);i>=(int)(l);i--)
#define pb push_back
#define fi first
#define se second
inline char gc(){
    static char buf[100000],*p1=buf,*p2=buf;
    return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
}
#define gc getchar
inline ll read(){
	ll x = 0; char ch = gc(); bool positive = 1;
	for (; !isdigit(ch); ch = gc())	if (ch == '-')	positive = 0;
	for (; isdigit(ch); ch = gc())	x = x * 10 + ch - '0';
	return positive ? x : -x;
}
inline void write(ll a){
    if(a<0){
    	a=-a; putchar('-');
	}
    if(a>=10)write(a/10);
    putchar('0'+a%10);
}
inline void writeln(ll a){write(a); puts("");}
inline void wri(ll a){write(a); putchar(' ');}
inline ull rnd(){
	return ((ull)rand()<<30^rand())<<4|rand()%4;
}
const int N=300005;
int n,sum,a[N],ar[N];
bool check(int x){
	int dq=0;
	for(int i=2;i<=n;i+=2){
		if(ar[i-1]>=dq+x)dq=min(ar[i],dq);
	}
	return ar[n]>=dq+x;
}
int solve(){
	int l=0,r=2e8;
	while(l<r){
		int mid=(l+r)>>1; mid++;
		if(check(mid))l=mid; else r=mid-1;
	}
	return l;
}
int main(){
	n=read();
	For(i,1,n)sum+=(a[i]=read());
	For(i,1,n){ar[i]=ar[i-1]; if(i&1)ar[i]+=a[i]; else ar[i]-=a[i];}
	if(n%2==0){
		int ans=0;
		for(int i=1;i<=n;i+=2)ans+=a[i];
		cout<<max(ans,sum-ans)<<" "<<min(ans,sum-ans)<<endl;
	}else{
		int s=0;
		for(int i=2;i<=n;i+=2)s+=a[i];
		int ans=s+solve();
		cout<<ans<<" "<<sum-ans<<endl;
	}
}

Measured memory_bytes: 2560
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define REP(i, a, b) for(int i = a, i##_len = (b); i < i##_len; ++i)

const int MAX_HW = 25;
const int INF = 1e9;
char MAZE[MAX_HW][MAX_HW];
int mp[MAX_HW][MAX_HW];
int H, W, VERTEX;

int dy[4] = { 1, 0,-1, 0};
int dx[4] = { 0, 1, 0,-1};

void bfs(int sx, int sy){
    for(int i = 0; i < H; ++i) for(int j = 0; j < W; ++j) mp[i][j] = INF;
    mp[sx][sy] = 0;
    queue<int> task; // task.top() = p -> x = p/W, y = p%W
    task.push(sx*W + sy);
    while(!task.empty()){
        int p = task.front();
        task.pop();
        int x = p/W, y = p%W;
        for(int i = 0; i < 4; ++i) {
            int nx = x + dx[i], ny = y + dy[i];
            if(nx < 0 || nx >= H || ny < 0 || ny >= W) continue;
            if(MAZE[nx][ny] == '#') continue;
            if(mp[nx][ny] > mp[x][y] + 1) {
                mp[nx][ny] = mp[x][y] + 1;
                task.push(nx*W + ny);
            }
        }
    }
}

int max_distance(int sx, int sy) {
    bfs(sx,sy);
    int res = 0;
    for(int i = 0; i < H; ++i) for(int j = 0; j < W; ++j) if(MAZE[i][j] != '#')
        res = max(res, mp[i][j]);
    return res;
}

int main()
{
    scanf("%d %d", &H, &W);
    for(int i = 0; i < H; ++i) scanf("%s", MAZE[i]);

    int res = 0;
    for(int sx = 0; sx < H; ++sx) 
        for(int sy = 0; sy < W; ++sy) 
            if(MAZE[sx][sy] == '.') res = max(res, max_distance(sx,sy));

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

Measured memory_bytes: 256
const input = require('fs').readFileSync('/dev/stdin', 'utf8').trim()
const lines = input.trim().split("\n")
const a = lines[0].trim().toLowerCase()
let count = 0, i = 1, line = lines[i]
while (line !== 'END_OF_TEXT') {
    line = line.toLowerCase()

    count += line.trim().split(' ').filter(word => word === a).length


    line = lines[++i]
}

console.log(count)


Measured memory_bytes: 15164
#include<bits/stdc++.h>
#include<cassert>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace std;
using namespace __gnu_pbds; 
typedef tree<
int,
null_type,
less<int>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;
#define pfi(a) printf("%d",a);
#define pfl(a) printf("%lld",a);
#define pfin(a) printf("%d\n",a);
#define pfln(a) printf("%lld\n",a);
#define sfi(a) scanf("%d",&a);
#define sfl(a) scanf("%lld",&a);
#define pb push_back
#define f(i,a,b) for(int i=a;i<b;i++)
#define ll long long
#define inf INT_MAX
#define llinf LONG_LONG_MAX

const int MAXN=2e6+1;
const int M=1e9+7;
const int N=6e6+6;



void solve(){
	
	int n;
	sfi(n)

	ll k; sfl(k)

	int arr[n+1];

	bool vis[n+1];

	ll dis[n+1]={0};

	memset(vis,0,sizeof(vis));

	f(i,1,n+1){
		sfi(arr[i])
	}

	int curr=1;

	dis[1]=0;

	int key=-1,cyc_sz;

	vector<int> v;

	int d=0;

	while(!vis[curr]){
		v.push_back(curr);
		vis[curr]=true;
		dis[curr]=d;
		d++;
		curr=arr[curr];

		if(vis[curr]){
			cyc_sz=d-dis[curr];
			key=curr;
			break;
		}
	}

	vector<int> v1;

	int f=0;

	for(int x:v){
		if(x==key){
			v1.push_back(x);
			f=1;
		}
		else if(f==1){
			v1.push_back(x);
		}
	}

	if(k<=dis[key]){
		cout<<v[k]<<endl;
	}
	else{
		ll k1=k-dis[key];

		cout<<v1[k1%v1.size()]<<endl;
	}

//	ll ind=k%(v.size());

	//pfin(v[ind])

}


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

Measured memory_bytes: 7968
#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <iomanip>

using namespace std;

int main() {
    int N;
    cin >> N;
    vector<int> x(N);
    vector<int> y(N);
    for (int i=0; i<N; i++) {
        cin >> x[i] >> y[i];
    }    

    int reps = 2;
    for (int i=1; i<N; i++) {
        reps *= i;
    }

    // cout << reps << endl;

    double distance = 0;
    for (int i=0; i<N-1; i++) {
        for (int j=i+1; j<N; j++) {
            distance += reps * sqrt((double)(pow((x[i] - x[j]), 2) + pow((y[i] - y[j]), 2)));
            // cout << fixed << setprecision(6) << distance << endl;
        }
    }

    for (int i=1; i<N+1; i++) {
        distance = distance / i;
    }

    cout << fixed << setprecision(8) << distance;

    return 0;
}

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

int n,m; 
int P[1000001],Y[1000001];

int main(){
  cin>>n>>m;
  vector<int> num[n+1];
  for(int i=0;i<m;i++){
    cin>>P[i]>>Y[i];
    num[P[i]].push_back(Y[i]);
  }
  for(int i=0;i<n+1;i++){
    sort(num[i].begin(),num[i].end());
  }
  for(int i=0;i<m;i++){
    cout<<setfill('0')<<right<<setw(12)<<ll(P[i])*1000000+int(lower_bound(num[P[i]].begin(),num[P[i]].end(),Y[i])-num[P[i]].begin())+1<<endl;
   }
}

Measured memory_bytes: 11392
def main():
    N = int(input())
    plan = [[0, 0, 0]]
    for _ in range(N):
        plan.append(list(map(int, input().split(" "))))
    answer = True
    for i in range(N):
        distance = abs(plan[i + 1][1] - plan[i][1]) + abs(plan[i + 1][2] - plan[i][2])
        dt = plan[i + 1][0] - plan[i][0]
        if distance > dt or (dt - distance) % 2:
            answer = False
            break
    print("Yes" if answer else "No")


if __name__ == '__main__':
    main()

Measured memory_bytes: 27380
def i1():
 return int(input())
def i2():
 return [int(i) for i in input().split()]
[d,g]=i2()
e=[0 for i in range(1001)]

for i in range(1,d+1):
 [p,c]=i2()
 ee=e[:]
 for j in range(p-1):
   for k in range(1000)[::-1]:
    if e[k]>0 or k==0:
      e[k+1]=max(e[k+1],e[k]+100*i)
 
 for k in range(1001-p)[::-1]:
      if(ee[k]>0 or k==0):
        ee[k+p]=max(ee[k+p],ee[k]+100*i*p+c)
        e[k+p]=max(e[k+p],ee[k+p])
 
 
for i in range(1001):
 if e[i]>=g:
    print(i)
    break


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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
//const ull mod = 1e9 + 7;
const ll mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){
  os << "(" << v.first << ", " << v.second << ")"; return os;
}
template<class T> ostream& operator << (ostream& os, const vector<T> v){
  for(int i = 0; i < (int)v.size(); i++){if(i > 0){os << " ";} os << v[i];} return os;
}
template<class T> ostream& operator << (ostream& os, const vector<vector<T>> v){
  for(int i = 0; i < (int)v.size(); i++){if(i > 0){os << endl;} os << v[i];} return os;
}

const ll INF = (1ll<<60);
ll dp[303030][55];

string num2bit(ll num, ll len){
	string bit = "";
	REP(i, len){
		bit += char('0'+(num>>i & 1));
	}
	return bit;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    REP(i, 303030)REP(j, 55) dp[i][j] = INF;
    dp[0][0] = 0;

    ll N;
    cin >> N;
    vector<ll> A(N), B(N);
    REP(i, N) cin >> A[i];
    REP(i, N) cin >> B[i];

    REP(mask, (1ll<<N)){
    	vector<ll> cnt(N, 0);
    	REP(i, N){
    		REP(j, N){
    			if(i<j){
    				if((mask>>j & 1)) cnt[i]++;
    			}
    		}
    	}
    	ll kosu = __builtin_popcountll(mask);

    	//debug(mask)
    	//cout << cnt << endl;

    	REP(s, 55){
	    	REP(i, N){
	    		if(!(mask>>i & 1)){
	    			ll val = (abs(i-kosu)%2==0 ? A[i] : B[i]);
	    			if(s<=val){
	    				//debug(i)
	    				//debug(s)
		    			dp[mask|(1<<i)][val] = min(dp[mask|(1<<i)][val], dp[mask][s]+cnt[i]);
		    		}
	    		}
	    		
	    	}
	    }
    }
    ll mi = INF;
    REP(i, 55) mi = min(mi, dp[(1<<N)-1][i]);
    cout << (mi == INF ? -1 : mi) << endl;
   
   	/*
   	REP(i, 1<<N){
   		cout << num2bit(i, N) << " ";
   		REP(j, 10){
   			cout << dp[i][j] << " ";
   		}
   		cout << endl;
   	}
   	*/
    return 0;
}

Measured memory_bytes: 130560