akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define int long long int
#define pb push_back
#define MAX INT_MAX
#define MIN INT_MIN
#define MOD 1000000007
#define FO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
set <int> s;
bool ar[100001];
void seive() {
	ar[0] = ar[1] = true;

	for(int p=2; p*p<=100001; p++) {
		if(ar[p] == false) {
			for(int i=p*p;i<=100001;i+=p)
				ar[i] = true ;
		}
	}

	for(int p=2;p<=100001;p++) {
		if(ar[p] == false)
			s.insert(p);
	}
}
void solve() {
	int a[3][3];
	int f[3][3];
	for(int i=0;i<3;i++) {
		for(int j=0;j<3;j++) {
			f[i][j] = 0;
		}
	}
	for(int i=0;i<3;i++) {
		for(int j=0;j<3;j++) {
			cin >> a[i][j];
		}
	}
	int n, flag = 0, flag2 = 0, flag3 = 0, flag4 = 0;
	cin >> n;
	int c3 = 0;
	vector <int> v(n);
	for(int i=0;i<n;i++) {
		cin >> v[i];
		for(int j=0;j<3;j++) {
			for(int k=0;k<3;k++) {
				if(a[j][k] == v[i]) {
					f[j][k] = 1;
					c3++;
				}
			}
		}
	}
	if(c3 == 0) {
		cout << "No" << endl;
		return ;
	}
	for(int i=0;i<3;i++) {
			int c = 0;
		for(int j=0;j<3;j++) {
			if(f[i][j] == 1)
				c++;
			if(c == 3) {
			flag = 1;
			break;
			}
		}
		if(flag == 1) {
			cout << "Yes" << endl;
			return;
		}
	}

	for(int j=0;j<3;j++) {
		int c1 = 0;
		for(int i=0;i<3;i++) {
			if(f[i][j] == 1)
				c1++;
			if(c1 == 3) {
				flag2 = 1;
				break;
			}
		}
		if(flag2 == 1) {
			cout << "Yes" << endl;
			return;
		}
	}

	if(f[0][0] == 1 && f[1][1] == 1 && f[2][2] == 1) {
		cout << "Yes" << endl;
		return ;
	}
	else if(f[0][2] == 1 && f[1][1] == 1 && f[2][0] == 1) {
		cout << "Yes" << endl;
		return;
	}
		cout << "No" << endl;
}
int32_t main() {
    FO;
    solve();
    return 0;
}

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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  vector<int> p(m);
  vector<vector<int>> s(m);
  for (int i = 0; i < m; i++) {
    int k;
    cin >> k;
    for (int j = 0; j < k; j++) {
      int ss;
      cin >> ss;
      ss--;
      s[i].emplace_back(ss);
    }
  }
  for (int i = 0; i < m; i++) {
    cin >> p[i];
  }
  int ans = 0;
  for (int bit = 0; bit < (1 << n); bit++) {
    // cerr << bit << endl;
    bool ok = 1;
    for (int i = 0; i < m; i++) {
      int on = 0;
      for (const auto& e : s[i]) {
        if (bit & (1 << e)) on++;
      }
      if ((on % 2) ^ p[i]) {
        ok = 0;
        break;
      }
      // cerr << on << endl;
    }
    if (ok) ans++;
  }
  cout << ans << '\n';
  return 0;
}

Measured memory_bytes: 3596
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
#define INF 10000000001
#define DIM 200001
#define mod 1000000007
#define PI 3.1415926535897932384626433
#define se second
#define fi first
#define pb push_back
#define T true
#define F false
#define endl "\n"
typedef char ch;
typedef bool boll;
typedef string st;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef set < string > sst;
typedef set < long long > sl;
typedef queue < long long > que;
typedef vector < long long > vec;
typedef map < long long, long long > mll;
typedef pair < long long, long long > pll;
typedef vector < pair < long long, long long > > vpl;
typedef pair < long long, unsigned long long > pul;
ll t,n,z,x,s;
int main()
{
    string ss;
    cin>>ss;
    n=ss.length();
    for(int i=1;i<=n;i++)cout<<"x";

}


Measured memory_bytes: 256
A,B,C,D = map(int,input().split())

time = [0]*101

for i in range(A,B):
    time[i] += 1
for i in range(C,D):
    time[i] += 1

ans = 0
for i in time:
    if i == 2:
        ans += 1

print(ans)

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

int main(){
	int n;
	cin>>n;
	int hei[n+1];
	for(int i=0;i<n;i++)
		cin>>hei[i];
	int arr[n+1];
	arr[0]=0;
	arr[1]=(hei[1]-hei[0]);
	if(arr[1]<0)
		arr[1]=arr[1]*-1;
	for(int i=2;i<n;i++){
		int temp1=(hei[i-1]-hei[i]);
		int temp2=(hei[i-2]-hei[i]);
	//	cout<<temp1<<endl;
		if(temp1<0)
			temp1*=-1;
		temp1+=arr[i-1];
	//	cout<<temp1<<endl;
		if(temp2<0)
			temp2*=-1;
		temp2+=arr[i-2];
		if(temp1<temp2)
			arr[i]=temp1;
		else
			arr[i]=temp2;
		//cout<<arr[i]<<endl;
	}
	cout<<arr[n-1]<<endl;
}

Measured memory_bytes: 1024
N = int(input())
arr = [0] + list(map(int, input().split())) + [0]
ans = 0
for i in range(1,len(arr)):
    ans += abs(arr[i]-arr[i-1])
for i in range(1,len(arr)-1):
    print(ans-abs(arr[i-1]-arr[i])-abs(arr[i+1]-arr[i])+abs(arr[i-1]-arr[i+1]))

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

using ll = long long;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;
using vint = vector<int>;
using vvint = vector<vint>;
using vvvint = vector<vvint>;
using vdouble = vector<double>;
using vvdouble = vector<vdouble>;
using vvvdouble = vector<vvdouble>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using uint = unsigned int;
using ull = unsigned long long;

template<typename T> using uset = unordered_set<T>;
template<typename T1, typename T2> using umap = unordered_map<T1, T2>;

constexpr int INF = (1 << 30) - 1;
constexpr ll LLINF = 1LL << 60;
constexpr int dy[] = {1, 0, -1, 0, 1, -1, -1, 1};
constexpr int dx[] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr char el = '\n';
constexpr int mod = 1000000007;

template<typename T> T gcd(T a, T b) { return (b ? gcd(b, a % b) : a); }
template<typename T> T lcm(T a, T b) { return (a / gcd(a, b) * b); }
template<typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) { return (a > b && (a = b, true)); }
template<typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) { return (a < b && (a = b, true)); }

template<typename T>
ostream& operator <<(ostream &os, vector<T> &v) {
	os << v[0];
	for (int i = 1; i < v.size(); i++) os << " " << v[i];
	return (os);
}

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

template<typename T1, typename T2>
istream& operator >>(istream &is, pair<T1, T2> &p) {
	return (is >> p.first >> p.second);
}


void Main() {
	int ar[] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
	int K;
	cin >> K;
	cout << ar[K-1] << endl;
}

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


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

using namespace std;

template <typename T>
struct edge {
	int to;
	T cost;
	edge(int t, T c) : to(t), cost(c) {}
};
template <typename T>
void dijkstra(const vector<vector< edge<T> >>& G, vector<T>& d, int s) {
	priority_queue<pair<T, int>, vector< pair<T, int> >, greater< pair<T, int> >> que;
	d[s] = 0;
	que.emplace(0, s);

	while (!que.empty()) {
		auto p = que.top();
		que.pop();
		int u = p.second;
		if (d[u] < p.first) { continue; }

		for (auto e : G[u]) {
			if (d[e.to] <= d[u] + e.cost) { continue; }
			d[e.to] = d[u] + e.cost;
			que.emplace(d[e.to], e.to);
		}
	}
}

int main() {
	const Int INF = 1e18;
	int N, M;
	cin >> N >> M;
	vector<vector< edge<Int> >> g(N);
	for (int i = 1; i < N; ++i) {
		g[i].emplace_back(i - 1, 0);
	}
	for (int i = 0; i < M; ++i) {
		int L, R, C;
		cin >> L >> R >> C;
		g[L - 1].emplace_back(R - 1, C);
	}
	
	vector<Int> d(N, INF);
	dijkstra(g, d, 0);
	cout << (d[N - 1] < INF ? d[N - 1] : -1) << endl;

	return 0;
}


Measured memory_bytes: 10104
n = int(input())
A = list(map(int, input().split()))
B = {}
C = {}
for i, a in enumerate(A):
  if i % 2 == 0:
    B[a] = B.get(a, 0) + 1
  else:
    C[a] = C.get(a, 0) + 1
Bs = sorted(B.items(), key = lambda x: x[1], reverse = True)
Cs = sorted(C.items(), key = lambda x: x[1], reverse = True)
if Bs[0][0] != Cs[0][0]:
  print(n - Bs[0][1] - Cs[0][1])
elif len(Bs) == 1:
  if len(Cs) == 1:
    print(n // 2)
  else:
    print(n - Bs[0][1] - Cs[1][1])
else:
  if len(Cs) == 1:
    print(n - Bs[1][1] - Cs[0][1])
  else:
    print(min(n - Bs[0][1] - Cs[1][1], n - Bs[1][1] - Cs[0][1]))

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

int main(void){
    int i,end,point_a,point_z;
    string s;
    cin >> s;

    end = s.size();

    for(i=0; i<end; i++){
        if(s.at(i) == 'A'){
            point_a = i;
            break;
        }
    }
    for(i=end-1; i>=point_a; i--){
        if(s.at(i) == 'Z'){
            point_z = i;
            break;
        }
    }

    cout << point_z - point_a  + 1 << endl;
    return 0;
}

Measured memory_bytes: 640
include Math
a,b,x = gets.split.map(&:to_f)
S = x / a

if S <= a * b / 2.0
  a_ = 2.0 * S / b
  puts atan2(b, a_) * 180.0 / PI
else
  S_ = a * b - S
  b_ = 2.0 * S_ / a
  puts atan2(b_, a) * 180.0 / PI
end


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

int main() {
  int a, b,c,d;
  cin >>a >>b >>c >>d;
  int L=a+b, R=c+d;
  if (L<R){
    cout <<"Right" <<endl;
} 
else if(L==R){
    cout <<"Balanced" <<endl;
}
else if (L>R){
    cout <<"Left" <<endl;
}
}


Measured memory_bytes: 256
L,R = map(int,input().split())

mod = 10**9+7

def f(L,R):
    if L>R : return 0
    R = bin(R)[2:]
    N = len(R)
    ret = f(L,int("0"+"1"*(N-1),2))
    L = bin(L)[2:]
    if len(L) != N : L = "1"+"0"*(N-1)
    for i in range(N):
        if R[i] == "0" : continue
        R2 = R[:i] + "0" + "?"*(N-i-1)
        if i==0: R2 = R
        for j in range(N):
            if L[j] == "1" and j!=0 : continue
            L2 = L[:j] + "1" + "?"*(N-j-1)
            if j==0 : L2 = L
            if L2[0] == "0" : break
            tmp = 1
            for r,l in zip(R2[1:],L2[1:]):
                if r=="0" and l=="1" : tmp *= 0 ; break
                if r=="?" and l=="?" : tmp = tmp*3%mod
                if r=="?" and l=="0" : tmp = tmp*2%mod
                if r=="1" and l=="?" : tmp = tmp*2%mod
            ret += tmp
            ret %= mod
    return ret

print(f(L,R))

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

 int main (){
     struct process {string name;int value;};
     int n,q,count=0,total=0,b;
     string a;
     cin >> n >> q;
     queue <process> _process;
     struct process ___process[n];
     for (int i=0; i<n; i++){
          
         cin >> a >> b;
           _process.push(process{a,b});
     }
     while(count<n){
        
         process a = _process.front();
          _process.pop();
         int after = a.value - q;
         if(after <=0){
             int c;
             c = a.value;
             c +=total;
            ___process[count]=a;
            ___process[count].value=c;
            total+=a.value;
             count++;
             
             
         }else{

             a.value=after;
             total+=q;
             _process.push(a);

         }
     }
     for(int j=0; j<n; j++){
         cout << ___process[j].name << ' ' << ___process[j].value<<endl;;
     }
 }



Measured memory_bytes: 7140
//by shubham_bitsg

#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef vector <string> vs;
 
#define forl(i,a,b) for (int i = a; i < b; i++)
#define rfor(i,b,a) for (int i = b; i >= a; i--)
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define sort(x) sort(x.begin(), x.end())
#define sumup(x) accumulate(x.begin(), x.end(), 0)

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int x, y;
    cin>>x>>y;
    if((y>=2*x) && (4*x>=y) && (y-2*x)%2==0 && (4*x-y)%2==0)
        cout<<"Yes\n";
    else
        cout<<"No\n";
}

Measured memory_bytes: 3604
#include<iostream>
#include<algorithm>
#include <vector>
#include<cmath>
using namespace std;
int main() {
	int n;
	float sum = 0;
	cin >> n;
	vector<float>vec(n);
	for (int ia=0; ia < n; ia++) {
		cin >> vec.at(ia);
	}
	for (int ib = 0; ib < n; ib++) {
		sum += 1 / vec.at(ib);
	}
	float ans = 1 / sum;
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a) for(int i = 0; i < (a); i++)
#define ALL(a) (a).begin(),(a).end()
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const int MOD = 1e9 + 7;
#define MAX_N 200200

vector<int> G[MAX_N];
int cnt[MAX_N];
int ans[MAX_N];

signed main(){
    int n,q;
    cin >> n >> q;
    int a,b;
    REP(i,n - 1){
        scanf("%d %d", &a, &b);
        a--;
        b--;
        G[a].push_back(b);
    }
    int p,x;
    REP(i,q){
        scanf("%d %d", &p, &x);
        p--;
        cnt[p] += x;
    }
    queue<int> que;
	que.push(0);
	ans[0] = cnt[0];
	while(que.size()){
		int u = que.front();
		que.pop();
		for(auto v : G[u]){
            ans[v] = ans[u] + cnt[v];
            que.push(v);
        }
	}
    REP(i,n){
        printf("%d ", ans[i]);
    }
    printf("\n");
}

Measured memory_bytes: 14720
#include<stdio.h>
#include<string.h>
#define M /* your task*/1046527
#define L 14

char H[M][L]; /* Hash Table */

int getChar(char ch){
  if ( ch == 'A') return 1;
  else if ( ch == 'C') return 2;
  else if ( ch == 'G') return 3;
  else if ( ch == 'T') return 4;
  else return 0;
}

/* convert a string into an integer value */
long long getKey(char str[]){
  long long sum = 0, p = 1, i;
  for ( i = 0; i < strlen(str); i++ ){
    sum += p*(getChar(str[i]));
    p *= 5;
  }
  return sum;
}

int h1(int key){
  return /* your task */key%M;
}
int h2(int key){
  return /* your task */1+(key%(M-1));
}
int h(int key,int i){
  return (h1(key)+i*h2(key))%M;
}

int find(char str[]){

  /* your task */
  int i=0,j;
  while(1){
    j=h(getKey(str),i);
    if(strcmp(H[j],str)==0){
      return j;
    }
    else if(H[j][0]=='\0'|| i>=M){
      return 0;
    }
    else{
      i++;
    }
  }
}

int insert(char str[]){

  /* your task */
  int i=0,j;
  while(1){
    j=h(getKey(str),i);
    if(H[j][0]=='\0'){
      strcpy(H[j],str);
      return j;
    }
    else{
      i++;
    }
  }
}

int main(){
    int i, n, h;
    char str[L], com[9];
    for ( i = 0; i < M; i++ ) H[i][0] = '\0';
    
    scanf("%d", &n);
    
    for ( i = 0; i < n; i++ ){
	scanf("%s %s", com, str);
	
	if ( com[0] == 'i' ){
	    insert(str);
	} else {
	    if (find(str)){
		printf("yes\n");
	    } else {
		printf("no\n");
	    }
	}
    }

    return 0;
}



Measured memory_bytes: 16052
#include <iostream>
#include <vector>
#include <climits>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <bitset>
#include <utility>
#include <numeric>
#include <queue>
#include <stack>

using ll = long long;
using namespace std;

constexpr int MOD = 1e9 + 7;
constexpr ll MOD_LL = ll(1e9) + 7;

int main(void) {
	int n, k;
	cin >> n >> k;
	
	if( n % k == 0 ) cout << 0 << endl;
	else cout << 1 << endl;
	
	return 0;
}


Measured memory_bytes: 256
s=input()
le=len(s)

cn=0

if le%2==0:
    for i in range(int(le/2)):
        if s[i]!=s[le-1-i]:
            cn=cn+1

if le%2==1:
    for i in range(int(le/2)):
        if s[i]!=s[le-1-i]:
            cn=cn+1

print(cn)


Measured memory_bytes: 38384
#include<bits/stdc++.h>
using namespace std;
namespace FAST_IO
{
	template<typename T> void read(T &a)
	{
		a=0;
		int f=1;
		char c=getchar();
		while(!isdigit(c))
		{
			if(c=='-')
			{
				f=-1;
			}
			c=getchar();
		}
		while(isdigit(c))
		{
			a=a*10+c-'0';
			c=getchar();
		}
		a=a*f;
	}
	template <typename T> void write(T a)
	{
		if(a<0)
		{
			a=-a;
			putchar('-');
		}
		if(a>9)
		{
			write(a/10);
		}
		putchar(a%10+'0');
	}
	template <typename T> void writeln(T a)
	{
		write(a);
		puts("");
	}
}
int ans;
int main()
{
	int n;
	cin>>n;
	for(int i=1;i<=n;i+=2)
	{
		int t=0;
		for(int j=1;j<=i;j++)
		{
			if(i%j==0)
			{
				t++;	
			}
		}
		if(t==8)
		{
			ans++;
		}
	}
	cout<<ans;
}


Measured memory_bytes: 256
using System;
using System.IO;
using System.Net;
using System.Net.Sockets;
using System.Linq;
using System.Diagnostics;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
using System.Text.RegularExpressions;
using static System.Math;
using MethodImplAttribute = System.Runtime.CompilerServices.MethodImplAttribute;
using MethodImplOptions = System.Runtime.CompilerServices.MethodImplOptions;

public static class P
{
    public static void Main()
    {
        var n = int.Parse(Console.ReadLine());
        var d = Console.ReadLine().Split().Select(int.Parse).ToArray();
        var res = 0;
        for (int i = 0; i < n; i++)
        {
            for (int j = 0; j < n; j++)
            {
                if (i == j) continue;
                res += d[i] * d[j];
            }
        }
        Console.WriteLine(res / 2);
    }
}



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

using namespace std;

#define N 200000
#define INF 0x3f3f3f3f

char str[N + 2];
int sum[26][N + 2];
int dp[N + 2];
map<int, int> m[2];
int n;

int convert(int p){
	int ans, i;

	for (i = 0, ans = 0; i < 26; i++){
		if (sum[i][p] % 2){
			ans |= (1 << i);
		}
	}

	return ans;
}

int main(){
	int i, j, x;

	scanf("%[^\r\n]%n", str + 1, &n);

	// Cumulative sum of each character
	for (i = 'a'; i <= 'z'; i++){
		for (j = 1; j <= n; j++){
			sum[i - 'a'][j] = sum[i - 'a'][j - 1] + ((int)str[j] == i);
		}
	}

	m[0][convert(0)] = 0;
	dp[0] = 0;

	for (i = 1; i <= n; i++){
		x = convert(i);
		dp[i] = INF;

		// If same index parity has an entry with the same parity
		if (m[i % 2].count(x)){
			dp[i] = min(dp[i], m[i % 2][x] + 1);
		}

		// If the other index parity has an entry with the same parity except for one character
		for (j = 0; j < 26; j++){
			x ^= (1 << j);

			if (m[(i + 1) % 2].count(x)){
				dp[i] = min(dp[i], m[(i + 1) % 2][x] + 1);
			}

			x ^= (1 << j);
		}

		if (m[i % 2].count(x)){
			m[i % 2][x] = min(m[i % 2][x], dp[i]);
		}
		else{
			m[i % 2][x] = dp[i];
		}
	}

	printf("%d\n", dp[n]);

	return 0;
}

Measured memory_bytes: 30848
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <utility>
using namespace std;

#define rep(i,n) for((i)=0; (i)<(int)(n); ++(i))
#define foreach(c,itr) for(__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)
typedef long long ll;
typedef pair<ll,int> P;

struct Point {
  int x, y, id;
  Point(){
  }
  Point(int a, int b, int c) : x(a), y(b), id(c) {
  }
};

struct Edge {
  int to, cost;
  Edge(int a, int b) : to(a), cost(b) {
  }
};

int w, h, max_num;
vector<Point> V[2500];
vector<Edge> es[2500];
Point s, g;

const int inf = 1<<28;
ll dp[2500];

int dijkstra(int s, int g) {
  priority_queue<P,vector<P>,greater<P> > q;
  fill(dp, dp + 2500, inf);
  dp[s] = 0;
  q.push(P(0, s));
  
  while (!q.empty()) {
    P p = q.top(); q.pop();
    int v = p.second, i;
    if (dp[v] < p.first) continue;
    //cout << v << "|" << dp[v] << endl;
    rep (i,es[v].size()) {
      Edge te = es[v][i];
      if (dp[te.to] > dp[v] + te.cost) {
        dp[te.to] = dp[v] + te.cost;
        q.push(P(dp[te.to], te.to));
      }
    }
  }
  
  return dp[g];
}

void solve() {
  int i, j, k, id = 1;
  int s_id = 0, g_id;
  max_num = 0;
  string in;
  
  rep (i,h) rep (j,w) {
    cin >> in;
    if (in == ".") continue;
    if (in == "S") {
      s.x = j, s.y = i; continue;
    }
    if (in == "G") {
      g.x = j, g.y = i; continue;
    }
    int num = atoi(in.c_str());
    max_num = max(max_num, num);
    V[num].push_back(Point(j,i,id));
    id++;
  }
  if (max_num != 0) {
    g_id = id;
    // id of S is 0, id of G is @id.
    // connect S & 1
    rep (i,V[1].size()) {
      int dist = abs(s.x - V[1][i].x) + abs(s.y - V[1][i].y);
      es[0].push_back(Edge(V[1][i].id, dist));
    }
    // connect
    for (i = 1; i < max_num; i++) {
      rep (j,V[i].size()) rep (k,V[i+1].size()) {
        int dist = abs(V[i][j].x - V[i+1][k].x) + abs(V[i][j].y - V[i+1][k].y);
        int a_id = V[i][j].id, b_id = V[i+1][k].id;
        es[a_id].push_back(Edge(b_id, dist));
      }
    }
    // connect max_num & G
    rep (i,V[max_num].size()) {
      int dist = abs(g.x - V[max_num][i].x) + abs(g.y - V[max_num][i].y);
      int t_id = V[max_num][i].id;
      es[t_id].push_back(Edge(g_id, dist));
    }
  } else {
    cout << abs(s.x - g.x) + abs(s.y - g.y) << endl;
    return;
  }
    
  
  // dijkstra
  cout << dijkstra(s_id, g_id) << endl;
  
  // clear
  rep (i,max_num+1) V[i].clear();
  rep (i,g_id+1) es[i].clear();
}

int main() {
  while (cin >> w >> h, w|h) {
    solve();
  }
  return 0;
}

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

//WA

struct segmentTree{
	static const int MAX_SIZE = 1 << 17;
	long long segMin[2 * MAX_SIZE - 1]={}, segAdd[2 * MAX_SIZE - 1]={};
	int n;
	segmentTree(){}
	segmentTree(int sz, long long* v){
		n=sz;
		rep(i,n)add(i,i+1,v[i]);
	}

	//区間[a, b)に値xを加算する.
	void add(int a, int b, int x, int k = 0, int l = 0, int r = MAX_SIZE)
	{
		if (r <= a || b <= l) return; //もし交差しない区間であれば終える.
		
		if (a <= l && r <= b){ //もし今みている区間[l, r)が[a, b)に完全に内包されていれば
			segAdd[k] += x;  //区間[l, r)にkを加算する.
			return;
		}
		
		add(a, b, x, k * 2 + 1, l, (l + r) / 2); //子の区間に(必要があれば)xを加算する.
		add(a, b, x, k * 2 + 2, (l + r) / 2, r); //〃

		//親の区間の最小値は, 子の区間の最小値 + 自分に一様に加算されている値 である.一様に加算される値は更新しなくて良い.
		segMin[k] = min(segMin[k * 2 + 1] + segAdd[k * 2 + 1], segMin[k * 2 + 2] + segAdd[k * 2 + 2]);
	}

	long long getMin(int a, int b, int k = 0, int l = 0, int r = MAX_SIZE)
	{
		if (r <= a || b <= l) return (LLONG_MAX);
		
		if (a <= l && r <= b) return (segMin[k] + segAdd[k]); //完全に内包されていれば,その区間の最小値を返す.
		
		long long left = getMin(a, b, k * 2 + 1, l, (l + r) / 2); //子の区間の最小値を求める.
		long long right = getMin(a, b, k * 2 + 2, (l + r) / 2, r); //子の区間の最小値を求める
		
		return (min(left, right) + segAdd[k]); //親の区間の最小値は, 子の区間の最小値 + 自分に一様に加算されている値 である (大切なので2回書きました!!)
	}
};


int main(void){
	ll N,x,A[100010],ans=inf;
	cin>>N>>x;
	rep(i,N){
		cin>>A[i];
	}
	segmentTree f(N,A);
	rep(i,N){//魔法の回数
		ll sum=x*i;
		rep(j,N){//スライムjを手に入れるのにかかる最小コスト
			if(j>=i){
				sum+=f.getMin(j-i,j+1);
			}else{
				sum+=min(f.getMin(0,j+1),f.getMin(N-(i-j),N));
			}
		}
		// cout<<sum<<endl;
		ans=min(ans,sum);
	}
	// cout<<f.getMin(1,3)<<endl;
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 5120
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <iostream>
#include <vector>
#include <string>
#include <sstream>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <functional>

using namespace std;

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

#define fst first
#define scd second
#define PB push_back
#define MP make_pair
#define rep(i,x) for(int i=0;i<(x);++i)
#define rep1(i,x) for(int i=1;i<=(x);++i)
#define rrep(i,x) for(int i=(x)-1;i>=0;--i)
#define rrep1(i,x) for(int i=(x);i>=1;--i)
#define FOR(i,a,x) for(int i=(a);i<(x);++i)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()

#define omajinai ios::sync_with_stdio(false);cin.tie(0)

template<typename T>bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;}
template<typename T>bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;}
template<typename T>T get(){T a;cin>>a;return a;}
template<typename T>T rev(T a){reverse(all(a));return a;}
template<typename T>istream&operator>>(istream&is,vector<T>&vec){rep(i,vec.size())is>>vec[i];return is;}
template<typename T>vector<T>&sort(vector<T>&a){sort(all(a));return a;}

const int inf = 1e9;
const ll linf = 3e18;
const double eps = 1e-9;

int M, N;
int P[10000], C[500], E[500];
int dp[20010];

signed main()
{
    cin >> M >> N;

    rep(i, M) {
        cin >> P[i];
    }

    rep(i, N) {
        cin >> C[i] >> E[i];
    }

    sort(P, P + M, greater<int>());

    fill_n(dp, M + 10000 + 1, inf);
    dp[0] = 0;

    rep(i, N) {
        rrep(j, M + 1) {
            if (dp[j] != inf) {
                chmin(dp[j + C[i]], dp[j] + E[i]);
            }
        }
    }

    int ma = 0;
    int sum = 0;

    for (int i = 1; i <= M + 10000; ++i) {
        if (i <= M) sum += P[i - 1];
        chmax(ma, sum - dp[i]);
    }

    cout << ma << endl;
}

Measured memory_bytes: 1300
#include <stdio.h>

int main(void)
{
    int N;
    int key = 0;
    int i;
    int flag = 1000000000;
	int a;

    scanf("%d", &N);
	
	a = N;
	
	while (N < flag) {
		flag /= 10;
	}

    while (N != 0) {
		key += (N / flag);
		N %= flag;;
		flag /= 10;
    }
		

    if (a % key == 0) {
        printf("Yes\n");
    }
    else {
        printf("No\n");
    }

    return (0);
}

Measured memory_bytes: 128
unittest
{
	assert( [ "3", "2 3", "1 1", "3 2" ].parse.expand.solve == 10 );
	assert( [ "4", "1 1", "1 1", "1 5", "1 100" ].parse.expand.solve == 101 );
	assert( [ "5", "3 10", "48 17", "31 199", "231 23", "3 2" ].parse.expand.solve == 6930 );
}



import std.conv;
import std.range;
import std.stdio;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto n = input.front.to!( long );
	auto tas = new long[][]( n, 2 );
	foreach( ref ta; tas )
	{
		input.popFront;
		ta = input.front.split.to!( long[] );
	}
	return tuple( tas );
}

auto solve( long[][] tas )
{
	auto tv = 1L;
	auto av = 1L;
	
	foreach( ta; tas )
	{
		// tvを一番近いtの倍数に揃える
		if( tv % ta[ 0 ] != 0 ) tv += ta[ 0 ] - tv % ta[ 0 ];
		
		// avを一番近いaの倍数に揃える
		if( av % ta[ 1 ] != 0 ) av += ta[ 1 ] - av % ta[ 1 ];
		
		// tvとavをt:aに揃える
		auto tr = tv / ta[ 0 ];
		auto ar = av / ta[ 1 ];
		if( tr < ar ) tv += ta[ 0 ] * ( ar - tr );
		if( ar < tr ) av += ta[ 1 ] * ( tr - ar );
	}
	
	return tv + av;
}


Measured memory_bytes: 508
#include <cstdio>
#include <algorithm>

using namespace std;

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

const int inf = 1e9;

int N, R;

int main()
{
	scanf("%d\n%d", &N, &R);

	int mi = R, ma = -inf;

	for (int i = 1; i < N; ++i) {
		scanf("%d", &R);
		ma = max(ma, R - mi);
		mi = min(mi, R);
	}

	printf("%d\n", ma);
}

Measured memory_bytes: 1024
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;

int[10^^5] R;
int[][10^^5] NS;

void main()
{
    auto nm = readln.split.to!(int[]);
    auto N = nm[0];
    auto M = nm[1];
    auto XS = readln.split.to!(int[]);
    if (M == 1) {
        writeln(N/2);
        return;
    }
    sort(XS);
    foreach (x; XS) {
        ++R[x%M];
        NS[x%M] ~= x;
    }
    int ans = R[0]/2;
    foreach (i; 1..(M+1)/2) {
        auto d = min(R[i], R[M-i]);
        ans += d;
        R[i] -= d;
        R[M-i] -= d;
    }
    if (M%2 == 0) {
        auto d = R[M/2]/2;
        ans += d;
        R[M/2] -= d*2;
    }
    foreach (i; 1..10^^5) {
        int c;
        for (int j; j < NS[i].length; ++j) {
            if (NS[i].length > j+1 && NS[i][j] == NS[i][j+1]) {
                ++c;
                ++j;
            }
        }
        ans += min(c, R[i]/2);
    }
    writeln(ans);
}

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

int ExhaustiveSearch(int n,int i,int A[],int m) {
	
	if (m == 0) return 1;
	if (i >= n) return 0;
	int res = ExhaustiveSearch(n, i + 1, A, m) || ExhaustiveSearch(n, i + 1, A, m - A[i]);

	return res;

}
int main() {

	int A[10000],n,q,m,i;

	cin >> n;
	for (i = 0; i < n; i++) cin >> A[i];
		cin >> q;
	for (i = 0; i < q; i++) {
		cin >> m;

		if (ExhaustiveSearch(n, 0, A, m)) cout << "yes" << endl;
		else cout << "no" << endl;
	}



	
}

Measured memory_bytes: 3088
//Jai Bhole Ki
#include <bits/stdc++.h>
using namespace std;
#define fast static int fastline = []() { std::ios::sync_with_stdio(false); cin.tie(NULL); return 0; }();
#define ll long long
#define LL unsigned ll
#define pb push_back
#define pi pair<ll,ll>
#define debug(x) cout<<x<<"\n";
#define debug cout<<"debugged\n";
#define minval -2e9
#define maxval 2e9
long double PI =3.14159265358979323846;
 
const ll M=1e9+7;
const ll inf=1e18;
const ll ms=2e5+5;
fast;
ll n,m,c,ans;
bool compare(ll &a,ll &b)
{
    return ((a-1)%10+1)>((b-1)%10+1);
}
void solve()
{
    vector<ll> ar(5);
   for(int i=0;i<5;i++)
    cin>>ar[i];
   sort(ar.begin(),ar.end(),compare);
   for(int i=0;i<5;i++)
   {
       ans=ceil(ans*1.0/10)*10+ar[i];
   }
    cout<<ans<<endl;
}
int main()
{
 // freopen("input.txt","r",stdin);
//  freopen("output.txt","w",stdout);
    //int t;cin>>t;while(t--)
    {
        solve();
    }
    return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python
# -*- coding: utf-8 -*-

while True:
    N = int(input())
    if N == 0:
        break
    W,H = map(int,input().split(" "))
    Map = [[-1 for i in range(W)] for j in range(H)]
    for i in range(N):
        x,y = map(lambda x:int(x)-1,input().split(" "))
        Map[y][x] = 1
    S,T = map(int,input().split(" "))
    count = 0
    for i in range(0,H-T+1):
        for j in range(0,W-S+1):
            count = max(count,sum([1 if Map[k][l] == 1 else 0 for k in range(i,i+T) for l in range(j,j+S)]))
    print(count)

Measured memory_bytes: 6788
#include<iostream>
#include<stdio.h>
#include<cmath>

using namespace std;

int main (void){
    string b;

    cin >> b;

    if(b=="A"){
        cout << "T" << endl;
    }
    else if(b=="T"){
        cout << "A" << endl;
    }
    else if(b=="C"){
        cout << "G" << endl;
    }
    else if(b=="G"){
        cout << "C" << endl;
    }

return 0;

}

Measured memory_bytes: 256
import java.util.*;
import java.io.*;
import java.math.*;
 
public class Main
{
    public static void process()throws IOException
    {
 		int n=ni(),k=ni();
 		long h[]=new long[n+1],dp[]=new long[n+1];

 		for(int i=1;i<=n;i++) h[i]=nl();
 		Arrays.fill(dp,Integer.MAX_VALUE);
 		
 		dp[1]=0;

 		for(int i=2;i<=n;i++){
 			for(int j=1;j<=k;j++){
 				if(i-j<1)
 					continue;
 				dp[i]=Math.min(dp[i], dp[i-j]+Math.abs(h[i]-h[i-j]));
 			}
 		}       
 		pn(dp[n]);
    }
 
 
    static FastReader sc;
    static PrintWriter out;
    public static void main(String[]args)throws IOException
    {
        out = new PrintWriter(System.out);
        sc=new FastReader();
 
        long s = System.currentTimeMillis();
        int t=1;
//        t=ni();
        while(t-->0)
            process();
 
        out.flush();
        System.err.println(System.currentTimeMillis()-s+"ms");
    }
    
    
    static void pn(Object o){out.println(o);}
    static void p(Object o){out.print(o);}
    static int ni()throws IOException{return Integer.parseInt(sc.next());}
    static long nl()throws IOException{return Long.parseLong(sc.next());}
    static double nd()throws IOException{return Double.parseDouble(sc.next());}
    static String nln()throws IOException{return sc.nextLine();}
    static long gcd(long a, long b)throws IOException{return (b==0)?a:gcd(b,a%b);}
    static int gcd(int a, int b)throws IOException{return (b==0)?a:gcd(b,a%b);}
    static int bit(long n)throws IOException{return (n==0)?0:(1+bit(n&(n-1)));}
    
    static long mod=(long)1e9+7l;
 
    static<T> void r_sort(T arr[],int n){
        Random r = new Random(); 
        for (int i = n-1; i > 0; i--){ 
            int j = r.nextInt(i+1); 
                  
            T temp = arr[i]; 
            arr[i] = arr[j]; 
            arr[j] = temp; 
        } 
        Arrays.sort(arr); 
    }
    
/////////////////////////////////////////////////////////////////////////////////////////////////////////
    static class FastReader{ 
        BufferedReader br; 
        StringTokenizer st; 
  
        public FastReader(){ 
            br = new BufferedReader(new InputStreamReader(System.in)); 
        } 
  
        String next(){ 
            while (st == null || !st.hasMoreElements()){ 
                try{ st = new StringTokenizer(br.readLine()); } catch (IOException  e){ e.printStackTrace(); } 
            } 
            return st.nextToken(); 
        } 
  
        String nextLine(){ 
            String str = ""; 
            try{ str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } 
            return str; 
        } 
    } 
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
}

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

using ll = long long;
using ull = unsigned long long;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i < (n); i++)
#define all(a) begin(a),end(a)
template<class T> inline void sort_uniq(T& c) { sort(ALL(c)); c.erase(unique(ALL(c)), c.end()); }
template<class T> istream& operator >> (istream& s, vector<T>& v)
{ for (T& x: v) { s >> x; } return s;}
template<class T> void cout_v(const vector<T>& c)
{ for (int i = 0; i < c.size(); i++) cout << c[i] << endl; }
template<class K, class V> void cout_v(map<K, V>& m)
{ for(auto it=m.begin();it!=m.end();it++)cout<<it->first<<":"<<it->second<<endl;}
template<class T> void cout_h(const vector<T>& c)
{ for (int i = 0; i < c.size(); i++) cout << c[i] << (i==c.size()-1?"\n":" "); }
template<class T> inline bool chmin(T& a, T b) {return a>b?a=b,true:false;}
template<class T> inline bool chmax(T& a, T b) {return a<b?a=b,true:false;}
inline int powi(int x,int y) {int p=1; while(y--) p*=x; return p;}
inline ll powll(ll x,ll y) {ll p=1; while(y--) p*=x; return p;}
template<class T> inline bool is_overlap(const T& a, const T& b, const T& p, const T& q)
{ return p <=b && a <= q; }
#define MOD = 1000000007;
#define SP << " " <<
#define FMT(a) #a<<":"<<a 
#define FMT2(a,b) #a<<":"<<a<<", "<<#b<<":"<<b 
#define FMT3(a,b,c) #a<<":"<<a<<", "<<#b<<":"<<b<<", "<<#c<<":"<<c 
#define FMT4(a,b,c,d) #a<<":"<<a<<", "<<#b<<":"<<b<<", "<<#c<<":"<<c<<", "<<#d<<":"<<d 
void yes(bool f){cout<<(f?"yes":"no")<<endl;}
void Yes(bool f){cout<<(f?"Yes":"No")<<endl;}
void YES(bool f){cout<<(f?"YES":"NO")<<endl;}

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

    ll N, T; cin >>N>>T;
    vector<ll> w(N), v(N);

    ll X = T * N;
    ll t[2];
    cin >> t[0];
    rep(i, N-1) {
        cin >> t[1];
        X -= max(0LL, T - (t[1]-t[0]));
        t[0] = t[1];
    }
    cout << X << endl;
}


Measured memory_bytes: 3456
#include<iostream>
#include<string.h>
using namespace std;
int a[100005];
int b[100005];

int main()
{
	int q,w,e;
	cin >> q >> w >> e;
	int mina = 100000000;
	int  minb = 100000000;
	for (int i = 0; i < q; i++)
	{
		scanf("%d", &a[i]);
		if (a[i] < mina)
			mina = a[i];
	}
	for (int i = 0; i < w; i++)
	{
		scanf("%d", &b[i]);
		if (b[i] < minb)
			minb = b[i];
	}
	int minx = mina + minb;
	for (int i = 0; i < e; i++)
	{
		int z, x, c;
		scanf("%d%d%d", &z, &x, &c);
		if (minx > a[z - 1] + b[x - 1] - c)
			minx = a[z - 1] + b[x - 1] - c;
	}
	cout << minx;
}

Measured memory_bytes: 1024
import java.util.*;
 
public class Main {
  public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt();
    int B = sc.nextInt();
    if (B%A == 0)
      System.out.print(A+B);
    else
      System.out.print(B-A);
  }
}

Measured memory_bytes: 35876
def main():
    import sys,heapq
    from collections import defaultdict
    input = sys.stdin.readline

    n,q = map(int,input().split())
    #used[i]:0より大きいならi
    used = defaultdict(int)
    tank = []

    p = []
    for i in range(n):
        s,t,x = map(int,input().split())
        p.append((s-x,x))
        p.append((t-x,-x))
    p.sort()

    cnt = 0
    for i in range(q):
        d = int(input())
        while cnt<=len(p)-1 and p[cnt][0] <= d:
            w = p[cnt][1]
            if w>=0:
                used[w] += 1
                heapq.heappush(tank,w)
            else:
                used[-w] -= 1
            cnt += 1
        while True:
            if len(tank) == 0:
                print(-1)
                break
            kouho = tank[0]
            if used[kouho] > 0:
                print(kouho)
                break
            else:
                heapq.heappop(tank)
if __name__ == '__main__':
    main()

Measured memory_bytes: 79104
// practice with kaiboy
import java.io.*;
import java.util.*;

public class Main extends PrintWriter {
	Main() { super(System.out, true); }
	Scanner sc = new Scanner(System.in);
	public static void main(String[] $) {
		Main o = new Main(); o.main(); o.flush();
	}

	static final int INF = 0x3f3f3f3f;
	static class E {
		int i, j, w;
		E(int i, int j, int w) {
			this.i = i; this.j = j; this.w = w;
		}
	}
	void main() {
		int n = sc.nextInt();
		int[][] aa = new int[n][n];
		int[][] dd = new int[n][n];
		int m = n * n;
		E[] ee = new E[m];
		m = 0;
		for (int i = 0; i < n; i++)
			for (int j = 0; j < n; j++) {
				int w = sc.nextInt();
				aa[i][j] = dd[i][j] = w;
				ee[m++] = new E(i, j, w);
			}
		for (int k = 0; k < n; k++)
			for (int i = 0; i < n; i++)
				for (int j = 0; j < n; j++)
					dd[i][j] = Math.min(dd[i][j], dd[i][k] + dd[k][j]);
		for (int i = 0; i < n; i++)
			for (int j = 0; j < n; j++)
				if (dd[i][j] != aa[i][j]) {
					println(-1);
					return;
				}
		for (int i = 0; i < n; i++)
			for (int j = 0; j < n; j++)
				dd[i][j] = INF;
		Arrays.sort(ee, (e, f) -> e.w - f.w);
		long ans = 0;
		for (int h = 0; h < m; h++) {
			E e = ee[h];
			int i = e.i, j = e.j, w = e.w;
			int d = dd[i][j];
			for (int k = 0; k < n; k++)
				d = Math.min(d, dd[i][k] + dd[k][j]);
			if (d > w) {
				d = w;
				ans += w;
			}
			dd[i][j] = dd[j][i] = d;
			for (int k = 0; k < n; k++) {
				dd[i][k] = dd[k][i] = Math.min(dd[i][k], d + dd[j][k]);
				dd[j][k] = dd[k][j] = Math.min(dd[j][k], d + dd[i][k]);
			}
		}
		println(ans);
	}
}


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

//////全探索したいときに開けよ////////
vector<vector<int>> fspattern;
vector<int> fspattern_draft;
int fspcnt = 0;

void setfspattern_core(int floor,int number,int degree){
  if(floor==degree){
    fspattern.at(fspcnt) = fspattern_draft;
    fspcnt++;
  }else{
    rep(i,number){
      fspattern_draft.at(floor) = i;
      setfspattern_core(floor+1,number,degree);
    }
  }
}

void setfspattern(int number,int degree){
  int64_t array_num = 1;
  rep(i,degree){
    array_num *= number;
  }
  fspattern = vector<vector<int>>(array_num,vector<int>(degree));
  fspattern_draft = vector<int>(degree);
  setfspattern_core(0,number,degree);
}

//////nCrのmodを求めたいときに開けよ/////////
//int64_t univMod = 1000000007;
//int64_t factnum = 100000
//vector<int64_t> modfact(factnum);
//vector<int64_t> modinvfact(factnum);

/*void setmodfact(){
  for(int i=0;i<factnum;i++){
    if(i == 0){
      modfact.at(i) = 1;
    }else{
      modfact.at(i) = (modfact.at(i-1)*i)%univMod;
    }
  }
}

int64_t calcmodpower(int64_t a,int64_t n){
  int64_t res = 1;
  while(n != 0){
    if(n & 1){
      res = (res * a) % univMod;
    }
    a = (a*a) % univMod;
    n = n >> 1;
  }
  return res;
}

int64_t calcinverse(int64_t n){
	return calcmodpower(n,univMod-2);
}

void setmodinvfact(){
  for(int i=0;i<factnum;i++){
    if(i==0){
      modinvfact.at(i) = 1;
    }else{
      modinvfact.at(i) = calcmodpower(modfact.at(i),univMod-2);
    }
  }
}

int64_t calcmodcomb(int64_t n,int64_t r){
  return (((modfact.at(n)*modinvfact.at(r))%univMod)*modinvfact.at(n-r))%univMod;
}

int64_t calcmodpositive(int64_t n){
  return (n + ((abs(n)+univMod-1)/univMod)*univMod)%univMod;
}
  
    */


/*
int64_t calcGCD(int64_t a,int64_t b){
	int64_t p = a;
	int64_t q = b;
	int64_t c = a%b;
	while(c != 0){
		p = q;
		q = c;
		c = p%q;
	}
	return q;
}
*/

int main(){
  int a,b,c,d;
  cin >> a >> b >> c >> d;
  int x = a+b;
  int y = c+d;
  if(x < y){
    cout << "Right" << endl;
  }else if(x > y){
    cout << "Left" << endl;
  }else{
    cout << "Balanced" << endl;
  }
  
}


Measured memory_bytes: 256
#include <cstdio>

int main() {
	int x, a, b;
	scanf("%d %d %d", &x, &a, &b);
	if (b > a) {
		if ((b - a) > x) {
			printf("dangerous");
		}
		else
		{
			printf("safe");
		}

	}
	else
	{
		printf("delicious");
	}
}


Measured memory_bytes: 128
#include <iostream>

using namespace std;

int main()
{
	int a,b,c;
	cin >> a >> b >> c;
	int count = 0;
	if(b >= c) count = b+c;
	if(b < c) {
		c = c - b;
		if(a>=c) count = b*2+c;
		else count = b*2+a+1;
	}
	cout << count << endl;

	return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
	
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        
        String s = sc.next();
        
        for (int i = 0; i < s.length() - 1; i++) {
        	if (s.charAt(i) == s.charAt(i+1)) {
        		System.out.println((i+1) + " "+ (i+2));
        		return;
        	}
        }
        
        for (int i = 0; i < s.length() - 2; i++) {
        	if (s.charAt(i) == s.charAt(i+2)) {
        		System.out.println((i+1) + " "+ (i+3));
        		return;
        	}
        }
        
        System.out.println("-1 -1");
    }
}

Measured memory_bytes: 24904
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for (ll i=0; i<n; ++i)
#define all(c) begin(c),end(c)
template<typename T1, typename T2>
bool chmax(T1 &a,T2 b){if(a<b){a=b;return true;}else return false;}
template<typename T1, typename T2>
bool chmin(T1 &a,T2 b){if(a>b){a=b;return true;}else return false;}
/*

*/
int main(){
  cin.tie(0);
  ios::sync_with_stdio(0);
  
  ll N,K; cin>>N>>K;
  vector<int> A(101,0);
  rep(i, K){
    ll d; cin>>d;
    rep(j, d){
      ll a; cin>>a;
      A[a]++;
    }
  }
  ll ans = 0;
  for(int i=1; i<=N; i++)
    if(A[i] == 0) ans++;
  cout<<ans<<endl;
}


Measured memory_bytes: 3628
def main():
    import sys
    input = sys.stdin.readline

    H, W = map(int, input().split())
    grid = []
    for _ in range(H):
        grid.append(input().rstrip('\n'))

    le = [''] * H
    for i in range(H):
        le[i] = grid[i][0]

    ans = 0
    for w in range(1, W):
        ri = [''] * H
        for i in range(H):
            ri[i] = grid[i][w]
        cost = [[0] * (H+1) for _ in range(H+1)]
        for i in range(1, H+1):
            for j in range(1, H+1):
                cost[i][j] = cost[i-1][j-1] + int(le[i-1] == ri[j-1])

        inf = 1000000007
        dp = [[inf] * (H+1) for _ in range(H+1)]
        dp[0][0] = 0
        for i in range(H+1):
            for j in range(H+1):
                if i+1 <= H:
                    if dp[i][j] + cost[i+1][j] < dp[i+1][j]:
                        dp[i+1][j] = dp[i][j] + cost[i+1][j]
                if j+1 <= H:
                    if dp[i][j] + cost[i][j+1] < dp[i][j+1]:
                        dp[i][j+1] = dp[i][j] + cost[i][j+1]
        ans += dp[-1][-1]
        le = ri[:]
    print(ans)


if __name__ == '__main__':
    main()


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

typedef long long ll;

const int INF = 1e9;
const int MOD = 1e9+7;
const ll LLINF = 1e18;

#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define ANS(n) cout << (n) << endl

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define FORR(i,a,b) for(int i=(a);i>=(b);i--)

#define ALL(obj) (obj).begin(),(obj).end()

#define pii pair<int,int>

#define pb(a) push_back(a)
#define mp make_pair

ll f(ll a, ll b)
{
	if(a == 0){
		if(b % 4 == 0){
			return b;
		}else if(b % 4 == 1){
			return 1;
		}else if(b % 4 == 2){
			return b+1;
		}else{
			return 0;
		}
	}else{
		return f(0,b) ^ f(0,a) ^ a;
	}
}

int main()
{
	ll a,b;
	cin >> a >> b;
	ANS(f(a,b));
	return 0;
}


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


int main() {

    int n;
    cin >> n;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    sort(a.begin(), a.end());
    cout << a[n-1] - a[0] << endl;
    return 0;
}

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

int main(void){
  int n;
  cin >> n;
  int sum = 0;
  int b = -1, prev_b = -1;
  for(int i = 0; i < n-1; i++){
    cin >> b;
    if(i == 0) sum += b;
    else sum += min(prev_b, b);
    prev_b = b;
  }

  cout << sum + b << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
using namespace std;
typedef long long ll;
int main() {
    string s;
    cin >> s;
    string t = "";
    for (int i = 0; i < s.size(); i++) {
        t+="x";
    }
    cout << t << endl;
    return 0;
}

Measured memory_bytes: 256
/* Isn't passion overrated?*/

#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define ll long long
using namespace std;
ll gcd(ll a, ll b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}
ll mod = 998244353;
ll power(ll a, ll x)
{
    if(x == 0)
        return 1;
    ll ans = power(a, x/2)%mod;
    ans = (ans%mod * ans%mod)%mod;
    ans %= mod;
    if(x % 2)
        ans = (ans%mod * a)%mod;
    return ans % mod;
}

vector<ll>per(200010);

ll ncr(ll n, ll i)
{
    return (per[n] % mod * power(per[i], mod-2) % mod * power(per[n-i], mod-2) % mod)%mod;
}
int main()
{
    ios_base:: sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);
    ll n, m, k;
    cin >> n >> m >> k;
    per[0] = 1;
    ll h = per.size();
    for(ll i = 1; i < h; i++)
    {
        per[i] = i * per[i-1];
        per[i] %= mod;
    }
    ll ans = 0;
    for(ll i = 0; i <= k; i++)
    {
        ll temp = ncr(n-1, i)%mod;
        temp = (temp * m) % mod;
        temp = (temp * power(m-1,n-1-i) % mod) % mod;
        ans = ans + temp;
        ans %= mod;
    }
    cout<<ans % mod;
    return 0;
}


Measured memory_bytes: 4660
// In the name of God //
 
#include <bits/stdc++.h>
#define ll long long
#define all(x) (x).begin(), (x).end()
#define pii pair <int, int>
using namespace std;
const ll mod = 998244353;

void solve() {
    int l, r, d;
    cin >> l >> r >> d;
    cout << r/d - (l + d  -1)/d + 1;
}

int main()  {
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL);
    int tt = 1;
    // cin >> tt;
    for (int tc = 1; tc <= tt; ++tc) {
        solve();
    } 
    // cout << 15*modInverse(6, mod)%mod << " " << 39*modInverse(10, mod)%mod;
}                               

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

int a[200010];
int b[200010];
int main() {
	int n; cin >> n;
	for (int i=1; i<=n; ++i)	{
		cin >> a[i];
		b[i] = a[i];
	}

	for (int i=n; i>=1; --i) {
		int sum = 0;
		for (int j=i; j<=n; j+=i) {
			sum += b[j];
		}
		if (sum%2!=a[i]) {
			b[i] ^= 1;
		}
	}
	
	for (int i=1; i<=n; ++i) {
		int sum = 0;
		for (int j=i; j<=n; j+=i) {
			sum += b[j];
		}
		if (sum%2!=a[i]) {
          	cout << -1 << endl;
          	return 0;
		}
	}
  
	int m = 0;
	for (int i=1; i<=n; ++i) {
    	if (b[i] == 1) m++;
    }
	cout << m << endl;
	for (int i=1; i<=n; ++i) {
		if (b[i] == 1) cout << i << " ";
	}
	
	return 0;
}


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

using namespace std;
typedef long long ll;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
#define all(a) (a).begin(), (a).end()

int main()
{
    string s;
    cin >> s;

    s[5] = ' ';
    s[13] = ' ';
    cout << s << '\n';
    return 0;
}


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

//template
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(a);i>(b);i--)
#define ALL(v) (v).begin(),(v).end()
typedef long long int ll;
const int inf = 0x3fffffff; const ll INF = 0x1fffffffffffffff; const double eps=1e-12;
void tostr(ll x,string& res){while(x)res+=('0'+(x%10)),x/=10; reverse(ALL(res)); return;}
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; }
//template end



int main(){
   string s; cin>>s;
   cout<<string(s.size(),'x')<<endl;
   return 0;
}

Measured memory_bytes: 256