akhauriyash/Code-Regression huggingface dataset:
from collections import deque

H, W = map(int, input().split())
Ch, Cw = map(lambda x: x - 1, map(int, input().split()))
Dh, Dw = map(lambda x: x - 1, map(int, input().split()))
S = []
already = []
yet = 1000000
for i in range(H):
    S.append(input())
    already.append([yet] * W)
queue = deque()
queue.append((Cw, Ch, 0))
already[Ch][Cw] = 0
answer = -1
while len(queue) > 0:
    #print(queue)
    #print(already)
    x, y, cost = queue.popleft()
    #print(x, y, cost)
    if x == Dw and y == Dh:
        answer = cost
        break
    for i in range(-2, 3):
        for j in range(-2, 3):
            new_x, new_y = (x + i, y + j)
            # 場外
            if new_x < 0 or new_y < 0 or W <= new_x or H <= new_y:
                continue
            # 動かない
            if new_x == x and new_y == y:
                continue
            # 壁
            if S[new_y][new_x] == '#':
                continue
            # 探索済み
            if already[new_y][new_x] <= cost:
                continue
            if (i == 0 and j == -1) \
            or (i == 0 and j == 1) \
            or (i == 1 and j == 0) \
            or (i == -1 and j == 0):
                queue.appendleft((new_x, new_y, cost))
                already[new_y][new_x] = cost
            else:
                queue.append((new_x, new_y, cost+1))
                already[new_y][new_x] = cost+1
print(answer)

Measured memory_bytes: 228396
#pragma warning(disable:4996)
#pragma comment(linker, "/STACK:336777216")
#pragma GCC optimize("Ofast")

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <functional>

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
#define int long long int
typedef complex<long double> cd;
const long double pi=acos(-1);
typedef double db;
typedef long double ldb;
typedef pair <int, int> pii;
typedef pair <db, db> pdd;
typedef vector<int> vi;
typedef vector<vector<int> > matrix;

#define m1 make_pair
#define pb push_back
#define flush fflush(stdout)
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);
#define reset(x,v) memset(x,v,sizeof(x))

#define fi first
#define se second
#define endl "\n"
#define debug(x) (cerr << #x << ": " << x << "\n")
#define setbits(x) __builtin_popcount(x)
#define setbitsll(x) __builtin_popcountll(x)
#define all(x) x.begin(),x.end()
#define pii pair<int,int>

inline ll gcd(ll a,ll b){if(a==0) return b;return gcd(b%a,a);}
inline ll power(ll a,ll n,ll m){if(n==0)return 1;ll p=power(a,n/2,m);p=(p%m*p%m)%m;if(n%2) return (p%m*a%m)%m;else return p;}
const ll MOD =998244353;
const ll hell=1000000007;
const int INF = 1e17;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
typedef tree<int, null_type, less<int>, rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;
const int N=200005;
multiset<int>s;vi adj[N+1];int a[N];int ans[N+1];

void dfs(int u,int p)
{
    auto it=s.lower_bound(a[u]);
    int toerase= -1;
    if(it!=s.end())
    {
        toerase=(*it);
        s.erase(it);
    }
    s.insert(a[u]);
    ans[u]=s.size();
    for(int v:adj[u])
        if(v!=p)
            dfs(v,u);
    s.erase(s.find(a[u]));
    if(toerase!= -1)
        s.insert(toerase);
}
void solve()
{
    int n;
    cin>>n;
    int u,v;
    for(int i=1;i<=n;i++)
        cin>>a[i];
    for(int i=0;i<n-1;i++)
    {
        cin>>u>>v;
        adj[u].pb(v);
        adj[v].pb(u);
    }
    dfs(1,0);
    for(int i=1;i<=n;i++)
        cout<<ans[i]<<endl;
}


int32_t main()
{
    IOS;
    
    int t;
    t=1;
    /// cin>>t;
    while(t--)
    {
        solve();
    }
    return 0;
}




Measured memory_bytes: 31972
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<utility>
#include<cmath>
#include<climits>
#include<queue>
#include<stack>
#include<numeric>
#include<set>
#include<iomanip>
#include<map>
#include<type_traits>
#include<tuple>
#include<deque>
#include<cassert>
using namespace std;
typedef long long ll;
typedef pair<ll,int> P;
#define rep(i,N) for(ll (i)=0;(i)<(N);(i)++)
const int mod = 1000000007;
const int INF = 1001001001;

int main(){
  int h, w;
  cin >> h >> w;
  vector<string> s(h);
  rep(i, h) cin >> s[i];
  vector<vector<int>> cnt(h, vector<int>(w));
  rep(i, h) {
    rep(j, w) {
      int r = j;
      
      while(r < w && s[i][r] != '#') {
        ++r;
      }
      int diff = r - j;
      while (j < r) {
        cnt[i][j] = diff;
        ++j;
      }
    }
  }
  
  rep(j, w) {
    rep(i, h) {
      int d = i;
      while (d < h && s[d][j] != '#') {
        ++d;
      }
      int diff = d - i;
      while (i < d) {
        cnt[i][j] += diff;
        ++i;
      }
    }
  }

  int ans = 0;
  rep(i, h) {
    rep(j, w) {
      ans = max(ans, cnt[i][j]);
    }
  }
  cout << ans - 1 << endl;
}

Measured memory_bytes: 20096
#include <bits/stdc++.h>
#include <cstdio>
 
using namespace std;
using ll = long long;
 
#define rep(i, a) for (int i = 0; (i) < (int) (a); (i)++)
#define reps(i, a, b) for (int i = (int) (a); (i) < (int) (b); (i)++)
#define rrep(i, a) for (int i = (int) a-1; (i) >= 0; (i)--)
#define rreps(i, a, b) for (int i = (int) (a)-1; (i) >= (int) (b); (i)--)
#define MP(a, b) make_pair((a), (b))
#define PB(a) push_back((a))
#define all(v) (v).begin(), (v).end()
#define PERM(v) next_permutation(all(v))
#define UNIQUE(v) sort(all(v));(v).erase(unique(all(v)), v.end())
#define CIN(type, x) type x;cin >> x
#define TRUE__  "Yes"
#define FALSE__ "No"
#define PRINT(f) if((f)){cout << (TRUE__) << endl;}else{cout << FALSE__ << endl;}
#define RS resize
#define CINV(v, N) do {\
	v.RS(N);\
	rep(i, N) cin >> v[i];\
} while (0);
#define RCINV(v, N) do {\
	v.RS(N);\
	rrep(i, N) cin >> v[i];\
} while (0);
 
#define MOD 1000000007
void init();
void solve();

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

int H, W;

void init()
{
	cin >> H >> W;
}

void solve()
{
	rep(i, H) {
		rep(j, W) {
			string s;
			cin >> s;
			if (s == "snuke") {
				cout << (char) ('A' + j) << i+1 << endl;
				return;
			}
		}
	}
}



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

#define int long long
int A[223456];

signed main(){
  int n,p;string s;cin>>n>>p>>s;
  if(p==2||p==5){
    int a=0;
    for(int i=0;i<s.size();i++)if((s[i]-'0')%p==0)a+=i+1;
    cout<<a<<endl;return 0;
  }
  reverse(s.begin(),s.end());
  for(int i=0,t=1;i<s.size();i++){
    int a=s[i]-'0';
    A[i+1]=(A[i]+a*t)%p;
    (t*=10)%=p;
  }
  map<int,int> m;
  for(int i=0;i<=s.size();i++)m[A[i]]++;
  int ans=0;
  for(auto p:m)ans+=p.second*(p.second-1)/2;
  cout<<ans<<endl;
}


Measured memory_bytes: 2564
#include<cstdio>
#include<iostream>
#include<cmath>
#include<cstring>

using namespace std;

int main(){
	int A,B,K,n=0;
	scanf("%d %d %d",&A,&B,&K);
     	 while(n != K ){
     	 if(A % 2 != 0 ){
     	 	 A--;
     	 	 A = A / 2;
     	 	 B = B + A;
     	 	 n++;
     	 	 if(n == K)  break;
     	 	 }
     	 	 else{
     	 	 	 A = A / 2;
     	 	 	 B = B + A;
     	 	 	 n++;
     	 	 	 if(n == K) break;

     	 	 	 }
     	     if(B % 2 != 0){
     	     	 B--;
     	     	 B = B / 2;
     	     	 A = A + B;
                 n++;
                 if(n == K) break;

     	     	 }
     	     	 else{
     	     	 	 B = B / 2;
     	     	 	 A = A + B;
     	     	 	 n++;
                     if(n == K) break;
                     }
     	     	 	 }
     	 
     	 printf("%d %d\n",A,B);
     	 return 0;
	}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll,string>;
using Map = map<string,ll>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;


int main(){
  string N;
  cin >> N;
  ll check=0;
  for(ll i=0;i<3;i++){
    if(N[i]=='7'){check=1;break;}
  ;}
  if(check)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
return 0;
}


Measured memory_bytes: 3624
#B
n = int(input())
s = [input() for _ in range(n)]
ac = 0
wa = 0
tle = 0
re = 0

for i in s:
    if i == "AC":
        ac += 1
    if i == "WA":
        wa += 1
    if i == "TLE":
        tle += 1
    if i == "RE":
        re += 1

print('AC x' , ac)
print('WA x' , wa)
print('TLE x' , tle)
print('RE x' , re)

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

using namespace std;

using ll = long long;
using ull = unsigned long long;

int n,m;
std::vector<string> a,b;

bool check(int x, int y){
	for (int i = 0; i < m; i++) {
		for (int j = 0; j < m; j++) {
			if (a[x+i][y+j] != b[i][j]) {
				return false;
			}
		}
	}
	return true;
}

int main(int argc, char const *argv[]) {
	std::cin >> n >> m;
	a.resize(n);
	b.resize(m);
	for (size_t i = 0; i < a.size(); i++) {
		std::cin >> a[i];
	}
	for (size_t i = 0; i < b.size(); i++) {
		std::cin >> b[i];
	}

	for (int i = 0; i <= n-m; i++) {
		for (int j = 0; j <= n-m; j++) {
			if (a[i][j] == b[0][0]) {
				if (check(i, j)) {
					std::cout << "Yes" << '\n';
					return 0;
				}
			}
		}
	}

	std::cout << "No" << '\n';
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define mp make_pair
#define PII pair<int,int>
#define fi first
#define se second
#define pb push_back
#define ll long long
#define ull unsigned long long
#define ui unsigned int
#define sci(x) scanf("%d",&x)
#define scs(s) scanf("%s",s)
#define scc(c) scanf("%c",c)
#define scd(d) scanf("%lf",&d)
#define scld(ld) scanf("%Lf",&ld)
using namespace std;

//********************************************
//Error tracking
#define show(args...) { vector<string> _v = split(#args, ','); err(_v.begin(), args); }

vector<string> split(const string& s, char c) {
    vector<string> v;
    stringstream ss(s);
    string x;
    while (getline(ss, x, c))
        v.emplace_back(x);
    return move(v);
}

void err(vector<string>::iterator it) {}
template<typename T, typename... Args>
void err(vector<string>::iterator it, T a, Args... args) {
    cerr << it -> substr((*it)[0] == ' ', it -> length()) << " = " << a << '\n';
    err(++it, args...);
}
//********************************************

const int NMAX = 100005;

int n, a[NMAX], b[NMAX];
int sol;

int main()
{
 //   freopen("input","r",stdin);
//    freopen("output","w",stdout);
    cin.sync_with_stdio(false);
    
    int i;
    cin >> n;
    for (i = 1; i <= n; i++) 
    {
        cin >> a[i];
        if (a[i] == i) b[i] = 1;
    }

    for (i = 1; i <= n; i++)
    {
        int j = i, cnt = 0;
        while (j <= n && b[j] == 1)
        {
            j++;
            cnt++;
        }

        sol += cnt / 2;
        if (cnt & 1) sol++;
        i = j;
    }

    cout << sol << "\n";  
    return 0;   
}

Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner stdIn = new Scanner(System.in);
		
		int M = stdIn.nextInt();
		
		System.out.println((24-M)+24);

	}

}


Measured memory_bytes: 35792
#include "bits/stdc++.h"
using namespace std;

int main(){
	//freopen("input.txt","r",stdin);
	int a,b;
	cin >> a >> b;
	if (a>b){
		cout << "No" << endl;
	}
	else if (a==b){
		cout << "Yes" << endl; 
	}
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
 int x;
  cin >> x;
  int happy = 0;
  while(1){
    if(x>=500){
      x-=500;
      happy+=1000;
    }
    else if(x>=5){
      x-=5;
      happy+=5;
    }
    else if(x<5) break;
  }
  cout << happy << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include<string>
#include<cctype>
using namespace std;
int main(void){
    // Your code here!
     int a,b;
     cin>>a>>b;
     string c;
     cin>>c;
     c[b-1]=tolower(c[b-1]);
     cout<<c;
  return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <iostream>
#include <cmath>
#include <bits/stdc++.h>
#include <set>
#include <string>
#include <cstring>
#include <string>
#define rep(i,n) for (int i = 0; i < (n); i++)
#define FIXED_FLOAT(x)  std::fixed <<std::setprecision(7)<<(x)
#define MAX 100
#define fast ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define INF 1e9
#define ll long long
#define vi vector<int>
#define all(a) a.begin(), a.end()
#define pb push_back
#define ull unsigned long long


using namespace  std;
const int N = 1e3 + 5;


void solve(){
    ll n;
    cin >> n;
    ll p =100, nas = 0;
    while(p < n) {
        p *= 1.01;
        nas++;
    }
    cout << nas << '\n';
}
int main() {
    fast;
    solve();

}



Measured memory_bytes: 3664
x,y = map(int,input().split())
ans = 0
if x == 3:
         ans += 100000
elif x == 2:
         ans += 200000
elif x == 1:
         ans += 300000
if y == 3:
         ans += 100000
elif y == 2:
         ans += 200000
elif y == 1:
         ans += 300000
if x == 1 and y == 1:
         ans += 400000
print(ans)



Measured memory_bytes: 3060
#include <stdio.h>
long long unsigned int kaijou(int n)
{
	if(n==0)return 1;
	return kaijou(n-1)*n;
}
int main(void)
{
	int i;
	scanf("%d",&i);
	printf("%llu\n",kaijou(i));
	return 0;
}

Measured memory_bytes: 596
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {

	static BufferedReader reader;
	//static field here
	
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		reader = new BufferedReader(new InputStreamReader(System.in));
		//code here
		String[] strings = readLine();
		int A1 = Integer.parseInt(strings[0]);
		int A2 = Integer.parseInt(strings[1]);
		int A3 = Integer.parseInt(strings[2]);
		if(A1+A2+A3>=22) {print("bust");}
		else {print("win");}
		//String[] s = readLine();
		//print(num);
	}
	
	//functions here
	//note that all methods should be STATIC

	private static String[] readLine(){
		try{
			return reader.readLine().split(" ");
		}catch(Exception e){
			e.printStackTrace();
			return new String[]{e.getMessage()};
		}
	}
	private static void print(Object o){
		System.out.println(o);
	}
	private static void print(){
		System.out.println();
	}
}


Measured memory_bytes: 21204
#include<bits/stdc++.h>
#define rep(i,k,n) for(ll i= (ll) k;i< (ll) n;i++)
#define all(v) (v).begin(), (v).end()
#define SZ(v) (int)((v).size())
#define pb push_back
#define ft first
#define sd second
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const long long INF = 1e18L + 1;
const int IINF = 1e9 + 1;

using namespace std;

template<class TH> void _dbg(const char *sdbg, TH h){ cerr<<sdbg<<'='<<h<<endl; }
template<class TH, class... TA> void _dbg(const char *sdbg, TH h, TA... a) {
  while(*sdbg!=',')cerr<<*sdbg++;cerr<<'='<<h<<','; _dbg(sdbg+1, a...);
}

#ifdef LOCAL
#define DBG(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#else
#define DBG(...) (__VA_ARGS__)
#define cerr if(0)cout
#endif

int main() {
	#ifndef LOCAL
    ios_base::sync_with_stdio(0);
    cin.tie(0);
	#endif
	int n, k;
	cin >> n >> k;
	cout << (n - 1) / (k - 1) + ((n - 1) % (k - 1) != 0); 
}


Measured memory_bytes: 256
n, m, x ,y = map(int, input().split())
l_x = list(map(int, input().split()))
l_y = list(map(int, input().split()))

if max(l_x)>=min(l_y) or max(l_x)>=y or min(l_y)<=x:
    print("War")
else:
    print("No War")

Measured memory_bytes: 3060
#![allow(non_snake_case)]
use std::collections::VecDeque;

fn main() {
    let s = std::io::stdin();
    let mut sc = Scanner { stdin: s.lock() };
    let N:usize = sc.read();
    let M:usize = sc.read();
    let mut E: Vec< Vec<usize>> = vec![vec![];N];
    let mut Vcount:Vec<usize> = vec![0;N];

    for _ in 0..(N+M-1) {
        let mut a:usize = sc.read();
        let mut b:usize = sc.read();
        a -= 1;
        b -= 1;
        E[a].push(b);
        Vcount[b] += 1;
    }
    let mut q:VecDeque<usize> = VecDeque::new();
    for i in 0..N{
        if Vcount[i] == 0{
            q.push_back(i);
        }
    }
    let mut ans:Vec<usize> = vec![N;N];

    while let Some(v) = q.pop_front(){
        for &w in E[v].iter(){
            Vcount[w] -= 1;
            if Vcount[w] == 0{
                q.push_back(w);
                ans[w] = v;
            }

        }
    }
    for i in 0..N{
        if ans[i] == N{
            println!("0");
        }else{
            println!("{}", ans[i]+1);
        }
    }

}

pub struct Scanner<R> {
    stdin: R,
}

impl<R: std::io::Read> Scanner<R> {
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .stdin
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n')
            .take_while(|&b| b != b' ' && b != b'\n')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
        .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}




Measured memory_bytes: 15100
import java.util.*;

public class Main{
  public static void main(String[]args){
    Scanner sc = new Scanner(System.in);
    String S = sc.next();
    int s = S.length();
    
    String T = "";
    for(int i = 0; i < s; i++){
      if(i == 0){
        T = T+String.valueOf(S.charAt(0));
      }else{
        T = T + "9";
      }
    }
    
    long a = Long.parseLong(S);
    long b = Long.parseLong(T);
    int ans = 0;
    if(a < b){
      ans += 9*(s-1);
      ans += S.charAt(0)-'1';
    }else{
      ans += 9*(s-1);
      ans += S.charAt(0)-'0';
    }
    System.out.println(ans);
  }
}

Measured memory_bytes: 22868
K, N = map(int, input().split())
A = list(map(int, input().split()))

maximum = 0
for i in range(1, N):
    maximum = max(A[i] - A[i - 1], maximum)

tmp = (K - A[-1]) + A[0]
maximum = max(tmp, maximum)

print (K - maximum)

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

int main(){
  long long X,K,D;
  cin >> X >> K >> D;
  X=abs(X);
  long long A=X/D;
  if(A>=K){
    cout << X-K*D << endl;
    return 0;
  }
  K-=A;
  X-=A*D;
  if(K%2==0){
    cout << X << endl;
  }
  else{
    cout << abs(X-D) << endl;
  }
}
  

Measured memory_bytes: 3644
#include <stdio.h>
#include <math.h>

int main(void){
	int n;
	double x, y;
	double shahen;
	double theta;

	while(1){
		scanf("%d", &n);
		if(n == -1) break;

		x = 1;
		y = 1;
		shahen = sqrt(x*x + y*y);
		x = shahen;
		theta = M_PI/4.0;
		for(int i=0; i<n-2; i++){
			shahen = sqrt(x*x + y*y);
			theta += atan(y/x);
			x = shahen;
		}
		x = shahen * cos(theta);
		y = shahen * sin(theta);

		printf("%f\n%f\n", x, y);
	}

	return 0;
}

Measured memory_bytes: 0
#define NDEBUG
NDEBUG


#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cstring>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <memory>
#include <queue>
#include <random>


using namespace std;

template<class T>
using vec = std::vector<T>;

template<class T>
using vec2d = std::vector<std::vector<T>>;


template<class T>
vec2d<T> makeVec2d(const int n1, const int n2, const T initValue) {
  return vec2d<T>(n1, vec<T>(n2, initValue));
}


// TC_REMOVE_BEGIN
/// caide keep
bool __hack = std::ios::sync_with_stdio(false);
/// caide keep
auto __hack1 = cin.tie(nullptr);
// TC_REMOVE_END


// Section with adoption of array and vector algorithms.


//#include <ext/pb_ds/tree_policy.hpp>
//#include <ext/pb_ds/assoc_container.hpp>
//
//template <class T> using StdTree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;


namespace template_util {
    

    constexpr int bytecount(uint64_t x) {
        return x ? 1 + bytecount(x >> 8) : 0;
    }

    template<int N>
    struct bytetype {
        
    };

    
    /// caide keep
    template<uint64_t N>
    struct minimal_uint : bytetype<bytecount(N)> {
    };
}


template<class T>
T next(istream& in) {
    T ret;
    in >> ret;
    return ret;
}

template<class T>
vector<T> next_vec(istream& in, size_t n) {
  vector<T> ret(n);
  for (size_t i = 0; i < n; ++i) {
    ret[i] = next<T>(in);
  }
  return ret;
}


void solve(istream& in, ostream& out) {
  auto n = next<int>(in);
  auto a = next_vec<int64_t>(in, n);
  vec2d<int> u = makeVec2d<int>(n, n, 0);
  vec2d<int64_t> dp = makeVec2d<int64_t>(n, n, 0);

  function<int64_t(int, int)> rec = [&] (int le, int ri) -> int64_t {
    int eaten = le + (n - 1 - ri);
    if (le == ri) {
      if (eaten % 2 == 0) {
        return a[le];
      } else {
        return -a[le];
      }
    }
    if (u[le][ri]) {
      return dp[le][ri];
    }

    auto& res = dp[le][ri];
    u[le][ri] = 1;

    if (eaten % 2 == 0) {
      auto cutLeft = a[le] + rec(le + 1, ri);
      auto cutRight = a[ri] + rec(le, ri - 1);
      res = max(cutLeft, cutRight);
      return res;
    } else {
      auto cutLeft = -a[le] + rec(le + 1, ri);
      auto cutRight = -a[ri] + rec(le, ri - 1);
      res = min(cutLeft, cutRight);
      return res;
    }
  };

  out << rec(0, n-1) << "\n";

}

//#include <fstream>


int main() {
//  ifstream fin("bridges.in");
//  ofstream fout("bridges.out");
    solve(cin, cout);
//  solve(fin, fout);
    return 0;
}



Measured memory_bytes: 106368
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

/**
 *
 * @author k16069kk
 */
public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String line;
        String out = "";
        int a = 0;
        int b = 0;
        while ((line = br.readLine()) != null) {
            java.util.StringTokenizer st = new StringTokenizer(line, " ");

            while (st.hasMoreTokens()) {
                a = Integer.parseInt(st.nextToken());
                b = Integer.parseInt(st.nextToken());

                if (a < b) {
                    out = a + " " + b;
                } else {
                    out = b + " " + a;
                }
            }
            if (a == 0 && b == 0) {
                break;
            }
            System.out.println(out);

        }

    }
}



Measured memory_bytes: 27048
from collections import deque
n, m = map(int,input().split())
d = [[] for i in range(n)]
#print(d)
for i in range(m):
    a, b = map(int,input().split())
    a -= 1
    b -= 1
    d[a].append(b)
    d[b].append(a)
#print(d)
def bfs():
    flg = [True] * n
    ans = [0] * n
    flg[0] = False
    que = deque([0])
    #print(flg)
    while len(que) != 0:
        val = que.popleft()
        #print(d[val2])
        #print(flg)
        #print(ans)
        #print(val)

        for i in range(len(d[val])):
            if flg[d[val][i]] == True:
                que.append(d[val][i])
                flg[d[val][i]] = False
                ans[d[val][i]] = val
    return ans
ans = bfs()
#print(ans)
print('Yes')
for i in range(1,n):
    print(ans[i]+1)


Measured memory_bytes: 34652
#include "bits/stdc++.h"
using namespace std;
int s[510][510];
int main(){
    int n,m,q;cin>>n>>m>>q;
    int l,r;
    for (int i=0; i<m; ++i){
        cin>>l>>r;
        ++s[l][r];
    }
    for (int i=1; i<=n; ++i)for (int j=1; j<=n; ++j)
        s[i][j]+=s[i-1][j]+s[i][j-1]-s[i-1][j-1];
    for (int i=0; i<q; ++i){
        cin>>l>>r;
        cout<<s[r][r]-s[r][l-1]-s[l-1][r]+s[l-1][l-1]<<endl;
    }
}

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

int main() {
  int x,y;
  cin >> x >> y;
  int value = 4 * x - y;
  if(value % 2 == 0 && value >= 0 && value <= 2*x){
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 3624
#include<iostream>
#include<algorithm>
#include<iomanip>
#include<queue>
#include<vector>
#include<complex>
#include<map>
#include<set>
using namespace std;
#define int long long
vector<int> SS;
int hs(vector<int> &X) {
	int res = 0;
	for (int i = 0; i < X.size(); i++) {
		res += X[i];
		res *= 10;
	}
	return res;
}
signed main() {
	int N;
	cin >> N;
	vector<int> A(N);
	for (int i = 0; i < N; i++) {
		cin >> A[i];
		A[i]--;
	}

	queue<int > qu;
	map<int, int> mp;
	vector<int> B(N);
	for (int i = 0; i < N; i++) {
		B[i] = i;
	}
	int pow10[12];
	pow10[0] = 1;
	for (int i = 1; i <= 11; i++) {
		pow10[i] = pow10[i - 1] * 10;
	}
	mp[hs(B)] = 0;

	qu.push(hs(B));
	/*{
		int r = 5;
		int l = 0;
		int hh = hs(B);
		hh += pow10[N - l] * (B[r] - B[l]);
		hh += pow10[N - r] * (B[l] - B[r]);
		swap(B[l], B[r]);
		cerr << hh << " " << hs(B) << endl;
	}*/
	vector<int> t(N);
	vector<int> t2;
	int cnt = 0;
	int l, r;
	int z = 0;
	while (!qu.empty()) {

		z = qu.front(); qu.pop();
		int h;
		h = z;
		z /= 10;
		for (int i = N - 1; i >= 0; i--) {
			t[i] = z % 10;
			z /= 10;
		}
		
		int ht = h;
		int a = mp[h];
		/*if (cnt % 100000 == 0) {
			cerr << a << " " << qu.size() << " " << mp.size() << endl;
		}
		cnt++;*/
		//cerr << h << endl;
		for (int i = 0; i < N; i++) {

			for (int j = 1; j <= 2; j++) {
				l = i;
				r = i + j;
				h = ht;
				while (l >= 0 && r < N) {
					h += pow10[N - l] * (t[r] - t[l]);
					h += pow10[N - r] * (t[l] - t[r]);
					//cerr << h << " " << l << " " << r << endl;
					auto m = mp.find(h);
					if (m == mp.end() || (*m).second > a + 1) {
						mp[h] = a + 1;
						if (a + 1 <= 4) {
							qu.push(h);
						}
					}
					l--;
					r++;
				}
			}
		}
		//break;
	}
	vector<int> C(N);
	for (int i = 0; i < N; i++) {
		C[A[i]] = i;
	}
	int res = 9;
	int p = 0;
	for (auto t : mp) {
		p = t.first;
		p /= 10;
		for (int i = N - 1; i >= 0; i--) {
			B[i] = C[p % 10];
			p /= 10;
		}
		auto k = mp.find(hs(B));
		if (k != mp.end()) {
			res = min(res, t.second + (*k).second);
		}
	}
	cout << res << endl;
}


Measured memory_bytes: 82332
def inpl(): return [int(i) for i in input().split()]

def trapezoid(St, En, H, i):
    if St+H[i][0] >= En-H[i][0]:
        return (En-St)**2/4
    result = H[i][0]*(En-St-H[i][0])
    if H[i][1] > St + H[i][0]:
        result += trapezoid(St+H[i][0],min(En-H[i][0],H[i][1]),H,i+1)
    if H[i][2] < En - H[i][0]: 
        result += trapezoid(max(St+H[i][0],H[i][2]),En-H[i][0],H,i+1)       
    return result

N = int(input())
t = inpl()
v = inpl()
H = [[v[0], 0, t[0]]]
for i in range(1,N):
    H.append([v[i], H[i-1][2], H[i-1][2]+t[i]])

H.append([float('inf'), 0, 0])
H.sort(key = lambda x: x[0])
for i in range(N,0,-1):
    H[i][0] -= H[i-1][0]    
print(trapezoid(0,sum(t), H, 0))

Measured memory_bytes: 3064
#include <algorithm>
#include <climits>
#include <iostream>
#include <string>
#include <utility>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <iomanip>

using namespace std;
using ll = long long int;

template <class T> ostream &operator<<(ostream &os, vector<T> &v) {
  for (auto i = v.begin(); i != v.end(); i++) {
    os << *i << " ";
  }
  return os;
}

string f(ll x) {
  string s = to_string(x);
  return s.insert(0, 3-s.size(), '0');
}

void solve(long long N, string S){
  ll ans = 0;
  for(ll i=0; i<1000; i++) {
    string x = f(i);
    ll p = 0;
    for(auto it = S.begin(); it!=S.end(); ++it) {
      if(*it==x[p]) {
	if(p==2) {
	  ans++;
	  break;
	} else {
	  p++;
	}
      }
    }
  }
  std::cout << ans << std::endl;
}

int main(){
  long long N;
  scanf("%lld",&N);
  string S;
  cin>>S;
  solve(N, S);
  return 0;
}



Measured memory_bytes: 384
N, M = map(int, input().split())
AB = [list(map(int, input().split())) for i in range(N)]

AB.sort()

sum_d = 0
cost = 0
for i in range(N):
  sum_d += AB[i][1]
  cost += AB[i][0] * AB[i][1]
  if sum_d >= M:
    cost -= (sum_d - M) * AB[i][0]
    break
print(cost)

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

#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define MIN(a) *min_element(all(a))
#define MAX(a) *max_element(all(a))
#define SUM(a, b) accumulate(all(a), b)
#define REP(i, n) for(int (i)=0; (i)<(n); (i)++)
#define RREP(i, n) for(int (i)=(n)-1; (i)>=0; (i)--)
#define FOR(i, m, n) for(int (i)=(m); (i)<(n); i++)
#define FORR(i, m, n) for(int (i)=(n)-1; (i)>=(m); i--)
#define ios() cin.tie(0), ios::sync_with_stdio(false)
#define debug(x) cerr << #x << " = " << x << endl
//#define int long long

typedef long long ll;
typedef unsigned long long ull;
//ll const MOD = 998244353;
ll const MOD = 1e9+7;
ll const INF = 1e18;

template<typename T> int size(const T& a){return (int)a.size();}
template<typename T> T Div(T a, T b){return (a + b - 1) / b;}
template<typename T> bool chmin(T& a, const T& b){if(a > b){a = b; return true;} return false;}
template<typename T> bool chmax(T& a, const T& b){if(a < b){a = b; return true;} return false;}



signed main(){
    int a, b;
    cin >> a >> b;
    int ans = 0;
    if(a <= 5){
        ans = 0;
    }else if(a <= 12){
        ans = b / 2;
    }else{
        ans = b;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i,n) for(int i=n; i>-1; --i)
#define ALL(a) (a).begin(),(a).end()
#define INIT(a,n,x); REP(i,(n)){ (a)[i]=(x); }
#define CINA(a,n); REP(i,(n)){ cin >> (a)[i]; }
#define INIT2(a,n,m,x); REP(i,(n)){ REP(j,(m)){(a)[i][j]=(x);} }
#define CINA2(a,n,m); REP(i,(n)){ REP(j,(m)){cin >> (a)[i][j];} }
#define LINY "YES\n"
#define Liny "Yes\n"
#define LINN "NO\n"
#define Linn "No\n"
#define umap unordered_map
//std::cout << std::setfill('0') << std::right << std::setw(4) << 12; // "0012"

ll min(ll x,ll y){return (x<y ? x:y);}
ll max(ll x,ll y){return (x>y ? x:y);}
int keta(ll x){ if(x<10){return 1;} else{return keta(x/10) + 1;}}
int keta_wa(ll x){ if(x<10){return x;} else{return keta_wa(x/10) + x%10;} }
int ctoi(char c){ return ( (c>='0' && c<='9')? c - '0': 0 );}
ll gcd(ll a,ll b){if(a<b)swap(a,b); return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){if(a<b){swap(a,b);} return a*b /gcd(a,b);}

int N,A,B,C;
int l[10];
int dfs(int point,int a,int b,int c){
  if(point==N){
    if(a==0 || b==0 || c==0) return pow(10,9);
    return abs(a-A)+abs(b-B)+abs(c-C);
  }
  int use_idx = point;
  ++point;
  int r0 = dfs(point, a, b, c);
  int r1 = dfs(point, a+l[use_idx], b, c)+ (a?10:0);
  int r2 = dfs(point, a, b+l[use_idx], c)+ (b?10:0);
  int r3 = dfs(point, a, b, c+l[use_idx])+ (c?10:0);
  return min( min(r0,r1), min(r2,r3) );
}

int main(){
  cin>>N>>A>>B>>C;
  CINA(l,N);
  cout << dfs(0,0,0,0);
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <utility>
#include <cmath>
#include <iomanip>
#include <queue>
#include <map>
#include <set>
#include <random>
#include <sstream>
#include <stack>
#include <deque>

using namespace std;

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

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

int main() {
    int N;
    cin >> N;
    vi p_list;
    vi used((int)55556, 0);
    set<int> p_map;
    vi wa;
    int c = 0;
    REP(i,2,(int)55555) {
        if (!used[i]) {
            p_list.push_back(i);
            p_map.insert(i);
            for (int j = 2; j*i <= 55555; j++) {
                used[j*i] = 1;
            }
        }
    }
    vi ans;
    int n = 0;
    for (int p : p_list) {
        if (p % 10 == 1) {
            ans.push_back(p);
            n++;
        }
        if (n == N) break;
    }

    rep(i,N) cout << ans[i] << " ";
    cout << endl;

    return 0;
}

Measured memory_bytes: 768
#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
#define endl "\n"
#define sz(x) ((ll)(x).size())
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define prt(x) cout << (x)
#define prtl(x) cout << (x) << endl
#define rep(i,a,b) for(ll i=a; i<b; i++)
#define rrep(i,a,b) for(ll i=a; i>b; i--)
#define mp(a, b) make_pair(a, b)
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define debug(v) cout << #v<< ": " << v <<endl;
using namespace std;
using vi = vector<int>;
using vll = vector<long long int>;
using vb = vector<bool>;
using vvb = vector<vector<bool>>;
using vc = vector<char>;
using vvi = vector<vector<int>>;
using vvll = vector<vector<long long int>>;
using vvc = vector<vector<char>>;
using ll = long long int;
using P = pair<long long int, long long int>;
using Map = map<long long int, long long int>;
ll INF = 1LL<<60;
ll M = 1000000007;

class Radix {
private:
  const char* s;
  int a[128];
public:
  Radix(const char* s = "0123456789ABCDEF") : s(s) {
    int i;
    for(i = 0; s[i]; ++i)
      a[(int)s[i]] = i;
  }
  std::string to(long long p, int q) {
    int i;
    if(!p)
      return "0";
    char t[64] = { };
    for(i = 62; p; --i) {
      t[i] = s[p % q];
      p /= q;
    }
    return std::string(t + i + 1);
  }
  std::string to(const std::string& t, int p, int q) {
    return to(to(t, p), q);
  }
  long long to(const std::string& t, int p) {
    int i;
    long long sm = a[(int)t[0]];
    for(i = 1; i < (int)t.length(); ++i)
      sm = sm * p + a[(int)t[i]];
    return sm;
  }
};

string bist(ll n, ll dig){
    Radix r;
    string p = r.to(n, 2);
    string q = "";
    if(p.size() < dig){
        for(int i=0; i<dig - p.size(); i++){
            q += '0';
        }
        p = q + p;
    }
    return p;
} //［警告］nbaseの呼び出しを先にすること

int main(){
    ll h, w, k; cin >> h >> w >> k;
    vvc m(h, vc(w));
    rep(i, 0, h){
        rep(j, 0, w){
            cin >> m[i][j];
        }
    }
    ll ans = 0;
    rep(i, 0, pow(2, h+w)){
        string s = bist(i, h+w);
        vvc v = m;
        rep(j, 0, h){
            if(s[j] == '1'){
                rep(l, 0, w){
                    v[j][l] = '.';
                }
            }
        }
        rep(j, h, h+w){
            if(s[j] == '1'){
                rep(l, 0, h){
                    v[l][j-h] = '.';
                }
            }
        }
        ll c = 0;
        rep(j, 0, h){
            rep(l, 0, w){
                if(v[j][l] == '#'){
                    c++;
                }
            }
        }
        if(c == k){
            ans++;
        }
    }
    prtl(ans);
}



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

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

#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define br() p("")
#define pn(s) cout << (#s) << " " << (s) << endl
#define p_yes() p("Yes")
#define p_no() p("No")

const ll mod = 1e9 + 7;
const ll inf = 1e18;

template < typename T >
void vprint(T &V){
	for(auto v : V){
    	cout << v << " ";
	}
	cout << endl;
}

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

    // input
    ll N;
    cin >> N;
    vector<ll> A(N);
    FOR(i, 0, N){
        cin >> A.at(i);
    }

    vector<ll> C(10001);
    for(ll a : A){
        C[a]++;
    }

    vector<ll> Ans;
    FOR(i, 0, 10001){
        while(C[i]--){
            Ans.push_back(i);
        }
    }

    cout << Ans[0];
    FOR(i, 1, N){
        cout << ' ' << Ans[i];
    }
    cout << endl;
    
    return 0;
}


Measured memory_bytes: 34932
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main()
{
    ll n;
    cin>>n;
    
    if(n%1000==0)
    {cout<<0<<endl;return 0 ;}
    
    int x = 1000 - n%1000;
cout<<x<<endl;
    
}

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

int main(){
  int N;
  cin>>N;
  
  map<int,int64_t> S;
  for(int i=0;i<N;++i){
    int64_t s;
    cin>>s;
    ++S[s];
  }

  int count=0;
  for(auto p:S){
    if(p.second%2!=0){
      ++count;
    }
  }
  
  cout<<count<<endl;
}

Measured memory_bytes: 6528
import math

n, d = map(int, input().split())
xy = [map(int, input().split()) for _ in range(n)]
x, y = [list(i) for i in zip(*xy)]

count = 0
for i in range(n):
    if math.sqrt(x[i]**2+y[i]**2) <= d:
        count += 1

print(count)

Measured memory_bytes: 116744
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define int long long
#define fr(i,a,b) for(int i=a;i<b;i++)
#define frn(i,a,b) for(int i=a;i>=b;i--)
#define vi vector<int>
#define pii pair<int,int>
#define vpi vector<pair<int,int>>
#define vvi vector<vector<int>>
#define test int t;cin>>t; while(t--)
#define mp make_pair
#define pb push_back
#define pu push
#define fi first
#define se second
#define mod 1000000007
typedef tree<int, null_type, less<int>, rb_tree_tag,
        tree_order_statistics_node_update> seti;
void fast() {
    ios_base::sync_with_stdio(false); cin.tie(NULL);
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
}

int32_t main()
{
    //fast();
    string s;
    cin>>s;
    int n = s.length();
    int ans = 0;
    fr(i,0,n){
        int j = 0;
        while(s[i]=='R' && i<n){
            i++;
            j++;
        }
        ans = max(ans,j);
    }
    cout<<ans;
    return 0;
}

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

typedef complex<double> P;
const double eps=1.0e-10;
bool ip(P a,P b){return abs(a.real()*b.real()+a.imag()*b.imag())<eps;}

int main(void){
	P p[4];
	while(1){
		rep(i,4){
			double x,y;
			cin >> x >> y;
			p[i]={x,y};
		}
		if(cin.eof()) break;
		if(ip(p[1]-p[0],p[3]-p[2]))
			puts("YES");
		else
			puts("NO");
	}
	return 0;
}

Measured memory_bytes: 1184
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cassert>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
using namespace std;


typedef long long i64;
const i64 inf = (i64)1.05e18;

pair<i64, int> compute(int pos, vector<i64>& xs, vector<pair<i64,int>>& memo)
{
	const int n = xs.size();
	if(pos >= n) return {0LL, n};
	auto& val = memo[pos];

	if(val.first != -inf)
		return val;

	val = {xs[pos], n};

	for(int p = pos + 2; p < n; p += 2) {
		auto t = compute(p, xs, memo);
		t.first += xs[pos];
		t.second = p;
		val = max(val, t);
	}

	return val;
}

int main()
{
	int n;
	vector<i64> as;

	scanf("%d", &n);
	as.resize(n);
	for(int i = 0; i < n; ++i)
		scanf("%lld", &as[i]);

	vector<pair<i64,int>> memo(n, pair<i64,int>(-inf, n));
	i64 best = -inf;
	int start = n;

	for(int i = 0; i < n; ++i) {
		auto t = compute(i, as, memo);
		if(t.first > best) {
			best = t.first;
			start = i;
		}
	}

	int last = start;
	while(true) {
		int next = compute(last, as, memo).second;
		if(next >= n)
			break;
		last = next;
	}

	vector<int> op;

	for(int i = n - 1; i > last; --i)
		op.push_back(i + 1);
	for(int i = 0; i < start; ++i)
		op.push_back(1);

	int it = start;

	while(it < last) {
		int next = compute(it, as, memo).second;
		int diff = next - it;
		while(diff > 2) {
			op.push_back(3);
			diff -= 2;
		}
		op.push_back(2);
		it = next;
	}

	printf("%lld\n%d\n", best, (int)op.size());
	for(auto o : op)
		printf("%d\n", o);

	return 0;
}

/* waffle */


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

int main(){
    int n,d;
    cin >> n >> d;
    int ans;
    if(n%(2*d+1)==0){
        ans=n/(2*d+1);
    }
    else{
        ans=n/(2*d+1)+1;
    }

    cout << ans << endl;
    

    return 0;
}

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

// TYPEDEF
// ----------------------------------------
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> Pair;
typedef vector<ll> vll;
typedef vector<vector<ll>> Graph;
typedef vector<string> vs;
typedef vector<pair<ll, ll>> Pll;
typedef queue<ll> qll;

// REPEAT
// ----------------------------------------
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define REPA(i,a) for(ll i=0;i<(ll)(a.size());i++);
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define COUT(a) cout << (a) << endl;
#define ENDL(a) cout << endl;
#define COUTA(i,a) for(ll i=0;i<(ll)(a.size());i++) {cout << (a)[i] << " ";} cout << endl;

// UTIL
// ----------------------------------------
#define pb push_back
#define paired make_pair
#define ALL(a) (a).begin(),(a).end()
#define SORT(a) sort((a).begin(),(a).end())
#define RSORT(a) sort((a).rbegin(), (a).rend())

// DEBUG
// ----------------------------------------
#ifdef _DEBUG
#define debug(x) cout << "[debug] " << #x << ": " << x << endl
#else
#define debug(x)
#endif

template <typename T>
void debugV(const vector<T> v) {
#ifdef _DEBUG
  rep(i, v.size()) {
    cout << i << ":" << v[i] << " ";
  }
  cout << endl;
#else
  (void)v;
#endif
}

// BIT FLAG
// ----------------------------------------
const unsigned int BIT_FLAG_0 = (1 << 0); // 0000 0000 0000 0001
const unsigned int BIT_FLAG_1 = (1 << 1); // 0000 0000 0000 0010
const unsigned int BIT_FLAG_2 = (1 << 2); // 0000 0000 0000 0100
const unsigned int BIT_FLAG_3 = (1 << 3); // 0000 0000 0000 1000
const unsigned int BIT_FLAG_4 = (1 << 4); // 0000 0000 0001 0000
const unsigned int BIT_FLAG_5 = (1 << 5); // 0000 0000 0010 0000
const unsigned int BIT_FLAG_6 = (1 << 6); // 0000 0000 0100 0000
const unsigned int BIT_FLAG_7 = (1 << 7); // 0000 0000 1000 0000
const unsigned int BIT_FLAG_8 = (1 << 8); // 0000 0001 0000 0000
const unsigned int BIT_FLAG_9 = (1 << 9); // 0000 0010 0000 0000
const unsigned int BIT_FLAG_10 = (1 << 10); // 0000 0100 0000 0000
const unsigned int BIT_FLAG_11 = (1 << 11); // 0000 1000 0000 0000

// CONST
// ----------------------------------------
constexpr ll INF = 0x3f3f3f3f3f3f3f3f;
constexpr double PI=3.14159265358979323846; // or M_PI
constexpr int MOD = 1000000007;


void Main() {
  string s;
  cin >> s;
  if (s == "SUN") {
    COUT(7);
  }
  else if (s == "MON") {
    COUT(6);
  }
  else if (s == "TUE") {
    COUT(5);
  }
  else if (s == "WED") {
    COUT(4);
  }
  else if (s == "THU") {
    COUT(3);
  }
  else if (s == "FRI") {
    COUT(2);
  }
  else if (s == "SAT") {
    COUT(1);
  } 
}

int main()
{
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
}

/*

3 2
*/


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

int main(){
    char str[20];
    int l;
    
    scanf("%s",str);
    l = strlen(str);
    for (l=l-1; l>=0; l--) {
        printf("%c",str[l]);
    }
    printf("\n");
    return 0;
}

Measured memory_bytes: 520
#include <bits/stdc++.h>
typedef long long int lint;

#define PI acos(-1)
#define INF64 1LL << 60
#define INF32 1 << 29
#define LIMIT(d_in, d_min, d_max) max(d_min, min(d_max, d_in))
#define all(a) (a).begin(), (a).end()
#define INV ((long long int)1000000007)

using namespace std;

struct UnionFind
{
	vector<int> data;
	vector<int> size;

	UnionFind(int n)
	{
		size = vector<int>(n, 1);
		for (int i = 0; i < n; i++)
		{
			data.push_back(i);
		}
	}

	int Root(int n)
	{
		if (data[n] == n)
			return n;

		return Root(data[n]);
	}

	void Union(int n, int m)
	{
		n = Root(n);
		m = Root(m);

		if (Check(n, m))
			return;

		if (size[n] < size[m])
			swap(n, m);

		size[n] += size[m];
		data[m] = n;
	}

	bool Check(int n, int m)
	{
		return Root(n) == Root(m);
	}

	int Size(int n)
	{
		return size[Root(n)];
	}
};

void execute()
{
	int N, M, K;
	cin >> N >> M >> K;

	UnionFind u = UnionFind(N);
	vector<set<int>> frend(N);
	vector<vector<int>> enemy(N);
	for (int i = 0; i < M; i++)
	{
		int a, b;
		cin >> a >> b;
		a--;
		b--;
		u.Union(a, b);
		frend[a].insert(b);
		frend[b].insert(a);
	}

	for (int i = 0; i < K; i++)
	{
		int a, b;
		cin >> a >> b;
		a--;
		b--;
		enemy[a].push_back(b);
		enemy[b].push_back(a);
	}
	for (int i = 0; i < N; i++)
	{
		int count = u.Size(i);
		count -= frend[i].size();
		for (int j = 0; j < enemy[i].size(); j++)
		{
			if (u.Check(i, enemy[i][j]))
			{
				if (frend[i].find(enemy[i][j]) == frend[i].end())
				{
					count--;
				}
			}
		}
		cout << count - 1 << " ";
	}
	cout << endl;
	return;
}

int main()
{
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	std::cout << std::fixed << std::setprecision(15);
	execute();

	int stop;
	cin >> stop;

	return 0;
}

Measured memory_bytes: 20856
#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <array>
#include <algorithm>
#include <set>
#include <iomanip>
#include <cstdio>

using namespace std;

#define int long long

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

    int a, s, d;

    cin >> a >> s >> d;

    cout << min(a* s, d) << endl;

}

Measured memory_bytes: 256
using System;

namespace atcoderA
{
    class Program
    {
        static void Main(string[] args)
        {
            var input = Console.ReadLine().Split(' ');
            int A = int.Parse(input[0]);
            int B = int.Parse(input[1]);
            Console.WriteLine(A + B >= 10 ? "error" : (A + B).ToString());
        }
    }
}

Measured memory_bytes: 13140
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define ff first
#define ss second
typedef long long ll;
ll power(ll a, ll b){//a^b
    ll res=1;
    a=a%MOD;
    while(b>0){
        if(b&1){res=(res*a)%MOD;b--;}
        a=(a*a)%MOD;
        b>>=1;
    }
    return res;
}
ll fermat_inv(ll y){return power(y,MOD-2);}
ll gcd(ll a, ll b){return (b==0)?a:gcd(b,a%b);}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll t=1;
    //cin>>t;
    while(t--){
        int n;
        cin>>n;
        ll a[n];
        for(int i=0;i<n;i++)
            cin>>a[i];
        int ans=0;
        ll curr=1000;
        for(int i=0;i+1<n;i++){
            int j=i;
            while(j+1<n&&a[j+1]>=a[j]){
                j++;
            }
            ll val=max(0ll,a[j]-a[i])*(curr/a[i]);
            curr+=val;
            i=j;
        }
        cout<<curr<<"\n";
    }
    return 0;
}

Measured memory_bytes: 3648
#include <iostream>

using namespace std;

int main(){
	int n, asco, bsco;
	int a[10000], b[10000];

	while (cin >> n, n != 0){

		asco = bsco = 0;

		for (int i = 0; i < n; i++){
			cin >> a[i] >> b[i];
			
			if (a[i] == b[i]){
				asco += a[i];
				bsco += b[i];
			}
			else if(a[i] > b[i]){
				asco += a[i] + b[i];
			}
			else {
				bsco += a[i] + b[i];
			}
		}

		cout << asco << " " << bsco << endl;
	}
	return 0;
}

Measured memory_bytes: 3164