akhauriyash/Code-Regression huggingface dataset:
import java.util.*;
public class Main {
	public static void main(String[] args){
	  Scanner sc = new Scanner(System.in);
      int n = sc.nextInt();
      int k = sc.nextInt();
      int[] a = new int[n];
      for(int i=0;i<n;i++){
        a[i] = sc.nextInt();
      }
      long tmp = 0;
      for(int i=k;i<n;i++){
        if( a[i] - a[i-k] > 0 ){
          System.out.println("Yes");
        }else{
          System.out.println("No");
        }
      }
	}
}

Measured memory_bytes: 52276
#include<cstdio>
#include<utility>
#include<iostream>
#define RI register int
#define CI const int&
#define mp make_pair
#define fi first
#define se second
using namespace std;
typedef pair <int,int> pi;
const int N=1005,dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};
inline char get_ch(void)
{
	char ch; while (ch=getchar(),ch!='#'&&ch!='.'); return ch;
}
int n,m,stp[N][N],ans; pi q[N*N];
int main()
{
	RI i,j,H=0,T=0; for (scanf("%d%d",&n,&m),i=1;i<=n;++i)
	for (j=1;j<=m;++j) if (get_ch()=='#') q[++T]=mp(i,j); else stp[i][j]=1e9;
	while (H<T)
	{
		int nx=q[++H].fi,ny=q[H].se; for (i=0;i<4;++i)
		{
			int tx=nx+dx[i],ty=ny+dy[i];
			if (tx>=1&&tx<=n&&ty>=1&&ty<=m&&stp[tx][ty]>stp[nx][ny]+1)
			stp[tx][ty]=stp[nx][ny]+1,q[++T]=mp(tx,ty);
		}
	}
	for (i=1;i<=n;++i) for (j=1;j<=m;++j) ans=max(ans,stp[i][j]);
	return printf("%d",ans),0;
}

Measured memory_bytes: 15468
#include <cstdio>
#include <iostream>
#include <algorithm>
using namespace std;
int n,t,s;
int a[3333],b[3333];
int dp[3333][3333];
int main(void){
  cin >> n >> t >> s;
  for(int i = 1; i <=n; i++){
    cin >> a[i] >> b[i];
  }

  for(int i = 1; i <=n; i++){
    for(int j = 1; j <= t; j++){
      dp[i][j] = max(dp[i][j-1],dp[i-1][j]);
      if(b[i] <= j && (j <= s || s <= j - b[i]) ) dp[i][j] = max(dp[i][j],dp[i-1][j-b[i]]+a[i]);
    }
  }
  cout << dp[n][t] << endl;
}

Measured memory_bytes: 42140
#!/usr/bin/env python3
#ABC50 C

from collections import Counter
from operator import itemgetter

n = int(input())
a = list(map(int,input().split()))
mod = 10**9+7

c = Counter(a)
c = list(c.items())
ccc = sorted(c,key = itemgetter(0))
if n % 2 == 1:
    k = 0
    for i,j in ccc:
        if j == 2 and i == 2*k:
            k += 1
            continue
        if j == 1 and i == 0:
            k += 1
            continue
        else:
            print(0)
            quit()
if n % 2 == 0:
    k = 0
    for i,j in ccc:
        if j == 2 and i == 2*k+1:
            k += 1
            continue
        else:
            print(0)
            quit()
print(2**(n//2) % mod)


Measured memory_bytes: 16096
#include<bits/stdc++.h>
using namespace std;
const int mod=998244353;
string s;
map<string,int>f;
map<string,int>g;
int G(string s);
int F(string s);
int main()
{
    cin>>s;
    f[""]=1;
    cout<<F(s)<<endl;
    return 0;
}
int F(string s)
{
    if(f.find(s)!=f.end())
    return f[s];
    for(int i=1;i<=s.size();++i)
    f[s]=(f[s]+1ll*F(s.substr(0,s.size()-i))*G(s.substr(s.size()-i,i))%mod)%mod;
    return f[s];
}
int G(string s)
{
    if(g.find(s)!=g.end())
    return g[s];
    if(s.size()==1)
    return g[s]=s[0]-'0'+1;
    int i=1,j;
    while(i<s.size())
    {
        if(s.size()%i==0)
        {
            string t;
            j=0;
            while(j<i)
            {
                int r=1;
                for(int k=0;k<s.size()/i;++k)
                if(s[i*k+j]=='0')
                r=0;
                t=t+(char)(r+'0');
                j=j+1;
            }
            g[s]=(g[s]+F(t))%mod;
        }
        i=i+1;
    }
    return g[s];
}

Measured memory_bytes: 12928
n=int(input())
h=list(map(int,input().split()))
H=max(h)
ans=0
for i in range(1,H+1):
  if h[0]>=i:
    piece=1
  else:
    piece=0
  for j in range(n-1):
    if h[j]<i and h[j+1]>=i:
      piece+=1
  ans+=piece
print(ans)

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

int main()
{
  int N,M,X;
  cin >> N >> M >> X;
  vector<int> C(N);
  vector<vector<int>> A(N,vector<int>(M));
  for(int i = 0;i < N;i++){
    cin >> C[i];
    for(int j = 0;j < M;j++){
      cin >> A[i][j];
    }
  }
  int sum0 = 1200000;
  bool ans = false;
  for (int tmp = 1; tmp < (1 << 12); tmp++){
    bitset<12> s(tmp);
    if(N != 12){
      if(s.test(N)) break;
    }
    vector<int> Adash(M);
    int sum1 = 0;
    for(int i = 0;i < 12;i++){
      if(s.test(i)){
        sum1 += C[i];
        for(int j = 0;j < M;j++){
          Adash[j] += A[i][j];
        }
      }
    }
    bool ans1 = true;
    for(int j = 0;j < M;j++){
      if(Adash[j] < X) ans1 = false;
    }
    if(ans1){
      sum0 = min(sum0,sum1);
      ans = true;
    }
  }
  if(ans) cout << sum0 << endl;
  else cout << -1 << endl;
}


Measured memory_bytes: 3632
from itertools import combinations

N = int(input())
l = [tuple(map(int, input().split())) for _ in range(N)]
t = {i for i in l}

if N==1 or N==2:
    print(1)
else:
    ans = N
    for i in range(N):
        for j, k in combinations([l[j] for j in range(N) if j!=i], 2):
            x1, y1 = j
            x2, y2 = k
            x, y = x1-x2, y1-y2

            b = 1
            for m in range(N):
                if i==m:continue
                x3, y3 = l[m]
                if not (x3-x, y3-y) in t:
                    b += 1
            ans = min(ans, b)
    print(ans)


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

using namespace std;

#define loop(i, n) for(int i = 0;i < int(n);i++)
#define rloop(i, n) for(int i = int(n);i >= 0;i--)
#define range(i, a, b) for(int i = int(a);i <= int(b);i++)
#define SZ(c) int(c.size())
#define ALL(c) c.begin(), c.end()
#define RALL(c) c.rbegin(), c.rend()
#define PI acos(-1)
#define pb push_back
#define mp make_pair
#define fr first
#define sc second
#define sfi1(v) scanf("%d",&v)
#define sfi2(v1, v2) scanf("%d %d",&v1,&v2)
#define sfi3(v1, v2, v3) scanf("%d %d %d",&v1,&v2,&v3)
#define sfll1(v) scanf("%I64d",&v);
#define sfll2(v1, v2) scanf("%I64d %I64d",&v1,&v2)
#define sfll3(v1, v2, v3) scanf("%I64d %I64d %I64d",&v1,&v2,&v3)
#define endl '\n'

typedef vector<int> vi;
typedef vector<pair<int, int> > vii;
typedef long long ll;
typedef pair<int, int> pii;

const int N = 1e5 + 5;
int dp[N][2][2];
int vis[N][2][2], visid;
int F, L;
string str;
int n;
//sheep 0 , wolf 1

int solve(int idx, int cur, int lst) {
    int &ret = dp[idx][cur][lst];
    if (vis[idx][cur][lst] == visid)return ret;
    vis[idx][cur][lst] = visid;
    if (idx == n - 1) {
        if (cur != L)return ret = 0;
        if (cur == 0) {
            ret = (str[idx] == 'o' && F == lst || str[idx] == 'x' && F != lst);
        } else {
            ret = (str[idx] == 'x' && F == lst || str[idx] == 'o' && F != lst);
        }
        return ret;
    }

    int nxt;
    if (cur == 0) {
        //truth
        nxt = (str[idx] == 'o') ? lst : (!lst);
        ret = solve(idx + 1, nxt, cur);
    } else {
        //lie
        nxt = (str[idx] == 'o') ? (!lst) : lst;
        ret = solve(idx + 1, nxt, cur);
    }
    return ret;
}

string ans;

void build(int idx, int cur, int lst) {
    ans += (cur ? 'W' : 'S');
    if (idx == n - 1)return;
    int nxt;
    if (cur == 0) {
        //truth
        nxt = (str[idx] == 'o') ? lst : (!lst);
        build(idx + 1, nxt, cur);
    } else {
        //lie
        nxt = (str[idx] == 'o') ? (!lst) : lst;
        build(idx + 1, nxt, cur);
    }
}

int main() {

#ifndef ONLINE_JUDGE
    freopen("in.in", "r", stdin);
    //freopen("out.in", "w", stdout);
#endif
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    cin >> n >> str;

    loop(f, 2) {
        loop(l, 2) {
            F = f, L = l;
            visid++;
            if (solve(0, f, l)) {
                build(0, f, l);
                cout << ans << endl;
                return 0;
            }
        }
    }

    cout << -1 << endl;

    return 0;
}


Measured memory_bytes: 9948
#include <stdio.h>

int main(void)
{
   int n, A[50], i;

   scanf("%d", &n);

   A[ 0 ] = 1;
   A[ 1 ] = 1;

   for ( i = 2; i < 50; i++ ) {
      A[ i ] = A[ i - 1 ] + A[ i - 2 ];
   }

   printf("%d\n", A[ n ]);
   return 0;
}

Measured memory_bytes: 1852
use v5.18;
use warnings;
sub read_line { chomp(my $str = <STDIN>); $str }
sub splited_read_line { split / /, read_line }

my $s = read_line;
my $k = read_line;

sub solve {
    my ($s, $k) = @_;
    my %substrs;
    my $s_len = length $s;
    for my $i ( 0 .. $s_len ) {
        for my $len ( 1 .. $k ) {
            my $substr = substr( $s, $i, $len );
            $substrs{$substr} = 1;
        }
    }
    my @substrs = sort keys %substrs;
    $substrs[$k];
}

say solve($s, $k);


Measured memory_bytes: 3840
#include "bits/stdc++.h"
#define int long long
using namespace std;

const int mod = 1e9 + 7;

int32_t main() {
    string s;
    cin >> s;
    int d;
    cin >> d;
    vector<vector<int>> dp(s.size() + 1, vector<int>(d, 0));
    dp[0][0] = 1;
    for (int i = 0; i < s.size(); i++) {
        for (int j = 0; j < d; j++) {
            for (int k = 0; k < 10; k++) {
                dp[i + 1][(j + k) % d] += dp[i][j];
                dp[i + 1][(j + k) % d] %= mod;
            }
        }
    }
    int ans = 0;
    int cur = 0;
    for (int i = 0; i < s.size(); i++) {
        for (int j = 0; j < s[i] - '0'; j++) {
            ans += dp[s.size() - i - 1][(d - (cur + j) % d) % d];
            ans %= mod;
        }
        cur += s[i] - '0';
        cur %= d;
    }
    if (cur == 0) {
        ans++;
        ans %= mod;
    }
    ans += mod - 1;
    ans %= mod;
    cout << ans << endl;
}


Measured memory_bytes: 11564
import Control.Arrow
import Control.Monad
import Data.List
import qualified Data.ByteString.Char8 as B
import Data.Ord

main :: IO ()
main = readLine >>= print . solve

solve :: [Int] -> Int
solve [n, l] = (n - 1) * l + sum [0..(n - 1)] - v
    where
        v = minimumBy (comparing (abs . (+ l))) [0..(n - 1)]

readLine :: IO [Int]
readLine = unfoldr (fmap (second (maybe B.empty snd . B.uncons)) . B.readInt) <$> B.getLine

readContents :: Int -> IO [[Int]]
readContents = flip replicateM readLine

Measured memory_bytes: 508
#include <bits/stdc++.h>
using namespace std;
#define Rep(i,N) for(int i = 0; i < N;i++)
typedef pair<int,int> Pi;
#define F first
#define S second
#define INF 1 << 28

inline void chmax(int &a,int b) {
  a = max(a,b);
}

inline void chmin(int &a,int b) {
  a = min(a,b);
}

int main()
{
  int N, K;
  while(cin >> N >> K,N || K) {
    int data[100005];
    Rep(i,N)cin >> data[i];
    int sum = 0;
    Rep(i,K)sum += data[i];
    int maxv = sum;
    for(int i = K; i < N; i++) {
      sum += data[i] - data[i - K];
      chmax(maxv,sum);
    }
    cout << maxv << endl;
  }
  return 0;
}

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

int main(){

  int n;
  cin >> n;
  vector<int> V,S;
  for(int i = 0; i < n; i++){
    int p;
    cin >> p;
    S.push_back(p);
  }
  int res = 0;
  int ans = 100000;

for(int j = 0; j < 2; j++){
  V = S;
  for(int i = j; i < n-1; i++){
    while( !(V[i] <= 0) ){
      V[i]--; V[i+1]--;
      res+=2;
    }
  }
  while( !(V[n-1] <= 0) ){
      V[n-1]--; res++;
  }
  while( !(V[0] <= 0) ){
      V[0]--; res++;
  }
  if(j == 0 && S[0] > S[1]) res -= S[0] - S[1];
  ans = min(ans,res);
  //cout << res << " ";
  res = 0;
}
  cout << ans << endl;

  return 0;
}



Measured memory_bytes: 3212
#include<iostream>
#include<string>
using namespace std;
const int maxn = 100001;
string s[maxn];
int n;
char name[5] = { 'M','A','R','C','H' };
long long cnt[5];
int vis[5];
long long total = 0;
void dfs(int cur,long long temp,int pos) {
	if (cur == 3) {
		total += temp; return;
	}
	for (int i = pos; i < 5; i++) {
		if (cnt[i] && !vis[i]) {
			vis[i] = 1;
			temp *= cnt[i];
			dfs(cur + 1, temp,i+1);
			temp /= cnt[i];
			vis[i] = 0;
		}
	}
}
int main()
{
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> s[i];
		for (int j = 0; j < 5; j++) {
			if (s[i][0] == name[j]) {
				cnt[j]++;
				break;
			}
		}
	}
	dfs(0, 1,0);
	cout << total;
	return 0;
}

Measured memory_bytes: 6144
k = int(input())
s = list(range(1, 10))
l = []
while s:
    p = s.pop()
    l.append(p)
    n = p % 10
    for d in range(max(0, n - 1), min(10, n + 2)):
        if p * 10 + d <= 3234566667:
            s.append(p * 10 + d)
l.sort()
print(l[k - 1])


Measured memory_bytes: 47472
import java.util.*;

public class Main {
    public static void main(String[] args) {

        Scanner scanner = new Scanner(System.in);

        int n = scanner.nextInt();
        int k = scanner.nextInt();
        int[] nums = new int[n];
        for(int i = 0; i < n; i++){
            nums[i] = scanner.nextInt();
        }

        int[] dp = new int[n];
        Arrays.fill(dp, Integer.MAX_VALUE);
        dp[0] = 0;
        dp[1] = Math.abs(nums[0] - nums[1]);

        for(int i = 2; i < n; i++){
            for(int j = 1; j <= Math.min(i, k); j++){
                dp[i] = Math.min(dp[i], dp[i - j] + Math.abs(nums[i - j] - nums[i]));
            }
        }
        System.out.println(dp[n - 1]);
    }
}


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

signed main(){
	ll x,k,d;cin>>x>>k>>d;
	x=abs(x);
	ll q=x/d;
	if(q>=k){
		cout<<x-k*d<<endl;
	}
	else{
		x-=q*d;
		k-=q;
		if(k&1)cout<<d-x<<endl;
		else cout<<x<<endl;
	}
}

Measured memory_bytes: 3668
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<cmath>
using namespace std;

template<typename A, typename B> bool chmin(A &a, const B &b){ return b < a && (a = b, true); }
template<typename A, typename B> bool chmax(A &a, const B &b){ return a < b && (a = b, true); }

int main(){
  int a[3];
  cin >> a[0] >> a[1] >> a[2];
  sort(a,a+3);
  if (a[0] == a[1]){
    cout << a[2] << '\n';
  }
  if (a[1] == a[2]){
    cout << a[0] << '\n';
  }
  if (a[0] == a[2]){
    cout << a[1] << '\n';
  }
  return 0;
}

Measured memory_bytes: 256
from __future__ import division, print_function
# import threading
# threading.stack_size(2**27)
# import sys
# sys.setrecursionlimit(10**7)
# sys.stdin = open('inpy.txt', 'r')
# sys.stdout = open('outpy.txt', 'w')
from sys import stdin, stdout
import bisect            #c++ upperbound
import math
import heapq
i_m=9223372036854775807
def inin():
    return int(input())
def stin():
    return input()
def spin():
    return map(int,stin().split())
def lin():                           #takes array as input
    return list(map(int,stin().split()))
def matrix(n):
    #matrix input
    return [list(map(int,input().split()))for i in range(n)]

################################################
def calculate_sum(a, N): #sum of a to N
    # Number of multiples 
    m = N / a 
    # sum of first m natural numbers 
    sum = m * (m + 1) / 2
    # sum of multiples 
    ans = a * sum
    return ans
def series(N):
    return (N*(N+1))//2

def count2Dmatrix(i,list):
    return sum(c.count(i) for c in list)

def modinv(n,p):
    return pow(n,p-2,p)

def GCD(x, y): 
    x=abs(x)
    y=abs(y)
    if(min(x,y)==0):
        return max(x,y)
    while(y): 
        x, y = y, x % y 
    return x
def LCM (x, y):
    return (x * y) // GCD(x, y)
    
def Divisors(n) : 
    l = []  
    for i in range(1, int(math.sqrt(n) + 1)) :
        if (n % i == 0) : 
            if (n // i == i) : 
                l.append(i) 
            else : 
                l.append(i)
                l.append(n//i)
    return l
def isprime(n):
    for i in range(2, int(math.sqrt(n))+1):
        if n%i==0:
            return False
    return True
prime=[]
def SieveOfEratosthenes(n): 
    global prime
    prime = [True for i in range(n+1)] 
    p = 2
    while (p * p <= n): 
        if (prime[p] == True): 
            for i in range(p * p, n+1, p): 
                prime[i] = False
        p += 1
    f=[]
    for p in range(2, n): 
        if prime[p]: 
            f.append(p)
    return f
q=[]       
def dfs(n,d,v,c):
    global q
    v[n]=1
    x=d[n]
    q.append(n)
    j=c
    for i in x:
        if i not in v:
            f=dfs(i,d,v,c+1)
            j=max(j,f)
            # print(f)
    return j
# d = {}
 
"""*******************************************************"""
x, k, d = spin()
x = abs(x)
m = x//d
ans = 0
if m > k:
    ans = x - k * d
else :
    x -= d*m
    k -= m
    if k%2==1:
        x -= d
        ans = abs(x)
    else :
        ans = abs(x)
print(ans)



Measured memory_bytes: 9272
#include <bits/stdc++.h>
#define REP(i, n) for (int (i) = 0; (i) < (int)(n); i++) 
#define FOR(i, a, b) for(int (i) = a; (i) < (int)b; i++)
#define RREP(i, n) for(int (i)=((int)(n)-1); (i)>=0; i--)
#define RFOR(i, a, b) for(int (i) =((int)(b)-1); (i)>=(int)a; i--)
#define ALL(v) (v).begin(),(v).end()
#define MOD 1000000007
#define NIL -1
#define FI first
#define SE second
#define MP make_pair
#define PB push_back
#define SZ(x)  (int)x.size()
#define SP(x)  setprecision((int)x)


using namespace std ;
typedef long long ll;
using Graph = vector<vector<int>>;
typedef vector<int> vint;
typedef vector<vint> vvint;
typedef vector<string> vstr;
typedef pair<int, int> pii;
const int INF = 1e9;
const ll LINF = 1e18;
const double EPS = 1e-9;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
ll gcd(ll a, ll b) {return b ? gcd(b, a % b) : a;} //最大公約数
ll lcm(ll a, ll b) {return a / gcd(a, b) * b;} //最小公倍数

//-------------------------------------------------
// 
void yes(){
  cout <<"Yes"<<endl ;
}
void no(){
  cout <<"No"<<endl ;
}


//-------------------------------------------------
// メモ
/*






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


int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n, k ;
  cin >> n >> k ;
  vector<pair<ll,ll>> pai(n) ;
  REP(i,n){
    ll a, b ;
    cin >> a >> b ;
    pai[i] = MP(a,b) ;
  }
  sort(ALL(pai)) ;
  REP(i,n){
    k -= pai[i].SE ;
    if(k<=0){
      cout << pai[i].FI <<endl ;
      return 0 ;
    }
  }
  
  
  
  return 0 ;
}




Measured memory_bytes: 1792
import java.util.Scanner;

public class Main {

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

		int a = Integer.parseInt(sc.next());
		int b = Integer.parseInt(sc.next());

		if((a+b)%2==0) {
			System.out.println((a+b)/2);
		} else {
			System.out.println("IMPOSSIBLE");
		}
	}
}


Measured memory_bytes: 21972
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<stack>
#include<queue>
#define rep(i,n) for(int i=0;i<(n);i++)
typedef long long ll;
using namespace std;

int main() {
	int n, m;
	cin >> n >> m;
	if (n == m) cout << "Yes" << endl;
	else cout << "No" << endl;
}

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

fun solve(N: Long, M: Long){
    // p/(p-1)(p-1)
    val p = Math.pow(2.toDouble(), M.toDouble()).toInt()
    val ans = p * (1900*M + 100*(N-M))
    println(ans)
    return
}


fun main(args: Array<String>) {
    fun StringArray(size: Int, init: (Int) -> String = { "\u0000" }): Array<String> {
        return Array<String>(size, init)
    }
    class Scanner(stream: InputStream) {
        private val reader = BufferedInputStream(stream).bufferedReader()
        private var st: StringTokenizer? = null
        fun next(): String {
            while (!(st?.hasMoreTokens() ?: false)) st = StringTokenizer(reader.readLine())
            return st!!.nextToken()
        }
    }
    val sc = Scanner(System.`in`)
    val N = sc.next().toLong()
    val M = sc.next().toLong()
    solve(N, M)
}



Measured memory_bytes: 31392
line = STDIN.gets.chomp().split(" ")
a = line[0].to_i
b = line[1].to_i
c = line[2].to_i

h = b * Math.sin(c * Math::PI / 180.0).to_f
s = a * h / 2.to_f


l = (a + b + Math.sqrt((b * Math.cos(c * Math::PI / 180.0) - a) * (b * Math.cos(c * Math::PI / 180.0) - a) + h * h)).to_f

puts s
puts l
puts h

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

#define MAX_N 100

int N;
long long W;
long long w0, w1, w2, w3;
vector<int> vec[4];

long long vsum[4][MAX_N + 1];

int main()
{
	cin >> N >> W;
	for( int i = 0; i < N; i++ ) {
		int w, v;
		cin >> w >> v;
		if( i == 0 ) {
			w0 = w;
		}
		vec[w - w0].push_back( v );
	}

	for( int i = 0; i < 4; i++ ) {
		sort( vec[i].begin(), vec[i].end(), greater<int>() );
	}
	for( int i = 0; i < 4; i++ ) {
		for( int j = 0; j < vec[i].size(); j++ ) {
			vsum[i][j + 1] = vsum[i][j] + vec[i][j];
		}
	}
	w1 = w0 + 1;
	w2 = w0 + 2;
	w3 = w0 + 3;
	long long ans = 0;
	for( int i = 0; i < vec[0].size() + 1; i++ ) {
		for( int j = 0; j < vec[1].size() + 1; j++ ) {
			for( int k = 0; k < vec[2].size() + 1; k++ ) {
				for( int l = 0; l < vec[3].size() + 1; l++ ) {
					if( W >= i * w0 + j * w1 + k * w2 + l * w3 ) {
						ans = max( ans, vsum[0][i] + vsum[1][j] + vsum[2][k] + vsum[3][l] );
					}
				}
			}
		}
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
#include<iostream>
 using namespace std;
 int main()
 {
     string s1= "Rainy",s2="Sunny",s3="Cloudy",s;

     cin>>s;
     if(s==s1)
     {
         cout<<s2<<endl;
     }
     else if(s==s2)
     {
         cout<<s3<<endl;
     }
     else
     {
         cout<<s1<<endl;
     }
 }


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

using namespace std;

int main(){
  int n,k;
  cin>>n>>k;
  vector<int> h(n),d(n,1e9);
  for(int&x : h)
    scanf("%d",&x);

  d[0]=0;
  for(int i=0;i<n;i++){
    for(int j=i+1; j<=(i+k); j++){
      if(j<n)
        d[j] = min(d[j],d[i]+abs(h[i]-h[j]));
    }
  }
  cout<<d[n-1]<<"\n";
}

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

int main() {
    int N;  cin >> N;
    vector<int> L(N);
    int sum = 0;
    for (int i = 0; i < N; ++i) {
        cin >> L[i];
        sum += L[i];
    }
    for (int i = 0; i < N; ++i) {
        if (sum - L[i] <= L[i]) {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
}


Measured memory_bytes: 256
/**
 * Dont raise your voice, improve your argument.
 * --Desmond Tutu
 */

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

const bool ready = [](){
    ios_base::sync_with_stdio(false); cin.tie(0);
    cout << fixed << setprecision(12);
    return true;
}();

const double PI = acos(-1);
using ll= long long;
#define int ll
#define all(v) (v).begin(), (v).end()
#define fori(n) for(int i=0; i<int(n); i++)

#define cini(i) int i; cin>>i;
#define cins(s) string s; cin>>s;
#define cind(d) double d; cin>>d;
#define cinai(a,n) vi a(n); fori(n) { cin>>a[i]; }
#define cinas(s,n) vs s(n); fori(n) { cin>>s[i]; }
#define cinad(a,n) vd a(n); fori(n) { cin>>a[i]; }

using pii= pair<int, int>;
using pdd= pair<double, double>;
using vd= vector<double>;
using vb= vector<bool>;
using vi= vector<int>;
using vvi= vector<vi>;
using vs= vector<string>;

#define endl "\n"

void solve() {
    cins(s);
    int cnt=0;
    int ans=0;
    for(int i=0; i<s.size(); i++)  {
        if(s[i]=='R') {
            cnt++;
            ans=max(ans, cnt);
        } else
            cnt=0;
    }

    cout<<ans<<endl;
}

signed main() {
    solve();
}

// FIRST THINK, THEN CODE
// DO NOT JUMP BETWEEN PROBLEMS


Measured memory_bytes: 3524
import math
N = int(input())
res = []
M = int(math.sqrt(N))

for i in range(1, M + 1):
    if N % i == 0:
        A = int(i)
        B = int(N / i)

        res.append(max([len(str(A)), len(str(B))]))

print(min(res))

Measured memory_bytes: 3060
package main

import "fmt"

func larger(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func ceilDivision(x, y int) int {
	return (x + y - 1) / y
}

func main() {
	var n int
	fmt.Scan(&n)
	ts := make([]int, n)
	as := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&ts[i], &as[i])
	}

	votesT, votesA := ts[0], as[0]
	for i := 1; i < n; i++ {
		n := larger(ceilDivision(votesT, ts[i]), ceilDivision(votesA, as[i]))
		votesT, votesA = ts[i]*n, as[i]*n
	}
	fmt.Println(votesT + votesA)
}


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

using namespace std;
typedef long long ll;
#define int ll

#define REP(i,n) for(int i=0;i<n;++i)
#define SORT(name) sort(name.begin(), name.end())
#define ZERO(p) memset(p, 0, sizeof(p))
#define MINUS(p) memset(p, -1, sizeof(p))
#if 1
#  define DBG(fmt, ...) printf(fmt, ##__VA_ARGS__)
#else
#  define DBG(fmt, ...)
#endif

const ll LLINF = (1LL<<60);
const int INF = (1LL<<30);
const double DINF = std::numeric_limits<double>::infinity();
const int MOD = 1000000007;
#define MAX_N 100010

#define SUBMIT

ll A, B;

ll fact[64] = {};

ll solve() {
    if(A == B) { return A; }

    // fact の計算
    fact[0] = 1;
    for(ll i = 1; i < 64; ++i) { fact[i] = fact[i-1] * 2; }

    ll ans = 0;
    // 一桁目の計算
    {
        ll cnt = 0;
        if(A % 2 == 0) {
            if(B % 2 == 0) { cnt = (B - A) / 2; }
            else { cnt = (B - A + 1) / 2; }
        }
        else {
            if(B % 2 == 0) { cnt = (B - A + 1) / 2; }
            else { cnt = (B - A + 2) / 2; }
        }
        ans = (cnt % 2 == 0) ? 0 : 1;
    }
    for(ll i = 1; i < 60; ++i) {
        // i 桁目の 0/1 入れ替わりスパン
        ll span = fact[i];
        // A から先の i 桁目 1 の数(次に 0 が出るまでの領域)
        ll a_one = 0;
        if((A / span) % 2 == 1) {
            // span で割った時に奇数なら 1 の数が
            // 奇数になる可能性がある
            a_one = span - (A % span);
        }
        // B までの i 桁目の 1 の数(次に 0 が出るまでの領域)
        ll b_one = 0;
        if((B / span) % 2 == 1) {
            b_one = (B % span) + 1;
        }
        // 以上の 2 つを足したものが奇数ならこの桁は 1
        if((a_one + b_one) % 2 == 1) {
            ans |= (1LL << i);
        }
    }
    return ans;
}

ll blute_force() {
    ll ret = 0;
    for(int i = A; i <= B; ++i) {ret ^= i; }
    return ret;
}

signed main()
{
#ifdef SUBMIT
    cin >> A >> B;
    ll ans = solve();
    //ll ans = blute_force();
    printf("%lld\n", ans);
#else
    random_device r;
    mt19937_64 mt(r());
    uniform_int_distribution<ll> dist(0LL, 100000LL);
    REP(loop, 10000) {
        A = dist(mt);
        B = dist(mt);
        if(A > B) { swap(A, B); }
        ll cand = solve();
        ll ans = blute_force();
        if(cand != ans) {
            printf("A: %lld B: %lld cand: %lld ans: %lld\n",
                    A, B, cand, ans);
            return 0;
        }
    }
#endif
    return 0;
}


Measured memory_bytes: 256
# /user/bin/python
# -*- coding: utf-8 -*-


N = int(input())
S = str(input())

num = S[1:].count('E')
ans = num
for i in range(1,N):
  if S[i-1] == 'W':
    num += 1
  if S[i] == 'E':
    num -= 1
  ans = min(ans, num)
print(ans)

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

#define ll long long
#define vvi vector< vector<int> >
#define vi vector<int>
#define All(X) X.begin(),X.end()
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define pb push_back
#define pii pair<int,int>
#define mp make_pair
#define pi 3.14159265359
#define shosu(X) fixed << setprecision(X)
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
const int INF = 1e9;
int data[20][20];
int main(){
	while(1){
		int n;
		cin >> n;
		if(n == 0) break;
		REP(i,20) REP(j,20) data[i][j] = INF;
		REP(i,20) data[i][i] = 0;
		int m = 0;
		REP(i,n){
			int a,b,c;
			cin >> a >> b >> c;
			m = max(m, a+1); m = max(m, b+1);
			data[a][b] = c;
			data[b][a] = c;
		}
		REP(k,m){
			REP(i,m){
				REP(j,m){
					data[i][j] = min(data[i][j], data[i][k] + data[k][j]);
				}
			}
		}
		int sum[20] = {0};
		int nowmin = INF;
		int ans;
		REP(i,m){
			REP(j,m){
				// cout << data[i][j] << " ";
				sum[i] += data[i][j];
			}
			if(nowmin > sum[i]) {
				nowmin = sum[i];
				ans = i;
			}
		}
		cout << ans << " " << sum[ans] << endl;
	}
}

Measured memory_bytes: 1160
//exawiz2019_c.cpp
//Sat Mar 30 20:43:05 2019

#include <iostream>
#include <string>
#include <queue>
#include <map>
#include <unordered_map>
#include <vector>
#include <algorithm>
#include <math.h>
#include <set>
#define INTINF 2147483647
#define LLINF 9223372036854775807
using namespace std;
using ll=long long;
typedef pair<int,int> P;

int main(){
	int n,q;
	cin >> n >> q;
	string s;
	cin >> s;

	char t[q],d[q];
	for (int i=0;i<q;i++){
		cin >> t[i] >> d[i];
	}

	//Left.
	int left = 0;
	for (int i=q-1;i>=0;i--){
		if (t[i]==s[left] && d[i]=='L'){
			left++;
		}else if (left>0 && t[i]==s[left-1] && d[i]=='R'){
			left--;
		}
	}

	//Right.
	int right = n-1;
	for (int i=q-1;i>=0;i--){
		if (t[i]==s[right] && d[i]=='R'){
			right--;
		}else if (right<n-1 && t[i]==s[right+1] && d[i]=='L'){
			right++;
		}
	}

	if (left>right){
		cout << 0 << endl;
	}else {
		cout << n-(left + (n-1-right)) << endl;
	}

}

Measured memory_bytes: 900
#include <vector>
#include <iostream>
#include <cmath>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <fstream>
#include <unistd.h>
#include <string>
#include <numeric>
#include <queue>
#include <deque>
#include <sstream>
#include <iomanip>
#include <set>
#include <stack>
#include <cassert>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<vvb> vvvb;
typedef vector<vvvb> vvvvb;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;
typedef vector<char> vc;
typedef vector<vector<char>> vvc;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<vvd> vvvd;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
typedef vector<P> vp;
typedef vector<PL> vpl;
typedef vector<vector<P>> vvp;
typedef vector<vector<PL>> vvpl;
const int INF = 1001001001;
const ll LINF = 1e16;
const double pi = 3.1415926535897932;
const string endstr = "\n";
#define FOR(i, a, b) for(ll i = (a); i < b; i++)
#define RFOR(i, a, b) for(ll i = (a); i > b; i--)
#define REP(i, n) for(ll i = 0; i < n; i++)
#define RREP(i, n) for(ll i = n-1; i > -1; i--)
#define FORMAP(it, m) for(auto it = m.begin(); it != m.end(); it++)
#define ff first
#define ss second
#define pb push_back
#define epb emplace_back

template <typename T>
T gcd(T a, T b) {
    return (a == 0) ? b : gcd(b%a, a);
}
template <typename T>
T lcm(T a, T b) {
    return a / gcd(a, b) * b;
}

bool p_comp_fs(const PL p1, const PL p2){ return p1.first < p2.first;};
bool p_comp_fg(const PL p1, const PL p2){ return p1.first > p2.first;};
bool p_comp_ss(const PL p1, const PL p2){ return p1.second < p2.second;};
bool p_comp_sg(const PL p1, const PL p2){ return p1.second > p2.second;};
template <typename T>
vector<T> uniquen(vector<T> vec){
    vec.erase(unique(vec.begin(), vec.end()), vec.end());
    return vec;
}


char nxt[305][305];
char cur[305][305];

int main(){
    ll N; cin >> N;
    REP(i, N) REP(j, N) cin >> cur[i][j];
    
    ll ans = 0;
    FOR(c, 0, N){
        bool ok = true;
        
        REP(i, N) REP(j, N){
            nxt[i][j] = cur[(i+1)%N][j];
        }
        
        REP(i, N){
            REP(j, N){
                if(nxt[i][j] != nxt[j][i]){
                    ok = false; break;
                }
            }
            if(!ok) break;
        }
        if(ok){
            ans += N;
        }
        
        REP(i, N) REP(j, N) cur[i][j] = nxt[i][j];
    }
    cout << ans << endstr;
    return 0;
}


Measured memory_bytes: 384
import java.io.*;
import java.math.*;
import java.util.*;
public class Main {
	public static void main(String[] args) {  
		FastScanner I = new FastScanner(); //Input
		OutPut O = new OutPut(); //Output
		int S = 0;
		S+=I.nextInt();
		S+=I.nextInt();
		S+=I.nextInt();
		O.pln(S<22?"win":"bust");
	}
	public static long min(long a, long b) {return Math.min(a,b);}
	public static long max(long a, long b) {return Math.max(a,b);}
	public static long abs(long x, long y) {return Math.abs(x-y);}
	public static long ceil(long num, long den) {long ans = num/den; if (num%den!=0) 
	ans++; return ans;}
	public static long GCD(long a, long b) {
		if (a==0||b==0) return max(a,b);
		return GCD(max(a,b),max(a,b)%min(a,b));
	}
	public static long FastExp(long base, long exp, long mod) {
		long ans=1;
		while (exp>0) {
			if (exp%2==1) ans*=base;
			exp/=2;
			base*=base;
			base%=mod;
			ans%=mod;
		}
		return ans;
	}
	public static long ModInv(long num,long mod) {return FastExp(num,mod-2,mod);}
	public static int pop(long x) { //Returns number of bits within a number
		int cnt = 0;
		while (x>0) {
			if (x%2==1) cnt++;
			x/=2;
		}
		return cnt;
	}
	static class FastScanner {
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st=new StringTokenizer("");
		String next() {
			while (!st.hasMoreTokens())
				try {
					st=new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			return st.nextToken();
		}
		int nextInt() {return Integer.parseInt(next());}
		long nextLong() {return Long.parseLong(next());};
		double nextDouble() {return Double.parseDouble(next());}
	}
	static class OutPut{
		PrintWriter w = new PrintWriter(System.out);
		void pln(double x) {w.println(x);w.flush();}
		void pln(boolean x) {w.println(x);w.flush();}
		void pln(int x) {w.println(x);w.flush();}
		void pln(long x) {w.println(x);w.flush();}
		void pln(String x) {w.println(x);w.flush();}
		void pln(char x) {w.println(x);w.flush();}
		void pln(StringBuilder x) {w.println(x);w.flush();}
		void pln(BigInteger x) {w.println(x);w.flush();}
		void p(int x) {w.print(x);w.flush();}
		void p(long x) {w.print(x);w.flush();}
		void p(String x) {w.print(x);w.flush();}
		void p(char x) {w.print(x);w.flush();}
		void p(StringBuilder x) {w.print(x);w.flush();}
		void p(BigInteger x) {w.print(x);w.flush();}
		void p(double x) {w.print(x);w.flush();}
		void p(boolean x) {w.print(x);w.flush();}
	}
}


Measured memory_bytes: 25548
def check(n, k, w, p):
    i = 0
    for j in range(k):
        s = 0
        while s + w[i] <= p:
            s += w[i]
            i += 1
            if i == n:
                return n
    return i


def solve(n, k, w):
    left = 0
    right = n * max(w)
    while right - left > 1:
        mid = (left + right) // 2
        v = check(n, k, w, mid)
        if v >= n:
            right = mid
        else:
            left = mid

    return right


n, k = [int(i) for i in input().split()]
w = [int(input()) for i in range(n)]
print(solve(n, k, w))


Measured memory_bytes: 9576
#include<bits/stdc++.h>
#define ll long long
using namespace std;
bool a[1000005],b[1000005]; 

int main()
{
      ios_base::sync_with_stdio(false);
      cin.tie(NULL);
    int s;
    cin>>s;
    int h=s/500;
    int k=s-h*500;//cout<<k;
    int g=k/5;
   cout<<h*1000+g*5;
    
  //  cout<<s*2-h;
    }

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
typedef long long ll;
typedef vector<int> vint;
#define rep(i,n) for (ll i = 0; i < (ll)(n); ++i)
#define rrep(i,j,n) for(ll i = (ll)(j); i < (ll)(n); i++)
#define mrep(i,n) for (ll i = (ll)(n); i > 0; i--)
#define be(v) (v).begin(), (v).end()
#define dcout cout << fixed << setprecision(20) 
ll INF = 1LL << 60;
ll mod = 1e9 + 7;

int main() {
	int a,b; char s; cin >> a >> s >> b;
	if(s=='+') cout << a+b << endl;
	else cout << a-b << endl;
}


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

const int nax = 305;
double p[nax][nax][nax], ev[nax][nax][nax];
// ev[a][b][c] - the expected number of operations so far to get to state (a,b,c)
// easier: p-bility of getting to this state at all, p[a][b][c]

int main() {
	int n;
	scanf("%d", &n);
	vector<int> cnt(4);
	for (int i = 0; i < n; ++i) {
		int x;
		scanf("%d", &x);
		++cnt[x];
	}
	p[cnt[1]][cnt[2]][cnt[3]] = 1;
	for (int c = n; c >= 0; --c) {
		for (int b = n; b >= 0; --b) {
			for (int a = n; a >= 0; --a) {
				if (a == 0 && b == 0 && c == 0) {
					continue;
				}
				if (a + b + c > n) {
					continue;
				}
				// dp[a][b][c]

				double p_waste = (double)(n - (a + b + c)) / n;
				// p_waste + p_waste^2 + ... = S
				// 1 + S = S / p_waste
				double ev_waste = p_waste / (1 - p_waste) + 1;
				ev[a][b][c] += ev_waste * p[a][b][c];

				// remove 1 -> dp[a-1][b][c]
				// we will eventually choose one of a+b+c
				if (a != 0) {
					double p_go = (double)a / (a + b + c);
					p[a - 1][b][c] += p[a][b][c] * p_go;
					ev[a - 1][b][c] += ev[a][b][c] * p_go;
				}

				// remove 2 -> dp[a+1][b-1][c]
				if (b != 0) {
					double p_go = (double)b / (a + b + c);
					p[a + 1][b - 1][c] += p[a][b][c] * p_go;
					ev[a + 1][b - 1][c] += ev[a][b][c] * p_go;
				}

				// remove 3
				if (c != 0) {
					double p_go = (double)c / (a + b + c);
					p[a][b + 1][c - 1] += p[a][b][c] * p_go;
					ev[a][b + 1][c - 1] += ev[a][b][c] * p_go;
				}
			}
		}
	}
	printf("%.10lf\n", ev[0][0][0]); // + cnt[1] + 2 * cnt[2] + 3 * cnt[3]);
}

Measured memory_bytes: 438528
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<stack>
#include<algorithm>
#include<cmath>
#include<climits>
#include<string>
#include<set>
#include<numeric>
#include<map>
#include<iostream>
using namespace std;
#define rep(i,n) for(int i = 0;i<((int)(n));i++)
#define reg(i,a,b) for(int i = ((int)(a));i<=((int)(b));i++)
#define irep(i,n) for(int i = ((int)(n)-1);i>=0;i--)
#define ireg(i,a,b) for(int i = ((int)(b));i>=((int)(a));i--)
typedef long long ll;
typedef pair<ll, ll> mp;
ll MOD = 1e9+7;
//LLONG_MIN

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

int main(void){
	int H,W;
	string s[52];
	bool can=true;
	scanf("%d%d",&H,&W);
	rep(i,H){
		cin>>s[i];
	}
	rep(i,H){
		rep(j,W){
			if(s[i][j]=='#'){
				int exist=0;
				rep(k,4){
					if(i+dy[k]>=0 &&
					i+dy[k]<=H-1 &&
					j+dx[k]>=0 &&
					j+dx[k]<=W-1 &&
					s[i+dy[k]][j+dx[k]]=='#'){
						exist++;
					}
				}
				if(exist==0){
					can=false;
					break;
				}
			}
		}
		if(!can)break;
	}
	if(can){
		printf("Yes\n");
	}else{
		printf("No\n");
	}
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define SPEED ios_base::sync_with_stdio(false); cin.tie(NULL);
#define FOR(i, a, b) for (ll i = a; i < b; ++i)
#define RFOR(i, b, a) for (ll i = b; i >= a; --i)
#define ALL(x) x.begin(), x.end()
#define DEBUG(args...) { string _s = #args; replace(ALL(_s), ' ', '\0');\
replace(ALL(_s), ',', ' ');\
stringstream _ss(_s); istream_iterator<string> _it(_ss); _debug(_it, args);}
#define endl "\n"
#define F first
#define S second
#define pb(x) push_back(x)
#define mp(x, y) make_pair(x, y)

using namespace std;
using namespace __gnu_pbds;

template<typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

void _debug(istream_iterator<string>) {}
template<typename T, typename... Args>
void _debug(istream_iterator<string> it, T first, Args... args) {
    cerr << ">> " << *it << " : " << first << endl; _debug(++it, args...);
}
template <typename T1, typename T2>
inline ostream& operator << (ostream& out, const pair<T1, T2>& p) {
    return out << "(" << p.F << ", " << p.S << ")";
}
template<typename T>
inline ostream& operator << (ostream& out, const vector<T>& v) {
    if (v.empty()) return out << "[]";
    else { out << '['; for (auto& e : v) { out << e << ", "; } return out << "\b\b]"; }
}
template<typename T>
inline ostream& operator << (ostream& out, const deque<T>& s) {
    if (s.empty()) return out << "{}";
    else { out << '{'; for (auto& e : s) { out << e << ", "; } return out << "\b\b}"; }
}
template<typename T>
inline ostream& operator << (ostream& out, const unordered_set<T>& s) {
    return out << set<T>(ALL(s));
}
template<typename T1, typename T2>
inline ostream& operator << (ostream& out, const map<T1, T2>& m) {
    if (m.empty()) return out << "{}";
    out << '{'; for (auto& p : m) { out << p << ", "; } return out << "\b\b}";
}
template<typename T1, typename T2>
inline ostream& operator << (ostream& out, const unordered_map<T1, T2>& m) {
    return out << map<T1, T2>(ALL(m));
}
template<typename T>
inline ostream& operator << (ostream& out, const ordered_set<T>& s) {
    return out << set<T>(ALL(s));
}

typedef long long ll;
typedef long double ld;
typedef vector<long long> vll;
typedef pair<ll, ll> pll;
typedef vector<pair<ll, ll>> vpll;
typedef unordered_map<ll, ll> STll;
/************************************** MAIN PROGRAM ********************************************/
const int MAX = 1e5 + 1;
vector<int> adj[MAX];
ll cache[MAX];

ll dfs(int v) {
    if (cache[v] != -1) return cache[v];
    ll val = 0;
    for (int w : adj[v]) {
        val = max(val, 1 + dfs(w));
    }
    return cache[v] = val;
}

int main()
{
    //freopen("input.txt", "r", stdin);
    SPEED
    ll n, m;
    cin >> n >> m;
    memset(cache, -1, sizeof cache);
    FOR(i, 0, m)
    {
        ll u, v;
        cin >> u >> v;
        u--, v--;
        adj[u].pb(v);
    }
    ll ans = 0;
    for (int i = 0; i < n; ++i) {
        ans = max(ans, dfs(i));
    }

    cout << ans;
}
/************************************** END OF PROGRAM ******************************************/


Measured memory_bytes: 8576
package main

import (
	"fmt"
	"os"
)

func run() int {
	var a, b int
	fmt.Scanf("%d\n", &a)
	fmt.Scanf("%d\n", &b)

	answer := []int{1, 2, 3}

	for _, o := range answer {
		if o == a || o == b {
			continue
		}

		fmt.Println(o)
		break
	}
	return 0
}

func main() {
	os.Exit(run())
}


Measured memory_bytes: 512
func readInts() -> [Int] {
    return readLine()!.split(separator: " ").map { Int($0)! }
}

func isAllEven(_ ints: [Int]) -> Bool {
    let existsOdd = ints.contains { (i) -> Bool in
        i % 2 == 1
    }
    return !existsOdd
}

func modAll(_ ints: [Int]) -> [Int] {
    let result = ints.map { (i) -> Int in
        i / 2
    }
    return result
}

func main() {
    let _ = Int(readLine()!)!
    var tmpInts = readInts()
    var count = 0
    var canContinue = isAllEven(tmpInts)
    while canContinue {
        count += 1
        tmpInts = modAll(tmpInts)
        canContinue = isAllEven(tmpInts)
    }
    
    print("\(count)")
}

main()


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

# define C continue;
# define R return

#define int long long
# define D double
# define I insert
# define ld long double
# define ull unsigned long long
# define ui unsigned int

# define pb push_back
# define pf push_front

# define vi vector < int >
# define vc vector < char >
# define vs vector < string >
# define vb vector < bool >
# define vd vector < D >
# define vull vector < ull >
# define vld vector < ld >

# define vvi vector < vector < int > >
# define vvb vector < vector < bool > >
# define vvc vector < vector < char > >
# define vvs vector < vs >
# define vvd vector < vector < D > >
# define vvld vector < vector < ld > >

# define all(v) v.begin() , v.end()
# define allcomp(v) v.begin() , v.end() , comp

# define pii pair < int , int >
# define pll pair < ll , ll >
# define pld pair < ld , ld >
# define pDD pair < D , D >

# define vpld vector < pld >
# define vpii vector < pii >
# define vpDD vector < pDD >

# define vvpii vector < vector < pii > >
# define F first
# define S second
# define mp make_pair

#define PQ(type) priority_queue<type>
#define PQD(type) priority_queue<type, vector<type>, greater<type>>

#define mii map<int, int>
#define mll map<ll, ll>
#define mci map<char, int>
#define msi map<string, int>
#define mis map<int, string>
#define mib map<int, bool>
#define mcb map<char,bool>

#define umii unordered_map<int, int>
#define umll unordered_map<ll, ll>
#define umci unordered_map<char, int>
#define umsi unordered_map<string, int>
#define umis unordered_map<int, string>

#define init(arr,val) memset(arr,val,sizeof(arr))
#define REP(i,a,b) for(int i=a; i<b; i++)
#define distance(a,b,p,q) sqrt((p-a)*(p-a) + (q-b)*(q-b))

# define pp(n) printf("%.10Lf",n);
# define line cout<<"\n";
# define fast ios_base::sync_with_stdio(false) ; cin.tie(0) ; cout.tie(0);

string vow = "aeiou";
int month[] = { -1, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

const int dxhorse[] = { -2, -2, -1, -1, 1, 1, 2, 2};
const int dyhorse[] = {1, -1, 2, -2, 2, -2, 1, -1};

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

const ld pie = 3.1415926535897932384626 ;
const int mod = 1e9 + 7 ;
#define test int t; cin>>t;
# define fast ios_base::sync_with_stdio(false) ; cin.tie(0) ; cout.tie(0);
/// Tip : If a and b are positive integers ; we may say - ceil (a/b) = 1 + floor ( (a-1)/b ) .
void a_b_c()
{
    #ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
    #endif
}

void solve()
{
   int n; cin>>n;
   if(n>=30) cout<<"Yes";
   else cout<<"No";
}
int32_t main()
{	fast
    int t=1;
    //freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
    //int t;  cin>>t;
    for(int i=1; i<=t; i++) solve();

}


Measured memory_bytes: 3632
#include<bits/stdc++.h>
#define ll long long int
#define mod 1000000007
using namespace std;
ll dp[300];
int c[100];
ll solve(int n,int m)
{
	int i;
	if(dp[n]==0)
	{
		for(i=0;i<m;i++)
		{
			if(n-c[i]<0)
			break;
			dp[n]+=solve(n-c[i],m);
		}
	}
	return dp[n];
}

int main(){
 
ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n,i;
    cin>>n;
    int a[n];
    for(i=0;i<n;i++)
    cin>>a[i];
    int min=a[0],count=1;
    for(i=1;i<n;i++)
    {
    	if(a[i]<min)
    	{
    		count++;
    		min=a[i];
		}
	}
	cout<<count;
    
    
    
    
    
    
}


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

#define MAX 3000

struct Point{
	int x,y;
	Point():x(0),y(0){}
	Point(int x, int y):x(x),y(y){}
	bool operator<(const Point &t)const{
		if( x < t.x )
			return true;
		if( x == t.x  && y < t.y )
			return true;
		return false;
	}
	bool operator==(const Point &t)const{
		return x == t.x && y == t.y;
	}
};
int main(){
	while(true){
		int n;
		int ans = 0;
		map< Point, int > xy;
		Point p[MAX];
		
		scanf("%d", &n);
		if( n == 0 ) break;
		for(int i = 0; i < n; ++i){
			scanf("%d%d", &p[i].x, &p[i].y);
			xy[ p[i] ] = 1;	
		}

		for(int i = 0; i < n; ++i){
			for(int j = 0; j < n; ++j){
				if( i != j ){
					int dx = p[j].x - p[i].x;
					int dy = p[j].y - p[i].y;
					if( dx >= 0 && dy <= 0 ){
						dy = -dy;
						Point p2(p[j].x + dy, p[j].y + dx);
						Point p3(p[i].x + dy, p[i].y + dx);

						if( xy.find( p2 ) != xy.end() && xy.find( p3 ) != xy.end() ){
							ans = max( ans, dx*dx + dy*dy );
						}
					}
				}
			}
		}
		printf("%d\n", ans);
	}
	return 0;
}

Measured memory_bytes: 1040
#include <bits/stdc++.h>
typedef long long int LL;
typedef unsigned long long int ULL;
using namespace std;

// 插入此處

char s[4005];

int main() {
    int n;
    scanf("%d", &n);
    scanf("%s", s);
    LL r = 0, g = 0, b = 0;
    LL rg = 0, gb = 0, br = 0;
    LL rgb = 0;
    for (int i = 0; i < n; i++) {
        if (s[i] == 'R') {
            r++;
            rg += g;
            br += b;
            rgb += gb;
        }
        if (s[i] == 'G') {
            g++;
            rg += r;
            gb += b;
            rgb += br;
        }
        if (s[i] == 'B') {
            b++;
            gb += g;
            br += r;
            rgb += rg;
        }
    }
    LL ans = rgb;
    for (int dis = 1; dis <= n; dis++) {
        for (int i = 0; i + dis * 2 < n; i++) {
            if (s[i] != s[i + dis] && s[i + dis] != s[i + dis * 2] && s[i + dis * 2] != s[i]) {
                ans--;
            }
        }
    }
    printf("%lld\n", ans);
}


Measured memory_bytes: 3812