akhauriyash/Code-Regression huggingface dataset:
H,W = [int(s) for s in input().split()]
s = [list(input()) for l in range(H)]

def check(s,i,j):
    p = []
    if i-1 >= 0: p.append(s[i-1][j])
    if i+1 <= H-1:p.append(s[i+1][j])
    if j-1 >= 0: p.append(s[i][j-1])
    if j+1 <= W-1:p.append(s[i][j+1])

    if all(k == '.' for k in p):
        return False
    else:
        return True
    


for i in range(H):
    for j in range(W):
        if s[i][j] == '#':
            a = check(s,i,j)
            if a == False:
                print('No')
                exit()
print('Yes')
            

Measured memory_bytes: 3064
#include <cstdio>
#include <algorithm>
#include <cmath>
using namespace std;
int f[5050],a[5050],n,k,sum=0;
int main()
{
    scanf("%d%d",&n,&k);
    for(int i=1;i<=n;++i)
	{
		scanf("%d",&a[i]);
		a[i]=min(a[i],k);
		sum+=a[i];
	}
    sort(a+1,a+n+2);
	f[0]=1;
    for(int i=n+1;i;--i)
	{
        bool check=true;
        for(int j=k-1;j>=k-sum && j>=0;--j)
			if(f[j])
			{
				check=false;
				break;
			}
        if(check)
		{
			printf("%d",i-1);
			return 0;
		}
        for(int j=k;j>=a[i];--j) f[j] |= f[j - a[i]];
        sum-=a[i];
    }
    return 0;
}

Measured memory_bytes: 256
/*

                   Ø¨ÙØ³Ù’Ù…Ù Ù±Ù„Ù„ÙŽÙ‘Ù°Ù‡Ù Ù±Ù„Ø±ÙŽÙ‘Ø­Ù’Ù…ÙŽÙ°Ù†Ù Ù±Ù„Ø±ÙŽÙ‘Ø­ÙÙŠÙ…Ù
                  Ù„Ø¢ Ø§ÙÙ„ÙŽÙ‡ÙŽ Ø§ÙÙ„Ù‘Ø§ Ø§Ù„Ù„Ù‘Ù‡Ù Ù…ÙØ­ÙŽÙ…ÙŽÙ‘Ø¯ÙŒ Ø±ÙŽØ³ÙÙˆÙÙ„ Ø§Ù„Ù„Ù‘Ù‡Ù
*/

/*
    Auther:   n0oO0o0Ob(None of them)
    from  :   https://n0oo0o0ob.sleek.page/

*/




#include <bits/stdc++.h>

using namespace std;
#define endl "\n"
#define pb push_back

                                        #define noob n0oO0o0Ob
// ---------------------------------
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef double db;
//----------------------------------
const ld PI = acos((ld)-1);
const int MOD = 1000000007;
//----------------------------------


int main()
{
    ios::sync_with_stdio(false);cin.tie(0);
    long a, b;
    cin >> a >> b;
    
    cout << (a*b)/__gcd(a, b) ;
	
		
	return 0;
}









Measured memory_bytes: 3648
n = int(input())
a = list(map(int, input().split()))

hs = dict()
for i in range(len(a)):
    hs[a[i]] = hs.get(a[i], 0) + 1

pattern = 0
for k in hs:
    if hs[k] <= 1:
        continue
    pattern += hs[k] * (hs[k] - 1) // 2

for i in range(len(a)):
    if hs[a[i]] <= 1:
        print(pattern)
    else:
        print(pattern - (hs[a[i]] * (hs[a[i]] - 1) // 2) + ((hs[a[i]] - 1) * (hs[a[i]] - 2) // 2))





Measured memory_bytes: 26140
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <bitset>
#include <map>
#include <unordered_map>
#include <list>
#include <numeric>
#include <utility>
#include <iterator>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <ctime>
#include <cassert>

#define INF 1000000000
#define LINF 9000000000000000000
#define mod 1000000007

#define rep(i,n) for(int i=0;i<int(n);i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define REP(i,a,b) for(int i=(a);i<int(b);i++)
#define all(x) (x).begin(),x.end()
#define pb push_back
#define mp make_pair

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int,int> pi;

int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
int ddx[8]={-1,-1,0,1,1,1,0,-1};
int ddy[8]={0,1,1,1,0,-1,-1,-1};
bool debug=false;

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

int main(){
  int a,b;
  cin>>a>>b;
  cout<<(a<=b?a:a-1)<<endl;
  return 0;
}


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

  
int main(){
 string s,t;
  cin >> s >> t ;
 int l=s.size();
  bool a=false;
  VI count(l);
    rep(i,l){
      rep(j,l){
        int n;
        if(i+j <= l-1) n=j+i;
        else if(i+j > l-1) n=j+i-l;
        
        if(t.at(j)==s.at(n)){
          count.at(i)++;
        }
      }
    }
  rep(i,l){
    
      if(count.at(i)==l) {
        a=true;
      break;
                         }
    }
   
  if(a) cout << "Yes" <<endl;
  else  cout << "No" <<endl;
    
}
  

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <ctype.h>
#include <limits.h>	
#define inf (INT_MAX-1)
#define INF 9223372036854775807
#define sq(n) ((n)*(n))
#define rep(i,n) for(i=0;i<n;i++)
#define rev(i,n) for(i=n-1;i>=0;i--)
#define sort(a,n) qsort(a,n,sizeof(TYPE),cmp)
#define sort_r(a,n) qsort(a,n,sizeof(TYPE),cmp_r);
#define TYPE int
#define MEMSET(a) memset(a,0,sizeof(a))
const int mod=(int)1e09+7;

int in(void){
	int i;scanf("%d",&i);
	return i;
}
long long llin(void){
	long long i;scanf("%lld",&i);
	return i;
}
double din(void){
	double i;scanf("%lf",&i);
	return i;
}
void chin(char s[]){
	scanf("%s",s);
}
void print(int a){
	printf("%d\n",a);
}
void llprint(long long a){
	printf("%lld\n",a);
}
void dprint(double a){
	printf("%.10f\n",a);
}
void print2(int a,int b){
	printf("%d %d\n",a,b);
}
long long max(long long a,long long b){
	return a>b?a:b;
}
long long min(long long a,long long b){
	return a<b?a:b;
}
long long llabs(long long a){
	return a>0?a:-a;
}
double dmax(double a,double b){
	return a>b?a:b;
}
int cmp(const void *a,const void *b){
	return *(TYPE *)a-*(TYPE *)b;
}
int cmp_r(const void *a,const void *b){
	return *(TYPE *)b-*(TYPE *)a;
}
void swap(int *a,int *b){
	int t=*a;
	*a=*b;
	*b=t;
}

int main(void){
	long long x=llin(),y=llin(),ans=0,n;
	n=x;
	while(n<=y){
		ans++;
		n*=2;
	}
	llprint(ans);
	return 0;
}

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

using namespace std;

#define UB upper_bound
#define LB lower_bound
#define BS binary_search
#define MP make_pair
#define EB emplace_back
#define endl "\n"
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007
#define F first
#define S second
#define ALL(a) (a).begin(),(a).end()
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define int long long

typedef long long int64;
typedef vector<int> VI64;
typedef vector<pair<int,int>> VII64;
typedef vector<string> VS;
typedef vector<vector<int>> VVI;

int n;

int dp[2005][2005];

int suri(int idx,int iav,VII64 &v)
{
	if(idx==n)
		return 0;
	int &ans=dp[idx][iav];
	if(ans!=-1)
		return ans;
	ans=(abs(iav-v[idx].S)*v[idx].F)+suri(idx+1,iav+1,v);
	int jav=n-1-(idx-iav);
	ans=max(ans,(abs(jav-v[idx].S)*v[idx].F)+suri(idx+1,iav,v));
	return ans;
}

int32_t main()
{
	IOS;
	int T=1;
	//cin>>T;
	while(T--)
	{
		int i,j;
		cin>>n;
		VII64 v(n);
		for(i=0;i<n;i++)
		{
			cin>>v[i].F;
			v[i].S=i;
		}
		memset(dp,-1,sizeof dp);
		sort(ALL(v),greater<pair<int,int>>());
		cout<<suri(0,0,v)<<endl;
	}

	return 0;
}

Measured memory_bytes: 35236
#include<iostream>
#include <cmath>
#include<vector>
#define rep(i, n) for (int i=0;i<n;i++)
#include <map> 
#include<algorithm>
#include <numeric>
#include<deque>
#include<queue>

using namespace std;
typedef long long ll;

int main(void){
    ll n, m;
    cin>>n>>m;
    vector<ll> a(n);
    rep(i, n){
        cin>>a[i];
    }
    vector<pair<ll, ll> > bc(m);
    rep(i, m){
        ll b, c;
        cin>>b>>c;
        bc[i].first=c;
        bc[i].second=b;
    }
    priority_queue<pair<int, int> >q;
    rep(i, n){
        q.push(make_pair(a[i], 1));
    }
    rep(i, m){
        q.push(make_pair(bc[i].first, bc[i].second));
    }
    ll ans=0;
    rep(i, n){
        pair<int, int> p=q.top();
        q.pop();
        ans+=p.first;
        if(p.second>1){
            p.second--;
            q.push(p);
        }
    }
    cout<<ans<<endl;

}

Measured memory_bytes: 4724
#include<queue>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
inline void read(int &x)
{
	x=0;
	int p=1;
	char c=getchar();
	while(!isdigit(c)){if(c=='-')p=-1;c=getchar();}
	while(isdigit(c)) {x=(x<<1)+(x<<3)+(c^'0');c=getchar();}
	x*=p;
}
string s;
int main()
{
	cin>>s;
	for(int i=0;i<s.size()-1;i++)if(s[i]=='A'&&s[i+1]=='C')return puts("Yes"),0;
	puts("No");
	return 0;
}

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

int main(){
  
  int n, u, k, v;
  bool a[110][110] = {}; //adjacency matrix

  //input
  cin >> n;
  for(int i = 0;i < n;i++){
    cin >> u >> k;
    for(int j = 0;j < k;j++){
      cin >> v;
      a[u][v] = true;
    }
  }

  //output
  for(int i = 1;i <= n;i++){
    for(int j = 1;j <= n;j++){
      cout << (j - 1?" ":"");
      cout << a[i][j];
    }
    cout << endl;
  }
  
  return 0;
}




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

int main(){
	int a,b,c;
	int ans;
	
	string cunning="7767555555555555555555555555555555555555545";
	
	for(int i=0;i<104;i++){
		cin>>a>>b;c=a+b;
		//-----test-----
		if(i<cunning.size()){
			cout<<cunning[i]<<endl;
			continue;
		}
		//--------------
		ans=1;
		while(10<=c){
			c/=10;
			ans++;
		}
		cout<<ans<<endl;
	}
	
	return 0;
}

Measured memory_bytes: 1204
// in the name of Allah

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

#define endl '\n'
#define pb push_back
#define ll long long
#define double long double
#define sz(x) ((int) (x.size()))

#define fr first
#define se second

#define inf 1e9
#define max_n 123456
#define mod 1000000007

ll add(ll a, ll b) {
	a += b;
	if(a >= mod) return a - mod;
	return a;
}

ll mul(ll a, ll b) {
	a *= b;
	if(a >= mod) return a % mod;
	return a;
}

ll power(ll a, ll b) {
	ll p = 1;
	while(b) {
		if(b&1) p = mul(p, a);
		a = mul(a, a);
		b /= 2;
	}
	return p;
}

int a[333];
int n, sum = 0;
bool seen[333][333][333];
double dp[333][333][333];

double memo(int one, int two, int three) {
	if(one == 0 && two == 0 && three == 0) return 0;
	if(seen[one][two][three]) return dp[one][two][three];
	int all = one + two + three;
	double co = 1 / ( all / (1.0*n) );
	double xx = (n - all) / (1.0*n);
	double res = xx;
	if(one > 0) {
		res += one / (1.0*n) * (memo(one-1, two, three)+1);
	}
	if(two > 0) {
		res += two / (1.0*n) * (memo(one+1, two-1, three)+1);
	}
	if(three > 0) {
		res += three / (1.0*n) * (memo(one, two+1, three-1)+1);
	}
	// cout << one << " " << two << " " << three << " " << co << " " << co * res << endl;
	seen[one][two][three] = 1;
	return dp[one][two][three] = res * co;
}

int main() {
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> n;
	int cnt[4] = {0, 0, 0, 0};
	for(int i=0; i<n; i++) {
		cin >> a[i];
		cnt[a[i]]++;
		sum += a[i];
	}
	memset(seen, 0, sizeof seen);
	cout << fixed << setprecision(12) << memo(cnt[1], cnt[2], cnt[3]) << endl;
	return 0;
}

Measured memory_bytes: 557952
import std.algorithm;
import std.array;
import std.container;
import std.conv;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

void scan(T...)(ref T a) {
    string[] ss = readln.split;
    foreach (i, t; T) a[i] = ss[i].to!t;
}
T read(T)() { return readln.chomp.to!T; }
T[] reads(T)() { return readln.split.to!(T[]); }
alias readint = read!int;
alias readints = reads!int;

void main() {
    int n, r; scan(n, r);
    int ans = n >= 10
        ? r
        : r + 100 * (10 - n);
    writeln(ans);
}


Measured memory_bytes: 256
class MathAlgorithm(object):

    MOD = 10000000 + 7

    @classmethod
    def gcd(cls, a: int, b: int) -> int:
        if b < 0 or (a == 0 and b == 0):
            raise ValueError

        if b > a:
            return cls.gcd(b, a)

        if b == 0:
            return 0

        if a % b == 0:
            return b

        return cls.gcd(b, a % b)


if __name__ == '__main__':
    A, B, K = map(int, input().split())

    gcd = MathAlgorithm.gcd(A, B)
    common_divides = []

    for i in range(1, gcd+1):
        if gcd % i == 0:
            common_divides.append(i)

    print(common_divides[-K])


Measured memory_bytes: 3064
quote,half,one,two = gets.split(" ").map(&:to_i)
request = gets.to_i
min_two = [quote * 8,half * 4,one * 2,two].min
min_one = [quote * 4,half * 2,one].min
min_half = [quote * 2,half].min
sum = 0
if request >= 2
  sum += (min_two * (request / 2)) 
  request = request % 2
end
if request >= 1
  sum += min_one
  request -= 1
end
if request >= 0.5
  sum += min_half
  request -= 0.5
end
if request == 0.25
  sum += quote
end
puts sum

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

const int MAX = 510000;
const int MOD = 1000000007;
long long fac[MAX], finv[MAX], inv[MAX];

void COMinit() {
    fac[0] = fac[1] = 1; finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

long long calc(long long n) {
  if (n == 1) {
    return 2;
  } else if (n % 2 == 0) {
    long long a = calc(n / 2);
    return (a * a) % MOD;
  } else {
    long long b = calc((n - 1) / 2);
    b = ((b * b) % MOD) * 2;
    b %= MOD;
    return b;
  }
}
int main() {
  int n, a, b;
  cin>>n>>a>>b;
  int size = max(a, b) + 1;
  COMinit();
  long long cnt[size];
  cnt[0] = 0;
  cnt[1] = n;
  for (int i=2; i<size; i++) {
    cnt[i] = ((cnt[i-1] * (n - i + 1)) % MOD) * inv[i];
    cnt[i] %= MOD;
  }
  long long ans = calc(n) - cnt[a] - cnt[b] - 1;
  if (ans < 0) {
    ans += MOD;
  }
  if (ans < 0) {
    ans += MOD;
  }
  cout<<ans % MOD<<endl;
}

Measured memory_bytes: 13696
def main():
  a = input()
  b = input()
  c = input()
  ab = [None]*20000
  ac = [None]*20000
  bc = [None]*20000
  def match(c1,c2):
    return (c1=='?')or(c2=='?')or(c1==c2)

  A = len(a)
  B = len(b)
  C = len(c)
  def solve(d1,d2,n,m,l):
    for i in range(n):
      for j in range(m):
        if not(match(d1[i],d2[j])):
          l[i-j+10000]=True
          continue
    return l
  ab = solve(a,b,A,B,ab)
  ac = solve(a,c,A,C,ac)
  bc = solve(b,c,B,C,bc)
  ans = 6000
  AB = A+B
  AC = A+C
  for i in range(-AC,AC,1):
    for j in range(-AB,AB,1):
      if (not(ab[i+10000]))and(not(ac[j+10000]))and(not(bc[j-i+10000])):
        L = min(0,min(i,j))
        R = max(A,max(B+i,C+j))
        ans = min(ans,R-L)
  print(ans)
  
main()

Measured memory_bytes: 48500
#include<bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define int ll
#define pb push_back
#define setbits(x)          __builtin_popcountll(x)
#define endl "\n"
typedef long long ll;
void solve()
{
    int n;
  cin>>n;
  if(n>=30)
    cout<<"Yes"<<endl;
  else
    cout<<"No"<<endl;
}
int32_t main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
solve();
    return 0;
}

Measured memory_bytes: 3644
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Linq;
using System.Numerics;

namespace AtCoderWorkspace
{
    public class Solver
    {
        public void Solve()
        {
            var cin = new Scanner();
            var s = cin.next();
            Console.WriteLine(s[0] == s[2]?"Yes":"No");
        }
    }

    class Scanner
    {
        string[] s;
        int i;

        char[] cs = new char[] { ' ' };

        public Scanner()
        {
            s = new string[0];
            i = 0;
        }

        public string next()
        {
            if (i < s.Length) return s[i++];
            string st = Console.ReadLine();
            while (st == "") st = Console.ReadLine();
            s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
            if (s.Length == 0) return next();
            i = 0;
            return s[i++];
        }

        public int nextInt()
        {
            return int.Parse(next());
        }
        public int[] ArrayInt(int N, int add = 0)
        {
            int[] Array = new int[N];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextInt() + add;
            }
            return Array;
        }

        public int[] DPArrayInt(int N, int ex)
        {
            int[] Array = new int[N + ex];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextInt();
            }
            return Array;
        }

        public long nextLong()
        {
            return long.Parse(next());
        }

        public long[] ArrayLong(int N, long add = 0)
        {
            long[] Array = new long[N];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextLong() + add;
            }
            return Array;
        }

        public long[] DPArrayLong(int N, int ex)
        {
            long[] Array = new long[N + ex];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextLong();
            }
            return Array;
        }

        public double nextDouble()
        {
            return double.Parse(next());
        }


        public double[] ArrayDouble(int N, double add = 0)
        {
            double[] Array = new double[N];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextDouble() + add;
            }
            return Array;
        }
    }

    class Program
    {
        static void Main(string[] s) => new Solver().Solve();
    }
}


Measured memory_bytes: 11092
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
	int a,b,c,x;
	int i,j,k,ans = 0;
	cin >> a >> b >> c >> x;
	x /= 50;
	for(i = 0;i <= a; i++)
	{
		for(j = 0;j <= b; j++)
		{
			for(k = 0;k <= c; k++)
			{
				if(i * 10 + j * 2 + k == x)
					ans++;
			}
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
def gcd( a , b ):
    if a == 0 :
        return b 
    return gcd( b % a , a )
n = int(input())
l = []
for i in range(n):
    l.append(int(input()))
ans = 1
for i in range(n):
    cur = gcd( ans , l[i] )
    ans *= l[i] // gcd(ans,cur)
print(ans)

Measured memory_bytes: 3316
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<cstring>
using namespace std;
typedef long long LL;
const int MOD=998244353;
const int N=205;
int n;
struct qq
{
	int x,y;
	void print ()	{printf("%d %d\n",x,y);}
}a[N],b[N];
int tot;
int ans;
qq tmp;
int mul (qq x,qq y,qq z)
{
	int x1=x.x-z.x,y1=x.y-z.y;
    int x2=y.x-z.x,y2=y.y-z.y;
    return x1*y2-x2*y1;
}
int dis (qq x,qq y)	{return (x.x-y.x)*(x.x-y.x)+(x.y-y.y)*(x.y-y.y);}
bool cmp (qq x,qq y)
{
	if (mul(x,y,tmp)==0) return dis(x,tmp)<dis(y,tmp);
	return mul(x,y,tmp)>0;
}
bool check (qq x,qq y,qq z)//z是否在 (tmp,x,y)
{
	if (mul(z,x,tmp)==0) return false;
	if (mul(z,y,x)>0) return false;
	return true;
}
int f[N][N];
int g[N][N];
int mul (int x,int y)	{return (LL)x*y%MOD;}
int add (int x,int y)	{x=x+y;return x>=MOD?x-MOD:x;}
void solve (int x)
{
	tot=0;tmp=a[x];
	for (int u=1;u<=n;u++)
	{
		if (a[u].y>a[x].y||(a[u].y>=a[x].y&&a[u].x>=a[x].x))	b[++tot]=a[u];
	}
	sort(b+1,b+1+tot,cmp);
//	for (int u=1;u<=tot;u++) b[u].print();
	for (int u=1;u<=tot;u++)	
		for (int i=1;i<=tot;i++)
			g[u][i]=f[u][i]=0;
	for (int u=1;u<=tot;u++)
		for (int i=u+1;i<=tot;i++)//(1,u,i)
		{
			g[u][i]=1;
			for (int k=u+1;k<i;k++)
				if (check(b[u],b[i],b[k]))
					g[u][i]=add(g[u][i],g[u][i]);
		}
	for (int u=2;u<=tot;u++)
	{
		f[1][u]=1;
		for (int i=2;i<u;i++)
			if (mul(b[i],b[u],b[1])==0)
				f[1][u]=add(f[1][u],f[1][u]);
	}
	for (int u=1;u<=tot;u++)
		for (int i=u+1;i<=tot;i++)
			for (int k=i+1;k<=tot;k++)
			{
				if (mul(b[k],b[i],b[u])<0)
				{
				//	printf("YES:%d %d %d %d %d\n",u,i,k,f[u][i],g[i][k]);
					f[i][k]=add(f[i][k],mul(f[u][i],g[i][k]));
				}
			}
	for (int u=2;u<=tot;u++)
		for (int i=u+1;i<=tot;i++)
		{
		//	printf("%d %d %d\n",u,i,f[u][i]);
			ans=add(ans,f[u][i]);
		}
//	system("pause");
}
int main()
{
	scanf("%d",&n);
	for (int u=1;u<=n;u++)	scanf("%d%d",&a[u].x,&a[u].y);
	for (int u=1;u<=n;u++) solve(u);
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 512
nu = gets.to_i
array = gets.chomp.split(" ").map(&:to_i)
ar_s = array.sort

for i in 0..nu - 1
  if array[i] >= ar_s[nu / 2]
    puts ar_s[(nu / 2) - 1]
  else
    puts ar_s[(nu / 2)]
  end
end


Measured memory_bytes: 25316
#include<iostream>
#include<string>
#include<cstring>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;
#define PI 3.141592653589793

int main(){
  int n; cin >> n; ll gru[n];
  rep(i, n){
    ll a, k; cin >> a >> k;
    while(1){
      if(a%k==0){
        gru[i]=a/k; break;
      }
      if(a<k){
        gru[i] = 0; break;
      }
      ll syuki = a/k + 1;
      a-=max(((a%k)/syuki)*syuki, syuki);
      //cout << a << endl;
    }
  }
  ll tmp = 0;
  rep(i, n){
    tmp^=gru[i]; //cout << gru[i] << endl;
  }
  if(tmp==0){
    cout << "Aoki" << endl;
  }
  else cout << "Takahashi" << endl;
}

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

#define all(A) begin(A), end(A)
#define sz(A) int(A.size())

using namespace std;

typedef long long ll;

const int MAX_N = 110;

int A[MAX_N][MAX_N];

int main () {
  ios::sync_with_stdio(false); cin.tie(0);
  int n;
  cin >> n;
  for (int u = 1; u <= n; u++) for (int v = 1; v <= n; v++) A[u][v] = 1;
  for (int u = 1; u <= n; u++) A[u][u] = 0;
  if (n % 2 == 0) {
    for (int u = 1; u <= n; u++) {
      A[u][n - u + 1] = 0;
    }
  }
  else {
    for (int u = 1; u <= n; u++) {
      A[u][n - u] = 0;
    }
  }
  vector <int> tmp;
  vector <pair <int, int>> E;
  for (int u = 1; u <= n; u++) {
    for (int v = u + 1; v <= n; v++) {
      if (A[u][v]) E.emplace_back(u, v);
    }
    int sum = 0;
    for (int v = 1; v <= n; v++) {
      if (A[u][v]) sum += v;
    }
    tmp.push_back(sum);
  }
  cout << sz(E) << '\n';
  for (auto pp: E) cout << pp.first << ' ' << pp.second << endl;
  /*
  int len = (n - 1) * n / 2;
  for (ll mask = 0; mask < (1 << (len)); mask++) {
    memset(A, 0, sizeof A);
    int bit = 0;
    for (int r = 0; r < n; r++) {
      for (int c = r + 1; c < n; c++) {
        A[r][c] = A[c][r] = (mask >> bit) & 1;
        bit++;
      }
    }
    vector <bool> vis(n);
    queue <int> Q;
    Q.push(0);
    for (int c = 0; c < n; c++) vis[0] = vis[0] | A[0][c];
    while (not Q.empty()) {
      int u = Q.front();
      Q.pop();
      for (int v = 0; v < n; v++) {
        if (A[u][v] and vis[v] == false) {
          vis[v] = true;
          Q.push(v);
        }
      }
    }
    bool ok = true;
    for (int c = 0; c < n; c++) ok &= vis[c];
    if (not ok) continue;
    vector <int> tmp;
    for (int r = 0; r < n; r++) {
      int sum = 0;
      for (int c = 0; c < n; c++) {
        if (A[r][c]) sum += c+ 1;
      }
      tmp.push_back(sum);
    }
    ok = true;
    for (int i = 1; i < n; i++) ok &= (tmp[i] == tmp[i - 1]);
    if (not ok) continue;
    cout << "MATRIX" << endl;
    for (int r = 0; r < n; r++) {
      for (int c = 0; c < n; c++) {
        cout << A[r][c] << ' ';
      }
      cout << endl;
    }
  }
  */
  return (0);
}


Measured memory_bytes: 384
def main():
    N = int(input())
    a = [int(input()) for _ in range(N)]
    
    b = a[0]
    count = 1
    if b == 2:
        ans = 1
    else:
        while True:
            count += 1
            b = a[b - 1]
            if b == 2:
                ans = count
                break
        
            if count > N:
                ans = -1
                break
    print(ans)

if __name__ == "__main__":
    main()

Measured memory_bytes: 7084
#include<bits/stdc++.h>
using namespace std;
int main(){
    long long n,x,a1,a2,res,num;
    cin>>n>>x;
    res = 0;
    num = 0;
    cin>>a1;
    for(long long i=1;i<n;i++){
        cin>>a2;
        num = x<(a1+a2)?a1+a2-x:0;
        res += num;
        if(a2 >= num){
            a2 -= num;
        }else{
            a2 = 0;
        }
        a1 = a2;
    }
    cout<<res;
    return 0;
}

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

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

using namespace std;

typedef long long ll;

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

  ll n, k; cin >> n >> k;
  vector<ll> h(n);

  rep(i, n) { cin >> h[i]; }
  sort(h.begin(), h.end());

  ll ans = 1e18;

  rep(i, n-k+1) {
    ans = min(ans, h[i+k-1]-h[i]);
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using PLL = pair<ll, ll>;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repn(i,n) for(int i = 0; i <= (int)(n); i++)
#define srep(i,l,n) for(int i = l; i < (int)(n); i++)
#define srepn(i,l,n) for(int i = l; i <= (int)(n); i++)
#define drep(i,n) for(int i = (int)(n-1); i >= 0; i--)
#define drepn(i,n) for(int i = (int)(n); i >= 0; i--)
#define size(s) (int)s.size()
#define debug(var)  do{std::cout << #var << " : ";view(var);}while(0)
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }
template<typename T> inline istream& operator>>(istream &i, vector<T> &v) {rep(j, size(v)) i >> v[j]; return 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; }
template<class T> T gcd(T a, T b) {if(b==0)return a; else return gcd(b,a%b);}
template<class T> T lcm(T a, T b) {return a/gcd(a,b)*b;}
template<class T = int> using V = vector<T>;
template<class T = int> using VV = vector<V<T>>;
bool isIn(int i, int j, int h, int w) {return i >= 0 && i < h && j >= 0 && j < w;}
void Yes(){cout << "Yes" << endl;}
void No(){cout << "No" << endl;}
void YES(){cout << "YES" << endl;}
void NO(){cout << "NO" << endl;}
void err() {cout << -1 << endl;}
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define pb push_back
#define ep emplace_back

const int MOD = 1000000007;
const int INF = 1e9;

#define PI acos(-1);
int dx[4] = {1,-1,0,0};
int dy[4] = {0,0,1,-1};
int ddx[8] = {1,1,1,-1,-1,-1,0,0};
int ddy[8] = {0,1,-1,0,1,-1,1,-1};


int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    V<> p(5);
    rep(i, 5) cin >> p[i];
    sort(all(p));
    int ans = INF;
    do {
        int now = 0;
        rep(i, 5) {
            now = (now + 9) / 10 * 10;
            now += p[i];
        }
        chmin(ans, now);
    }while(next_permutation(all(p)));
    cout << ans << endl;
}

Measured memory_bytes: 3628
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
 
struct node{
  unsigned int key;
  struct node *next;
  struct node *prev;
};

typedef struct node * NodePointer;

NodePointer nil;

NodePointer listSearch(int key){
  /* your code */
  NodePointer p = nil->next;

  while(p != nil && p->key != key){
    p = p->next;
  }
  return p;
}

void init(){
  nil = malloc(sizeof(struct node));
  nil->next = nil;
  nil->prev = nil;
}

void printList(){
  NodePointer cur = nil->next;
  int isf = 1;
  while(1){
    if ( cur == nil ) break;
    if ( isf == 0)  printf(" ");
    printf("%d", cur->key);
    cur = cur->next;
    isf = 0;
  }
  printf("\n");
}

void deleteNode(NodePointer t){
  if(t==nil)return;
  t->prev->next=t->next;
  t->next->prev=t->prev;
  free(t);
}

void deleteFirst(){
  NodePointer t = nil->next;
  if ( t == nil ) return;
  deleteNode(t);
}

void deleteLast(){
  NodePointer g;
  g = nil->prev;
  if ( g == nil ) return;
  deleteNode(g);
}

void delete(int key){
  /* your code */
  deleteNode(listSearch(key));
}


void insert(int key){
  NodePointer x;
  x = malloc(sizeof(struct node));
  x->key = key;

  x->next = nil->next;
  nil->next->prev = x;
  nil->next = x;
  x->prev = nil;
}

int main(){
  int key, n, i;
  int size = 0;
  char com[20];
  int np = 0, nd = 0;
  scanf("%d", &n);
  init();
  for ( i = 0; i < n; i++ ){
    scanf("%s%d", com, &key);
    if ( com[0] == 'i' ) {insert(key); np++; size++;}
    else if ( com[0] == 'd' ) {
      if (strlen(com) > 6){
	if ( com[6] == 'F' ) deleteFirst();
	else if ( com[6] == 'L' ) deleteLast();
      } else {
	delete(key); nd++; 
      }
      size--;
    }
  }

  printList();
  return 0;
}



Measured memory_bytes: 33024
n = int(input())
c = input()

l_w = [0 for i in range(n+1)]
r_r = [0 for i in range(n+1)]

for i in range(n):
    l_w[i+1] = l_w[i]
    if c[i] == 'W':
        l_w[i+1] += 1
for i in range(n, 0, -1):
    r_r[i-1] = r_r[i]
    if c[i-1] == 'R':
        r_r[i-1] += 1

ans = int(1e9)

for i in range(n+1):
    ans = min(ans, max(l_w[i], r_r[i]))

print(ans)

Measured memory_bytes: 18772
#include <bits/stdc++.h>
#define mod 1000000007
#define m_k make_pair
#define inf 0x3f3f3f3f
#define int long long
using namespace std;
const int N=2*1e5+100;
int n,dp[N],sz[N];
vector <int> e[N];
int m_pow(int a,int b)
{
	int ans=1;
	while (b)
	{
		if (b&1) ans=(ans*a)%mod;
		b>>=1;
		a=(a*a)%mod;
	}
	return ans;
}
int inv(int x)
{
	return m_pow(x,mod-2);
}
void dfs(int x,int fa)
{
	sz[x]=1;
	for (int i=0;i<(int)e[x].size();i++)
	{
		int u=e[x][i];
		if (u==fa) continue;
		dfs(u,x);
		sz[x]+=sz[u];
	}
}
void dfs1(int x,int fa)
{
	for (int i=0;i<(int)e[x].size();i++)
	{
		int u=e[x][i];
		if (u==fa) continue;
		dp[u]=(dp[x]*(n-sz[u]))%mod;
		dp[u]=(dp[u]*inv(sz[u]))%mod;
		dfs1(u,x);
	}
}
signed main()
{
	scanf("%lld",&n);
	for (int i=1;i<n;i++)
	{
		int a,b;
		scanf("%lld%lld",&a,&b);
		e[a].push_back(b);
		e[b].push_back(a);
	}
	dfs(1,1);
	dp[1]=1;
	for (int i=1;i<=n;i++) dp[1]=(dp[1]*sz[i])%mod;
	dfs1(1,1);
	int ans=1;
	for (int i=1;i<=n;i++) ans=(ans*i)%mod;
	for (int i=1;i<=n;i++) dp[i]=(ans*inv(dp[i]))%mod;
	for (int i=1;i<=n;i++) printf("%lld\n",dp[i]);
	printf("\n");
}

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

int main(){
  int N; cin>>N;
  int cnt=0;
  int mx=0,cp;
  for(int i=0;i<N;i++){
    cin>>cp;
    if(cp>=mx){
      mx=cp; cnt++;
    }
  }
  cout<<cnt<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
int n;
int par[110000];
vector<int> ch[110000];
int depth[110000];
void solve(int a){
	vector<int> d;
	for(int i = 0; i < ch[a].size(); i++){
		solve(ch[a][i]);
		d.push_back(depth[ch[a][i]]);
	}
	sort(d.begin(), d.end());
	reverse(d.begin(), d.end());
	depth[a] = 0;
	for(int i = 0; i < d.size(); i++){
		depth[a] = max(d[i]+i,depth[a]);
	}
	depth[a] ++;
}
int main(){
	cin >> n;
	for(int i = 2; i <= n; i++){
		cin >> par[i];
		ch[par[i]].push_back(i);
	}
	par[1] = 0;
	solve(1);
	cout << depth[1] - 1 << endl;
}


Measured memory_bytes: 14592
import java.util.Scanner;

public class Main {
	static Scanner sc = new Scanner(System.in);
	static int[] x, y, z, r;
	static long[] l;

	public static void main(String[] args) {
		int N = sc.nextInt();
		int Q = sc.nextInt();
		x = new int[N];
		y = new int[N];
		z = new int[N];
		r = new int[N];
		l = new long[N];
		for (int i = 0; i < N; ++i) {
			x[i] = sc.nextInt();
			y[i] = sc.nextInt();
			z[i] = sc.nextInt();
			r[i] = sc.nextInt();
			l[i] = sc.nextLong();
		}
		for (int i = 0; i < Q; ++i) {
			int sx = sc.nextInt();
			int sy = sc.nextInt();
			int sz = sc.nextInt();
			int dx = sc.nextInt();
			int dy = sc.nextInt();
			int dz = sc.nextInt();
			long sum = 0;
			for (int j = 0; j < N; ++j) {
				double lo = 0;
				double hi = 1;
				for (int k = 0; k < 300; ++k) {
					double m1 = (lo * 2 + hi) / 3;
					double m2 = (lo + hi * 2) / 3;
					double d1 = dist(x[j], y[j], z[j], sx + (dx - sx) * m1, sy + (dy - sy) * m1, sz + (dz - sz) * m1);
					double d2 = dist(x[j], y[j], z[j], sx + (dx - sx) * m2, sy + (dy - sy) * m2, sz + (dz - sz) * m2);
					if (d1 < d2) {
						hi = m2;
					} else {
						lo = m1;
					}
				}
				if (dist(x[j], y[j], z[j], sx + (dx - sx) * lo, sy + (dy - sy) * lo, sz + (dz - sz) * lo) <= r[j] + 1e-8) {
					sum += l[j];
				}
			}
			System.out.println(sum);
		}
	}

	static double dist(double x1, double y1, double z1, double x2, double y2, double z2) {
		return Math.sqrt(sq(x1 - x2) + sq(y1 - y2) + sq(z1 - z2));
	}

	static double sq(double v) {
		return v * v;
	}

}

Measured memory_bytes: 21168
/////////////////////////////////////////////////////////
//
//  c/temp.cpp file
//  Last Updated: 2018-10-23 ...Maybe
//
//    I hope you adding this code to the setting file
//    alias g++='g++ -std=c++1y -DDEBUG_LOCAL'
//
/////////////////////////////////////////////////////////

#include <bits/stdc++.h>

using namespace std;

#define fi first
#define se second
#define mp make_pair
#define pb push_back

//#define int long long

#define _overload3(_1,_2,_3,name,...) name
#define _REP(i,n) REAP(i,0,n)
#define REAP(i,a,b) for(int i=int(a);i<int(b);++i)
#define REP(...) _overload3(__VA_ARGS__,REAP,_REP,)(__VA_ARGS__)

#define _REPR(i,n) REAPR(i,n,0)
#define REAPR(i,a,b) for(int i=int(a-1);i>=int(b);--i)
#define REPR(...) _overload3(__VA_ARGS__,REAPR,_REPR,)(__VA_ARGS__)

#define ALL(a) a.begin(),a.end()
#define rALL(a) a.rbegin(),a.rend()

#define coutALL(a) {int loop_coutALL=0;for(auto e:a) cout<<(loop_coutALL++?" ":"")<<e; cout<<endl;}

#define coutYN(a) cout<<((a)?"YES":"NO")<<endl;
#define coutYn(a) cout<<((a)?"Yes":"No")<<endl;
#define coutyn(a) cout<<((a)?"yes":"no")<<endl;

#define pcnt __builtin_popcount
#define buli(x) __builtin_popcountll(x)

const int INF=1145141919;
//const long long INF=114514191911451419;
const int MOD=(int)1e9+7;
const double EPS=1e-12;
const int dx[]={1,0,-1,0},dy[]={0,1,0,-1};
//const int dx[]={-1,-1,-1,0,1,1,1,0},dy[]={-1,0,1,1,1,0,-1,-1};

using vi=vector<int>;
using vvi=vector<vi>;
using vs=vector<string>;

typedef pair<int,int> pii;
typedef pair<int,string> pis;
typedef pair<string,int> psi;
typedef pair<string,string> pss;

typedef long long ll;

template<typename T> istream &operator >> (istream &is, vector<T> &v){for(T &x:v) is>>x;return is;}
template<typename T> ostream &operator << (ostream &os, vector<T> &v){int i=0;for(T &x:v) os<<(i++?" ":"")<<x;return os;}

ll rev(ll n){ll x=0;for(;n>0;){x=x*10+n%10;n/=10;}return x;}

ll upper(ll n,ll m){return (n+m-1)/m;};
ll rounding(ll n){return (long double)n+0.5;};

bool inG(ll x,ll n){return 0<=x && x<n;}
bool outG(ll x,ll n){return x<0 || n<=x;}

inline int qp(int a,ll b){if(!b)return 1;int ans=1;do{if(b&1)ans=1ll*ans*a;a=1ll*a*a;}while(b>>=1);return ans;}
inline int qp(int a,ll b,int mo){if(!b)return 1;int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}

inline ll fac(ll k,ll n){ll a=1;for(int i=0;i<n;i++)a*=k--;return a;}
inline ll fac(ll k,ll n,int mo){ll a=1;for(int i=0;i<n;i++)a*=k--,a%=mo;return a;}

inline int dsum(ll n){int a=0;for(;n;n/=10)a+=n%10;return a;}

struct Arithmetic{Arithmetic(){cin.tie(0);ios::sync_with_stdio(0);cout<<fixed<<setprecision(20);}};

//#define DEBUG_LOCAL

#ifdef DEBUG_LOCAL
template<typename T> void deb(T a){cerr<<"deb: "<<a<<"です"<<endl;}
#define debl {cerr<<"debug: "<<__LINE__<<"行目だ"<<endl;}
void what_cr(){cout<<__GCC_ATOMIC_CHAR16_T_LOCK_FREE<<" ←？"<<endl;}
//ori_func S

//ori_func E
#else
template<typename T>void deb(T a){}
#define debl
void what_cr(){}void t_t(){}
#endif

signed main(){

  Arithmetic Exception;

  int h,w,a,b;

  cin>>h>>w>>a>>b;

  cout<<h*w-(h/a)*(w/b)*a*b<<endl;

  return 0;

}



Measured memory_bytes: 3184
function main(input){
  var n = parseInt(input[0]);
  var a = input[1];
  var b = input[2];
  var c = input[3];
  
  var ans = 0;
  for (var i = 0; i < n; i++){
    var map = {};
    map[a[i]] = 1;
    map[b[i]] = 1;
    map[c[i]] = 1;
    ans += Object.keys(map).length - 1;
  }
  console.log(ans);
}

var input = '';

process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stdin.on('data', function(chunk) {
  input += chunk;
});
process.stdin.on('end', function() {
  input = input.split('\n');
  main(input);
});


Measured memory_bytes: 21320
#import numpy as np
n = int(input())
h = list(map(int,input().split(' ')))
#h_d = np.diff(h)

ans = 0
ans_a = [0]
#first_h_d = h_d[0]
first_h = h[0]
#print(h_d)
for i in h[1:]:
  #print(first_h,i,first_h >= i)
  if first_h >= i:
    ans+=1
    first_h = i
  else:
    ans_a.append(ans)
 #   print(ans)
    ans = 0
    first_h = i

ans_a.append(ans)

print(max(ans_a))

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

using namespace std;

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


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

#define cp_io ios_base::sync_with_stdio(0);cin.tie(0)
#define ll long long int
#define oo 1000000010
#define MAX 1000000
#define pb push_back
#define ff first
#define ss second
#define mp make_pair
#define nl "\n"

int main()
{
    cp_io;
    #ifndef ONLINE_JUDGE
    freopen("z_input.txt","rt",stdin);
    freopen("z_output.txt","wt",stdout);
    #endif
    string s;
    cin >> s;
    int ans = INT_MIN,c=0;
    for(int i=0; i<3; i++)
    {
        if(s[i]=='R')
        {
            c = 0;
            while(s[i]=='R' && i<3){
                i++;
                c++;
            }
        }
        ans = max(ans, c);
    }
    cout << ans << nl;
    return 0;
}

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

using namespace std;

int main(void){
    int n, d, x;
    cin >> n >> d >> x;
    vector<vector<int> > v(d, vector<int>(n));
    for (int i = 0; i < d; i++) {
        for (int j = 0; j < n; j++) {
            cin >> v[i][j];
        }
    }
    vector<int> cash(d,0);
    cash[0] = x;
    for (int l = 0; l < d; l++) {
        for (int r = l+1; r < d; r++) {
            int ma = cash[l];
            vector<int> dp(ma+1, ma);
            for (int i = l; i < r; i++) {
                for (int j = 0; j < n; j++) {
                    int a = v[i][j];
                    int b = v[r][j];
                    for (int k = ma; k-a >= 0; k--) dp[k-a] = max(dp[k-a], dp[k]+b-a);
                }
            }
            cash[r] = max(cash[r], dp[0]);
        }
    }
    cout << cash[d-1] << endl;
}

Measured memory_bytes: 3196
#include <bits/stdc++.h>
// #include <boost/multiprecision/cpp_int.hpp>
// using i128 = boost::multiprecision::int128_t;
#define _GLIBCXX_DEBUG
using namespace std;
using ll = long long;
using ld = long double;
using V = vector<int>;
using Vll = vector<ll>;
using Vld = vector<ld>;
using Vbo = vector<bool>;
using VV = vector<V>;
using VVll = vector<Vll>;
using VVld = vector<Vld>;
using VVbo = vector<Vbo>;
using VVV = vector<VV>;
using VVVll = vector<VVll>;
using P = pair<int, int>;
using Pll = pair<ll, ll>;
using Pld = pair<ld, ld>;
#define rep2(i, m, n) for(int i=int(m); i<int(n); ++i)
#define drep2(i, m, n) for(int i=int(m)-1; i>=int(n); --i)
#define rep(i, n) rep2(i, 0, n)
#define drep(i, n) drep2(i, n, 0)
#define all(a) a.begin(), a.end()
struct fast_ios { fast_ios(){ cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
template<typename T> inline int sz(T &x) { return x.size(); }
template<typename T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }
template<typename T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
template<typename T1, typename T2> istream &operator>>(istream &is, pair<T1, T2> &p) { is >> p.first >> p.second; return is; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
template<typename T> istream &operator>>(istream &is, vector<T> &v) { for (auto &e : v) is >> e; return is; }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &v) { for (auto &e : v) os << e << " "; return os; }
template<typename T> inline int count_between(vector<T> &a, T l, T r) { return lower_bound(all(a), r) - lower_bound(all(a), l); } // [l, r)
inline int fLog2(const int x) { return 31-__builtin_clz(x); } // floor(log2(x))
inline int fLog2(const ll x) { return 63-__builtin_clzll(x); }
inline int cLog2(const int x) { return (x == 1) ? 0 : 32-__builtin_clz(x-1); } // ceil(log2(x))
inline int cLog2(const ll x) { return (x == 1) ? 0 : 64-__builtin_clzll(x-1); }
inline int popcount(const int x) { return __builtin_popcount(x); }
inline int popcount(const ll x) { return __builtin_popcountll(x); }
const int INF  = 1<<30;
const ll INFll = 1ll<<62;
const ld EPS   = 1e-10;
const ld PI    = acos(-1.0);
const int MOD  = int(1e9)+7;
// const int MOD  = 998244353;


int grundy(int &k, int x) {
  int p = x / k;
  int r = x % k;
  if (x < k) return 0;
  int r2 = r % (p+1);
  if (r2 == 0) return p;
  return grundy(k, min(x-p-1, p*k+r2));
}


int main() {
  int n; cin >> n;
  
  int g = 0;
  rep(i, n) {
    int a, k; cin >> a >> k;
    g ^= grundy(k, a);
  }

  cout << (g == 0 ? "Aoki" : "Takahashi") << '\n';
  return 0;
}


Measured memory_bytes: 3640
#include<stdio.h>

int main(){
  int a,x,y,z;

  scanf("%d%d",&x,&y);
  if(x<y){
    a=x;
    x=y;
    y=a;
  }
  while(1){
  z = x % y;
  x = y;
  y = z;
  if(z==0){
    printf("%d\n",x);
    break;
    }
  }
  return 0;
}



Measured memory_bytes: 2120
#include <bits/stdc++.h>
#define rep(a,n) for (ll a = 0; a < (n); ++a)
using namespace std;
using ll = long long;
typedef pair<ll,ll> P;
typedef pair<P,ll> PP;
typedef vector<vector<ll> > Graph;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const ll INF = 1e9;

//入力
ll n;
vector<ll>t,a;

const ll mod = 1000000007;
//const ll mod = 998244353;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}



int main(){
    cin >> n;
    t.resize(n);
    a.resize(n);
    rep(i,n)cin>>t[i];
    rep(i,n)cin>>a[i];
    vector<ll>kakutei(n,-1);
    vector<ll>ika(n,INF);
    kakutei[0]=t[0];
    if(n!=1)kakutei[n-1]=a[n-1];
    ika[0]=t[0];
    bool flag=false;
    rep(i,n-1){
        ika[i+1]=t[i+1];
        if(t[i+1]>t[i]){
            kakutei[i+1]=t[i+1];
        }
    }
    chmin(ika[n-1],a[n-1]);
    for(ll i=n-2;i>=0;i--){
        chmin(ika[i],a[i]);
        if(a[i]>a[i+1]){
            if(kakutei[i]!=-1&&kakutei[i]!=a[i])flag=true;
            kakutei[i]=a[i];
        }
    }
    rep(i,n){
        if(kakutei[i]>ika[i])flag=true;
    }
    if(flag){
        cout << 0 << endl;
        return 0;
    }
    mint ans = 1;
    rep(i,n){
        if(kakutei[i]!=-1)continue;
        ans *= ika[i];
    }
    cout << ans << endl;
    /*
    cout << endl;
    rep(i,n){
        cout << ika[i] << endl;
    }
    cout << endl;
    rep(i,n){
        cout << kakutei[i] << endl;
    }
    */
    return 0;
}


Measured memory_bytes: 6428
n, m = map(int, raw_input().split())
a, b = [], []
c, d = [], []

for i in range(n):
    a0, b0 = map(int, raw_input().split())
    a.append(a0)
    b.append(b0)
for i in range(m):
    c0, d0 = map(int, raw_input().split())
    c.append(c0)
    d.append(d0)
for i in range(n):
    res = 10**9
    ans = 0
    for j in range(m):
        man = abs(a[i]-c[j])+abs(b[i]-d[j])
        if res > man:
            res = man
            ans = j
    print ans+1

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

string s;

bool Even(int len) {
  if(len % 2 != 0) return false;
  return s.substr(0, len / 2) == s.substr(len / 2, len / 2);
}


int main() {
  cin >> s;
  for(int i = s.size() - 1; i >= 0; --i) {
    if (Even(i)) {
      cout << i << endl;
      return 0;
    }
  }
}

Measured memory_bytes: 256
fun main(args : Array<String>) {
    val (N, M, X, Y) = readLine()!!.split(" ").map { it.toInt() }
    val x = readLine()!!.split(" ").map { it.toInt() }
    val y = readLine()!!.split(" ").map { it.toInt() }

    val maxX = x.max()!!
    val minY = y.min()!!

    val isPeaceful = (-100..100).find {z ->
        X < z && z <= Y && maxX < z && z <= minY
    } != null
    if (isPeaceful) {
        println("No War")
    } else {
        println("War")
    }
}

Measured memory_bytes: 37744
# various sushi
import heapq
N, K = map(int, input().split())
que = []
for i in range(N):
    t, d = map(int, input().split())
    que.append((t, d))

que.sort(key=lambda x: -x[1])
NOW = que[:K]

N_set = set()

sums = 0

cnt = [0 for i in range(N+1)]  # ねたxに何個いるか
ng,ok,sub = [], [], []
heapq.heapify(ng)
heapq.heapify(ok)
heapq.heapify(sub)

for index, value in NOW:
    sums += value
    cnt[index] += 1
    heapq.heappush(ng, (value, index))
    N_set.add(index)
while ng:
    value, index = heapq.heappop(ng)
    if cnt[index] > 1:
        heapq.heappush(ok, (value, index))
        cnt[index] -= 1
    elif cnt[index] == 1:
        heapq.heappush(sub, (value, index))

ng = sub

# ng とっちゃダメなやつ
# ok とってもいいやつ

S = len(N_set)
ans = S**2+sums


# これより更新することはあるか？

for i in range(K, N):
    taste, value = que[i]
    if taste in N_set:
        pass
    else:
        #taste not in N_set
        if ok:
            min_value, m_taste = heapq.heappop(ok)
            sums -= min_value
            sums += value
            S += 1
            cnt[taste] += 1
            N_set.add(taste)
            cnt[m_taste] -= 1
            heapq.heappush(ng, (value, taste))
            ans = max(ans, S**2+sums)

print(ans)

Measured memory_bytes: 27512
def i():
	return int(input())
def i2():
	return map(int,input().split())
def s():
	return str(input())
def l():
	return list(input())
def intl():
	return list(int(k) for k in input().split())

s = s()
for i in range(len(s)):
	print("x",end="")

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

#define y1 aklsdja
#define ii pair < int , int >
#define iii pair < int , ii >
#define iv pair < ii , ii >

#define fi first
#define se second
#define pb push_back
#define t top()
#define fr front()

#define FOR(i , x , n) for(int i = x ; i <= n ; ++i)
#define REP(i , x) for(int i = 0 ; i < x ; ++i)
#define FORD(i , x , n) for(int i = x ; i >= n ; --i)

#define oo 1e17 + 5
#define ll long long
#define int long long
#define pow poww

const int N = 1e5 + 5;
int n;
int dp[N] , h[N];

main()
{
    //reopen("A.inp","r",stdin);
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin >> n;
    FOR(i , 1 , n)
        cin >> h[i];
    dp[1] = 0;
    dp[2] = abs(h[2] - h[1]);
    FOR(i , 3 , n)
        dp[i] = min(dp[i - 1] + abs(h[i] - h[i - 1]) , dp[i - 2] + abs(h[i] - h[i - 2]));
    cout << dp[n];
}


Measured memory_bytes: 1792