akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;
public class Main{
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int m = scan.nextInt();
		int[][] matrix_A = new int[n][m];
		int[] matrix_B = new int[m];
		int[] matrix_C = new int[n];
		for(int i = 0; i<n; i++){
			for(int j = 0;j<m;j++){
				int matrix_element = scan.nextInt();
				matrix_A[i][j] = matrix_element;
			}
		}

		for(int i=0;i<m;i++){
			int matrix_element2 = scan.nextInt();
			matrix_B[i] = matrix_element2;
		}

		for(int i = 0;i<n; i++){
			for(int j = 0; j<m; j++){
				matrix_C[i] = matrix_C[i]+matrix_A[i][j] * matrix_B[j];
			}
		}

		for(int i = 0; i<matrix_C.length; i++){
			System.out.println(matrix_C[i]);
		}  
	}
}

Measured memory_bytes: 40480
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<string>
#define lol(i,n) for(int i=0;i<n;i++)
#define mod 1000000007
typedef long long ll;
using namespace std;
char m[110][110];
int main(){
	int h,w;
	cin>>h>>w;
	lol(i,h)lol(j,w)cin>>m[i][j];
	lol(i,h){
		lol(j,w){
			if(m[i][j]=='#'){
				cout<<"#";
				continue;
			}
			int cnt=0;
			for(int f=-1;f<=1;f++){
				for(int g=-1;g<=1;g++){
					int xx=f+j,yy=g+i;
					if(xx<0||xx==w||yy<0||yy==h)continue;
					if(m[yy][xx]=='#')cnt++;
				}
			}
			cout<<cnt;
		}
		cout<<endl;
	}
	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		int D = 25 - s.nextInt();
		String tmp = "Christmas";
		for(int i = 0;i < D;i++) {
			tmp += " Eve";
		}
		System.out.println(tmp);
	}

}

Measured memory_bytes: 23760
#include <bits/stdc++.h>
typedef long long ll;
#define  rep(i,a,b)for(long long i=a;i<b;++i)
#define  rrep(i,a,b)for(int i=a;i>=b;--i)
#define  yesno(flag)if(flag)cout<<"Yes"<<endl; else cout<<"No"<<endl;
using namespace std;
const ll INF=100000000000000LL;
const ll r197=1000000007;
typedef pair<int,int>P;
typedef pair<int,P>Pa;
typedef pair<int,string> Q;
bool Inframe(int a,int b,int c,int d,int h,int w){
	if(a+b>=0&&a+b<h&&c+d>=0&&c+d<w)return true;
	return false;
}
//void swap(ll a,ll b){
//	ll d;
//	d=a;
//	a=b;
//	b=d;
//	return;
//}
ll mypow(ll x,int m){
	if(m==0)return 1;
	if(m%2==0){
		int x2=mypow(x,m/2);
		return x2*x2;
	}else{
		int x2=mypow(x,m/2);
		return x2*x2*x;
	}
}
long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
//    	cout<<b<<endl;
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

ll total=0;
int a[200000],b[200000];
int n;
int m1,m2,n1,n2;
int c[100005]={};
string s;
vector<P> v[200001];
int ans[100005]={};
int main() {
	cin>>m1>>n1>>m2>>n2;
	if(m1==m2)cout<<0<<endl;
	else cout<<1<<endl;
	return 0;
}


Measured memory_bytes: 6016
import sys, re
from math import ceil, floor, sqrt, pi, factorial, gcd
from copy import deepcopy
from collections import Counter, deque
from heapq import heapify, heappop, heappush
from itertools import accumulate, product, combinations, combinations_with_replacement
from bisect import bisect, bisect_left, bisect_right
from functools import reduce
from decimal import Decimal, getcontext
# input = sys.stdin.readline 
def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_str(N): return [s_list() for _ in range(N)]
def s_row_list(N): return [list(s_input()) for _ in range(N)]
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 6)
INF = float('inf')
MOD = 10 ** 9 + 7
num_list = []
str_list = []

def main():
    s = s_input()

    afeter_index = len(s) - 2
    
    while True:
        middle_index = afeter_index // 2

        tmp1 = s[:middle_index]
        tmp2 = s[middle_index:afeter_index]

        if tmp1 == tmp2:
            print(afeter_index)
            exit()
        
        afeter_index -= 2

if __name__ == '__main__':
    main()


Measured memory_bytes: 77140
#include<cstdio>
#include<vector>
#include<cstring>
const int N=500005,mo=1000000007;
int dep[N],p,D,n,i,j,x,y,f[N],g[N],st[N],w,dfn[N],in[N],xb,ff[20][N],md,ans,mi[N];
int lo[N];
std::vector<int>e[N],ee[N],d[N];
void dfs(int x){
	d[dep[x]].push_back(x);
	dfn[in[x]=++xb]=x;
	md=dep[x]<md?md:dep[x];
	for(unsigned int i=0;i<e[x].size();++i){
		dep[e[x][i]]=dep[x]+1;
		dfs(e[x][i]);dfn[++xb]=x;
	}
}
inline void swap(int&a,int&b){int t=a;a=b;b=t;}
inline int lca(int x,int y){
	if(in[x]>in[y])swap(x,y);
	int l=lo[in[y]-in[x]+1],u=ff[l][in[x]],v=ff[l][in[y]-(1<<l)+1];
	return dep[u]<dep[v]?u:v;
}
inline int pow(int x,int y){
	int ans=1;
	for(;y;y>>=1,x=1ll*x*x%mo)y&1?ans=1ll*ans*x%mo:0;
	return ans;
}
void dp(int x){
	if(ee[x].empty()){f[x]=g[x]=1;return;}
	int y,s1=1,s2=0,i=0,s3=1;
	for(;i<int(ee[x].size());++i){
		y=ee[x][i];
		dp(y);s1=1ll*s1*g[y]%mo;
		s2=(s2+1ll*f[y]*pow(g[y],mo-2))%mo;s3=1ll*s3*(f[y]+g[y])%mo;
	}
	f[x]=1ll*s1*s2%mo;g[x]=(1ll*mo+s3-f[x])%mo;ee[x].clear();
}
int main(){
	scanf("%d",&n);
	for(i=1;i<=n;++i)scanf("%d",&p),e[p].push_back(i);
	dfs(0);
	for(i=1;i<=xb;++i)ff[0][i]=dfn[i];
	for(i=3;i<=xb;++i)lo[i]=lo[i-1]+(((1-i)&(i-1))==(i-1));
	for(i=1;1<<i<=xb;++i)
		for(j=0;j+(1<<i)-1<=xb;++j){
			x=ff[i-1][j],y=ff[i-1][j+(1<<(i-1))];
			ff[i][j]=dep[x]<dep[y]?x:y;
		}
	for(i=*mi=1;i<=n;++i)mi[i]=(mi[i-1]<<1)%mo;ans=mi[n];memset(st,-1,sizeof st);
	for(i=1;i<=md;++i){
		for(st[w=1]=0,st[2]=-1,j=0;j<int(d[i].size());++j){
			x=lca(st[w],d[i][j]);
			while(dep[st[w]]>dep[x] || (dep[st[w]]==dep[x] && st[w]!=x)){
				if(~st[w+1])ee[st[w]].push_back(st[w+1]);
				--w;
			}
			if(~st[w+1])ee[x].push_back(st[w+1]);
			if(st[w]!=x)st[++w]=x;
			st[++w]=d[i][j];st[w+1]=-1;
		}
		for(j=1;j<w;++j)ee[st[j]].push_back(st[j+1]);
		dp(0);
		ans=(ans+1ll*f[0]*mi[n+1-d[i].size()])%mo;
	}
	return printf("%d\n",ans),0;
}

Measured memory_bytes: 105600
#include<iostream>
#include<vector>

using namespace std;

int main(void) {
	int fact[3] = { 0 };
	int N;
	cin >> N;
	for (int i = 0; i < N; i++) {
		int a;
		cin >> a;
		if (a % 4 == 0) fact[2]++;
		else if (a % 2 == 0) fact[1]++;
		else fact[0]++;
	}
	if (fact[2] >= fact[0] || (fact[1] == 0 && fact[2] >= fact[0] - 1)) cout << "Yes" << endl;
	else cout << "No" << endl;
	system("pause");
	return 0;
}

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

#define REP(i, n) for(decltype(n) i = 0; i < n; i++)

#define ALL(c)   c.begin(), c.end()
#define SORT(c)  std::sort(ALL(c))
#define RSORT(c) std::sort(ALL(c), std::greater<decltype(c)::value_type>())

using namespace std;
using ll = long long;

const int MOD  = (int)1e9 + 7;
const int INF  = (int)1e9 + 1;
const ll  LINF = (ll)1e18 + 1;

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

    ll N;
    std::cin >> N;

    vector<ll> A(N + 1), B(N);
    REP(i, N + 1) {
        std::cin >> A[i];
    }
    REP(i, N) {
        std::cin >> B[i];
    }

    B.push_back(0);

    ll ans   = 0;
    ll carry = 0;
    REP(i, N + 1) {
        ans   += min(A[i], carry + B[i]);
        carry  = max(B[i] - max(A[i] - carry, 0LL), 0LL);
    }

    std::cout << ans << std::endl;

    return 0;
}


Measured memory_bytes: 2560
#include<stdio.h>
int main(){
  int a,n,b,ans=0;
  scanf("%d%d%d",&n,&a,&b);
  if(a*n>b){
    ans=b;
  }
  else{
    ans=a*n;
  }
  printf("%d\n",ans);
  return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef vector<pi> vpi;
typedef long double ld;
#define pb emplace_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define Aint(x) x.begin(), x.end()
#define SZ(x) (int)x.size()
#define f first
#define s second
const int MOD = 1e9+7;
const int INF = 1e9;
const int MAXN = 1050000;

ll N,T,a,b,c,d,e,f;
ll A[MAXN];

string S;
int main(){
  cin>>S;
  if (S[2]==S[3]&&S[4]==S[5])cout<<"Yes";
  else cout<<"No";
}

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

constexpr int inf = 0x3f3f3f3f;
constexpr ll linf = 0x3f3f3f3f3f3f3f3fLL;

inline bool ok(ll a, ll b) { return (a > 0 && b < 0) || (a < 0 && b > 0); }

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

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

    ll ans = linf;
    for (int c = 0; c < 2; c++) {
        ll sum = 0;
        ll res = 0;
        for (int i = 0; i < n; i++) {
            if (c ^ (i & 1)) {
                if ((sum += a[i]) >= 0) {
                    res += sum + 1;
                    sum = -1;
                }
            } else {
                if ((sum += a[i]) <= 0) {
                    res += 1 - sum;
                    sum = 1;
                }
            }
        }
        ans = min(ans, res);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1024
def insertionSort(A, n, g):
    global cnt
    for i in range(g, n):
        v = A[i]
        j = i - g
        while j >= 0 and A[j] > v:
            A[j + g] = A[j]
            j = j - g
            cnt += 1
        A[j + g] = v

def shellSort(A, n):
    global m, G
    for i in range(0, m): 
        insertionSort(A, n, G[i])

n = int(input())
A = []
for i in range(0, n):
    A.append(int(input()))

G = []
h = 1
for i in range(1, 999999):
    if h > n:
        break
    G.append(h)
    h = 3 * h + 1

G.reverse()

cnt = 0
m = len(G)
shellSort(A, n)
'''
m = 2
G = (4,1)
shellSort(A, n)
'''

print(m)
print(" ".join(map(str, G)))
print(cnt)
for i in range(0, n):
    print(A[i])

Measured memory_bytes: 47520
using System;
using System.Diagnostics;
using System.IO;
using System.Text;
using System.Linq;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using System.Security.Cryptography;

class Program
{
    const string Yes = "Yes";
    const string No = "No";
    const char White = '.';
    const char Black = '#';
    const long Mod = 1000000007;

    static void Main(string[] args) {
#if DEBUG
        MyDebugger.Test(process, "../TextFile1.txt");
#else
        object ret = process(new StreamReader(Console.OpenStandardInput()));
        Console.WriteLine(ret);
#endif
    }

    static object process(TextReader input) {
        var t = input.ReadLine();

        StringBuilder sb = new StringBuilder(t);

        for(int i=0; i<t.Length; i++) {
            if(sb[i] == '?') sb[i] = 'D';
        }

        return sb;
    }

    static long[] ToIntArray(string strs, int n) {
        var ret = new long[n];
        var spl = strs.Split(' ');
        for (int i = 0; i < n; i++)
            ret[i] = long.Parse(spl[i]);
        return ret;
    }
}

Measured memory_bytes: 27272
// {{{ include
#include <cstdio>
#include <cmath>
#include <cstring>
#include <iostream>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
// }}}

//{{{ graph.hpp
#ifndef INCLUDE_GRAPH_HPP
#define INCLUDE_GRAPH_HPP
#include <vector>
#include <climits>
namespace orliv {
namespace graph {
struct Edge {
  typedef int weight_type;
  static constexpr weight_type INF =
      std::numeric_limits<weight_type>::max() - 100;

  int from, to;
  weight_type w;
  Edge(int from, int to, weight_type w = 1) : from(from), to(to), w(w) {}
  bool operator<(const Edge& rhs) const {
    if (w != rhs.w) return w > rhs.w;
    if (from != rhs.from) return from < rhs.from;
    return to < rhs.to;
  }
};

typedef Edge::weight_type Weight;
typedef std::vector<Edge> Edges;
typedef std::vector<Weight> Weights;
typedef std::vector<int> Path;
}
typedef std::vector<graph::Edges> Graph;
}
#endif
//}}}
//{{{ bridge.cc
#ifndef INCLUDE_GRAPH_HPP
#include "graph.hpp"
#endif

namespace orliv {
namespace graph {
namespace bridge_internal {
struct BridgeImpl {
  const Graph& G;
  int k;
  std::vector<int> ord, low;
  Edges bridges;
  BridgeImpl(const Graph& g) : G(g), k(0), ord(g.size(), -1), low(g.size()) {}
  void dfs(int v, int p = -1) {
    low[v] = ord[v] = k++;
    for (const auto& e : G[v]) {
      int u = e.to;
      if (u == p) continue;
      if (ord[u] >= 0) {
        low[v] = std::min(low[v], ord[u]);
      } else {
        dfs(u, v);
        low[v] = std::min(low[v], low[u]);
      }
      if (ord[v] < low[u]) bridges.emplace_back(e);
    }
  }
  Edges get() {
    dfs(0);
    return std::move(bridges);
  }
};
}
Edges bridges(const Graph& g) {
  return std::move(bridge_internal::BridgeImpl(g).get());
}
}
}
//}}}

using namespace std;

typedef long long ll;
inline int in() {
  int x;
  scanf("%d", &x);
  return x;
}

int main() {
  int V = in(), E = in();
  orliv::Graph g(V);
  for (int i = 0; i < E; i++) {
    int s = in(), t = in();
    g[s].emplace_back(s, t, 1);
    g[t].emplace_back(t, s, 1);
  }
  auto bridges = orliv::graph::bridges(g);
  for (auto& e : bridges) {
    if (e.from > e.to) swap(e.from, e.to);
  }
  sort(bridges.begin(), bridges.end());
  for (auto& e : bridges) {
    cout << e.from << " " << e.to << endl;
  }
  return 0;
}

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

/*
	Name:
	Author: Xia Ruize
	Date:
*/

/*
bool is_prime(int x)
{
	if(x<2)
		return false;
	for(int i=2;i*i<=x;i++)
	{
		if(x%i==0)
		{
			return false;
		}
	}
	return true;
}
*/

int main()
{
	int n;
	cin>>n;
	string s="";
	cin>>s;
	string s1="",s2=""; 
	 s1=s.substr(0,n/2);
	 s2=s.substr(n/2);
	 if(s1==s2)
	 {
	 	cout<<"Yes"<<endl;
	 	return 0;
	 }
	 cout<<"No"<<endl;
	return 0;
}


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

using namespace std;

#define llong long long int
#define ldouble long double
#define rep(i, n) for (int i = 0; i < n; ++i) 
#define stl_rep(itr, x) for (auto itr = x.begin(); itr != x.end(); ++itr)
#define stl_repr(itr, x) for (auto itr = x.begin(); itr != x.end(); ++itr)
#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()

constexpr static int MOD = 1000000000 + 7;
constexpr static int inf = INT_MAX / 2;
constexpr static llong INF = 1LL << 31;
constexpr static int dx[] = {1, 0, -1, 0};
constexpr static int dy[] = {0, 1, 0, -1};

int main (int argc, char *argv[]) {
    cin.tie(0); 
    ios::sync_with_stdio(false);

    int n, k;
    cin >> n >> k;
    string s;
    cin >> s;
    s[k - 1] = s[k - 1] + 32;

    cout << s << endl;
    
    return 0;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
	"math"
	"strings"
)

var s1, s2, s3, ans string

func main() {
	fmt.Scan(&s1, &s2, &s3)
	fmt.Println(strings.ToUpper(string(s1[0])) + strings.ToUpper(string(s2[0])) + strings.ToUpper(string(s3[0])))
}

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

func gcd(x, y uint64) uint64 {
	if x%y == 0 {
		return y
	} else {
		r := x % y
		return gcd(y, r)
	}
}

func combination(x, y int) int {
	return permutation(x, y) / permutation(y, y)
}

func permutation(x, y int) int {
	var ans int = 1
	for i := x - y; 0 < i; i-- {
		ans *= i
	}
	return ans
}

func max(x ...int) int {
	var res int = x[0]
	for i := 1; i < len(x); i++ {
		res = int(math.Max(float64(x[i]), float64(res)))
	}
	return res
}

func min(x ...int) int {
	var res int = x[0]
	for i := 1; i < len(x); i++ {
		res = int(math.Min(float64(x[i]), float64(res)))
	}
	return res
}

func pow(x, y int) uint64 { return uint64(math.Pow(float64(x), float64(y))) }
func abs(x int) int       { return int(math.Abs(float64(x))) }
func floor(x int) int     { return int(math.Floor(float64(x))) }

type si struct {
	s int
	i int
}

type SortBy []si

func (a SortBy) Len() int           { return len(a) }
func (a SortBy) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }
func (a SortBy) Less(i, j int) bool { return a[i].s < a[j].s }


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

using namespace std;

int main()
{
	string s,t;
	cin>>s;
	cin>>t;
	int n=s.length();
	int m=t.length();
	int dp[n+1][m+1];
	for(int i=0;i<=n;i++)
	{
		for(int j=0;j<=m;j++)
		{
			if(i==0 || j==0)
			{
				dp[i][j]=0;
			}
			else if(s[i-1]==t[j-1])
			{
				dp[i][j]=dp[i-1][j-1]+1;
			}
			else
			{
				dp[i][j]=max(dp[i][j-1],dp[i-1][j]);
			}
		}
	}
	//cout<<dp[n][m]<<endl;
	int i=n,j=m;
	string lcs;
	while(i>0 && j>0)
	{
		if(s[i-1]==t[j-1])
		{
			lcs.push_back(s[i-1]);
			i--;
			j--;
		}
		else if(dp[i-1][j]>dp[i][j-1])
		{
			i--;
		}
		else
		{
			j--;
		}
		//cout<<i<<" "<<j<<endl;
	}
	if(lcs.length()==0)
	{
	    cout<<lcs;
	}
	for(int i=lcs.length()-1;i>=0;i--)
	{
	    cout<<lcs[i];
	}
	return 0;
}

Measured memory_bytes: 38768
import java.util.*;

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

		int max = scan.nextInt();
		int a; 
		int count = 0;
		for(int i = 0; i < max; i++){
			a = scan.nextInt();

			count += get2(a);
		}

		System.out.println(count);

	}

	private static int get2(int a){
		int count = 0;
		
		while(true){
			if(a % 2 != 0){
				return count;
			}

			a /= 2;
			count++;
		}
	}
}


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

using lint = long long;

int main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int n;
	cin >> n;
	vector<int> values(n);
	for (int i = 0; i < n; ++i) cin >> values[i];
	sort(values.begin(), values.end());
	int m = n/2, result = 0;
	int k = values[m-1] + 1;
	if (k-1 == values[m]) {
		cout << "0\n";
		exit(0);
	}
	while(1) {
		if (k < values[m]) {
			k++;
			result++;
		}
		else if (k == values[m]) {
			result++;
			break;
		}
	}
	cout << result << '\n';
}



Measured memory_bytes: 640
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define M 100000

typedef struct {
  char name[10];
  int t;
} process;
int head=0, tail=0;
process queue[M+1];

void put(process p){
  queue[tail++]=p;
  tail%=M;
}

process get(void){
  head %= M;
  return queue[head++];
}

int empty(){
  return head%M==tail;
}

int main(void){
  int i, n, q, t, total=0;
  char *name;
  scanf("%d %d", &n, &q);
  process p[n];
  name=malloc(sizeof(char));
  for(i=0; i<n; i++){
    scanf("%s %d", p[i].name, &p[i].t);
    put(p[i]);
  }
  while(!empty()){
    process p=get();
    if((p.t-q)<=0){
      total+=p.t;
      printf("%s %d\n", p.name, total);
    }else{
      total+=q;
      p.t-=q;
      put(p);
    }
  }
}

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

int main() {
  int a,b,c,d;
  cin >> a >> b >> c >> d;
  if (a+b>c+d){
    cout <<"Left"<<endl;
  }
  else if (a+b==c+d){
  cout <<"Balanced"<<endl;
  }
  else{
    cout<<"Right"<<endl;
  }

}

Measured memory_bytes: 3584
#include <iostream>
#include <string>
#include <vector>
#define M 1046527

std::vector<std::string> H(M);
long long getKey(std::string s){
	long long sum = 0;
	for(int i = 0; i < s.size(); i++){
		long long t = 0;
		switch(s[i]){
			case 'A':
				t = 1;
				break;
			case 'C':
				t = 2;
				break;
			case 'G':
				t = 3;
				break;
			case 'T':
				t = 4;
				break;
			default:
				t = 0;
				break;
		}
		sum += t;
		sum *= 5;
	}
	return sum;
}

int h1(int key){
	return key%M;
}

int h2(int key){
	return 1+(key%(M-1));
}

int find(std::string s){
	long long key, h;
	key = getKey(s);
	for(int i = 0; i < M; i++){
		h = (h1(key)+i*h2(key))%M;
		if(H[h] == s) return 1;
		else if(H[h].size() == 0) return 0;
	}
	return 0;
}

void insert(std::string s){
	long long  key, h;
	key = getKey(s);
	for(int i = 0; i < M; i++){
		h = (h1(key)+i*h2(key))%M;
		if(H[h] == s) return;
		else if(H[h].size() == 0){
			H[h] = s;
			return;
		}
	}
	return;
}

int main(){
	int n;
	std::cin >> n;
	std::vector<std::string> cmd(n);
	std::vector<std::string> s(n);
	for(int i = 0; i < n; i++){
		std::cin >> cmd[i] >> s[i];
	}
	for(int i = 0; i < n; i++){
		if(cmd[i][0] == 'i'){
			insert(s[i]);
		}else if(cmd[i][0] == 'f'){
			if(find(s[i])){
				std::cout << "yes" << std::endl;
			}else{
				std::cout << "no" << std::endl;
			}
		}
	}
}

Measured memory_bytes: 125004
fun main(arr:Array<String>) {

    val (a,b,c,x,y) = readLine()!!.split(" ").map { it.toInt() }
    val ans = (0..Math.max(x,y)*2).filter { it%2 == 0 }.map { it*c + Math.max(0, x-it/2)*a + Math.max(0,y-it/2)*b }.min()
    println(ans)
}


Measured memory_bytes: 39028
#include<iostream>
#include<array>
#include<vector>
#include <algorithm>
#include <stdio.h>
#include <string>
#include <utility>
#include <set>

using llint = long long int;
using namespace std;

namespace CsF {
#define MIN_INT -2147483648
#define MAX_INT 2147483647
#define nfor(I,J,K) for(int I = 0;I < J;I+=K)

	string ConvertBit(int N, int e) {
		string s = "";
		int r = 0;
		while (N != 0) {
			r = N % e;
			s = to_string(r) + s;
			N -= r;
			N /= e;
		}
		return s;
	}

	int GCD(int a, int b) {
		if (a < b)swap(a, b);
		int r = a % b;
		while (r != 0) {
			a = b;
			b = r;
			r = a % b;
		}
		return b;
	}

	int LCM(int a, int b) {
		int n = a * b;
		return (n / GCD(a, b));
	}

	int Count(string s, char c) {
		int cou = 0;
		nfor(i, s.length(), 1) {
			if (s[i] == c)cou++;
		}
		return cou;
	}

	vector<int> SieveOfEratosthenes(int N) {
		vector<bool> memo(N + 1);
		vector<int> ret;
		memo[0] = true;
		memo[1] = true;
		for (int i = 2; i < N; i++) {
			if (memo[i])continue;
			ret.push_back(i);
			for (int b = 2; true; b++) {
				if (i*b <= N) {
					memo[i*b] = true;
				}
				else break;
			}
		}
		return ret;
	}

	vector<int> SpInput(int N) {
		vector<int> ret(N);
		nfor(i, N, 1) { cin >> ret[i]; }
		return ret;
	}
}

using namespace CsF;




int main() {
	int dp[100010];
	int N;
	cin >> N;
	dp[0] = 0;
	int power = 1;
	for (int i = 1; i <= 100000; i++) {
		dp[i] = MAX_INT;
		power = 1;
		while (power <= i) {
			dp[i] = min(dp[i], dp[i - power] + 1);
			power *= 6;
		}
		power = 1;
		while (power <= i) {
			dp[i] = min(dp[i], dp[i - power] + 1);
			power *= 9;
		}
	}
	cout << dp[N] << "\n";

	return 0;
}



Measured memory_bytes: 640
import java.util.Scanner;

public class Main {
    public static void main(String[] args) throws Exception {
        //緑のカードに書かれている整数は、赤のカードに書かれている整数より真に大きい。
        //青のカードに書かれている整数は、緑のカードに書かれている整数より真に大きい。
        Scanner sc = new Scanner(System.in);
        int A = sc.nextInt(); //赤
        int B = sc.nextInt(); //緑
        int C = sc.nextInt(); //青
        int K = sc.nextInt();
        boolean flag = false;
        for (int i = 0; i < K; i++) {
                if (B <= A){            // ①
                    B = B * 2;
                } else if (C <= B) {    // ②
                    C = C * 2;
                }
                if(A < B && B < C){
                    flag = true;
                    break;
                }
        }
        if (flag) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    }
}

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

bool isPrime(int x){
  for(int i=6;i*i<=x;i+=7){
    if(x % i == 0 || x % (i+2) == 0){
      return false;
    }
  }
  return true;
}

int main(){
  int n;
  vector<int> p;

  for(int i=6;i<=300100;i+=7){
    if(isPrime(i)){
      p.push_back(i);
    }
    if(isPrime(i+2)){
      p.push_back(i+2);
    }
  }

  while(cin>>n,n!=1){
    cout<<n<<":";
    for(int i=0;p[i]<=n;i++){
      if(n % p[i] == 0){
        cout<<" "<<p[i];
      }
    }
    cout<<endl;
  }
}

Measured memory_bytes: 1176
//おまじない
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <utility>
#define INF 1e9+7
#define rep(i,m,n) for(int i=m;i<n;i++)
#define mrep(i,m,n) for(int i=m;i<n;i--)
#define NO cout<<"NO"<<endl;
#define YES cout << "YES"<<endl;
#define No cout << "No"<<endl;
#define Yes cout << "Yes"<<endl;
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;


//(int)'a'は97 (int)'A'は65
//おまじない



int main() {

	string o, e;
	cin >> o >> e;

	int co = 0, ce = 0;

	rep(i,0,o.size()+e.size()) {
		if (i % 2 == 0) {
			cout << o[co];
			co++;
		}
		else {
			cout << e[ce];
			ce++;
		}
	}

	cout << endl;


	return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define test int t; cin >> t; while (t--)
#define fast ios::sync_with_stdio(NULL); cin.tie(NULL)
#define mod 1000000007
#define endl "\n"
#define gcd(m,n) __gcd(m,n)
#define lcm(m,n) m*(n/GCD(m,n))
#define all(v) v.begin(),v.end()
#define ll long long
typedef vector<ll> vecll;
typedef vector<int> veci;
typedef vector<char> vecc;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
#define pb push_back
#define mp make_pair
#define time 1.0 * clock() / CLOCKS_PER_SEC
 
 
int main(){
    fast;
    ll n,m,s=0;
    cin >>n>>m;
    vecll ar(n);
    for(auto &x:ar){cin>>x;s+=x;} 
    ll ans=0;
    double c=s/(4.0*m);
    for(auto x:ar){
        if(x>=c){
            ans++;
        }
    }
    //cout<<s;
    if(ans>=m){
        cout<<"Yes";
    }
    else cout<<"No";
    return 0;
}

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

int main(void){
    int sx,sy,tx,ty;
    cin >> sx >> sy >> tx >> ty;
    const int dx=tx-sx,dy=ty-sy;

    //Path 1
    cout << string(dy,'U') << string(dx,'R');

    //Path 2
    cout << string(dy,'D') << string(dx,'L');

    //Path3
    cout << 'L' << string(dy+1,'U') << string(dx+1,'R') << "D";

    //Path4
    cout << 'R' << string(dy+1,'D') << string(dx+1,'L') << "U";

    //Endline
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
//#ifndef rd
#define endl '\n'
//#endif
#ifdef rd
#define trace(...) cout<<"Line:"<<__LINE__<<" "; __f(#__VA_ARGS__, __VA_ARGS__)
template<typename Arg1>
void __f(const char* name, Arg1&& arg1) {
	cout<<name<<" : "<<arg1<<endl;
}
template<typename Arg1, typename ... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
	const char* comma=strchr(names+1,',');
	cout.write(names,comma-names)<<" : "<<arg1<<" | ";
	__f(comma+1,args...);
}
#else
#define trace(...)
#endif
#define pb push_back
#define fi first
#define se second
#define mkp make_pair
//#define int long long
typedef long long ll;
typedef long double f80;
//#define double long double
#define pii pair<int,int>
#define pll pair<ll,ll>
#define sz(x) ((long long)x.size())
#define fr(a,b,c) for(int a=b; a<=c; a++)
#define frdec(a,b,c) for(int a=b; a>=c; a--)
#define rep(a,b,c) for(int a=b; a<c; a++)
#define trav(a,x) for(auto &a:x)
#define all(con) con.begin(),con.end()
const ll infl=2e18;
const int infi=2e9;
const int mod=1e9+7;
typedef vector<int> vi;
//typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> oset;
mt19937 rang(chrono::high_resolution_clock::now().time_since_epoch().count());
auto clk=clock();
int rng(int lim) {
	uniform_int_distribution<int> uid(0,lim-1);
	return uid(rang);
}
template<class t1, class t2, class t3>
t1 fast_expo(t2 x, t3 p) {
	if(p == 0) return 1;
	t1 r = fast_expo(x,p/2);
	if(p%2 != 0) return r * r * x;
	return r * r;
}
// Code from here...
int n, k; ll ans;
map<int, vector<int>> T;

void solve() {
	cin >> n >> k;
	fr(i,1,n-1) {
		int u, v; cin >> u >> v;
		T[u].pb(v);
		T[v].pb(u);
	}
	ans = k;
	deque<pii> q;
	q.pb(mkp(1, -1));
	while(!q.empty()) {
		int v = q.back().fi;
		int p =	q.back().se;
		q.pop_back();
		int s = (v==1) ? 1 : 2;
	
		for(auto u : T[v]) {
			if(u != p) {
				ans = ((ans%mod) * ((k-s)%mod)) % mod;
				s++;
				q.pb(mkp(u, v));
			}
		}
	}
	cout << ans;
}

signed main() {
	ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	srand(chrono::high_resolution_clock::now().time_since_epoch().count());
	cout<<fixed<<setprecision(10);
	int t=1;
	// cin>>t;
	while(t--)
		solve();
#ifdef rd
	cout<<endl<<endl<<"Time elapsed: "<<(double)(clock()-clk)/CLOCKS_PER_SEC<<endl;
#endif
	return 0;
}

Measured memory_bytes: 12408
use proconio::marker::*;
use proconio::*;
use std::cmp::max;

fn main() {
    input! {
        s: Chars,
    };

    let mut ans = 0;
    let mut con = 0;

    for &c in s.iter() {
        if c == 'R' {
            con += 1;
        } else {
            con = 0;
        }
        ans = max(con, ans);
    }

    println!("{}", ans);
}


Measured memory_bytes: 2176
#include <algorithm>
#include <iostream>
using namespace std;
typedef long long ll;
int main(){
	int w,h,i,n,ans=0,xs,ys;
	cin>>w>>h>>n;
	int x[n],y[n];
	for(i=0;i<n;i++)cin>>x[i]>>y[i];
	xs=x[0];
	ys=y[0];
	for(i=0;i<n;i++){
		while(xs!=x[i]||ys!=y[i]){
			if(xs<x[i]&&ys<y[i]){
				xs++;
				ys++;
			}else if(xs>x[i]&&ys>y[i]){
				xs--;
				ys--;
			}else if(xs<x[i])xs++;
			else if(xs>x[i])xs--;
			else if(ys<y[i])ys++;
			else if(ys>y[i])ys--;
			ans++;
			//cout<<xs<<" "<<ys<<endl;
		}
	}
	cout<<ans<<endl;
}
/*
4 7 5
.#.....
.....##
.......
#......
  */


Measured memory_bytes: 3088
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main() {
  int n, l;
  cin >> n >> l;
  int sum = 0;
  if(l <= 0 && 0 <= l+n-1) {
    for(int i=1; i<=n; i++) {
      sum += l+i-1;
    }
    cout << sum << endl;
  }
  
  else if(l > 0) {
    for(int i=1; i<=n; i++) {
      if(i != 1) {
        sum += l+i-1;
      }
    }
    cout << sum << endl;
  }
  else if (l+n-1 < 0) {
    for(int i=1; i<=n; i++) {
      if(i != n) {
        sum += l+i-1;
      }
    }
    cout << sum << endl;
  }
  return 0;
}

Measured memory_bytes: 3636
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
		int n = in.nextInt();
		long k = in.nextLong();
		long[][] matrix = getIntArr(in, n, n);
		long r = solve(n, k, matrix);
		System.out.println(r);
		in.close();
	}

	static long mod = 1000000007;

	private static long solve(int n, long k, long[][] matrix) {
		long[][] r = fastMatrixExp(matrix, k);
		long sum = 0;
		for (int i = 0; i < r.length; i++) {
			for (int j = 0; j < r[i].length; j++) {
				sum = (sum + r[i][j]) % mod;
			}
		}
		return sum;
	}

	public static long[][] fastMatrixExp(long[][] a, long exp) {
		if (exp == 0) {
			long[][] b = new long[a.length][a.length];
			for (int i = 0; i < a.length; i++) {
				b[i][i] = 1;
			}
			return b;
		} else if (exp % 2 == 1) {
			return multiplyMatrice(a, fastMatrixExp(a, exp - 1));
		} else {
			long[][] half = fastMatrixExp(a, exp / 2);
			return multiplyMatrice(half, half);
		}
	}

	private static long[][] multiplyMatrice(long[][] a, long[][] b) {
		long[][] mul = new long[a.length][b[0].length];
		for (int i = 0; i < a.length; i++) {
			for (int j = 0; j < b[0].length; j++) {
				for (int k = 0; k < a[i].length; k++) {
					mul[i][j] = (mul[i][j] + (a[i][k] * b[k][j]) % mod) % mod;
				}
			}
		}
		return mul;
	}

	static String str(int[] a) {
		String[] str = new String[a.length];
		for (int i = 0; i < a.length; i++) {
			str[i] = a[i] + "";
		}
		return String.join(" ", str);
	}

	static long[] getIntArr(Scanner in, int size) {
		long[] arr = new long[size];
		for (int i = 0; i < size; i++) {
			arr[i] = in.nextLong();
		}
		return arr;
	}

	static long[][] getIntArr(Scanner in, int row, int col) {
		long[][] arr = new long[row][];
		for (int i = 0; i < row; i++) {
			arr[i] = getIntArr(in, col);
		}
		return arr;
	}

	static char[] getCharArr(Scanner in, int size) {
		char[] arr = in.next().toCharArray();
		return arr;
	}

	static String[] getStringArr(Scanner in, int size) {
		String[] arr = new String[size];
		for (int i = 0; i < size; i++) {
			arr[i] = in.next();
		}
		return arr;
	}

	static Map<Integer, List<Integer>> getEdges(Scanner in, int size, boolean directed) {
		Map<Integer, List<Integer>> edges = new HashMap<>();
		for (int i = 0; i < size; i++) {
			int from = in.nextInt();
			int to = in.nextInt();
			if (!edges.containsKey(from)) {
				edges.put(from, new ArrayList<Integer>());
			}
			edges.get(from).add(to);
			if (!directed) {
				if (!edges.containsKey(to)) {
					edges.put(to, new ArrayList<Integer>());
				}
				edges.get(to).add(from);
			}

		}
		return edges;
	}
}


Measured memory_bytes: 29072
#include <iostream>
using namespace std;
int main(){
    int N;
    cin >> N;
    int onecount = 0;
    int totalcount = 0;
    for(int m = 1; m <= N; m=m+2){
        for(int i = 1; i <= m; i++){
            if(m%i == 0){
                onecount++;
            }
        }
        if(onecount == 8){
            totalcount++;
        }
        onecount = 0;
    }
    cout << totalcount << endl;
    return 0;
}

Measured memory_bytes: 256
from collections import defaultdict, deque

n,m = map(int, input().split())
path = defaultdict(set)
for _ in range(m):
   a, b = map(int, input().split())
   path[a] |= {b}
   path[b] |= {a}

queue = deque([(1, 0)])

visited = set()
res = {1: 0}
while queue != deque([]):
   pos, depth = queue.popleft()
   for p in path[pos]:
      if p in res:
         continue
      res[p] = pos
      queue.append((p, depth+1))
   
print('Yes')
for k,v in sorted(res.items(), key=lambda x: x[0]):
   if k != 1:
      print(v)

Measured memory_bytes: 73440
// #pragma GCC target("avx2")  // CPU 処理並列化
// #pragma GCC optimize("O3")  // CPU 処理並列化
// #pragma GCC optimize("unroll-loops")  // 条件処理の呼び出しを減らす
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<stack>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<stdlib.h>
#include<cassert>
#include<time.h>
#include<bitset>
#include<numeric>
using namespace std;
const long long mod=1000000007;
const long long inf=mod*mod;
const long long d2=(mod+1)/2;
const double EPS=1e-10;
const double INF=1e+10;
const double PI=acos(-1.0);
const int C_SIZE = 3121000;
long long fact[C_SIZE];
long long finv[C_SIZE];
long long inv[C_SIZE];
long long Comb(int a,int b){
 	if(a<b||b<0)return 0;
 	return fact[a]*finv[b]%mod*finv[a-b]%mod;
}
void init_C(int n){
	fact[0]=finv[0]=inv[1]=1;
	for(int i=2;i<n;i++){
		inv[i]=(mod-(mod/i)*inv[mod%i]%mod)%mod;
	}
	for(int i=1;i<n;i++){
		fact[i]=fact[i-1]*i%mod;
		finv[i]=finv[i-1]*inv[i]%mod;
	}
}
long long pw(long long a,long long b){
	if(a<0LL)return 0;
	if(b<0LL)return 0;
	long long ret=1;
	while(b){
		if(b%2)ret=ret*a%mod;
		a=a*a%mod;
		b/=2;
	}
	return ret;
}
int ABS(int a){return max(a,-a);}
long long ABS(long long a){return max(a,-a);}
double ABS(double a){return max(a,-a);}
int sig(double r) { return (r < -EPS) ? -1 : (r > +EPS) ? +1 : 0; }
// ここから編集しろ
int t[310][310];
long long g[310][3];
long long dp[310][310];
int main(){
	init_C(1000);
	int a;scanf("%d",&a);
	for(int i=0;i<a;i++){
		for(int j=0;j<a;j++){
			scanf("%d",&t[i][j]);
		}
	}
	int R=0;
	for(int i=0;i<a;i++){
		int at=-1;
		for(int j=R;j<a;j++){
			if(t[j][i])at=j;
		}
		if(at!=-1){
			for(int j=0;j<a;j++){
				swap(t[at][j],t[R][j]);
			}
			for(int j=R+1;j<a;j++){
				if(t[j][i]){
					for(int k=0;k<a;k++)t[j][k]^=t[R][k];
				}
			}
			R++;
		}
	}
	for(int i=0;i<=a;i++){
		for(int j=1;j<=i;j+=2){
			g[i][0]=(g[i][0]+Comb(i,j)*pw(3,i-j))%mod;
		}
		g[i][2]=(mod+pw(2,2*a)+(mod+1-pw(2,a-i+1))*pw(2,2*i))%mod;
		g[i][1]=(pw(2,2*a)+mod-(g[i][0]+g[i][2])%mod)%mod;
		//printf("%lld %lld %lld\n",g[i][0],g[i][1],g[i][2]);
	}
 
	dp[0][R]=1;
	for(int i=0;i<a;i++){
		for(int j=0;j<=a;j++){
			for(int k=0;k<3;k++){
				if(j+k-1>=0&&j+k-1<=a){
					dp[i+1][j+k-1]=(dp[i+1][j+k-1]+dp[i][j]*g[j][k])%mod;
				}
			}
		}
	}
	printf("%lld\n",dp[a][0]);
}

Measured memory_bytes: 5376
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
template <typename T>
struct BinaryIndexedTree
{
  vector<T> data;

  BinaryIndexedTree(ll sz)
  {
    data.assign(++sz, 0);
  }

  T sum(ll k)
  {
    T ret = 0;
    for (++k; k > 0; k -= k & -k)
      ret += data[k];
    return (ret);
  }

  void add(ll k, T x)
  {
    for (++k; k < data.size(); k += k & -k)
      data[k] += x;
  }
};
struct point {
    ll l,r,ii;
    point(ll l, ll r, ll ii) : l(l), r(r), ii(ii) {};
};
bool cmp(const point &a, const point &b){
  return a.r < b.r; //>なら降順 
}
int main()
{
ll n , q ;
cin >> n >> q ;
vector<ll> ans(q,0);

vector<ll> c(n);
rep(i, n){
  cin >> c[i];
}
vector<point> v;
vector<ll> la(n+1,-1);
rep(i,q){
  ll a , b ;
  cin >> a >> b ;
  v.emplace_back(a,b,i);
}
sort(v.begin(),v.end(),cmp);
BinaryIndexedTree<ll> bit(n+1);
ll now=0;
rep(i,q){
  while(now<v[i].r){
    if(la[c[now]]>=0)bit.add(la[c[now]], -1);
    la[c[now]]=now;
    bit.add(la[c[now]], 1);
    now++;
  }

  ans[v[i].ii]=bit.sum(v[i].r-1);
  if(v[i].l>1)ans[v[i].ii]-=bit.sum(v[i].l-2);
}
for(auto an:ans)cout << an << endl;
return 0;
}

Measured memory_bytes: 31156
<?php

fscanf(STDIN, "%s %s", $s, $t);
fscanf(STDIN, "%d %d", $a, $b);
fscanf(STDIN, "%s", $u);

switch ($u) {
    case $s:
        --$a;
        break;
    case $t:
        --$b;
        break;
    default:
        break;
}
echo "$a $b";



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

int main()
{
ll int a,b,ans;
cin>>a>>b;
if(a<=9 && a>=1 && b<=9 && b>=1)
{
    ans=a*b;
}
else
    ans=-1;
cout<<ans<<endl;

return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python
import itertools
n = int(input())
nums = []
pre_nums = ['3','5','7']

for i in range(3,10):
    for ids in itertools.product(pre_nums, repeat=i):
        if '3' in ids and '5' in ids and '7' in ids:
            nums.append(int(''.join(ids)))
for i,num in enumerate(nums):
    if n < num:
        print(i)
        break
else:
    print(len(nums))

Measured memory_bytes: 4084
import math
import string
import collections
from collections import Counter
from collections import deque


def readints():
    return list(map(int, input().split()))


def nCr(n, r):
    return math.factorial(n)//(math.factorial(n-r)*math.factorial(r))


def has_duplicates2(seq):
    seen = []
    for item in seq:
        if not(item in seen):
            seen.append(item)
    return len(seq) != len(seen)


def divisor(n):
    divisor = []
    for i in range(1, n+1):
        if n % i == 0:
            divisor.append(i)
    return divisor


# coordinates
dx = [-1, -1, -1, 0, 0, 1, 1, 1]
dy = [-1, 0, 1, -1, 1, -1, 0, 1]

# n=int(input())
# h=readints()
n, k = map(int, input().split())
if n % k < k-n % k:
    print(n % k)
else:
    print(k-n % k)


Measured memory_bytes: 3960
n, m = map(int, input().split())
NRD = list(0 for i in range(n))
for i in range(m):
    r1, r2 = map(int, input().split())
    NRD[r1 - 1] += 1
    NRD[r2 - 1] += 1
for i in range(n):
    print(NRD[i])

Measured memory_bytes: 9136
#include <iostream>

using namespace std;

int main() {
  char d[4];
  cin >> d;
  if ((d[0] == d[1] && d[1] == d[2]) || (d[1] == d[2] && d[2] == d[3]))
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    bool possible = false;
    int n;
    cin>>n;
    vector<pair<int, int>> v(n);
    for(int i=0; i<n; i++)
        cin>>v[i].first>>v[i].second;
    for(int i=0; i<n-2; i++){
        if(v[i].first==v[i].second && v[i+1].first==v[i+1].second && v[i+2].first==v[i+2].second){
            possible = true;
            break;
        }
    }
    cout<<(possible?"Yes":"No");
    return 0;
}


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

#define int long long
#define otp(n) cout << n;
#define ct(n) cout << n << endl;
#define cts(n) cout << n << " ";
#define cte cout << endl;
#define ctv(v) rep(i,(v).size()) otp(v[i]) cte
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define repo(i,o,n) for(int i=o;i<n;i++)
#define repm(i,n) for(int i=n-1;i>=0;i--)
#define repv(i,v) for(int i=0;i<(v).size();i++)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define sperase(v,n) (v).erase(remove(all(v), n), (v).end());
#define vdelete(v) (v).erase(unique(all(v)), (v).end());
#define vcopy(v1,v2) copy((v1).begin(), (v1).end(), back_inserter((v2)));
#define pb(n) push_back(n);

int w,h,n,x,y,a,memo[100][100],ans;

main() {
    cin >> w >> h >> n;
    rep(i,n) {
        cin >> x >> y >> a;
        if (a==1) rep(i,h) rep(j,x) memo[i][j] = 1;
        else if (a==2) rep(i,h) repo(j,x,w) memo[i][j] = 1;
        else if (a==3) rep(i,y) rep(j,w) memo[i][j] = 1;
        else repo(i,y,h) rep(j,w) memo[i][j] = 1;
    }
    rep(i,h) rep(j,w) if (!memo[i][j]) ans++;
    ct(ans)
}


Measured memory_bytes: 384
#include<stdio.h>

int main()
{
	int a,b,c,d,x;
	
	scanf("%d%d%d%d",&a,&b,&c,&d);
	if(a*b>c*d)x=a*b;
	else x=c*d;
	
	printf("%d\n",x);
	
	return 0;
}

Measured memory_bytes: 128
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <chrono>
#define _USE_MATH_DEFINES
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <iterator>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;

#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()

const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-8;
const int MOD = 1000000007; // 998244353;
const int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1};
/*-------------------------------------------------*/
int main() {
  cin.tie(0); ios::sync_with_stdio(false);
  // freopen("input.txt", "r", stdin);

  int n; cin >> n;
  cout << 180 * (n - 2) << '\n';
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
 
int main() {
  int N, M;
  cin >> N >> M;
  
  dsu Douro(N);  // n頂点0辺無向グラフ
  
  int A, B;
  for (int i = 0; i < M; i++) {
    cin >> A >> B;
    Douro.merge(A-1, B-1);
  }
  
  vector<vector<int>> Renketsu = Douro.groups();
  cout << Renketsu.size()-1 << endl;  // 行数m
}

Measured memory_bytes: 9024
/**
 *      purpose : ABC 116 A
 *      author  : kyomukyomupurin
 *      created : 
**/

#include <bits/stdc++.h>
using namespace std;
using int64 = int64_t;
using pii = pair<int, int>;
using pll = pair<int64_t, int64_t>;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(v) (v).begin(), (v).end()
#define print(x) cout << (x) << '\n'
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define fi first
#define se second

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int x, y, z; cin >> x >> y >> z;
    print(x * y / 2);
    
    return 0;
}

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

int main(){
  string S;
  cin >> S;
  if (S[0] == S[1] && S[2] == S[3] && S[0] != S[2]) cout << "Yes" << endl;
  else if (S[0] == S[2] && S[1] == S[3] && S[0] != S[1]) cout << "Yes" << endl;
  else if (S[0] == S[3] && S[1] == S[2] && S[0] != S[1]) cout << "Yes" << endl;
  else cout << "No" << endl;

  return 0;
}

Measured memory_bytes: 256
N, x = map(int,input().split())
a = [int(_) for _ in input().split()]
s = sum(a)
a.sort()
cnt = 0
for i in range(N):
    if x >= a[i]:
        cnt += 1
        x -= a[i]
    elif x > 0:
        x -= max(x,a[i])
if x > 0:
    cnt -= 1
print(cnt)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
typedef long long lint;
 
int main() {
  char c;
  cin >> c;
  
  cout << char(c+1) << endl;
}



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

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

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

  sort(p.begin(), p.end());

  long ans = 0;
  for(int i = 0; i < N; i++){
    if(i == N-1){
      ans += p[i] / 2;
    }else{
      ans += p[i];
    }
  }
  
  cout << ans << endl;
  
  return 0;

}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline

INF = float("inf")


def warshall_floyd(n, d):
    for k in range(n):
        for i in range(n):
            d_ik = d[i][k]
            if d_ik == INF:
                continue
            for j in range(n):
                if d[i][j] > d_ik + d[k][j]:
                    d[i][j] = d_ik + d[k][j]


def main():
    H, W = map(int, input().split())
    c = [None] * 10
    for i in range(10):
        c[i] = list(map(int, input().split()))
    A = [None] * H
    for i in range(H):
        A[i] = list(map(int, input().split()))

    warshall_floyd(10, c)

    ans = 0
    for h in range(H):
        for w in range(W):
            if A[h][w] != -1:
                ans += c[A[h][w]][1]
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 3444
#include <iostream>
#define INF 100000
using namespace std;

int main(void){
	int h,w,d;
	int min;
	bool b;
	while (cin >> h >>w,h|w){
		b=false;
		min=INF;
		d=w*w+h*h;
		for(int i=h+1;i<150;i++)
			for(int j=i+1;j<150;j++)
				if(d==(i*i+j*j))
					cout << i <<' ' << j << endl,j=150,i=150,b=true;
		if(b)
			continue;
		for(int i=1;i<150;i++)
			for(int j=i+1;j<150;j++)
				if(min>(i*i+j*j)&&(i*i+j*j)>d)
					min=(i*i+j*j),h=i,w=j;
		cout << h <<' ' << w << endl;
	}
	return 0;
}

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

//testテスト

bool p[260000];

void erato(){
	fill(p, p+260000, true);
	p[0] = p[1] = false;

	for(int i=0; i < 260000; i++){
		if(!p[i]) continue;

		for(int j=i+i; j < 260000; j+=i){
			p[j] = false;
		}
	}
}

int main(){
	erato();
	int n;

	while(cin >> n, n){
		int ans = 0;
		for(int i =n+1; i <= 2 * n; i++){
			if(p[i]) ans++;
		}
		cout << ans << endl;
	}
}

Measured memory_bytes: 1412
#include<bits/stdc++.h>
using namespace std;
map<int,int> mp;
map<int,int>::iterator it;
int main(){
	int i,ans=0,x,n;
	cin>>n;
	for(i=1;i<=n;i++){
		cin>>x;
		if(mp[x]==0)mp[x]=1;
		else mp[x]=0;
	}
	for(it=mp.begin();it!=mp.end();it++){
		if(it->second==1) ans++;
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 4864
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cstdio>
using namespace std;
int main(void) {
    long long x, n, i;
    cin >> x;
    n = 100;
    i = 0;
    while (n < x) {
        n += n / 100;
        i++;
    }

    cout << i << endl;
    return 0;
}

Measured memory_bytes: 3672
N = int(input())
sss = [input() for _ in range(N)]

ans = 0
for ss in sss:
    ans += ss.count('AB')

num_A = numB_ = numBA = 0
for ss in sss:
    is_A = ss.endswith('A')
    isB_ = ss.startswith('B')
    if is_A:
        num_A += 1
    if isB_:
        numB_ += 1
    if is_A and isB_:
        numBA += 1

ans += min(num_A, numB_)
if num_A == numB_ == numBA and num_A > 0:
    ans -= 1

print(ans)


Measured memory_bytes: 3828