akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
template<class T> using vc = vector<T>;
template<class T> using vvc = vector<vector<T>>;

#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define repr(i, n) for (ll i = (n)-1; i >= 0; i--)
#define repe(i, l, r) for (ll i = (l); i < (r); i++)
#define reper(i, l, r) for (ll i = (r)-1; i >= (l); i--)
#define repa(i,n) for (auto& i: n)

template<class T> inline bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
void init() {cin.tie(0);ios::sync_with_stdio(false);cout << fixed << setprecision(15);}

#ifdef DEBUG
template <class T, class N> void verr(const T& a, const N& n) { rep(i, n) cerr << a[i] << " "; cerr << "\n" << flush; }
ll dbgt = 1; void err() { cerr << "passed " << dbgt++ << "\n" << flush; }
template<class H, class... T> void err(H&& h,T&&... t){ cerr<< h << (sizeof...(t)?" ":"\n") << flush; if(sizeof...(t)>0) err(forward<T>(t)...); }
#endif

const ll INF = 5e18;
const ld EPS = 1e-11;
const ld PI = acos(-1.0L);
const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
//--------------------------------------------------------------------------------//
ll V[90005];
pair<ll, ll> P[90005];
int main() {
    init();
    ll H, W, D;
    cin >> H >> W >> D;
    rep(i,H)rep(j,W){
        ll a;
        cin >> a;
        P[a] = {i, j};
    }

    rep(i,D){
        ll v = H * W - i;
        while(v-D>0){
            V[v] = abs(P[v].first - P[v - D].first) + abs(P[v].second - P[v - D].second);
            v -= D;
        }
    }    

    rep(i,D){
        ll v = i + 1;
        while(v+D<=H*W){
            V[v + D] += V[v];
            v += D;
        }
    }

    ll Q;
    cin >> Q;
    rep(q,Q){
        ll l, r;
        cin >> l >> r;
        cout << V[r] - V[l] << '\n';
    }

    
}

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

using namespace std;
#define int long long
#define pb push_back
#define fio ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define vin(vec) for(auto &elem:vec)cin>>elem
#define vi vector<int>
template<class L,class R> ostream& operator<<(ostream& cout,pair<L, R> P)
{return cout<<'('<<P.first<<','<< P.second<<')';}
template<class T> ostream& operator<<(ostream& cout,vector<T> V)
{cout<<"[ ";for(auto v:V)cout<<v<<' ';return cout<<']';}
#define show(x) cout<<#x<<" : "<<x<<'\n';


signed main(){
	fio;
	int t=1;
	// cin>>t;
	while(t--){
		int n, cap;
		cin>>n>>cap;
		vector<int> w(n); 		
		vector<int> v(n);
		for(int i=0; i<n; i++){
			cin>>w[i]>>v[i];
		}
		vector<vector<int>> dp(cap+1, vector<int>(n+1, 0));

		for(int i=1; i<=cap; i++){
			for(int j=n-1; j>=0; j--){
				dp[i][j]=dp[i][j+1];
				if(i-w[j]>=0)
					dp[i][j]=max(dp[i][j], dp[i-w[j]][j+1]+v[j]);
			}
		}
		cout<<dp[cap][0]<<'\n';
	}
}

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

int main(void) {
    int A,B;

      cin >> A>>B;

      if(A>8||B>8){
        cout<<":(" << endl ;
      }else{
          cout<<"Yay!" << endl ;
      }


    return 0;
}


Measured memory_bytes: 256
import sys
import math
#from queue import *
#import random
#sys.setrecursionlimit(int(1e6))
input = sys.stdin.readline
 
############ ---- USER DEFINED INPUT FUNCTIONS ---- ############
def inp():
    return(int(input()))
def inara():
    return(list(map(int,input().split())))
def insr():
    s = input()
    return(list(s[:len(s) - 1]))
def invr():
    return(map(int,input().split()))
################################################################
############ ---- THE ACTUAL CODE STARTS BELOW ---- ############

n=inp()
ara=inara()
ans=0

for i in range(0,n,2):
	if ara[i]%2:
		ans+=1

print(ans)

Measured memory_bytes: 62208
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A;
  int B;
  int C;
  int D;
  cin >> A >> B >> C >> D;

  if (A + B > C + D) {
    cout << "Left" << endl;
  }  
  else if (A + B < C + D) {
    cout << "Right" << endl;
  }
  else {
    cout << "Balanced" << endl;
  }
}  

Measured memory_bytes: 256
#include <stdio.h>

int main(int argc, const char * argv[]) {
    int a,b,c;
    scanf("%d %d %d",&a,&b,&c);
    if (a<b && b<c) {
        printf("Yes\n");
    }
    else {
        printf("No\n");
    }
    return 0;
}


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

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

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main() {
    char s[4] = {0};
    scanf("%s", s);
    if (strcmp(s, "AAA") == 0 || strcmp(s, "BBB") == 0) {
        printf("No");
    } else {
        printf("Yes");
    }
    return 0;
}

Measured memory_bytes: 128
a=0
w=0
t=0
r=0
for _ in range(int(input())):
    p=input()
    
    if p=="AC":
        a+=1
    elif p=="TLE":
        t+=1
    elif p=="WA":
        w+=1
    else:
        r+=1
print("AC","x",a) 


print("WA","x",w) 
print("TLE","x",t) 
print("RE","x",r) 

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

int main() {
  string S;
  cin >> S;
  int count=0;
  if(S.size()%2!=0) {
    cout << "No" <<endl;
    return 0;
  }
  for(int i=0; i<S.size(); i++) {
    if(i%2==0 && S.at(i)=='h') {
      count++;
    }
    if(i%2==1 && S.at(i)=='i') {
      count++;
    }
  }
  if(count==S.size()) {
    cout << "Yes" <<endl;
  }
  else {
    cout << "No" <<endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void){
  int x,y,a=0;
  scanf("%d%d",&x,&y);
  if(x>y){
    a+=x;
    x--;
  }else{
    a+=y;
    y--;
  }
  
    if(x>y){
    a+=x;
      x--;
  }else{
    a+=y;
      y--;
  }
  
  printf("%d",a);
  
  return 0;
  
  
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define chmin(a, b) ((a)=min((a), (b)))
#define chmax(a, b) ((a)=max((a), (b)))
#define fs first
#define sc second
#define eb emplace_back
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;

const ll MOD=1e9+7;
const ll INF=1e18;
const double pi=acos(-1);
const double eps=1e-10;

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

int main(){
    string s; cin>>s;
    int n=s.size();
    stack<char> st;
    int ans=0;
    for(int i=0; i<n; i++){
        while(i<n && st.size() && (char)s[i]!=st.top()){
            i++;
            ans+=2;
            st.pop();
        }
        st.push(s[i]);
    }
    cout << ans << endl;
}

Measured memory_bytes: 512
#include<stdio.h>
#include<algorithm>
using namespace std;
int main()
{
	int a[201][201];
	int i2,i,n, m,o[300], x[300], y[300], z[300],i3;
	scanf("%d %d", &n, &m);
	for (i = 1; i <= n; i++)
		scanf("%d", &o[i]);
	for (i = 1; i <= m; i++)
		scanf("%d %d %d", &x[i], &y[i], &z[i]);
	for (i = 0; i <= n; i++)
	for (i2 = 0; i2 <= m; i2++)
		a[i][i2] = -1;
	for (i = 1; i <= m; i++){
		if (o[1] >= x[i] && o[1] <= y[i]){
			a[1][i] = 0;
		}	
	}

	for (i = 1; i <= n; i++){
		for (i2 = 1; i2 <= m; i2++){
			if (a[i][i2] >= 0){
				for (i3 = 1; i3 <= m; i3++){
					if (o[i + 1] >= x[i3] && o[i + 1] <= y[i3])
						a[i + 1][i3] = max(a[i][i2] + abs(z[i2] - z[i3]), a[i + 1][i3]);


				}
			}
		}
	}
		/*for (i = 1; i <= n; i++){
			for (i2 = 1; i2 <= m; i2++){
				printf("%3d", a[i][i2]);
			}
			printf("\n");
		}*/
		int ma = 0;
		for (i = 1; i <= m; i++){
			if (a[n][i] > ma)
				ma = a[n][i];
		}
		printf("%d\n", ma);
	
}

Measured memory_bytes: 1192
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <iostream>
using namespace std;

int int_sort(const void*a,const void *b){
    return *(int*)b-*(int*)a;
}
int even[100001]={};
int odd[100001]={};

int main(){
    int a,b;
    int max_ev=0,max_od=0,sec_ev=0,sec_od=0;
    int max1=1,max2=1;
    int sum1,sum2,sum3;
    
    
    cin >>a;
    for(int i=1;i<a+1;i++){
        if(i%2==1){
            cin >> b;
            odd[b]+=1;
        }
        else{
            cin>>b;
            even[b]+=1;
        }
    }
    
    for(int i=1;i<=100000;i++){
        if(odd[max1]<odd[i]) max1=i;
        if(even[max2]<even[i]) max2=i;
        
    }
    qsort(even,100001,sizeof(even[0]),int_sort);
    qsort(odd,100001,sizeof(odd[0]),int_sort);
    max_ev=even[0]; max_od=odd[0];
    sec_ev=even[1]; sec_od=odd[1];
    
    sum1=a-(max_ev+sec_od);
    sum2=a-(sec_ev+max_od);
    sum3=a-(max_od+max_ev);
    
    if( max1!=max2){
        printf("%d\n",sum3);
    }
    
    else if(sum1<=sum2){
        printf("%d\n",sum1);

    }
    else{
        printf("%d\n",sum2);
    }
    return 0;
}


Measured memory_bytes: 1364
import sys
readline = sys.stdin.readline

N = int(readline())
A = [0] * N
B = [0] * N
C = [0] * N
for i in range(N):
  A[i],B[i] = map(int,readline().split())
  C[i] = (A[i] + B[i], i)
  
C = sorted(C, key = lambda x:x[0], reverse = True)

ans = 0
for i in range(len(C)):
  if i % 2 == 0:
    ans += A[C[i][1]]
  else:
    ans -= B[C[i][1]]
    
print(ans)

Measured memory_bytes: 32588
#include <bits/stdc++.h>
#define cina(a, n) for (int i = 0; i < n; ++i){ cin >> a[i]; }
#define ll long long

using namespace std;

int main () {
	
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	ll x;
	cin >> x;
	ll a = 100, i = 0;
	while (a < x) {
		a += a / 100;
		i++;
	}
 	cout << i;
	return 0;
}

Measured memory_bytes: 3572
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
using namespace std;
int main(){
	long long x,ans;cin>>x;
	ans=2*(x/11);
	x%=11;
	if(x>6)ans++;
	if(x>0)ans++;
	cout<<ans<<endl;
	return 0;	
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("O3")
#define REP(i,n) for(int i=0;i<n;i++)
#define REPP(i,n) for(int i=1;i<=n;i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define EPS (1e-9)
#define INF (1e17)
#define PI (acos(-1))
//const double PI = acos(-1);
//const double EPS = 1e-15;
//long long INF=(long long)1E17;
#define i_7 (long long)(1e9+7)
//#define i_7 998'244'353
long mod(long a){
    long long c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
long long po(long a, long b){
    if(b==0){
        return 1;
    }
    
    long long z = po(a,b/2);
    z = mod(z*z);
    if(b%2!=0){
        z = mod(a*z);
    }
    return z;
}
 
bool prime_(int n){
  if(n==1){
    return false;
  }else if(n==2){
    return true;
  }else{
    for(int i=2;i<=std::sqrt(n);i++){
      if(n%i==0){
        return false;
      }
    }
    return true;
  }
}
 
long long gcd_(long long a, long long b){
  if(a<b){
    std::swap(a,b);
  }
  if(a%b==0){
    return b;
  }else{
    return gcd_(b,a%b);
  }
}
 
long long lcm_(long long x, long long y){
  return (x/gcd_(x,y))*y;
}
 
//using namespace std;
//using namespace boost::multiprecision;
//using namespace __gnu_pbds;
 
int main(){
  using namespace std;
  int x;
  cin>>x;
  int ans = 0;
  ans += (x / 500) * 1000;
  ans += ((x % 500) / 5) * 5;
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
N=int(input())
A=list(map(int,input().split()))
l=[]
cnt=0
for i in range(N):
    if A[i]<0:
        cnt+=1
        l.append(A[i])
wa=0
l_ab=[]
for i in range(N):
    wa+=abs(A[i])
    l_ab.append(abs(A[i]))
if cnt%2!=0:
    wa-=2*min(l_ab)

print(wa)
    
    
    


Measured memory_bytes: 14224
#include <iostream>
#include <string>

using namespace std;

int main(){	
	string input;
	cin >> input;
	
	while(input != "-"){
		int m,b;
		cin >> m;
		for(int i=0; i<m; ++i){
			cin >> b;
			input = input + input.substr(0,b);
			input = input.erase(0,b);
		}
		
		cout << input << endl;
		cin >> input;
	}
}


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

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

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

    if (rate < 1200) {
        cout << "ABC" << endl;
    } else {
        cout << "ARC" << endl;
    }
    
    return 0;
}

Measured memory_bytes: 3608
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<queue>
#include<stack>
#include<cmath>	

using namespace std;

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

	for (int i = 0; i < N; ++i) {
		int a;
		a = A[i];
		int j = i - 1;
		while (j >= 0 && a < A[j]) {
			A[j + 1] = A[j];
			--j;
		}
		A[j + 1] = a;
		for (int k = 0; k < N - 1; ++k) {
			cout << A[k] << " ";
		}
		cout << A[N - 1] << endl;
	}
	


	return 0;
}


Measured memory_bytes: 3124
import sys
stdin = sys.stdin

from itertools import accumulate

sys.setrecursionlimit(10 ** 7)

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x) - 1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())


def yoko(h, w):
    return 0 if h%3 == 0 else w

def tate(h, w):
    return 0 if w%3 == 0 else h

def tee1(h, w):
    h1 = h//3
    w1 = w//2

    top = h1 * w
    lef = (h-h1)*w1
    rig = (h-h1)*(w-w1)

    return max(abs(top-lef), abs(top-rig), abs(lef-rig))

def tee2(h, w):
    h1 = h // 3 + 1
    w1 = w // 2

    top = h1 * w
    lef = (h - h1) * w1
    rig = (h - h1) * (w - w1)

    return max(abs(top - lef), abs(top - rig), abs(lef - rig))

def to1(h, w):
    w1 = w//3
    h1 = h//2

    lef = w1*h
    top = (w-w1)*h1
    bot = (w-w1)*(h-h1)

    return max(abs(lef-top), abs(lef-bot), abs(top-bot))


def to2(h, w):
    w1 = w // 3 + 1
    h1 = h // 2

    lef = w1 * h
    top = (w - w1) * h1
    bot = (w - w1) * (h - h1)

    return max(abs(lef - top), abs(lef - bot), abs(top - bot))


def judge(h, w):
    return min(yoko(h, w), tate(h, w), tee1(h, w), tee2(h, w), to1(h, w), to2(h, w))

h, w = li()

ans = judge(h, w)
print(ans)

Measured memory_bytes: 3192
def judge(a,b,c)
  if a == 'o'
    if b == 0
      if c == 0
        return 0
      else
        return 1
      end
    else
      if c == 1
        return 0
      else
        return 1
      end
    end
  else
    if b == 0
      if c == 0
        return 1
      else
        return 0
      end
    else
      if c == 0
        return 0
      else
        return 1
      end
    end
  end
end

n = gets.to_i
s = gets
cage = Array.new(n+1,0)
count = -1
for i in 0..1
  for j in 0..1
    cage[0] = i
    cage[1] = j
    for k in 2..n
      cage[k] = judge(s[k-1],cage[k-1],cage[k-2])
    end
    if (cage[n] == cage[0])&&(cage[1] == judge(s[0],cage[0],cage[n-1]))
      count = 1
      break
    end
  end
  if count == 1
    break
  end
end
if count == 1
  for i in 0..n-1
    if cage[i] == 0
      print"S"
    else
      print"W"
    end
  end
  print"\n"
else
  puts count
end

Measured memory_bytes: 2812
import math
n,d = map(int, input().split())
x = [0] * n
y = [0] * n
for i in range(n):
    x[i],y[i] = map(int, input().split())

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

print(cnt)

Measured memory_bytes: 24700
import math
import sys
sys.stdin.readline

def yogen(x):
    ans = (A ** 2 + B ** 2 - 2*A*B*math.cos(math.radians(x)))**(1/2)
    print("{:.20f}".format(ans))

A, B, H, M = map(int, input().split())

ji = int(H)*30 + int(M)/2
hun = int(M)*6

if ji == hun:
    aaa = abs(A-B)
    print("{:.20f}".format(aaa))
elif ji - hun < 180:
    yogen(ji-hun)
else:
    yogen(hun-ji)


Measured memory_bytes: 9524
# include <stdio.h>
# include <cctype>
int main () {
  char ch;
  while(1) {
    scanf("%c", &ch);
    if (ch == '\n' ) break;
    if (islower(ch)) {ch=toupper(ch); printf("%c", ch);}  // ch?????°?????????????true?????????
    else if (isupper(ch)){ ch=tolower(ch); printf("%c", ch); }  // ch??????§????????????true?????????
    else printf("%c", ch);
  }
  printf("\n");
  return 0;
}

Measured memory_bytes: 940
#include <functional>
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <queue>
#include <string>
#include <cstring>
#include <math.h>
using namespace std;
long long gcd(long long a, long long b)
{
   if (a%b == 0)
   {
       return(b);
   }
   else
   {
       return(gcd(b, a%b));
   }
}

long long lcm(long long a, long long b)
{
   return a * b / gcd(a, b);
}

int main() {
   long long a,b;
 
   cin >> a >> b;
 
  cout << lcm(a, b) << endl;
  
  return 0;
}


Measured memory_bytes: 3640
#include <bits/stdc++.h>
// iostream is too mainstream
#include <cstdio>
// bitch please
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <cmath>
#include <iomanip>
#include <time.h>
#define dibs reserve
#define OVER9000 1234567890
#define ALL_THE(CAKE,LIE) for(auto LIE =CAKE.begin(); LIE != CAKE.end(); LIE++)
#define tisic 47
#define soclose 1e-8
#define chocolate win
// so much chocolate
#define patkan 9
#define ff first
#define ss second
#define abs(x) (((x) < 0)?-(x):(x))
#define uint unsigned int
#define dbl long double
#define pi 3.14159265358979323846
using namespace std;
// mylittledoge

using cat = long long;

#ifdef DONLINE_JUDGE
	// palindromic tree is better than splay tree!
	#define lld I64d
#endif

int main() {
	cin.sync_with_stdio(0);
	cin.tie(0);
	cout << fixed << setprecision(10);
	int H, W;
	cin >> H >> W;
	vector<string> S(H);
	for(int i = 0; i < H; i++) cin >> S[i];
	vector< vector< vector<int> > > cnt(H, vector< vector<int> >(W, vector<int>(H+W, 0)));
	cat ans = 0;
	for(int k = 0; k < 2; k++) {
		for(int l = 0; l < 2; l++) {
			for(int i = 1; i < H; i++) for(int j = 1; j < W; j++) for(int d = 2; d <= i+j; d++) {
				cnt[i][j][d] = cnt[i][j-1][d-1];
				if(i-d+1 >= 0) cnt[i][j][d] += (S[i-d+1][j-1] == '#');
			}
			for(int i = 0; i < H; i++) for(int j = 0; j < W; j++) if(S[i][j] == '#')
				for(int d = 1; d <= min(i, W-1-j); d++) if(S[i-d][j+d] == '#') ans += cnt[i-d][j][d];
			reverse(begin(S), end(S));
		}
		for(int i = 0; i < H; i++) reverse(begin(S[i]), end(S[i]));
	}
	for(int i = 0; i < H; i++) for(int j = 0; j < W; j++) if(S[i][j] == '#') {
		for(int k = 1; k <= j/2; k++) if(S[i][j-2*k] == '#') {
			if(k <= i && S[i-k][j-k] == '#') ans++;
			if(i+k < H && S[i+k][j-k] == '#') ans++;
		}
		for(int k = 1; k <= i/2; k++) if(S[i-2*k][j] == '#') {
			if(k <= j && S[i-k][j-k] == '#') ans++;
			if(j+k < W && S[i-k][j+k] == '#') ans++;
		}
	}
	cout << ans << "\n";
	return 0;
}

// look at my code
// my code is amazing


Measured memory_bytes: 215552
N,K = [int(i) for i in input().split()]
A = [int(i) for i in input().split()]

for _ in range(K):
    new = [0]*N
    for i in range(N):
        m = max(0,i-A[i])
        new[m] += 1
        if i+A[i]+1 < N:
            new[i+A[i]+1] -= 1
    A[0] = new[0]
    for i in range(1,N):
        new[i] += new[i-1]
        A[i] = new[i]
    for a in A:
        if a != N:
            break
    else:
        break

A = [str(i) for i in A]
print(" ".join(A))

Measured memory_bytes: 148076
using System.Linq;
using System;

public class Hello
{
    public static void Main()
    {
        var n = int.Parse(Console.ReadLine().Trim());
        string[] line = Console.ReadLine().Trim().Split(' ');
        var a = Array.ConvertAll(line, long.Parse);
        Console.WriteLine(a.Sum() - n);
    }
}


Measured memory_bytes: 13316
import Data.List

main :: IO()
main = getContents >>= putStr.unlines.map show.solve.formatIn

type Faces = [Int]
type Roll  = Int
type Dice  = [Roll]
formatIn :: String -> (Dice, [Faces])
formatIn = (\(x:_:ys)->(x,ys)).map (map (read :: String->Int).words).lines

solve :: (Dice, [Faces]) -> [Roll]
solve (x,ys) = map (label x) ys
 
label :: Dice -> Faces -> Roll
label dice@[x1,x2,x3,x4,x5,x6] rolls = (!!) dice $f rolls 
    where f rolls 
            | isInfixOf rolls [x2,x3,x5,x4,x2] = 0
            | isInfixOf rolls [x1,x4,x6,x3,x1] = 1
            | isInfixOf rolls [x1,x2,x6,x5,x1] = 2
            | isInfixOf rolls [x1,x5,x6,x2,x1] = 3
            | isInfixOf rolls [x1,x3,x6,x4,x1] = 4
            | isInfixOf rolls [x2,x4,x5,x3,x2] = 5

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

#define trace(...) __f( #__VA_ARGS__ , __VA_ARGS__ )
template <typename Arg1>
void __f( const char* name , Arg1&& arg1 ) {
        cerr << name << " : " << arg1 << "\n";
}
template <typename Arg1, typename... Args>
void __f( const char* na , Arg1&& arg1 , Args&&... args ) {
        const char* c = strchr( na + 1 , ',' );
        cerr.write( na , c - na ) << " : " << arg1 << " , ";
        __f( c + 1 , args... );
}
#define endl "\n"
#define all(V) V.begin(),V.end()
#define Unique(V) sort(all(V)),V.erase(unique(all(V)),V.end())
#define IO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef long long int LL;
typedef pair <int,int> pii;
const int MOD = 1e9 + 7;
const int inf = 1e9;
const double EPS = 1e-9;
const double PI = acos(-1.0);
const long long INF = 1e18;
const int N = 1e5 + 5;

LL f[ N ];

int main( ) {
        IO;
        #ifdef LOCAL
            //freopen( "input.txt" , "r" , stdin );
        #endif // LOCAL
        int r , d , x;
        cin >> r >> d >> x;
        f[2000] = x;
        for( int i = 2000; i <= 2020; i++ ) {
                f[i+1] = 1LL * r * f[i] - d;
                //trace( i , f[i+1] );
        }
        for( int i = 2001; i <= 2010; i++ ) cout << f[i] << endl;
        return 0;
}










Measured memory_bytes: 256
//B - Painting Balls with AtCoDeer: 
//Assunto:
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define loop(i, a, b) for(int i = a; i < b; i++)
#define loopBack(i, a, b) for(int i = a; i >= b; i--)
#define INF INT_MAX
#define LINF LLONG_MAX
#define DINF DBL_MAX
#define MAX 100050
#define MOD 1000000007
using namespace std;
typedef long long int ll;
typedef pair<int, int> ii;

int main() {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    //freopen("in.txt", "r", stdin);
    //freopen("out.txt", "w", stdout);
    int n, k, ans;

    cin >> n >> k;
    ans = pow(k-1, n-1);
    ans *= k;
    cout << ans << "\n";
}

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

int main() {
 int n;cin>>n; int d[n];for(int i=0;i<n;i++)cin>>d[i];
  
  sort(d,d+n);
  
  cout<<d[n/2]-d[n/2-1]<<endl;
 }


Measured memory_bytes: 640
#include <algorithm>
#include <cstdlib>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
typedef long long LL;

template<typename T>
istream& operator >> (istream& is, vector<T>& vs){
  for(T& v: vs) is >> v;
  return is;
}

int main() {
  int N, K; cin >> N >> K;
  vector<int> h(N); cin >> h;
  vector<int> dp(N, 1e9); dp[0] = 0;
  for (int i = 1; i < N; ++i) {
    for (int k = 1; k <= K && i-k >= 0; ++k)
      dp[i] = min(dp[i], abs(h[i] - h[i-k]) + dp[i-k]);
  }
  cout << dp[N-1] << endl;
}


Measured memory_bytes: 4048
import java.util.Scanner;

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

        int a = sc.nextInt();
        int b = sc.nextInt();

        if (a + b < 10) {
            System.out.println(a + b);
        } else {
            System.out.println("error");
        }
    }
}


Measured memory_bytes: 21844
#include "stdio.h"



int main(void)
{
  unsigned N;
  int count = 0;
  unsigned min = 114514919;
  scanf("%d",&N);
  char S[N];
  scanf("%s",S);
  for(int i = 1;i < sizeof(S);i++)
    {
      if(S[i] == 'E')
	count++;
    }
  min = count;
  
  for(int i = 1;i < sizeof(S);i++)
    {
      if(S[i] == 'W')
	{
	  count++;
	}
      if(S[i - 1] == 'E')
	{
	  count--;
	}
      if(min > count)
	{
	  min = count;
	}
    }
  printf("%d\n",min);
}

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

int main(){
    long long n;
    cin >> n;

    map<long long, long long> T;
    long long num = n;

    for(long long i = 2; i * i <= num; i++){
        if(num % i != 0) continue;

        while(num % i == 0){
            if(T.find(i) == T.end()){
                T[i] = 1;
                num /= i;
            }
            else{
                T[i]++;
                num /= i;
            }
        }
    }
    if(num != 1) T[num] = 1;

    long long ans = 0;
    map<long long, long long>::iterator it;
    for(it = T.begin(); it != T.end(); it++){
        long long start = 1;
        long long cnt = 0;
        long long number = it->second;

        while(number - start >= 0){
            number -= start;
            cnt++;
            start++;
        }
        ans += cnt;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3584
#include<bits/stdc++.h>
using namespace std;
int main(){
  int x;
  cin>>x;
  int a[x];
  int mini=INT_MAX;
  int maxi=INT_MIN;
  for(int i=0;i<x;i++){
   cin>>a[i]; 
    maxi=max({maxi,a[i]});
    mini=min({mini,a[i]});
  }cout<<maxi-mini;
  
  
  
  
  
return 0;}

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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n, c;
  cin >> n >> c;
  vector< vector<int> > d(c, vector<int>(c));
  for (int i = 0; i < c; i++) {
    for (int j = 0; j < c; j++) {
      cin >> d[i][j];
    }
  }
  vector< vector<int> > t(3);
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      int a;
      cin >> a;
      a--;
      t[(i + j) % 3].push_back(a);
    }
  }
  vector< vector<int> > sum(3, vector<int>(c));
  for (int type = 0; type < 3; type++) {
    for (int i = 0; i < c; i++) {
      for (int cc : t[type]) {
        sum[type][i] += d[cc][i];
      }
    }
  }
  int ans = 1e9;
  for (int x = 0; x < c; x++) {
    for (int y = 0; y < c; y++) {
      for (int z = 0; z < c; z++) {
        if (x != y && y != z && x != z) {
          ans = min(ans, sum[0][x] + sum[1][y] + sum[2][z]);
          if (ans == 0) {
            cerr << x << ' ' << y << ' ' << z << endl;
          }
        }
      }
    }
  }
  cout << ans << endl;
  return 0;
}


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

int main() {
	int n;
	cin>>n;
	long long a[n-1],ans[n]={0},tmp;
	for(int i=0;i<n-1;i++){
		cin>>a[i];
		
	}
	for(int i=0;i<n-1;i++){
		tmp=a[i];
		ans[tmp-1]++;
	}
	
	for(int i=0;i<n;i++){
		cout<<ans[i]<<endl;
		
	}
	
	// your code goes here
	return 0;
}


Measured memory_bytes: 6748
n, m = map(int, raw_input().split())
a = map(int, raw_input().split())
dp = [0] * 256 * 101
dp[0] = 1
for i, x in enumerate(a):
    ndp = dp[:]
    for j in xrange(256):
        for k in xrange(i + 1):
            ndp[(j^x)+k*256+256] += dp[j+k*256]
            if ndp[(j^x)+k*256+256] >= 1000000007:
                ndp[(j^x)+k*256+256] -= 1000000007
    dp = ndp
ans = 0
s = 1
for i in xrange(1, n + 1):
    s = s * i % 1000000007
    ans += dp[m+i*256] * s % 1000000007
print ans % 1000000007


Measured memory_bytes: 4332
#include<bits/stdc++.h>
#define ll long long int

using namespace std;

const ll mod=1000000007;
const ll inf=1e18;

int main(){

  ll n;
  cin >>n;
  ll a[n];
  ll s=0;
  ll b=inf;
  ll o=0;
  for(int i=0;i<n;i++){
    cin >> a[i];
    s+=abs(a[i]);
    b=min(b,abs(a[i]));
    if(a[i]<0)o++;
  }

  if(o%2==1)cout << s-2*b << endl;
  else cout << s << endl;


}

Measured memory_bytes: 4400
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
//using System.Text;
//using System.Text.RegularExpressions;
//using System.Globalization;
//using System.Diagnostics;
using static System.Console;
//using System.Numerics;
//using static System.Math;
//using pair = Pair<int, int>;

class Program
{
    static void Main()
    {
        //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
        new Program().solve();
        Out.Flush();
    }
    Scanner cin = new Scanner();
    readonly int[] dd = { 0, 1, 0, -1, 0 }; //→↓←↑
    readonly int mod = 1000000007;


    void solve()
    {
        int N = cin.nextint;
        var A = new long[5];
        var D = new Dictionary<int, int> { ['M'] = 0, ['A'] = 1, ['R'] = 2, ['C'] = 3, ['H'] = 4 } ;

        for (int i = 0; i < N; i++)
        {
            var c = cin.next[0];
            if (D.ContainsKey(c))
            {
                A[D[c]]++;
            }
        }

        long ans = 0;
        for (int i = 0; i < 5; i++)
        {
            for (int j = i + 1; j < 5; j++)
            {
                for (int k = j + 1; k < 5; k++)
                {
                    ans += A[i] * A[j] * A[k];
                }
            }
        }

        WriteLine(ans);
    }

}

class Scanner
{
    string[] s; int i;
    char[] cs = new char[] { ' ' };
    public Scanner() { s = new string[0]; i = 0; }
    public string[] scan { get { return ReadLine().Split(); } }
    public int[] scanint { get { return Array.ConvertAll(scan, int.Parse); } }
    public long[] scanlong { get { return Array.ConvertAll(scan, long.Parse); } }
    public double[] scandouble { get { return Array.ConvertAll(scan, double.Parse); } }
    public string next
    {
        get
        {
            if (i < s.Length) return s[i++];
            string st = ReadLine();
            while (st == "") st = ReadLine();
            s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
            i = 0;
            return next;
        }
    }
    public int nextint { get { return int.Parse(next); } }
    public long nextlong { get { return long.Parse(next); } }
    public double nextdouble { get { return double.Parse(next); } }
}

Measured memory_bytes: 17352
/*
AuThOr GaRyMr
*/
#include<bits/stdc++.h>
#define rb(a,b,c) for(int a=b;a<=c;++a)
#define rl(a,b,c) for(int a=b;a>=c;--a)
#define LL long long
#define IT iterator
#define PB push_back
#define II(a,b) make_pair(a,b)
#define FIR first
#define SEC second
#define FREO freopen("check.out","w",stdout)
#define rep(a,b) for(int a=0;a<b;++a)
#define KEEP while(1)
#define SRAND mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define random(a) rng()%a
#define ALL(a) a.begin(),a.end()
#define POB pop_back
#define ff fflush(stdout)
#define fastio ios::sync_with_stdio(false)
using namespace std;
const int INF=0x3f3f3f3f;
typedef pair<int,int> mp;
typedef pair<mp,mp> superpair;
int main(){
	fastio;
	string s;
	cin>>s;
	if(s.length()%2==1){
		cout<<"No"<<endl;
	}
	else{
		for(int i=0;i<s.length();i+=2){
			if(s[i]=='h'&&s[i+1]=='i') continue;
			cout<<"No"<<endl;return 0;		}
			cout<<"Yes";
	}
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>

using namespace std;
typedef pair<int,int> P;

int main() {
    int i,j,n,p,q,temp;
    int t=0;
    int flag=0;
    string s;
    cin>>n;
    int d[n];
    for(i=0; i<n; ++i){
        cin>>d[i];
    }
    sort(d,d+n);
    flag=n/2;
    t=d[flag]-d[flag-1];
    cout<<t;

    return 0;
}

Measured memory_bytes: 640
def main():
    n, k = map(int, input().split())

    if n == 0:
        print(0)
        exit()

    if k == 1:
        print(0)
        exit()

    if n == k:
        print(0)
        exit()

    dist = abs(n-k)

    if n < dist:
        print(n)
        exit()

    if n == dist:
        print(0)
        exit()
                
    print(abs((n // k + 1) * k - n))
    exit()


if __name__ == '__main__':
    main()

Measured memory_bytes: 38384
INF=-10000000000

def bellman_ford(s,D,G):
    D[s]=0
    while True:
        update=False
        for i in range(E):
            e=G[i]
            if D[e[0]]!=INF and (D[e[1]]==INF or D[e[1]]>D[e[0]]+e[2]):
                D[e[1]]=D[e[0]]+e[2]
                update=True
        if not update:
            break

if __name__=="__main__":
    V,E,r=map(int,input().split())
    D=[INF]*V
    G=[]

    for i in range(E):
        G.append(list(map(int,input().split())))
    
    bellman_ford(r,D,G)

    for i in range(V):
        print("INF" if D[i]==INF else D[i])


Measured memory_bytes: 114244
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>

using namespace std;

inline int read()
{
	int x=0;char ch=getchar();
	while(ch<'0' || '9'<ch)ch=getchar();
	while('0'<=ch && ch<='9')x=x*10+(ch^48),ch=getchar();
	return x;
}

const int N=100009;

int n,c,k;
int t[N];

int main()
{
	n=read();c=read();k=read();
	for(int i=1;i<=n;i++)
		t[i]=read();
	sort(t+1,t+n+1);
	
	int cnt=0,ans=0,las=-1;
	for(int i=1;i<=n;i++)
	{
		if(las!=-1 && las+k<t[i])
			las=-1,ans++;
		else if(cnt==c)
			las=-1,ans++;
		if(las==-1)
			las=t[i],cnt=0;
		cnt++;
	}
	if(cnt)
		ans++;

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


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

int main(){
  set<int> s;
  int m, M, cnt = 0;
  int n; cin >> n;
  for(int i = 0; i < n; i++){
    int a; cin >> a;
    if(a/400 < 8) s.insert(a/400);
    else cnt++;
  }
  m = max((int)s.size(), 1);
  M = s.size() + cnt;
  cout << m << " " << M << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<n; i++)
#define rep1(i, n) for(int i=1; i<=n; i++)
#define repr(i, n) for(int i=n-1; i>=0; i--)
#define repr1(i, n) for(int i=n; i>=1; i--)
#define all(v) v.begin(),v.end()
using ll = long long;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const int INF = 1e9;
const ll LLINF = 1e18;
const ll MOD = 1e9+7;
const double EPS = 1e-10;
const double PI = acos(-1);
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int h, w, sy, sx, gy, gx;
string s[1010];
int dist[1010][1010];

int main() {
    cin >> h >> w;
    cin >> sy >> sx >> gy >> gx;
    sy--; sx--; gy--; gx--;
    rep(i, h) cin >> s[i];

    // Dijkstra
    rep(i, h) rep(j, w) dist[i][j] = INF;
    dist[sy][sx] = 0;
    priority_queue<pii, vector<pii>, greater<pii>> q;
    q.emplace(sy, sx);
    while (q.size()) {
        pii now = q.top(); q.pop();
        int y = now.first;
        int x = now.second;
        for (int dy = -2; dy <= 2; dy++) {
            for (int dx = -2; dx <= 2; dx++) {
                if (dy == 0 && dx == 0) continue;
                int ny = y + dy;
                int nx = x + dx;
                if (nx < 0 || nx >= w || ny < 0 || ny >= h) continue;
                if (s[ny][nx] == '#') continue;
                // move to adjacent
                if (max(abs(dy), abs(dx)) == 1 && min(abs(dy), abs(dx)) == 0) {
                    if (chmin(dist[ny][nx], dist[y][x])) {
                        q.emplace(ny, nx);
                    }
                } else { // warp
                    if (chmin(dist[ny][nx], dist[y][x] + 1)) {
                        q.emplace(ny, nx);
                    }
                }
            }
        }
    }

    int ans = dist[gy][gx];
    if (ans == INF) ans = -1;
    cout << ans << endl;
}


Measured memory_bytes: 9568
import sys
import heapq
import math
import fractions
import bisect
import itertools
from collections import Counter
from collections import deque
from operator import itemgetter
def input(): return sys.stdin.readline().strip()
def mp(): return map(int,input().split())
def lmp(): return list(map(int,input().split()))

class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

n,m=mp()
uf = UnionFind(n)
for i in range(m):
    X,Y,Z=mp()
    uf.union(X-1,Y-1)
print(len(uf.roots()))

Measured memory_bytes: 86760
#include <bits/stdc++.h>
#include <random>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rep1(i,n) for (int i = 1; i <= (n); ++i)

using namespace std;
using ll = long long;
using P = pair<int,int>;
using ull= unsigned long long;
const ll K_MAX=1e5+5;
const ll Lmax=ll(1e18);
const ll Nmax=1e9;
const ll INF=1e9;
const vector<int> dx={1,0,-1,0};
const vector<int> dy={0,1,0,-1};

ll intpow(ll n, int m){
  ll out=1;
  rep(i,m){
    out *=n;
  }
  return out;
}



int main(){
  ll n;
  cin>>n;
  if(n%2==1){//奇数の場合
    cout<<0<<endl;
    return 0;
  }
  ll ans=0;
  //偶数の場合
  //桁数計算


  // 5,5^2,5^3で割り切れる者の個数=2*5,2*5^2,2*5^3;
  rep1(m,26){
    //cout<<2*intpow(5,m)<<endl;
    ans +=n/(2*intpow(5,m));
  }
  cout<<ans<<endl;











}


Measured memory_bytes: 3620
#include <queue>
#include <vector>
#include <algorithm>
#include<cstring>
#include<cstdlib>
#include<iostream>
#include<string>
#include<stack>
#include<map>
#include<set>
#include<math.h>

using namespace std;
#define ll long long
#define ull unsigned long long
#define INF 1e9
#define eps 1e-6
#define PI acos(-1.0)
#define M 10010
typedef pair<int, int>P;
const int mod = 1e9 + 7;
const int maxn = 1e5 + 10;

ll n,m;
char a[maxn],b[maxn];

int main()
{
    cin >> n >> m;
    cin >> a >> b;
    if(a[0] != b[0]){
        cout << -1 <<endl;
        return 0;
    }
    if ( n == m ){
        for(int i = 0 ; i < n; i++)
        if(a[i] != b[i] ){
             cout << -1 <<endl;
             return 0;
        }
        cout << n << endl;
        return 0;
    }
    int l = 0 , r = 0;
    ll ans = 0;
    for(ll i = 1; i <= maxn; i++)
       if(i * n % m == 0){
           l = i;
           r = i * n / m;
           ans  = i * n;
           break;
       }
       //cout << l <<" " << r;
    for(int i = 1 ; i * r <= n && i * l <= m ; ++i ){
        if(a[i * r] != b[i * l]){
            cout << -1 << endl;
            return 0;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
#include <cmath>
#include <iomanip>

using namespace std;

int main(){
    static const long double pi = acosl(-1.0);
    long double a, b, x, ans;
    cin >> a >> b >> x;
    if(a * a * b < x * 2){
        ans = atan(2 * (a * a * b - x) / (a * a * a)) / pi * 180;
    }else{
        ans = atan((a * b * b) / (2 * x)) / pi * 180;
    }
    cout << fixed << setprecision(11) << ans << "\n";
}

Measured memory_bytes: 256
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# FileName: 	D_fix
# CreatedDate:  2020-08-08 01:53:55 +0900
# LastModified: 2020-08-08 01:56:11 +0900
#


import os
import sys
# import numpy as np
# import pandas as pd


def main():
    x = int(input())
    for a in range(-120, 120):
        for b in range(-120, a):
            if a**5-b**5 == x:
                print("{} {}".format(a, b))
                return


if __name__ == "__main__":
    main()


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

using namespace std;

using uint = unsigned int;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define dbg(...) cerr << #__VA_ARGS__ << " ->", debug_out(__VA_ARGS__)
#define dbg_p(x) cerr<<#x": "<<(x).first<<' '<<(x).second<<endl
#define dbg_v(x, n) {cerr<<#x"[]: ";for(long long _=0;_<n;++_)cerr<<(x)[_]<<' ';cerr<<endl;}
#define all(v) v.begin(), v.end()
#define fi first
#define se second
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << " " << H; debug_out(T...);}
 
template<typename T1, typename T2>
ostream& operator <<(ostream &out, const pair<T1, T2> &item) {
	out << '(' << item.first << ", " << item.second << ')';
	return out;
}
 
template <typename T>
ostream& operator <<(ostream &out, const vector<T>& v) {
	for(const auto &item : v) out << item << ' ';
	return out;
}

string s, t, u;
int a, b;

int main()
{
	ios_base::sync_with_stdio(false);

	cin>>s>>t;
	cin>>a>>b;
	cin>>u;
	if (u == s)
		a--;
	else
		b--;

	cout<<a<<" "<<b<<'\n';	

	return 0;
}

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

using namespace std;

// Repetitions
#define FOR(i,a,n) for(ll i = ((ll) a); i < ((ll) n); ++i)
#define FORR(i, s, g) for(ll i = ((ll)s - 1); i >= ((ll) g); --i)
#define REP(i, n) FOR(i, 0, n)
#define REPR(i, n) FORR(i, n, 0)

// Container Utils
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define SORTALL(v) sort(ALL(v))
#define SZ(a) int((a).size())
#define CLR(a) memset((a), 0 ,sizeof(a))
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())

// For Debug
#define DMP(x)  cerr << #x << " = " << (x) << endl
#define DBG(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl

// Aliases
#define PB push_back
#define MP make_pair
using ll = long long;
using ld = long double;
using str = string;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vs = vector<str>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vpii = vector<pii>;
using vpll = vector<pll>;

// Constant variables
const ld PI = (acos(-1));
const ll MOD = 1000000007;

// I/O Asynchronizing
struct __io_async{
    __io_async(){
        cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20);
    };
};

int main() {
    int n;
    cin >> n;
    set<int> st;
    str ans = "YES";
    REP(i, n) {
        int a;
        cin >> a;
        if(st.count(a) > 0) {
            ans = "NO";
        }
        else st.insert(a);
    }
    cout << ans << endl;

    return 0;
}


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

int N;
vector<set<int>> edge;

vector<int> get_path(int from, int to)
{
    vector<int> parent(N, -2);
    parent[from] = -1;
    queue<int> st;
    st.push(from);
    while (!st.empty())
    {
        int now = st.front();
        st.pop();
        if (now == to) break;
        for (auto nxt : edge[now])
        {
            if (parent[nxt] == -2)
            {
                parent[nxt] = now;
                st.push(nxt);
            }
        }
    }
    int tmp = to;
    vector<int> res;
    while (tmp != from)
    {
        res.push_back(tmp);
        tmp = parent[tmp];
    }
    res.push_back(from);
    reverse(res.begin(), res.end());
    return res;
}

int countConnected(int start)
{
    vector<bool> visited(N, false);
    queue<int> st;
    st.push(start);
    visited[start] = true;
    while (!st.empty())
    {
        int now = st.front();
        st.pop();
        for (auto nxt : edge[now])
        {
            if (!visited[nxt])
            {
                visited[nxt] = true;
                st.push(nxt);
            }
        }
    }
    int res = 0;
    for (auto v : visited) if (v) res++;
    return res;
}

int main()
{
    cin >> N;
    edge.resize(N);
    for (int i = 0; i < N - 1; i++)
    {
        int tmp1, tmp2;
        cin >> tmp1 >> tmp2;
        tmp1--; tmp2--;
        edge[tmp1].insert(tmp2);
        edge[tmp2].insert(tmp1);
    }

    vector<int> path = get_path(0, N - 1);
    int l = path.size();
    int e1 = path[(l - 1) / 2];
    int e2 = path[(l - 1) / 2 + 1];
    edge[e1].erase(e2);
    edge[e2].erase(e1);
    // cout << countConnected(0) << " " << countConnected(N - 1) << endl;

    if (countConnected(0) <= countConnected(N-1)) cout << "Snuke" << endl;
    else cout << "Fennec" << endl;
}

Measured memory_bytes: 15360
#include <iostream>
using namespace std;
int main()
{
    int x,a,b;
    cin>>x>>a>>b;
    if (b-a<=0)
        cout<<"delicious"<<endl;
    else
    {
        if (b-a<=x)
            cout<<"safe"<<endl;
        else
            cout<<"dangerous"<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<math.h>
#include<map>
#include<algorithm>
#include<set>
#include <stdexcept>
#define rep(i,N) for(int i=0;i<(N);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int dx[]={1,0,-1,0,1,-1,-1,1};
const int dy[]={0,1,0,-1,1,1,-1,-1};
int ceil(int a,int b){
    return (a+b-1)/b;
}
int main(void){
    char board[3][3];
    rep(i,3){
        rep(j,3){
            cin>>board[i][j];
        }
    }
    cout<<board[0][0]<<board[1][1]<<board[2][2]<<endl;
    return 0;
}

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

int main(){
  string str, task, what;
  int q, a, b;
  cin >> str >> q;
  while(q--){
    cin >> task;
    if(task.compare("replace") == 0){
      cin >> a >> b >> what;
      for(int i=a; i<=b; i++)
	str[i] = what[i-a];
    }
    else if(task.compare("reverse")==0){
      cin >> a >> b;
      string tmp(str);
      for(int i=a; i<=b; i++)
	str[i] = tmp[b-i+a];
    }
    else{
      cin >> a >> b;
      for(int i=a; i<=b; i++)
	cout << str[i];
      cout << endl;
    }
  }
  return 0;
}

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

#define REP(i, n) for(ll i = 0;i < n;i++)
#define REPR(i, n) for(ll i = n;i >= 0;i--)
#define FOR(i, m, n) for(ll i = m;i < n;i++)
#define FORR(i, m, n) for(ll i = m;i >= n;i--)
#define REPO(i, n) for(ll i = 1;i <= n;i++)
#define ll long long
#define INF (ll)1 << 60
#define MINF (-1 * INF)
#define ALL(n) n.begin(),n.end()
#define MOD 998244353
#define P pair<ll, ll>

ll n, m, x, ans = INF, c[20], a[20][20];
int main() {
    cin >> n >> m >> x;
    REP(i, n){
        cin >> c[i];
        REP(j, m) cin >> a[i][j];
    }
    REP(i, 1 << n){
        ll cost = 0;
        ll now[20] = {};
        REP(j, n){
            if(i & (1 << j)){
                cost += c[j];
                REP(k, m) now[k] += a[j][k];
            }
        }
        bool ok = true;
        REP(j, m) {
            if (now[j] < x) ok = false;
        }
            if (ok) ans = min(ans, cost);
    }
    if (ans == INF) cout << -1 << endl;
    else
        cout << ans << endl;
}


Measured memory_bytes: 3636
#include <stdio.h>
#include <algorithm>
int main(void){
  int n,ans=0;
  scanf("%d",&n);
  int b[n+1]={};
  for(int i=1;i<n;i++){
    scanf("%d",&b[i]);
  }
  for(int i=0;i<n;i++){
    ans=ans+std::min(b[i],b[i+1]);
  }
  ans=ans+b[1]+b[n-1];
  printf("%d",ans);
}

Measured memory_bytes: 128