akhauriyash/Code-Regression huggingface dataset:
N,M = map(int,input().split())
A = list(map(int,input().split()))
data = [list(map(int,input().split())) for i in range(M)]

A.sort()

from operator import itemgetter

data = sorted(data,key = itemgetter(1),reverse=True)

B = []
for i,j in data:
    if len(B) > N:
        break
    else:
        B += [j]*i

for i in range(min(N,len(B))):
    if A[i] < B[i]:
        A[i] = B[i]
print(sum(A))

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

// #define int long long
#define rep(i, n) for (long long i = (long long)(0); i < (long long)(n); ++i)
#define reps(i, n) for (long long i = (long long)(1); i <= (long long)(n); ++i)
#define rrep(i, n) for (long long i = ((long long)(n)-1); i >= 0; i--)
#define rreps(i, n) for (long long i = ((long long)(n)); i > 0; i--)
#define irep(i, m, n) for (long long i = (long long)(m); i < (long long)(n); ++i)
#define ireps(i, m, n) for (long long i = (long long)(m); i <= (long long)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) long long(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vs = vector<string>;
using vpll = vector<pair<ll, ll>>;
using vtp = vector<tuple<ll,ll,ll>>;
using vb = vector<bool>;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

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


signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  
  ll n; cin>>n;
  vll a(n);
  rep(i,n) cin>>a[i];
  
  ll ans=LINF;
  for(ll i=-100; i<=100; i++){
    ll tmp=0;
    rep(j,n){
      ll x=abs(i-a[j]);
      tmp+=x*x;
    }
    chmin(ans,tmp);
  }
  cout<<ans<<endl;
 }

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <string>
#include <vector>
#include <utility>
#include <queue>
#define llint long long
#define inf 1e18

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

llint n, y;
llint a[305], s[305];
llint dp[305][305][5];

int main(void)
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> n >> y;
	for(int i = 1; i <= n; i++) cin >> a[i];
	for(int i = 1; i <= n; i++) s[i] = s[i-1] + a[i];
	llint d = s[n]/5-y;
	
	llint ans = 0;
	for(int p = 0; p < n; p++){
		for(int i = p; i <= n; i++){
			for(int j = p; j <= n; j++){
				for(int k = 0; k <= 4; k++){
					dp[i][j][k] = 0;
				}
			}
		}
		dp[p][p][0] = 1;
		for(int i = p; i < n; i++){
			for(int j = p; j <= n; j++){
				for(int k = 0; k <= 4; k++){
					if(k+1 <= 4 && s[i+1]-s[j] >= d) dp[i+1][i+1][k+1] += dp[i][j][k];
					dp[i+1][j][k] += dp[i][j][k];
				}
			}
		}
		for(int j = p; j < n; j++){
			if(s[n]-s[j]+s[p] >= d) ans += dp[n][j][4];
		}
	}
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 6724
N, X = map(int, input().split())
def bisearch(n, l):
    half = (2**(n+2)-3) // 2
    return 0 if l <= 0 else 2**n + bisearch(n-1, min(l - 1 - half, half)) if half < l else bisearch(n-1, l-1)
print(bisearch(N, X))


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

int main(){
	while(1){
		int n;
		cin>>n;
		if(n==0)return 0;
		vector<pair <int,int>>v;
		for(int i=0;i<n;i++){
			int a,b;
			cin>>a>>b;
			v.push_back(make_pair(b,a));
		}
		sort(begin(v),end(v));
		int w=0;
		for(int i=0;i<n;i++){
			w+=v[i].second;
			if(w>v[i].first){
				cout<<"No"<<endl;
				goto next;
			}
		}
		cout<<"Yes"<<endl;
		next:;
	}
	return 0;
} 

Measured memory_bytes: 1188
import sys
sys.setrecursionlimit(10**7)
input = lambda: sys.stdin.readline().strip()

def main():
    A,B,C,D = map(int,input().split())
    takahashi_num = int(C/B) if C%B==0 else int(C/B)+1
    aoki_num = int(A/D) if A%D==0 else int(A/D)+1
    print("Yes" if takahashi_num<=aoki_num else "No")

main()


Measured memory_bytes: 9092
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <ctime>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>

using namespace std;

#ifdef _MSC_VER
#define __typeof__ decltype

template <class T>
int __builtin_popcount(T n) { return n ? 1 + __builtin_popcount(n & (n - 1)) : 0; }
#endif

#define foreach(it, c) for (__typeof__((c).begin()) it=(c).begin(); it != (c).end(); ++it)
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define popcount __builtin_popcount

const double EPS = 1e-8;
typedef long long ll;
typedef pair<int, int> pint;


int main()
{
	int x, y, z;
	while (scanf("%d%d%d", &x, &y, &z), x|y|z)
	{
		double p = 1.0 / x;
		int v[4], e[51], a[51];
		for (int i = 0; i < x; ++i)
			scanf("%d", v + i);
		memset(e, 0, sizeof(e));
		for (int i = 0; i < z; ++i)
		{
			int t;
			scanf("%d", &t);
			scanf("%d%d", e + t, a + t);
		}

		static double dp[51][5001];
		for (int i = 0; i <= y; ++i)
			for (int j = 0; j <= 5000; ++j)
				dp[i][j] = 0;
		dp[0][0] = 1;
		for (int i = 0; i < y; ++i)
		{
			for (int j = 0; j <= 5000; ++j)
			{
				if (dp[i][j] == 0)
					continue;

				for (int k = 0; k < x; ++k)
				{
					int to = min(y, i + v[k]);
					int money = j;
					if (e[to] == 1)
						to = min(y, to + a[to]);
					else if (e[to] == 2)
						money = min(5000, money + a[to]);
					else if (e[to] == 3)
						money = max(0, money - a[to]);

					dp[to][money] += dp[i][j] * p;
				}
			}
		}

		double res = 0;
		for (int i = 0; i <= 5000; ++i)
			res += i * dp[y][i];

		printf("%d\n", (int)res);
	}

	return 0;
}

Measured memory_bytes: 2872
#include <bits/stdc++.h>
#define FOR(i, a, b) for (ll i = a; i <= (ll)(b); i++)
using namespace std;
typedef long long ll;

int main()
{
  ll A, B;
  cin >> A >> B;

  FOR(c, 1, 1000)
  {
    if ((ll)(c * 0.08) == A && (ll)(c * 0.1) == B)
    {
      cout << c << endl;
      return 0;
    }
  }

  cout << -1 << endl;
  return 0;
}

Measured memory_bytes: 3624
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <cstdio>
#include <ctime>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>
#include <iostream>
#include <algorithm>
#include <functional>
#include <numeric>
#include <string>

using namespace std;

template <class T>
double area_of_polygon(vector<T> x, vector<T> y)
{
    assert(x.size() == y.size());
    int n = x.size();
    double ret = 0;
    for (int p = 0; p < n; p++) {
        for (int i = 1; i <= n - 2; i++) {
                int q = (p + i) % n, r = (p + i + 1) % n;
                T v1x, v1y, v2x, v2y;
                v1x = x[q] - x[p];
                v1y = y[q] - y[p];
                v2x = x[r] - x[p];
                v2y = y[r] - y[p];
                ret += v1x*v2y - v1y*v2x;
        }
    }
    ret = abs(ret / (2 * n));
    return ret;
}

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

    vector<int> x(n), y(n);
    for (int i = 0; i < n; i++) {
        cin >> x[i] >> y[i];
    }
    printf("%.1lf\n", area_of_polygon(x, y));
    return 0;
}

Measured memory_bytes: 1236
import sys
n = int(input())
a = list(map(int, input().split()))
if 0 in a:
  print(0)
  sys.exit()
ans = a[0]
for i in a[1:]:
    ans = ans*i
    if ans > 10**18:
        print(-1)
        break
else:
  	print(ans)

Measured memory_bytes: 21536
/*input
12 3 7
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef tree<long long, null_type, less<long long>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
#pragma GCC optimize("unroll-loops,no-stack-protector")
//order_of_key #of elements less than x
// find_by_order kth element
typedef long long int ll;
#define ld long double
#define pii pair<int,int>
#define f first
#define s second
#define pb emplace_back
#define REP(i,n) for(ll i=0;i<n;i++)
#define sz(_a) (ll)(_a.size())
#define FILL(n) memset(n,0,sizeof(n))
#define ALL(_a) _a.begin(),_a.end()
const ll maxn=100005;
const ll maxlg=__lg(maxn)+2;
const ll INF64=8000000000000000000LL;
const int INF=0x3f3f3f3f;
const ll MOD=ll(1e9+7);
const ld PI=acos(-1);
const ld eps=1e-9;
ll mypow(ll a,ll b){
    ll res=1LL;
    while(b){
        if(b&1) res=res*a%MOD;
        a=a*a%MOD;
        b>>=1;
    }
    return res;
}
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int a,b,c;
    cin>>a>>b>>c;
    cout<<c-min(a-b,c);
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(void){
    for(int i = 1; ; ++i){
        int x, y;
        cin >> x >> y;
        if(x == 0 && y == 0) break;
        cout << min(x, y) << " " << max(x, y) << endl;
    }
    return 0;
}

Measured memory_bytes: 1160
n, k = map(int, input().split())
h = [int(_) for _ in input().split()]
dp = [1000000000] * n
dp[0] = 0
for i in range(n):
    for j in range(1,k+1):
        if i+j < n:
            dp[i+j] = min(dp[i+j], dp[i] + abs(h[i] - h[i+j]))
print(dp[n-1])


Measured memory_bytes: 52448
#include<bits/stdc++.h>
using namespace std;
#define endl "\n"
typedef    pair<int,int> pii;
typedef    pair<int,pii> ppi;
typedef    pair<pii,int> pip;
typedef    long long int ll;
typedef    unsigned long long int ull;
typedef    pair<ll,ll> pll;
typedef    vector<int> VI;
typedef    vector<pii> Vii;
typedef    vector<VI> VVI;// 2D
//typedef    priority_queue<int> PQ;// MaxHeap
typedef    priority_queue<int,VI,greater<int> > PQ;// MinHeap
//int Dx[] ={-1,0, 0,1};
//int Dy[] ={ 0,1,-1,0};
//int Dx8[]={-1,-1,-1,0,1,1, 1, 0};
//int Dy8[]={-1, 0, 1,1,1,0,-1,-1};
//int Kx[] ={2,1,-1,-2,-2,-1, 1, 2};
//int Ky[] ={1,2, 2, 1,-1,-2,-2,-1};

// code starts from here
#define pi acos(-1.0)
const int MAX=1e6+10,MOD=1e9+7;
double fun(double deg){

    double ret = (pi*deg)/180.0;
    return ret;
}
void solve(){

    cout<<fixed<<setprecision(10);
    double a,b,h,m;
    cin >> a >> b >> h >> m;

    double minute = m*6.0;
    double hour = h*30.0 + m*0.5;

    double diff = min( abs(minute-hour) , 360.0 - abs(minute-hour));
    //cout<<diff<<endl;
    double c = a*a + b*b - 2*a*b*cos(fun(diff));

    c = sqrt(c);
    cout<<fixed<<setprecision(10)<<c<<endl;
}
int main (){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int t=1;
    while(t--)solve();
    return 0;
}



Measured memory_bytes: 4240
<?php

fscanf(STDIN, "%s", $str);
$smap = str_split($str);
$last = "";
$lvalue = 0;
$larray = [];
$first = $smap[0];
foreach($smap as $value){
       if($value == $last){
           $lvalue++;
       }else{
           if($lvalue > 0){
               $larray[] = $lvalue;
           }
           $lvalue = 1;
           $last = $value;
       }
}
if($lvalue > 0){
    $larray[] = $lvalue;
}
$ans = 0;
$alast = 0;
if($first == ">"){
    $mode = 1;
}else{
    $mode = 0;
}
foreach($larray as $value){
    if($mode == 0){
        $ans += ($alast + ($alast + $value))* ($value + 1) / 2;
        $alast = ($alast + $value);
        $mode = 1;
    }else{
        if($value > $alast){
            $ans += $value - $alast;
        }
        $ans += ($value - 1) * $value / 2;
        $alast = 0;
        $mode = 0;
    }
}
echo $ans;

Measured memory_bytes: 45560
#include <iostream>
#include <algorithm>
#include <string>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <vector>

using namespace std;

long gcd(long a, long b) {
	if (a < 0) { a = -a; }
	if (b < 0) { b = -b; }
	if (a == 0) { return b; }
	if (b == 0) { return a; }
	if (a < b) {
		return gcd(a, b % a);
	}
	return gcd(b, a % b);
}

int main() {
	long n, N, K;
	long s = 0;
	cin >> N >> K;
	n = N;
	double p = 0;
	if (K <= N) {
		s = N - K + 1;
		n = K - 1;
	}
	if (n == 0) {
		cout << 1 << endl;
		return 0;
	}
	long* r = new long[n];
	long rate = 1;
	long rmax = 0;
	for (long i = n; i > 0; i--) {
		while (i * rate < K) {
			rate *= 2;
		}
		r[i - 1] = rate;
		rmax = max(rmax, rate);
	}

	long sum = s * rmax;
	long buf = -1;
	for (long i = 0; i < n; i++) {
		if (i == n - 1 || r[i] != r[i + 1]) {
			sum += (i - buf) * (rmax / r[i]);
			buf = i;
		}
	}
	s = rmax * N;

	long g = gcd(sum, s);
	sum /= g;
	s /= g;
	p = (long double)sum / (long double)s;

	printf("%.20lf\n", p);
	return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
	string str;
	while(1){
		int I=0, J=0;
		cin>>str;
		if (cin.eof())
			break;
		for(int i = 0;(str.size()-2) > i; i++){
			if(str[i] == 'J' && str[i+1] == 'O' && str[i+2] == 'I')
				J++;
			if(str[i] == 'I' && str[i+1] == 'O' && str[i+2] == 'I')
				I++;
		}
		cout<<J<<endl<<I<<endl;
	}
	return 0;
}

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

int main() {
  string S;
  cin >> S;
  char pre = '#';
  bool good = true;
  for (char c : S) {
    if (pre == c) {
      good = false;
      break;
    }
    pre = c;
  }
  if (good) {
    cout << "Good" << endl;
  } else {
    cout << "Bad" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
/* Those who cannot remember the past are condemned to repeat it.*/
/* author:Ajeet */

#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL)
const int sz=1e3+5;
#define mod 1000000007
#define ull unsigned long long int
 long double d(int a,int b,int c,int d){
     return sqrt((long double)((a-b)*(a-b))+((c-d)*(c-d)));
 }
int main()
{
    fast_cin();
    ll n;
    cin>>n;
    int x[n],y[n];
    for(int i=0;i<n;i++) cin>>x[i]>>y[i];
    long double dist=0;
    for(int i=0;i<n-1;i++)
    for(int j=i+1;j<n;j++)
    dist+=d(x[i],x[j],y[i],y[j]);
    dist=2.0*dist/n;
    cout<<fixed<<setprecision(10)<<dist<<endl;
        return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i, a, b) for (int i = int(a); i < int(b); ++i)
typedef long long ll;
long long mod = 1e9 + 7;
const long long INF = 1LL << 60;
using namespace std;

template <class T>
inline bool chmin(T &a, T b)
{
  if (a > b)
  {
    a = b;
    return true;
  }
  return false;
}

template <class T>
inline bool chmax(T &a, T b)
{
  if (a < b)
  {
    a = b;
    return true;
  }
  return false;
}

int main()
{
  int k, n;
  cin >> k >> n;

  int a[n];
  rep(i, n)
  {
    cin >> a[i];
  }

  sort(a, a + n);

  int tmp = 0;
  rep(i, n)
  {
    if (i == n - 1)
    {
      tmp = max(tmp,  k - a[i] + a[0]);
    }
    else
    {
      tmp = max(tmp, a[i + 1] - a[i]);
    }

  }

  cout << k - tmp << endl;
  return 0;
}

Measured memory_bytes: 1024
N = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

assign_plus = 0
minus = 0

for i in range(N):
    assign_plus += max(0, (b[i]-a[i])//2)
    minus += max(0, a[i]-b[i])

if assign_plus >= minus:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 4596
import java.util.Scanner;

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

		int n = scanner.nextInt();
		String s = scanner.next();
		int k = scanner.nextInt();

		String asta = "*";

		char keyWord = s.charAt(k-1);

		System.out.println(s.replaceAll("[^"+keyWord+"]", asta));

		scanner.close();

	}
}

Measured memory_bytes: 21204
#include<bits/stdc++.h>
using   namespace      std;
typedef long long      LL;
typedef vector<int>    VI;
typedef pair<int,int>  PII;

const LL mod = 1e9 + 7; 
LL ar[100005];
int x;

int main(){

	int n, m;
	cin>> n>> m;

	while(m--){
		cin>> x;
		ar[x] = -1;
	}

	ar[0] = 1;
	if(ar[1] != -1)
		ar[1] = 1;

	for(int i=2; i<=n; i++){
		if(ar[i] != -1)
			ar[i] = ( max(0LL, ar[i-2]) % mod + max(0LL, ar[i-1]) % mod ) % mod;
	}

	cout<< ar[n]<< endl;

	return 0;
}

Measured memory_bytes: 1024
import java.util.*;

class Main{
	static int c=0;
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		Point p1 = new Point(0, 0);
		Point p2 = new Point(100, 0);
		print(p1);
		kock(n, p1, p2);
		print(p2);
	}
	static void kock(int n, Point p1, Point p2){
		if(n == 0) return;

		Point s = new Point(
			p1.x<p2.x?	p1.x+(p2.x-p1.x)/3:
						p1.x-(p1.x-p2.x)/3,

			p1.y<p2.y?	p1.y+(p2.y-p1.y)/3:
			p1.y>p2.y?	p1.y-(p1.y-p2.y)/3:
						p1.y);

		Point u = new Point(
			(p1.x<p2.x&&p1.y<p2.y)||(p1.x>p2.x&&p1.y>p2.y)?	p1.x:
			(p1.x<p2.x&&p1.y>p2.y)||(p1.x>p2.x&&p1.y<p2.y)?	p2.x:
			p1.x<p2.x&&p1.y==p2.y?							p1.x+(p2.x-p1.x)/2:
															p1.x-(p1.x-p2.x)/2,

			p1.x<p2.x&&p1.y<p2.y?	p1.y+(p2.y-p1.y)/3*2:
			p1.x>p2.x&&p1.y<p2.y?	p1.y+(p2.y-p1.y)/3:
			p1.x<p2.x&&p1.y>p2.y?	p1.y-(p1.y-p2.y)/3:
			p1.x>p2.x&&p1.y>p2.y?	p1.y-(p1.y-p2.y)/3*2:
			p1.x<p2.x&&p1.y==p2.y?	p1.y+(p2.x-p1.x)/6*Math.tan(Math.PI/3):
									p1.y-(p1.x-p2.x)/6*Math.tan(Math.PI/3));

		Point t = new Point(
			p1.x<p2.x?	p1.x+(p2.x-p1.x)/3*2:
						p1.x-(p1.x-p2.x)/3*2,

			p1.y<p2.y?	p1.y+(p2.y-p1.y)/3*2:
			p1.y>p2.y?	p1.y-(p1.y-p2.y)/3*2:
						p1.y);

		kock(n-1, p1, s);
		print(s);
		kock(n-1, s, u);
		print(u);
		kock(n-1, u, t);
		print(t);
		kock(n-1, t, p2);
	}
	static void print(Point d){
		System.out.println(d.x+" "+d.y);
	}
}
class Point{
	double x;
	double y;
	public Point(double x, double y){
		this.x = x;
		this.y = y;
	}
}

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

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

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <cmath>
#include <algorithm>
#include <utility>
#include <functional>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const int MOD = 1000000007;
const double EPS = 1e-9;


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

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

  return 0;
}


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

int main() {
  int n, k;
  cin >> n >> k;
  int h[n];
  for ( int i = 0; i < n; i++ ) { cin >> h[i]; }
  sort(h, h+n);

  int mn = 1e9 + 1;
  for ( int i = 0; i+k-1 < n; i++ ) {
    mn = ( mn > h[i+k-1]-h[i] ) ? h[i+k-1]-h[i] : mn;
  }

  cout << mn << endl;
  return 0;
}


Measured memory_bytes: 640
#include <cstdio>
using namespace std;
int main() {
	char from,to,ball='A';
	while (scanf("%c,%c",&from,&to)!=EOF) {
		if (ball==from) {
			ball=to;
		} else if (ball==to) {
			ball=from;
		}
	}
	printf("%c\n",ball);
}

Measured memory_bytes: 0
##a = int(stdin.readline().rstrip())
##b, c = [int(x) for x in stdin.readline().rstrip().split()]
##s = stdin.readline().rstrip()
##a = list(set(b))  重複を削除
##a = list(map(int,[int(x) for x in stdin.readline().rstrip().split()])) a[0, 1, 2, ...]
##a = [[0] * 2 for _ in range(n)]  a[0,0]
##v = [s[i: i+2] for i in range(0, len(s), 2)]
##  s="12345678" を v=["12","34","56","78"] にするイメージ
##s = "".join(list)リストを文字列に変換[""]は区切り文字
##a.sort(key=itemgetter(1))リストをソートできるよ(from operator import itemgetterが必要)
##sort_p = sorted(p) 昇順ソート

# -*- coding: utf-8 -*-
from sys import stdin
from operator import itemgetter
from collections import deque, Counter
import math
import pprint
from functools import reduce
import numpy as np
import random
import bisect
import copy
import time
# stdin = open("sample.txt")


MOD = int(1e9+7)
INF = float('inf')
alpha = ["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"]

def keta(kazu): # 入力されたintを桁ごとに分解，リストで出力
    kazu_str = str(kazu)
    kazu_list = [int(kazu_str[i]) for i in range(0, len(kazu_str))]
    return kazu_list

def gcd(*numbers): # 最小公倍数
    return reduce(math.gcd, numbers)

def combination(m,n): # mCn
    
    if n > m:
        return 'すまん'
    return math.factorial(m) // (math.factorial(m-n) * math.factorial(n))

def pow_k(x,n):  # (x**n)の計算の高速化
    if n == 0:
        return 1
    K = 1
    while n > 1:
        if n % 2 != 0:
            K *= x
        x *= x
        n //= 2
    return K * x

def fact(n): # nの素因数分解の結果を辞書で出力 fuct(24) → {2: 3, 3: 1}
    arr = {}
    temp = n
    for i in range(2,int(n**0.5)+1):
        if temp % i == 0:
            cnt = 0
            while temp % i == 0:
                cnt += 1
                temp //= i
            arr[i] = cnt
    if temp != 1:
        arr[temp] = 1
    if arr == {}:
        arr[n] = 1
    return arr
    
def main():
    N = int(stdin.readline().rstrip())
    A = list(map(int,[int(x) for x in stdin.readline().rstrip().split()]))
    now = sum(A)
    ans = 0
    for i in range(N-1):
        now -= A[i]
        ans += ((A[i]%MOD) * (now%MOD)) % MOD
    print(ans%MOD)
main()

Measured memory_bytes: 49860
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vb = vector<bool>;
using vl = vector<long>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvb = vector<vector<bool>>;
using vvc = vector<vector<char>>;
using vvl = vector<vector<long>>;
using pii = pair<int, int>;
using pil = pair<int, long>;
using pll = pair<long, long>;
#define fix20 cout << fixed << setprecision(20)
#define YES cout << "Yes" << endl
#define NO cout << "No" << endl
#define rep(i,n) for(int i=0; i<(int)(n);i++)
#define REP(i,s,t) for(int i=s; i<t; i++)
#define RNG(i,s,t,u) for(int i=s; i<t; i+=u)
#define MOD 1000000007
#define all(vec) vec.begin(), vec.end()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int main(){
  string s;
  cin >> s;
  if(s == "RSR"){
    cout << 1 << endl;
    return 0;
  }
  int ans = 0;
  rep(i,3){
    if(s.at(i) == 'R') ans++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 3584
#include <iostream>
#include <string>
#include <vector>
#include <queue>
using namespace std;
using ll = long long;   //long型よりも使用できる桁数が増える

// 座標 corrdinate とゴールまでのマス目の数を保持するための構造体
struct Corr {
    ll y;
    ll x;
    ll count;
};

ll H, W;
ll y, x, count;  // キューから取り出した座標と操作回数
vector<string> vec;  // 座標を受け取る配列
queue<Corr> q;   //構造体Corr型を格納するキューの生成

vector<ll> dy = {0, 0, -1, +1};
vector<ll> dx = {-1, +1, 0, 0};

ll bfs() {
  while ( !q.empty() )  {
    Corr now = q.front(); q.pop();   //キューの先頭を取り出す
    y = now.y, x = now.x, count = now.count;
    
    //上下左右4方向を探索、マス目内かつ白いマス目の場合、キューに追加
    for ( ll i = 0; i < 4; ++i) {
      Corr next = {y + dy[i], x + dx[i], count + 1};
      if (0 <= next.y && next.y <= H-1 && 0 <= next.x && next.x <= W-1 && vec[next.y][next.x] == '.') {
                vec[next.y][next.x] = '#';  // 同じ場所を探索しないようにする
                q.push(next);
            }
    }
  }
  return count;
}

int main() {
  cin >> H >> W;
  vec.resize(H); for ( ll i = 0; i < H; ++i ) cin >> vec[i];
  
  for ( ll y = 0; y < H; y++ ) {
    for ( ll x = 0; x < W; x++ ) {
      if( vec[y][x] == '#' ) {
        Corr start = {y, x, 0};   //スタート位置(黒いマス目)をキューに追加
        q.emplace(start);
      }
    }
  }
  
  cout << bfs() << endl;
  
  return 0; 
}

Measured memory_bytes: 25524
package main

import (
	"fmt"
)

func answer159A(m int, n int) int {
	evenPairs := m * (m - 1) / 2
	oddPairs := n * (n - 1) / 2

	return evenPairs + oddPairs
}


func main() {
	var m, n int
	fmt.Scanf("%d %d", &m, &n)
	
	fmt.Println(answer159A(m, n))
}


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

template<class T>
struct culsum_2D {
  int h,w;
  vector<vector<T>> sum;
  culsum_2D(vector<vector<T>>const& a){
    h = a.size();
    w = a[0].size();
    sum.resize(h+1,vector<T>(w+1));
    for(int i=0;i<h;++i)
      for(int j=0;j<w;++j)
        sum[i+1][j+1] = a[i][j];
    for(int i=0;i<h;i++)
      for(int j=0;j<w;j++)
        sum[i+1][j+1] += sum[i+1][j]+sum[i][j+1]-sum[i][j];
  }
  T get(int sy,int sx,int ty,int tx){
    assert(0<=sy&&0<=sx);
    assert(ty<=h&&tx<=w);
    assert(sy<=ty&&sx<=tx);
    return sum[ty][tx]-sum[ty][sx]-sum[sy][tx]+sum[sy][sx];
  }
};

//https://atcoder.jp/contests/abc159/tasks/abc159_e

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

signed main(){

  int h,w,k;
  cin>>h>>w>>k;
  vector<string> s(h);
  for(auto& si:s)cin>>si;

  vector<vector<int>> a(h,vector<int>(w));
  rep(i,h)rep(j,w){
    a[i][j] = (s[i][j]=='1');
  }
  culsum_2D<int> sum(a);

  int ans = 1<<28;
  for(int b=0;b<(1<<(h-1));++b){
    bitset<11> bit(b);
    vector<int> s;
    s.emplace_back(0);
    rep(i,h)if(bit[i])s.emplace_back(i+1);
    s.emplace_back(h);
    int res = bit.count();
    int px = 0;
    int n = s.size();
    for(int x=1;x<=w;++x){
      int tmp = 0;
      rep(i,n-1){
        tmp = max(tmp,sum.get(s[i],px,s[i+1],x));
      }
      if(tmp<=k)continue;
      if(abs(x-px)==1){
        res = 1<<28;
        break;
      }
      res++;
      px = x-1;
    }
    ans = min(ans,res);
  }
  cout<<(ans)<<endl;

}

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

int main() {
  int A, B;
  cin >> A >> B;
  int r = (B-1) % (A-1);
  int answer = r == 0 ? (B-1)/(A-1) : (B-1)/(A-1)+1;
  cout << answer << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
  int a,b,c,y,x,ans=0,ans1=0;
  scanf("%d%d%d%d%d",&a,&b,&c,&x,&y);
  ans=a*x+b*y;
  if(x>y){
    ans1=x*2*c;
    }
  else{
    ans1=y*2*c;
    }
  if(ans>=ans1){
    ans=ans1;
  }

  if(x>y){
    ans1=y*2*c+(x-y)*a;
  }
  else{
    ans1=x*2*c+(y-x)*b;
  }

  if(ans>=ans1){
    ans=ans1;
  }
  printf("%d\n",ans);
  return 0;
}


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

constexpr int MOD = 1000000007;
// constexpr int MOD = 998244353;
constexpr int MAX = 5000000;

vector<long> fact(MAX), finv(MAX), inve(MAX);

void init() {
  fact.at(0) = fact.at(1) = 1;
  finv.at(0) = finv.at(1) = 1;
  inve.at(1) = 1;
  for (int i = 2; i < MAX; i++) {
    fact.at(i) = fact.at(i - 1) * i % MOD;
    inve.at(i) = MOD - inve.at(MOD % i) * (MOD / i) % MOD;
    finv.at(i) = finv.at(i - 1) * inve.at(i) % MOD;
  }
}

long com(long n, long r) {
  if (n < r || n < 0 || r < 0) return 0;
  return fact.at(n) * (finv.at(r) * finv.at(n - r) % MOD) % MOD;
}

int main() {
  init();
  long N, K;
  cin >> N >> K;
  vector<long> A(N);
  for (int i = 0; i < N; i++) cin >> A.at(i);
  sort(A.begin(), A.end());
  long ans = 0;
  for (int i = 0; i < N; i++) {
    ans += com(i, K - 1) * A.at(i);
    ans %= MOD;
    ans -= com(N - i - 1, K - 1) * A.at(i);
    ans %= MOD;
    while (ans < 0) ans += MOD;
  }
  cout << ans << "\n";
}

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

using namespace std;

typedef long long int ll;
typedef pair<int,int> ii;

const int N = 1e5 + 5;

vector <int> ed[N];
int n;

int f(int cur,int back) {
  int cnt = 0;
  for (auto i : ed[cur]) {
    if (i != back)
      cnt += f(i,cur);
  }
  if (cnt > 1) {
    cout << "First\n";
    exit(0);
  }
  return !cnt; 
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL); cout.tie(NULL);
  cin >> n;
  for (int i = 1 ; i < n ; i++) {
    int u,v;
    cin >> u >> v;
    ed[u].push_back(v);
    ed[v].push_back(u);
  }
  if (n == 2) {
    cout << "Second\n";
    return 0;
  }
  int root = 1;
  for (int i = 1 ; i <= n ; i++)
    if (ed[i].size() != 1)
      root = i;
  f(root,-1);
  cout << "Second\n";
}

Measured memory_bytes: 5888
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)


func main() {
	var n int
	fmt.Scan(&n)

	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)

	a := make([]int, n)
	for i := 0; i < n; i++ {
		sc.Scan()
		a[i], _ = strconv.Atoi(sc.Text())
	}

	fmt.Println(gcd(a...))
}



func gcd(nums ...int) int {
	if len(nums) < 2 {
		panic("funciton gcd() requires at least two argument.")
	}

	f := func(a, b int) int {
		if a > b {
			return gcd(b, a)
		}
		for a != 0 {
			a, b = b%a, a
		}
		return b
	}

	res := nums[0]
	for i := 0; i < len(nums); i++ {
		res = f(res, nums[i])
	}
	return res
}


Measured memory_bytes: 4272
#include <iostream>
using namespace std;
int main()
{
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  int l, r;
  l = a + b;
  r = c + d;
  if (l == r) cout << "Balanced" << endl;
  else if (l > r) cout << "Left" << endl;
  else cout << "Right" << endl;
}

Measured memory_bytes: 3116
line = input()
result = []
for c in line:
    num = ord(c)
    if num >= ord("A") and num <= ord("Z"):
        c1 = chr(ord("a") + num - ord("A"))
        result.append(c1)
    elif num >= ord("a") and num <= ord("z"):
        c1 = chr(ord("A") + num - ord("a"))
        result.append(c1)
    else:
        result.append(c)
print("".join(result))

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

#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
using pii = pair<int, int>;
void solve () {
  int n, a, b, ans = 0;
  cin >> n;
  vector<pii> vr(n), vb(n);
  vector<bool> used(n, false);
  rep(i, n) {
    cin >> a >> b;
    vr[i] = make_pair(a, b);
  }
  rep(i, n) {
    cin >> a >> b;
    vb[i] = make_pair(a, b);
  }
  sort(vr.begin(), vr.end(), [](pii p1, pii p2){return p1.second > p2.second;});
  sort(vb.begin(), vb.end());
  rep(i, n) {
    int bx = vb[i].first, by = vb[i].second;
    rep(j, n) {
      if (used[j]) continue;
      int rx = vr[j].first, ry = vr[j].second;
      if (rx >= bx) continue;
      if (ry < by) {
        ++ans;
        used[j] = true;
        break;
      }
    }
  }
  cout << ans << endl;
}
int main () {
  cin.tie(0);
  ios::sync_with_stdio(false);
  solve();
}

Measured memory_bytes: 256
import math
import copy
import time


line1 = str(input()).split(" ")

for index in range(len(line1)):
    line1[index] = int(line1[index])
if (line1[1] > 1 and line1[0] > 1):
    print( line1[0]*line1[1] - (2*line1[1] + 2*(line1[0]-2)))
elif (line1[1] == 1 and line1[0] == 1):
    print(1)
elif (line1[1] == 0 or line1[1] == 0):
    print(0)
else:
    print(line1[0]*line1[1] - 2)


Measured memory_bytes: 3444
#include <algorithm>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <ctime>
#include <deque>
#include <iostream>
#include <list>
#include <map>
#include <memory.h>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <unordered_map>
#include <unordered_set>
using namespace std;
typedef long double LD;
typedef long long LL;
typedef pair<LL, LL> pll;
typedef pair<int, int> pii;
typedef vector<int> vi;
#ifdef LOCAL
#define DEBUG(x) { cerr << "# " << #x << ": " << x << endl;}
#else
#define DEBUG(x)
#endif
mt19937_64 mt(time(0));
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i
　　　　／　　　＼　 　  |　|
　　　 /　　 /￣￣￣￣/　　|
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿
　 　　　＼/＿＿＿＿/　（u　⊃
---------------------------------------------------------------------------------------------------*/
const int MAXN = 1000 + 10;
string mat[MAXN];
int n, m;
int graph[MAXN][MAXN];
int dx[] = {-1, 1, 0, 0};
int dy[] = {0, 0, -1, 1};
vi edges[MAXN*MAXN];
int dist[MAXN*MAXN];

void dfs(int i, int j, int id) {
  graph[i][j] = id;
  for (int k = 0; k < 4; k++) {
    int ii = i + dx[k];
    int jj = j + dy[k];
    if (ii < 0 || ii >= n || jj < 0 || jj >= m) continue;
    if (mat[ii][jj] == '#' || graph[ii][jj] != 0) continue;
    dfs(ii, jj, id);
  }


}



int main() {
  ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
  cout.precision(10); cout << fixed;
#ifdef LOCAL
  freopen("../test.txt", "r", stdin);
    // freopen("../output.txt", "w", stdout);
#endif
  cin >> n >> m;
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  a--; b--; c--; d--;
  for (int i = 0; i < n; i++) {
    cin >> mat[i];
  }
  int id = 1;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (graph[i][j] != 0) continue;
      if (mat[i][j] == '#') graph[i][j] = -1;
      else dfs(i, j, id++);
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (graph[i][j] <= 0) continue;
      for (int u = -2; u <= 2; u++) {
        if (i+u < 0 || i+u >= n) continue;
        for (int v = -2; v <= 2; v++) {
          if (j+v < 0 || j+v >= m) continue;
          if (graph[i+u][j+v] <= 0 || graph[i+u][j+v] == graph[i][j]) continue;
          edges[graph[i][j]].push_back(graph[i+u][j+v]);
          edges[graph[i+u][j+v]].push_back(graph[i][j]);
        }
      }
    }
  }
  memset(dist, -1, sizeof(dist));
  queue<int> q;
  q.push(graph[a][b]);
  dist[graph[a][b]] = 0;
  while (!q.empty()) {
    int cur = q.front(); q.pop();
    for (int nxt : edges[cur]) {
      if (dist[nxt] != -1) continue;
      dist[nxt] = dist[cur] + 1;
      q.push(nxt);
    }
  }
  cout << dist[graph[c][d]] << '\n';












/*---------------------------------------Coding Space End------------------------------------------*/
#ifdef LOCAL
  cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s." << endl;
#endif
  return 0;
}
/* author:  txingml */
/* picture is from hamayanhamayan(CF handle) */


Measured memory_bytes: 58520
def solve():
    N, K = map(int,input().split())
    L = []
    R = []
    MOD = 998244353
    for _ in range(K):
        l, r = map(int,input().split())
        L.append(l)
        R.append(r)
    
    dp = [0] * (N+1)
    dp[1] = 1
    acc = [0] * (N+1)
    acc[1] = 1

    for i in range(2,N+1):
        for j in range(K):
            if i - L[j] < 0:
                continue
            dp[i] += (acc[i-L[j]] - acc[max(0,i-R[j]-1)]) % MOD
            dp[i] %= MOD
        
        acc[i] = (acc[i-1] + dp[i]) % MOD
    
    print(dp[-1])
if __name__ == '__main__':
    solve()

Measured memory_bytes: 77176
/*  TAHMID RAHMAN
    DAMIAN FOREVER
     MATH LOVER
    NEVER GIVE UP
*/
#include<bits/stdc++.h>
using namespace std;
#define pi acos(-1.0)
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define ll long long
#define pb push_back
#define fi first
#define se second
#define in insert
#define mp make_pair
#define GCD(a,b) __gcd(a,b);
#define endl "\n"
#define FRU freopen("out.txt","w",stdout)
#define FRO freopen("in.txt","r",stdin)
#define INFLL 9223372036854775807
#define debug 0
#define MAXN   100001
#define ar array
const int mxN=2e5;
const int MOD=1e9+7;
bool sortbysec(const pair<int,int> &a,const pair<int,int> &b){return (a.second < b.second);}
//Don't hesitate to ask me if you don't understand my code.......Happy coding,Tahmid...;
ll func(ll x,ll y,ll z)
{
   return x*x+y*y+z*z+x*y+y*z+z*x;
}
int main()
{
    fastio;
    ll n,x,y,z,i;
    cin>>n;
    ll a[n+1]={0};
    for(x=1;x*x<=n;x++)
    {
        for(y=1;x*x+y*y+x*y<=n;y++)
        {
            for(z=1;func(x,y,z)<=n;z++)
            {
                a[func(x,y,z)]++;
            }
        }
    }
    for(i=1;i<=n;i++)
    {
       cout<<a[i]<<endl;
    }
}




Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;


int main() {
    ll n;
    cin >> n;
    ll ans = 1e18;
    for (ll i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            ll a = n / i;
            ll digit = max(to_string(i).size(), to_string(a).size());
            ans = min(ans, digit);
        }
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
n, a, b = map(int, input().split())
attrs = input()

num_passed = 0
num_passed_overseas = 0

for student in attrs:
    if student == 'a':
        if num_passed < a + b:
            print('Yes')
            num_passed += 1
        else:
            print('No')
    elif student == 'b':
        if num_passed < a + b and num_passed_overseas < b:
            print('Yes')
            num_passed += 1
            num_passed_overseas += 1
        else:
            print('No')
    elif student == 'c':
        print('No')


Measured memory_bytes: 4016
#include<stdio.h>
#define FOR(i,a,b) for(int i=a;i<b;i++)
int main(){
	int sx,sy,tx,ty;
	scanf("%d %d %d %d",&sx,&sy,&tx,&ty);

	FOR(i,0,tx-sx) printf("R");
	FOR(i,0,ty-sy) printf("U");

	FOR(i,0,tx-sx) printf("L");
	FOR(i,0,ty-sy) printf("D");

	printf("D");
	FOR(i,0,tx-sx+1) printf("R");
	FOR(i,0,ty-sy+1) printf("U");
	printf("L");

	printf("U");
	FOR(i,0,tx-sx+1) printf("L");
	FOR(i,0,ty-sy+1) printf("D");
	printf("R");

}


Measured memory_bytes: 128
// Bismillahir Rahmanir Rahim
// Mr_Emrul

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

typedef long long int ll;
typedef pair <ll, ll> pll;
typedef pair <ll, pll> plp;
typedef pair <int, int> pii;
typedef pair <int, pii> pip;
const ll MX = 1000005;

#define LCM(a,b)        (a / __gcd(a,b) ) *-b
#define gcd(a,b)        __gcd(a,b)
#define all(x)          (x).begin(), (x).end()
#define mem(a, n)       memset(a,n,sizeof(a))
#define for1(i, n)      for(i=1; i<=n; i++)
#define for0(i, n)      for(i=0; i<n; i++)
#define rof0(i, n)      for(i=n-1; i>=0; i--)
#define rof1(i, n)      for(i=n; i>=1; i--)
#define forab(i, a, b)  for(i=a; i<=b; i++)
#define rofab(i, a, b)  for(i=b; i>=a; i--)
#define pb              push_back
#define pbb             pop_back
#define YES             cout << "YES" << endl
#define NO              cout << "NO" << endl
#define sin(s)          getline(cin, s)
#define scf(a)          cin >> a
#define scf2(a, b)      cin >> a >> b
#define scf3(a, b, c)   cin >> a >> b >> c
#define scf4(a,b,c,d)   cin >> a >> b >> c >> d
#define pnf(a)          cout << (a) << endl
#define pnf2(a, b)      cout << (a) << " " << (b) << endl
#define pnf3(a, b, c)   cout << (a) << " " << (b) << " " << (c) << endl
#define pnfa(a)         cout << (a) << " "
#define pf(a)           cout << (a)
#define sp              cout << " "
#define nl              cout << endl
#define sz(n)           n.size()
#define clear(v)        v.clear()
#define bug(n)          cout << ">> " << n << " <<" << endl
#define min3(a, b, c)   min(a, min(b, c))
#define max3(a, b, c)   max(a, max(b, c))
#define in              freopen("in.txt", "r", stdin)
#define out             freopen("out.txt", "w", stdout)
#define fast            {ios_base::sync_with_stdio(false); cin.tie(0);}
#define F               first
#define S               second
#define mpp             make_pair

int main()
{
    string a, b, c;
    scf2(a, b);
    ll n=a.size();
    ll m=b.size();
    ll l = a.size()+b.size(), i, x=0, y=0;
    for0(i, l)
    {
        if(i & 1)
            pf(b[y]),y++;
        else
            pf(a[x]),x++;
    }
    nl;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
int a,b;
int main(){
	scanf("%d%d",&a,&b);
	if(a>0&&b>0)puts("Positive");
	if(a<=0&&b>=0)puts("Zero");
	if(a<0&&b<0&&(b-a+1)%2==0)puts("Positive");
	if(a<0&&b<0&&(b-a+1)%2!=0)puts("Negative");
	return 0;
} 

Measured memory_bytes: 256
# include "cstdio"

int main(){
	int ans=0,sum;
	char c[5]; 
	register int i;
	scanf("%s",c);
	for(i=0;i<=3;i++){
		if(c[i]=='+'){
			ans++; 
		}else{
			ans--; 
		} 
	} 
	printf("%d",ans); 
	return 0; 
} 

Measured memory_bytes: 128
n=int(input())
x=list(map(int,input().split()))
y=list(map(int,input().split()))
z=list(map(int,input().split()))

res=0

for i in range(n):
	res+=y[x[i]-1]
	if i>0 and x[i]==x[i-1]+1:
		res+=z[x[i]-2]

print(res)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<long long> vll;
typedef vector<pair<int, int>> vpi;
typedef vector<pair<long long, long long>> vpl;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
#define INF (int)(1e9)
#define MAXX 1.1529215e+18
#define inf 999999
#define EPS (1e-7)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, n) for (int i = 1; i <= (int)(n); i++)
#define FOR(i, k, n) for (int i = (k); i < (int)(n); i++)
#define ALL(a) a.begin(), a.end()
#define RALL(a) a.begin(), a.end(), greater<int>()
#define ROT(a) a.begin(), a.begin() + 1, a.end()
#define RROT(a) a.begin(), a.end() - 1, a.end()
#define PB push_back
#define MP make_pair
#define PI acos(-1.0)
#define sz(a) a.size()
const ll MOD = 1e9 + 7;
const int MAX = 10000000;
template <typename T1, typename T2>
inline bool chmin(T1& a, T2 b)
{
    if (a > b) {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T1, typename T2>
inline bool chmax(T1& a, T2 b)
{
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T>
T gcd(T a, T b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}
//cout << 'H' << endl;
/*--------------------------------------------*/

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

    ll N;
    cin >> N;

    ll total = N * (N + 1) / 2;

    ll m3 = (N / 3);
    ll n3 = 3 * m3 * (m3 + 1) / 2;

    ll m5 = (N / 5);
    ll n5 = 5 * m5 * (m5 + 1) / 2;


    ll m15 = (N / 15);
    ll n15 = 15 * m15 * (m15 + 1) / 2;


    //cout << m3 << ' ' << n3 << endl;
    cout << total - n3 - n5 + n15 << endl;
}


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


using namespace std;

using ll = long long;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
const ll MOD = 1000000007;




int main() {
	int n;

	cin >> n;


	vector<ll> ps(n + 1,0);

	for (int i = 1; i <= n; i++) {
		ll cur = i;
		for (int j = 2; j <= i; j++) {
			while(cur % j == 0) {
				cur /= j;
				ps[j]++;
			}
		}

	}

	ll ans = 1;

	for (int i = 2; i <= n; i++) {
		if (ps[i] > 0) {
			ans = (ans * (ps[i] + 1LL)) % MOD;
		}
	}


	cout << ans << endl;

	return 0;
}

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

bool ok = false;
int n;

int main() {
  cin >> n;
  while (n > 0) {
    if (n % 10 == 7) ok = 1;
    n /= 10;
  }
  if (ok) cout << "Yes";
  else cout << "No";
}

Measured memory_bytes: 3620
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;

namespace AtCoder.B
{
    public class Program
    {
        public static void Main() { var r = GetResult(); Debug.WriteLine(r); Console.Write(r); }

        private static object GetResult()
        {
            var S = ReadText();
            var min = long.MaxValue;
            for (int i = 0; i < S.Length - 2; i++)
            {
                var val = S.Substring(i, 3);
                min = Math.Min(Math.Abs(753 - int.Parse(val)), min);
            }
            return min;
        }

        #region Console.Read

        public static string ReadText() { return Console.ReadLine(); }
        public static List<string> ReadTexts() { return Console.ReadLine().Split(' ').ToList(); }
        public static long ReadLong() { return long.Parse(Console.ReadLine()); }
        public static (long, long) Read2Longs() { var ls = ReadLongs(); return (ls[0], ls[1]); }
        public static (long, long, long) Read3Longs() { var ls = ReadLongs(); return (ls[0], ls[1], ls[2]); }
        public static (long, long, long, long) Read4Longs() { var ls = ReadLongs(); return (ls[0], ls[1], ls[2], ls[3]); }
        public static (long, long, long, long, long) Read5Longs() { var ls = ReadLongs(); return (ls[0], ls[1], ls[2], ls[3], ls[4]); }
        public static List<long> ReadLongs() { return Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToList(); }

        #endregion
    }
}


Measured memory_bytes: 27348
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<map>
#include<vector>
using namespace std;

typedef long long ll;
ll x[55],y[55];
map<ll,int> cntx,cnty;
vector<ll> varx,vary;
int dp[55][55],a[55];
ll ans=5e18;

int main(){
	int n,k;	scanf("%d%d",&n,&k);
	for(int i=0;i<n;i++){
		scanf("%lld%lld",&x[i],&y[i]);
		varx.push_back(x[i]);
		vary.push_back(y[i]);
	}
	sort(varx.begin(),varx.end());
	sort(vary.begin(),vary.end());
	varx.erase(unique(varx.begin(),varx.end()),varx.end());
	vary.erase(unique(vary.begin(),vary.end()),vary.end());
	for(int i=0;i<varx.size();i++)	cntx[varx[i]]=i+1;
	for(int i=0;i<vary.size();i++)	cnty[vary[i]]=i+1;
	for(int i=0;i<n;i++)	dp[cntx[x[i]]][cnty[y[i]]]++;
	for(int i=1;i<=varx.size();i++){
		for(int j=1;j<=vary.size();j++)	dp[i][j]+=dp[i-1][j]+dp[i][j-1]-dp[i-1][j-1];
	}
	for(int L=1;L<=varx.size();L++){
		for(int R=L;R<=varx.size();R++){
			for(int i=1;i<=vary.size();i++)	a[i]=dp[R][i]-dp[L-1][i];
			for(int i=1;i<=vary.size();i++){
				int pos=lower_bound(a,a+vary.size()+1,a[i-1]+k)-a-1;
				if(pos!=vary.size()){
//					printf("%lld %lld %lld %lld\n",varx[L-1],varx[R-1],vary[i-1],vary[pos-1]);
					ans=min(ans,(varx[R-1]-varx[L-1])*(vary[pos]-vary[i-1]));
				}
			}
		}
	}
	printf("%lld\n",ans);
	return 0;
}

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

int main(){
  long long int wi;
  long long int x=1;
  while(cin>>wi){
    if(wi==0)break;
    long long int n;
    cin>>n;
    vector<long long int> v(n);
    vector<long long int> w(n);
    char t;
    for(long long int i=0;i<n;i++)cin>>v[i]>>t>>w[i];
    vector<vector<long long int> > dp(1002,vector<long long int>(1002,0));

    for(long long int i=1;i<=n;i++){
      for(long long int j=0;j<=wi;j++){
        if(w[i-1]<=j){
          dp[i][j]=max(dp[i-1][j],dp[i-1][j-w[i-1]]+v[i-1]);
        }else{
          dp[i][j]=max(dp[i][j],dp[i-1][j]);
        }
      }
    }

    /*
    for(int i=0;i<n;i++){
      for(int j=0;j<=wi;j++){
        cout<<dp[i][j]<<" ";
      }
      cout<<endl;
    }
    */

    long long int ans=0;
    long long int id=0;
    for(long long int i=0;i<=wi;i++){
      if(ans<dp[n][i])id=i;
      ans=max(ans,dp[n][i]);
    }
    cout<<"Case "<<x<<":"<<endl;
    cout<<ans<<endl;
    cout<<id<<endl;

    x++;
  }
}



Measured memory_bytes: 10716
# -*- coding: utf-8 -*-
N = int(input())

DP = list(range(N+1))
L = []

i = 1
while True:
    if 6**i > N:
        break
    L.append(6**i)
    i += 1

i = 1
while True:
    if 9**i > N:
        break
    L.append(9**i)
    i += 1
    
for l in sorted(L):
    for j in range(l, N+1):
        DP[j] = min(DP[j-l]+1, DP[j])
print(DP[-1])

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

using namespace std;
const int maxn = 50 + 1, mod = 1e9 + 7;

int n;

struct matrix{
    int c[maxn][maxn];
    void init()
    {
        for(int i=1; i<=n; ++i)
            for(int j=1; j<=n; ++j) c[i][j] = 0;
    }
};

matrix cs;
long long k;

matrix mul(matrix a, matrix b)
{
    matrix t; t.init();
    for(int i=1; i<=n; ++i)
        for(int j=1; j<=n; ++j) 
            for(int k=1; k<=n; ++k) 
        t.c[i][j] = (t.c[i][j] + (1LL*a.c[i][k]*b.c[k][j]) % mod) % mod;
    return t;
}
matrix power(long long b)
{
    if (b == 1) return cs;
    matrix t = power(b/2);
    t = mul(t, t);
    if (b&1) t = mul(t, cs);
    return t;
}

int main()
{
    #ifdef NTMA 
        freopen("abc.inp", "r", stdin);
    #endif
    //memset(f, 255, sizeof(f));
    cin >> n >> k;
    for(int i=1; i<=n; ++i)
        for(int j=1; j<=n; ++j) cin >> cs.c[i][j];
    long long ans = 0;
    matrix a = power(k);
    for(int i=1; i<=n; ++i)
        for(int j=1; j<=n; ++j) ans = (ans + a.c[i][j]) % mod;
    cout << ans;
    return 0;
}

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

char S[100001];

int main() {
    scanf("%s", S);
    int n = strlen(S), cnt = 1;
    int c = S[0];
    for (int i = 1; i < n; i++) {
        if (S[i] != c) {
            ++cnt;
            c = S[i];
        }
    }
    printf("%d\n", cnt - 1);
    return 0;
}

Measured memory_bytes: 384