akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define debug(x) cout<<#x<<" "<<x<<"\n";
#define lli long long int
long long int mod= 1000000007,modd=998244353;
int32_t main()
{
   ios_base::sync_with_stdio(0);
   cin.tie(0);  cout.tie(0);
   lli n;
   string s;
   cin>>s;
   n=s.length();
   cout<<s;
   if(s[n-1]=='s')
   {
     cout<<"es";
   }
   else
   {
      cout<<"s";
   }
   cout<<"\n";
   return 0;
}//main


Measured memory_bytes: 3660
#!/usr/bin/env python3
import sys


def solve(S: str):
    res = 0
    ACGT = {"A","C","G","T"}
    for i in range(len(S)):
        sub = 0
        for l in range(len(S) - i):
            if S[i + l] in ACGT:
                sub+=1
            else:
                break
        res = max(res,sub)
    print(res)
    return


# Generated by 1.1.3 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    S = next(tokens)  # type: str
    solve(S)

if __name__ == '__main__':
    main()


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

using namespace std;
#define ll long long
#define all(x) x.begin(), x.end()
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;
const int N = 1e5 + 10;
const double eps = 1e-9;

int main() {
    int n;
    cin >> n;
    int s = 0, tm = n;
    while (tm) {
        s += tm % 10;
        tm /= 10;
    }
    cout << (n % s ? "No" : "Yes") << endl;
}

Measured memory_bytes: 3560
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define repr(i, a, n) for (int i = n - 1; i >= a; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }

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

  int n;
  cin >> n;
  vector<ll> v(n), a(n + 1, 0);
  rep(i, 0, n) {
    cin >> v[i];
    a[v[i]]++;
  }

  ll all = 0;
  rep(i, 1, n + 1) { all += (a[i] * (a[i] - 1)) / 2; }

  rep(i, 0, n) {
    ll ans = 0;
    ll t1 = a[v[i]];
    ll t2 = a[v[i]] - 1;
    ans = all - ((t1 * (t1 - 1)) / 2 - (t2 * (t2 - 1)) / 2);
    cout << ans << endl;
  }
}


Measured memory_bytes: 6368
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
typedef long long ll;
namespace mp = boost::multiprecision;
using Mint = mp::cpp_int;

int main() {
	vector<string> hand(3);
	rep(i, 3) cin >> hand.at(i);

	int turn = 0;
	while(true) {
		if(hand.at(turn) == "") break;
		char next = hand.at(turn).at(0);
		hand.at(turn) = hand.at(turn).substr(1, hand.at(turn).size());
		switch(next) {
			case 'a': turn = 0; break;
			case 'b': turn = 1; break;
			case 'c': turn = 2; break;
			default: break;
		}
	}

	switch(turn) {
		case 0: cout << "A" << endl; break;
		case 1: cout << "B" << endl; break;
		case 2: cout << "C" << endl; break;
		default: break;
	}
}

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

class Union_Find {
private:
    vector<int> par;
    vector<int> rank;

public:
    // Initialization
    void init(int n) {
        for(int i = 0; i < n; ++i) {
            par.push_back(i);
            rank.push_back(0);
        }
    }

    // Ask for roots
    int root(int x) {
        return par[x] == x ? x : par[x] = root(par[x]);
    }

    // Whether it belongs to the same set or not
    bool same(int x, int y) {
        return root(x) == root(y);
    }

    // Merge the same set
    void unite(int x, int y) {
        x = root(x);
        y = root(y);
        if(x == y) return;

        if(rank[x] < rank[y]) {
            par[x] = y;
        } else {
            par[y] = x;
            if(rank[x] == rank[y]) ++rank[x];
        }
    }
};



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

    int N, M;
    cin >> N >> M;
    vector<int> p;
    for(int i = 0; i < N; ++i) {
        int temp;
        cin >> temp;
        p.push_back(temp);
    }

    Union_Find tree;

    tree.init(N + 1);

    for(int i = 0; i < M; ++i) {
        int temp1, temp2;
        cin >> temp1 >> temp2;
        tree.unite(temp1, temp2);
    }

    int ans = 0;
    for(int i = 0; i < N; ++i) {
        if(tree.same(i + 1, p[i])) ++ans;
    }

    cout << ans << endl;
}

Measured memory_bytes: 1912
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <numeric>
#include <cmath>
#include <iomanip>
#include <limits>
#include <map>

using namespace std;

int main(){
    long n;
    string s;
    cin >> n;
    cin >> s;
    int ans=n;
    for(int i=0;i<n-1;i++){
        if(s[i]==s[i+1]) ans--;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main() {
    int n, w;
    cin >> n >> w;
    
    vector<int> a(n), b(n);

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

    using ll = long long;

    vector<vector<ll>> dp(n + 1, vector<ll>(w + 1));

    for (int i = 0; i < n; i++) {
        for (int j = 0; j <= w; j++) {
            dp[i + 1][j] = dp[i][j];
            if (j - a[i] >= 0) {

                dp[i + 1][j] = max(dp[i + 1][j], dp[i][j - a[i]] + b[i]);
            }
        }
    }

    cout << dp[n][w] << endl;
}


Measured memory_bytes: 80256
a,b,c,x,y = map(int,input().split())
c *= 2
if x == y:
    print(min(c*x,a*x+b*y))
if x >y:
    print(min(c*x,c*y+a*(x-y),a*x+b*y))
if x< y:
    print(min(c*y,c*x+b*(y-x),a*x+b*y))

Measured memory_bytes: 3064
#include<iostream> JOI 2012 ???1
using namespace std;
int main(void)
{
	int nisu, kok, suu, saik, sais;
	int max,su,ko;
	cin >> nisu >> kok >> suu >> saik >> sais;
	ko = kok / saik;
	if (kok%saik > 0) {
		ko++;
	}
	su = suu / sais;
	if (suu%sais > 0) {
		su++;
	}
	if (ko > su) {
		max = ko;
	}
	else {
		max = su;
	}
	cout << nisu - max << endl;
	return 0;
}

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

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

using namespace std;

int main(){
	int n; scanf("%d",&n);
	int win[100]={}; // win[i] := ( チーム i の勝ち点 )
	rep(i,n*(n-1)/2){
		int a,b,c,d; scanf("%d%d%d%d",&a,&b,&c,&d); a--; b--;
		if(c>d) win[a]+=3;
		if(c<d) win[b]+=3;
		if(c==d) win[a]++, win[b]++;
	}

	int ans[100]={};
	for(int i=1;i<=n;){
		int win_max=-1;
		rep(j,n) if(ans[j]==0) win_max=max(win_max,win[j]);
		int cnt=0;
		rep(j,n) if(win[j]==win_max) ans[j]=i, cnt++;
		i+=cnt;
	}
	rep(i,n) printf("%d\n",ans[i]);

	return 0;
}

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

int main() {
  string S;
  cin >> S;
  
  if ( S.at(0) == S.at(1) && S.at(2) == S.at(3) && S.at(0) != S.at(2)) {
    cout << "Yes" << endl;  
  }
  else if ( S.at(0) == S.at(2) && S.at(1) == S.at(3) && S.at(0) != S.at(1)) {
    cout << "Yes" << endl;  
  }
  else if ( S.at(0) == S.at(3) && S.at(1) == S.at(2) && S.at(0) != S.at(1)) {
    cout << "Yes" << endl;  
  }
  else {
    cout << "No" << endl; 
  }
  
}


Measured memory_bytes: 256
X = int(input())
p_m = 10
ans = 0
for i in range(2,int(X**0.5)+2):
    for j in range(2,p_m):
        if i**j <= X:
            ans = max(ans, i**j)
if X == 1:
    print(1)
else:
    print(ans)


Measured memory_bytes: 2940
/***************************************** 
****       Solution by SlavicG        ****
*****************************************/
 
#include <bits/stdc++.h>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm> 
#include <set>
#include <utility>
#include <queue>
#include <map>
#include <assert.h>
#include <stack>
using namespace std;
#define ll long long
#define forn(i,n) for(int i=0;i<n;++i)
#define MX 10000000001
#define pow2(a) ((a)*(a))
#define pb push_back
#define pf push_front
#define all(v) v.begin(), v.end()
#define endl "\n"
#define FAST std::ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
 int longestIncreasingSubsequenceLenghtDP(int a[],int n){
    int dp[n],ans=0;
    for(int k = 0;k<n;k++){
        dp[k] = 1;
        for(int i = 0;i<k;i++){
            if(a[i] <= a[k]){
                dp[k] = max(dp[k],dp[i] + 1);
                ans = max(dp[k],ans);
            }
        }
    }
    return ans;
 }
int result[1000] = {0};
int factDP(int n) 
{
   if (n >= 0) {
      result[0] = 1;
      for (int i = 1; i <= n; ++i) {
         result[i] = i * result[i - 1];
      }
      return result[n];
   }
}
bool checkPrime(int n)
{
    if(n<2) return false;
    for(int x = 2;x*x <=n;x++)
    {
        if(n%x == 0)return false;
    }
    return true;
}
vector<int> primeFactors(int n){
    vector<int> f;
    for(int x = 2;x*x<=n;x++){
        while(n%x==0){
            f.push_back(x);
            n/=x;
        }
    }
    if(n>1)f.push_back(n);
    return f;
}
int binary_Search_Classic(int n, int arr[],int target){
	int l,r,mid;
	l=0;
	r=n-1;
	while(l<=r){
		mid= l+(r-l)/2;
		if(arr[mid] == target){
			return mid;
		}
		if(arr[mid] < target){
			l=mid+1;
		}else
		{
			r=mid-1;
		}
	}
	return -1;
}
int binary_Search_First_Greater(int n, int arr[],int target){
	int l,r,ans,mid;
	l = 0;
	r = n-1;
	ans=-1;
	while(l<=r){
		mid = l + (r-l)/2;
		if(arr[mid] > target){
			ans=mid;
			r=mid-1;
		}else{
			l = mid+1;
		}
	}
	return ans;
}
int countDistinctCharsString(string s) {
    unordered_map<char, int> m; 
    for (int i = 0; i < s.length(); i++) { 
        m[s[i]]++; 
    }
    return m.size(); 
} 
int main()
{
	int n;
	cin >> n;
	cout << n + n*n + n*n*n << endl;
	return 0;
}

Measured memory_bytes: 3596
from fractions import gcd
n, m = map(int, input().split())
s = list(input())
t = list(input())
i = 1
ans = n * m // gcd(n, m)
g = gcd(n, m)
for i in range(g):
    if s[i * n // g] != t[i * m // g]:
        ans = -1
        break
print(ans)


Measured memory_bytes: 6584
#include <bits/stdc++.h>
using namespace std;
#define dhoom ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);  
typedef long long ll;
const ll inf = 1e18;
const int nax = 2e5;
const ll mod = 1e9 + 7;
int main(int argc,char ** argv){
	dhoom;
	int a[3];
	cin >> a[0] >> a[1] >> a[2];
	sort(a , a + 3);
	if( (a[0] == a[1] && a[1] != a[2]) || (a[0] != a[1] && a[1] == a[2]))
		cout << "Yes" << endl;
	else 
		cout << "No" << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
template<class T> using vc = vector<T>;
template<class T> using vvc = vector<vector<T>>;

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

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

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

const ll INF = 5e18;
const ld EPS = 1e-11;
const ld PI = acos(-1.0L);
const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
//--------------------------------------------------------------------------------//
const ll MAX_SIZE = 200005;
ll N;
vvc<ll> G(MAX_SIZE);
ll dp[MAX_SIZE], ans[MAX_SIZE];
ll A[MAX_SIZE];

void dfs(ll now, ll p){
    // now_i dpの更新箇所
    ll now_i = lower_bound(dp, dp + N + 1, A[now]) - dp;
    ll prev = dp[now_i];
    dp[now_i] = A[now];
    ans[now] = lower_bound(dp, dp + N + 1, INF) - dp;

    for(auto to:G[now]){
        if (to == p) continue;
        dfs(to, now);
    }
    dp[now_i] = prev;
    return;
}


int main() {
    init();
    cin >> N;
    rep(i, N) cin >> A[i];
    rep(i,N-1){
        ll a,b;
        cin >> a >> b;
        a--, b--;
        G[a].eb(b);
        G[b].eb(a);
    }
    fill(dp, dp + N + 1, INF);

    dfs(0, -1);
    rep(i, N) cout << ans[i] << '\n';
}

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

int fre[27];

int main( )
{
    string w;
    int i, j, k;
    cin >> w;
    int l = (int) w.size();
    for (i = 0; i < l; i++) {
        fre[w[i] - 'a']++;
    }
    for (i = 0; i < 26; i++) {
        if (fre[i] % 2 == 1) {
            cout << "No\n";
            return 0;
        }
    }
    cout << "Yes\n";
    return 0;
}


Measured memory_bytes: 256
in1 = list(map(int, input().split()))
s = input()
n = in1[0]
k = in1[1]

l = 0
r = 0
c = 0
while r < n-1:
  if (s[r]=='1' and s[r+1]=='0' and c>=k): break
  if s[r]=='0' and s[r+1]=='1':
    c += 1
  r += 1
r += 1

m = r
while r < n and l < n:
  #move r
  while True:
    r+=1
    if r == n:
      break
    elif s[r-1]=='1' and s[r]=='0':
      break
  #move l
  while s[l]!='0' or s[l+1]!='1':
    l += 1
  l += 1
  m = max(m, r-l)
print(m)

Measured memory_bytes: 3316
import java.io.IOException;
import java.util.ArrayDeque;
import java.util.Arrays;
import java.util.Deque;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws IOException {
		new Main().run();
	}

	private void run() throws IOException {
		Scanner scanner = new Scanner(System.in);
		while (true) {
			m = scanner.nextInt();
			if (m == 0)
				break;
			n = scanner.nextInt();
			s = scanner.nextInt();
			int[][][] a = new int[s][m][n];
			for (int i = 0; i < s; i++) {
				a[i] = bfs(scanner.nextInt() - 1, scanner.nextInt() - 1);
			}
			int max = 0;
			int t = scanner.nextInt();
			while (t-- > 0) {
				int[][] r = bfs(scanner.nextInt() - 1, scanner.nextInt() - 1);
				int c = 0;
				for (int x = 0; x < m; x++) {
					for (int y = 0; y < n; y++) {
						boolean f = true;
						for (int k = 0; k < s; k++) {
							if (r[x][y] >= a[k][x][y]) {
								f = false;
								break;
							}
						}
						if (f)
							c++;
					}
				}
				max = Math.max(max, c);
			}
			System.out.println(max);
		}
	}

	private int[][] bfs(int x, int y) {
		int[][] r = new int[m][n];
		boolean[][] v = new boolean[m][n];
		int step = 1;
		Deque<List<Integer>> deque = new ArrayDeque<List<Integer>>();
		v[x][y] = true;
		deque.offer(Arrays.asList(x, y));
		while (!deque.isEmpty()) {
			int size = deque.size();
			for (int i = 0; i < size; i++) {
				List<Integer> a = deque.poll();
				for (int j = 0; j < 6; j++) {
					int nx = a.get(0)
							+ (a.get(1) % 2 == 1 ? move[j][0] : move2[j][0]);
					int ny = a.get(1)
							+ (a.get(1) % 2 == 1 ? move[j][1] : move2[j][1]);
					if (0 <= nx && nx < m && 0 <= ny && ny < n && !v[nx][ny]) {
						v[nx][ny] = true;
						r[nx][ny] = step;
						deque.offer(Arrays.asList(nx, ny));
					}
				}
			}
			step++;
		}
		return r;
	}

	int[][] move = { { 0, -1 }, { 1, -1 }, { -1, 0 }, { 1, 0 }, { 0, 1 },
			{ 1, 1 } };
	int[][] move2 = { { -1, -1 }, { 0, -1 }, { -1, 0 }, { 1, 0 }, { -1, 1 },
			{ 0, 1 } };
	int m, n, s;
}

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

#define sws ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ll long long
#define vi vector<int>
#define pb push_back
#define pii pair<int, int>
#define mp make_pair
#define ff first
#define ss second
#define vvi vector<vi>
#define all(x) x.begin(), x.end()
#define fo(i, n) for( int i = 0; i < n; i++ )

const int INF = 1e9;
const ll INFLL = 0x3f3f3f3f3f3f3f3f;
const int MOD = 1e9 + 7;


int main() {

    int h, w;
    cin >> h >> w;

    vector<string> desenho(h);
    fo(i, h) cin >> desenho[i];

    vector<pii> dxy = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}};

    bool pos = true;
    fo(i, h) {
        if ( !pos ) break;
        fo(j, w) {
            if ( desenho[i][j] == '.' ) continue;
            bool tem = false;
            for ( auto p : dxy ) {
                int x = p.ff + i, y = p.ss + j;
                if ( x < 0 or x >= h or y < 0 or y >= w ) continue;
                if ( desenho[x][y] == '#' ) {
                    tem = true;
                    break;
                }
            }
            if ( !tem ) {
                pos = false;
                break;
            }
        }
    }

    cout << (pos ? "Yes\n" : "No\n");

    return 0;
}

Measured memory_bytes: 3644
from collections import deque

while True:
    w,h=map(int,input().split())
    if (w,h)==(0,0):
        break
    p=[]
    p.append([False for j in range(w+2)])
    for i in range(1,h+1):
        p.append([False]+[cij==1 for cij in list(map(int,input().split()))]+[False])
    p.append([False for j in range(w+2)])

    r=[[False for j in range(w+2)] for i in range(h+2)]
    ans=0
    for i in range(1,h+1):
        for j in range(1,w+1):
            if p[i][j] and not r[i][j]:
                q=deque()
                q.append((i,j));r[i][j]=True
                while q:
                    u=q.popleft()
                    ui,uj=u
                    for v in [(vi,vj) for vi in [ui-1,ui,ui+1] for vj in [uj-1,uj,uj+1]]:
                        vi,vj=v
                        if p[vi][vj] and not r[vi][vj]:
                            q.append(v);r[vi][vj]=True
                ans+=1
    print(ans)


Measured memory_bytes: 6044
#include <bits/stdc++.h>
       
using namespace std;
typedef long long ll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int main() {
  string s;
  cin >> s;
  if (count((s).begin(), (s).end(), 'A') % 3 == 0) {
    cout << "No";
  } else {
    cout << "Yes";
  }
  cout << endl;
  return 0;
}


Measured memory_bytes: 256
N, M = map(int, input().split())
H = list(map(int, input().split()))
bads = set()
for i in range(0, M):
    Ai, Bi = map(int, input().split())
    if H[Ai-1] > H[Bi-1]:
        bads.add(Bi)
    elif H[Bi-1] > H[Ai-1]:
        bads.add(Ai)
    else:
        bads.add(Ai)
        bads.add(Bi)
print(N - len(bads))

Measured memory_bytes: 20020
//
//  RedAndBlack.cpp
//  
//
//  Created by ??°????????? on 2015/10/30.
//
//

#include <iostream>
using namespace std;

int w, h, num = 0, room[20][20];
int dx[] = {-1, 1, 0, 0};
int dy[] = { 0, 0,-1, 1};

void dfs(int x, int y) {
    num++;
    room[y][x] = 0;
    
    // ??????????????¢?´¢
    for (int i = 0; i < 4; i++) {
        int mx = x + dx[i];
        int my = y + dy[i];
        
        if (mx < 0 || w <= mx) continue;
        if (my < 0 || h <= my) continue;
        if (room[my][mx] == 0) continue;
        dfs(mx, my);
    }

    return;
}

int main() {
    while (cin >> w >> h, w || h) {
        int manX, manY;
        
        for (int i = 0; i < h; i++) {
            string s;
            cin >> s;
            for (int j = 0; j < w; j++) {
                if (s[j] == '.') {
                    room[i][j] = 1;
                } else if (s[j] == '#') {
                    room[i][j] = 0;
                } else if (s[j] == '@') {
                    room[i][j] = 1;
                    manX = j;
                    manY = i;
                }
            }
        }
        
        dfs(manX, manY);
        
        cout << num << endl;
        
        num = 0;
    }
    
    return 0;
}

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

int main() {
  long long a,b,c,d;
  long long r,tmp;
  cin >> a >> b;
  c = a;
  d = b;
  /*int M = 1;
  for ( int i = 1; i < 100001 ; i++ ){
    if (A%i == 0 && B%i == 0) {
       M = M * i;
    }
  }
  cout << (A*B)/M << endl; */
  
  if(a<b){
    
    tmp = a;
    a = b;
    b = tmp;
    
  }
  r = a % b;
  while(r!=0){
    a = b;
    b = r;
    r = a % b;
  }

  cout << (c*d)/b << endl;
  
}


Measured memory_bytes: 256
a, b, c = [int(i) for i in input().split(' ')]

def remainderSet(divident, divisor):
    mul = 1
    r_set = set()
    for _ in range(divisor):
        r_set.add((mul * divident) % divisor)
        mul += 1
    return r_set

if c in remainderSet(a, b):
    print('YES')
else:
    print('NO')

Measured memory_bytes: 3060
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10000000)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations, accumulate
    #from itertools import product
    from bisect import bisect_left,bisect_right
    import heapq
    from math import floor, ceil
    #from operator import itemgetter

    inf = 10**17
    #mod = 10**9 + 7

    N = int(input())
    a = list(map(int, input().split()))
    b = [0] + list(accumulate(a))
    dp = [[inf]*N for _ in range(N)]
    for i in range(N):
        dp[i][i] = 0
    for j in range(1, N):
        for l in range(0, N-j):
            r = l + j
            temp = b[r+1] - b[l]
            #区間の境界
            for k in range(l, r):
                dp[l][r] = min(dp[l][r], dp[l][k]+dp[k+1][r]+temp)
            
    print(dp[0][-1])

if __name__ == '__main__':
    main()

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

int main() {
	string S;
    long long K;
	cin >> S >> K;
    //文字列𝑆において、1文字目から𝐾文字目まで全て‘1’であれば、答えは‘1’
    //そうでなければ、答えは𝑆中に初めて出現する‘2’以上の文字
	for (int i = 0; i < K; i++) {
		if (S[i] >= '2'){
          cout << S[i] << endl;
          return 0;
        }
	}
	cout << '1' << endl;
	return 0;
}


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

#define li long long int
#define rep(i, to) for (li i = 0; i < ((li)(to)); i++)
#define repp(i, start, to) for (li i = (li)(start); i < ((li)(to)); i++)
#define allof(v) (v).begin(), (v).end()


li a[100100];
li sum[100100];

map<li, li> count_;

inline li comb(li x) {
	return x * (x - 1) / 2ll;
}

int main(void)
{
	li n, m;
	cin >> n >> m;
	sum[0] = 0;
	rep(i, n) {
		cin >> a[i];
		sum[i + 1] = sum[i] + a[i];
	}

	rep(i, n + 1) {
		count_[sum[i] % m]++;
	}

	li res = 0;
	for (auto it = count_.begin(); it != count_.end(); ++it) {
		res += comb(it->second);
	}
	cout << res << endl;
	return 0;
}

Measured memory_bytes: 5760
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define show(x) for(auto i: x){cout << i << " ";}
typedef long long ll;

int mapabs[81][81] = {0};
bool dp[81][81][160*160] = {0};
#define OFFSET 80*160

int main()
{
    int h, w;
    cin >> h >> w;
    rep(i, h)rep(j, w){
        int tmp; cin >> tmp;
        mapabs[i][j] = tmp; 
    }
    rep(i, h)rep(j, w){
        int tmp; cin >> tmp;
        mapabs[i][j] = abs(tmp - mapabs[i][j]); 
    }

    // rep(i, h){
    //     rep(j, w){
    //         cout << mapabs[i][j] << " ";
    //     }
    //     cout << endl;
    // }

    dp[0][0][OFFSET+mapabs[0][0]] = true;
    dp[0][0][OFFSET-mapabs[0][0]] = true;
    rep(i, h){
        rep(j, w){
            rep(k, OFFSET*2){
                if (i != 0){
                    if ((dp[i - 1][j][max(k - mapabs[i][j], 0)] == true) || 
                    (dp[i - 1][j][min(k + mapabs[i][j], 160*160-1)] == true))
                    {
                        dp[i][j][k] = true;
                    }
                }
                if (j != 0){
                    if ((dp[i][j - 1][max(k - mapabs[i][j], 0)] == true) || 
                    (dp[i][j - 1][min(k + mapabs[i][j], 160*160-1)] == true))
                    {
                        dp[i][j][k] = true;
                    }
                }

            }
        }
    }
    int ans = 81;
    for(int i = -80; i <= 80; i++){
        if (dp[h-1][w-1][i+OFFSET] == true){
            ans = min(ans, abs(i));
        }
    }
    cout << ans << endl;
}



Measured memory_bytes: 162944
//include
//------------------------------------------
#include <bits/stdc++.h>
using namespace std;
//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef long long ll;
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const long long INF = 1000000007;
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))
//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
// chmax chmin
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(void){
    int n,m; cin >> n >> m;
    cout << (n-1)*(m-1) << endl;
    return 0;
}

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

/* macro */
#define rep(i,a,b) for(int i=a;i<b;i++)
#define revrep(i,a,b) for(int i = a; i > b; i--)
#define int long long
#define exist(s,e) ((s).find(e)!=(s).end())
#define all(v) (v).begin(), (v).end()
#define each(s,itr) for(auto (itr) = s.begin(); (itr) != s.end(); (itr)++)
#define sum(v) accumulate(all(v), (0LL))
#define isin(a, b, c) (b <= a && a <= c)
#define println cout << "\n";
#define sz(v) (int)v.size()
#define bin(x) static_cast<bitset<16> >(x)


/* alias */
template<class T> using vec = vector<T>;
typedef vector<int> vi;
typedef pair<int, int> pi;
typedef tuple<int, int, int> ti;
typedef map<int, int> mi;
typedef set<int> si;


/* constant */
const int inf = 1LL << 62;
const int mod = 1e9 + 7;
const int dx[8]={1,0,-1,0,-1,1,-1,1};
const int dy[8]={0,1,0,-1,-1,-1,1,1};
const string alphabet = "abcdefghijklmnopqrstuvwxyz";

/* io_method */
int input(){int tmp;cin >> tmp;return tmp;}
string raw_input(){string tmp;cin >> tmp;return tmp;}
template<class T> void printx(T n){cout << n;}
template<class T, class U> void printx(pair<T, U> p){cout << "(" << p.first << "," << p.second << ")";}
template<class T, class U, class V> void printx(tuple<T, U, V> t){cout << "{" << get<0>(t) << "," << get<1>(t) <<"," << get<2>(t) << "}" << endl;}
template<class T> void printx(vector<T> v){cout << "{";rep(i,0,v.size()){printx(v[i]);if(i != v.size()-1)printx(",");}cout << "}";}
template<class T> void print(T n){printx(n);cout << endl;}
template<class T> void print(set<T> s){cout << "{";each(s, e){if(e != s.begin()) printx(",");printx(*e);}cout << "}" << endl;}
template<class T, class U> void print(map<T, U> mp){cout << "{";each(mp, e){cout << "(" << e -> first << "," << e -> second << ")";}cout << "}" << endl;}
template<class T> void printans(vec<T> v){rep(i,0,sz(v)){cout << v[i] << (i == sz(v) - 1 ? "" : " ");}cout << endl;}


/* general_method */
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<class T>T cut(T &a, int l, int r){return T(a.begin()+l, a.begin()+r);}


/* math_method */
int ceil(int a, int b){return a / b + (a % b > 0);}


/* main */

int r, d, x;
void in(){
    cin >> r >> d >> x;
}

void solve(){

    rep(i,0,10){
        x = x * r - d;
        print(x);
    }

}

signed main(){

    cin.tie(0);
    ios::sync_with_stdio(false);
    in();
    solve();
    
}

Measured memory_bytes: 256
#include <iostream>
#include <set>
#include <vector>
#include <string>
#include <algorithm>
#include <iterator>
#include <map>
#include <utility>
#include <list>
#include <climits>
#include <bitset>
#include <numeric>

using namespace std;

#define rep(i, n) for(int i = 0; i < n; i++)
#define repi(i, n) for(auto i = (n).begin(); i != (n).end(); i++)
#define in_arr(type, a, n) copy_n(istream_iterator<type>(cin), n, (a).begin());
#define ll long long int

int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    in_arr(int, a, n);
    int mv = 0, mi = -1, sv = 0, si = -1;
    map<int, int> m;
    for(int i = 0; i < n; i += 2){
        ++m[a[i]];
    }
    repi(i, m){
        if(mv <= i->second){
            sv = mv;
            si = mi;
            mv = i->second;
            mi = i->first;
        }else if(sv < i->second){
            sv = i->second;
            si = i->first;
        }
    }
    m.clear();
    int pmv = mv, pmi = mi, psv = sv, psi = si;
    for(int i = 1; i < n; i += 2){
        ++m[a[i]];
    }
    mv = 0;
    sv = 0;
    repi(i, m){
        if(mv <= i->second){
            sv = mv;
            si = mi;
            mv = i->second;
            mi = i->first;
        }else if(sv < i->second){
            sv = i->second;
            si = i->first;
        }
    }
    if(mi != pmi){
        cout << n - mv - pmv << endl;
    }else if(mv + psv < pmv + sv){
        cout << n - pmv - sv << endl;
    }else{
        cout << n - psv - mv << endl;
    }
    return 0;
}


Measured memory_bytes: 2944
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define int long long
#define MAX INT_MAX
#define MIN INT_MIN
#define ss second
#define ff first
const int mod = 1e9+7;

int minm(vector<int> &v){
	int n = v.size();
	vector<int> dp(n);
	dp[0] = 0;
	dp[1] = abs(v[1]-v[0]);
	for(int i = 2; i < n; i++){
		dp[i] = min(dp[i-1]+abs(v[i]-v[i-1]), dp[i-2]+abs(v[i]-v[i-2]));
	}
	return dp[n-1];
}


int32_t main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n;
	cin >> n;
	vector<int> v(n);
	for(int i = 0; i < n; i++)
		cin >> v[i];
	cout << minm(v) << endl;
	return 0;
}


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

static const int INF=1e9;
typedef long long ll;

bool compare_by_second(pair<ll, ll> a,pair<ll, ll> b)
{
    if(a.second != b.second){
        return a.second > b.second;
    }else{
        return a.first > b.first;
    }    
}

int main(){
    ll N,M; cin >> N >> M;
    ll A[N+1];
    for(int i=0;i<N;i++){
        cin >> A[i];
    }
    sort(A,A+N);
    pair<ll,ll> D[M];
    for(int i=0;i<M;i++){
        ll B,C; cin >> B >> C;
        D[i]=make_pair(B,C);
    }
    sort(D,D+M,compare_by_second);
    ll E[N]={};
    int cnt=0;
    for(int i=0;i<M;i++){
        for(int j=0;j<D[i].first;j++){
            if(cnt==N) break;
            E[cnt++]=D[i].second;
        }
        if(cnt==N) break;
    }
    for(int i=0;i<cnt;i++){
        if(A[i]<E[i]){
            A[i]=E[i];
        }
    }
    unsigned long long ans=0;
    for(int i=0;i<N;i++){
        ans+=A[i];
    }
    cout << ans << endl;
}

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

int main(){
  int N,A,s,t,min=200;
  cin >>N;
  
  for(int i=0;i<N;i++){
    cin >>A;
    t = 0;

    for(;A>1;A/=2){
      if(A%2==1)
        break;
      
      t++;
    }
    
    if(min>t)
      min = t;
  }
  cout << min <<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h> 
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define int long long
#define ld double
#define fi first
#define se second
#define pb push_back
#define pii pair<int,int>
#define sz(x) ((long long)x.size())
#define all(x) (x).begin(), (x).end()
const int MOD =1e9+7;
#define oset(x) tree<x, null_type, less<x>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
int mpow(int a,int b,int p=MOD){a=a%p;int res=1;while(b>0){if(b&1)res=(res*a)%p;a=(a*a)%p;b=b>>1LL;}return res%p;}
const int N=2*1e5+2,M=201;
int dis[N];
int32_t main(){
	ios_base::sync_with_stdio(false);cin.tie(NULL);
	#ifdef LOCAL
	freopen("input.txt", "r", stdin);
	#endif
	int k;
	cin>>k;
	for(int i=0;i<N;i++) dis[i]=1e16;
	set<pii> s;
	for(int i=1;i<=9;i++)
	{
		dis[i%k]=min(dis[i%k],i);
		s.insert({dis[i],i});
	}
	while(s.size())
	{
		auto it=s.begin();
		pii curr=*it;
		s.erase(it);
		for(int j=0;j<=9;j++)
		{
			int x=curr.se*10+j;
			x%=k;
			if(curr.fi+j<dis[x])
			{
				dis[x]=curr.fi+j;
				s.insert({dis[x],x});
			}
		}	
	}
	cout<<dis[0];
} 


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

using namespace std;

typedef vector <int> VI;
typedef vector <VI> VVI;
typedef vector <string> VS;
typedef pair<int,int> PII;
typedef long long LL;
typedef unsigned long long ULL;
typedef pair <int, LL> PIL;
typedef vector <PIL> VPIL;


#define each(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); i++)
#define sort(c) sort((c).begin(),(c).end())

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

#define MAX_INT 2147483647

int main(){
	int n, s, total;
	int max_s, min_s;
	while (1){
		cin >> n;
		if (!n) break;
		total = 0; max_s = 0; min_s= 1000; 
		rep(i,n){
			cin >> s;
			total += s;
			max_s = max(s, max_s);
			min_s = min(s, min_s);
		} 
		cout << (total - max_s - min_s) / (n-2) << endl;
	}
	return 0;
}

Measured memory_bytes: 1160
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <climits>
#include <cstdlib>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define DEBUG 1
using namespace std;
constexpr int kMod = 1000000007;
typedef long long LL;

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

int count(LL v) {
  int ret = 0;
  while (v % 2 == 0) {
    v /= 2;
    ++ret;
  }
  return ret;
}

LL gcd(LL a, LL b) {
  if(b == 0) return a;
  return gcd(b, a % b);
}

LL lcm(LL a, LL b) {
  if ((a == 0) || (b == 0)) return 0;
  return ((a / gcd(a, b)) * b);
}

int main() {
  int N, M; cin >> N >> M;
  vector<LL> a(N); cin >> a;
  int two = count(a[0]);
  if (two == 0) {
    cout << 0 << endl;
    return 0;
  }

  LL v = a[0]/2;
  for (LL x : a) {
    if (two != count(x)) {
      cout << 0 << endl;
      return 0;
    }
    v = lcm(v, x/2);
  }
  cout << M/v - M/(2*v) << endl;
}


Measured memory_bytes: 1024
#include <cstdio>
#include <vector>
#include <algorithm>

using namespace std;

const int mod = 1000000007;

int main() {
  int n;
  scanf("%d", &n);
  int lx = -1;
  int totcnt = 0;
  long long ans = 1;
  for (int i = 0; i < n; i++) {
    int x;
    scanf("%d", &x);
    totcnt++;
    if (lx + 1 >= x) {
      ans *= totcnt;
      ans %= mod;
      totcnt--;
      continue;
    }
    lx += 2;
  }
  for (int i = 1; i <= totcnt; i++) {
    ans *= i;
    ans %= mod;
  }
  printf("%lld\n", ans);
  return 0;
}

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

struct UnionFind {
    vector<int> dat;
    
    UnionFind(int n) : dat(n, -1) { }
    void init(int n) { dat.assign(n, -1); }
    
    int root(int x) {
        if (dat[x] < 0) return x;
        else return dat[x] = root(dat[x]);
    }
    
    bool issame(int x, int y) {
        return root(x) == root(y);
    }
    
    bool unite(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (-dat[x] < -dat[y]) swap(x, y); // union by size
        dat[x] += dat[y];
        dat[y] = x;
        return true;
    }
    
    int size(int x) {
        return -dat[root(x)];
    }
};

// 辺 e = (u, v) を {l(e), {u, v}} で表す
typedef pair<int, pair<int,int> > Edge;

int main() {
    // 入力
    int N, M; // 頂点数と辺数
    cin >> N >> M;
    vector<Edge> edges(M);
    for (int i = 0; i < M; ++i) {
        int u, v, w; // w は重み
        cin >> u >> v >> w;
        edges[i] = Edge(w, make_pair(u, v));
    }

    // 辺の重みが小さい順にソート
    // pair はデフォルトで (第一要素, 第二要素) の辞書順比較
    sort(edges.begin(), edges.end());

    // Kruskal 法
    long long res = 0;
    UnionFind uf(N);
    for (int i = 0; i < M; ++i) {
        int w = edges[i].first;
        int u = edges[i].second.first;
        int v = edges[i].second.second;
        if (uf.issame(u, v)) continue;

        // 辺を採用
        res += w;
        uf.unite(u, v);
    }
    cout << res << endl;
}



Measured memory_bytes: 4116
n, m, l = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(n)]
b = [list(map(int, input().split())) for _ in range(m)]
c = [[0]*100 for _ in range(100)]

for i in range(n):
    for j in range(m):
        for k in range(l):
            c[i][k] += a[i][j] * b[j][k]

for i in range(n):
    line = c[i][:l]
    print(' '.join(map(str, line)))


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

int main() {
  int n, m;
  cin >> n >> m;
  vector<P> ans;
  if (n%2) {
    for (int l = 1, r = n-1; l < r; l++, r--) {
      ans.emplace_back(l,r);
    }
  } else {
    bool flag = false;
    for (int l = 1, r = n-1; l < r; l++, r--) {
      if (!flag && r-l <= n/2) {
        --r;
        flag = true;
      }
      ans.emplace_back(l,r);
    }
  }
  rep(i,m) {
    cout << ans[i].first << ' ' << ans[i].second << endl;
  }
  return 0;
}


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

int main(){
  int a, b, c;
  cin>> a >> b >> c;
  
  if(a==5 && b==5 && c==7)
    cout<<"YES";
  else if(a==5 && b==7 && c==5)
    cout<<"YES";
  else if(a==7 && b==5 && c==5)
    cout<<"YES";
  else
    cout<<"NO";
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//#include <boost/multiprecision/cpp_int.hpp>
//typedef boost::multiprecision::cpp_int ll;
typedef long double dd;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
ll inf=(ll)1E17;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
///////////////////////////////////////

vector<l_l>fact(ll n){
    vector<l_l>v;
    for(ll i=2;i*i<=n;i++){
        ll c=0;
        if(n%i==0){
            while(n%i==0){
                n/=i;
                c++;
            }
            v.pb(l_l(i,c));
        }
    }
    if(n!=1)v.pb(l_l(n,1));
    return v;
}
ll len;
vector<l_l>v;
vector<ll>q;
void dfs(ll pos,ll val){
    if(pos==len){
        q.pb(val);return;
    }
    ll ne=val;
    rep(i,0,v[pos].second){
        dfs(pos+1,ne);
        ne*=v[pos].first;
    }
}

int main(){
    ll a,b,c;cin>>a>>b>>c;
    cout<<max(0,c-(a-b));
    return 0;
}

















Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <bitset>
#include <cstdio>
#include <cstdlib>
#include <cmath>
using namespace std;

using ll = long long;
using P = pair<int, int>;

const int INF = 1e9;
const int MOD = 1e9 + 7;

// 4近傍、8近傍
int dx[] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[] = {0, 1, 0, -1, 1, 1, -1, -1};

int main() {
  // 入力
  int grid[3][3];
  for (int i = 0; i < 3; i++) {
    for (int j = 0; j < 3; j++) {
      cin >> grid[i][j];
    }
  }

  int sum1 = grid[0][0] + grid[1][1] + grid[2][2];
  int sum2 = grid[0][1] + grid[1][2] + grid[2][0];
  int sum3 = grid[0][2] + grid[1][0] + grid[2][1];

  // 解答
  cout << (sum1 == sum2 && sum2 == sum3 ? "Yes" : "No") << endl;

  return 0;
}


Measured memory_bytes: 256
#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 << "Balanced" << endl;
  }
  else if (a + b > c + d) {
    cout << "Left" << endl;
  }
  else {
    cout << "Right" << endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <cstring>

using namespace std;
// ascending order
#define vsort(v) sort(v.begin(), v.end())
// descending order
#define vsort_r(v) sort(v.begin(), v.end(), greater<int>())
#define vunique(v) unique(v.begin(), v.end())
#define mp make_pair
#define ts(x) to_string(x)
#define rep(i, a, b) for(int i = (int)a; i < (int)b; i++)
#define repm(i, a, b) for(int i = (int)a; i > (int)b; i--)
#define bit(a) bitset<8>(a)
#define des_priority_queue priority_queue<int, vector<int>, greater<int> >
#define all(v) (v).begin(), (v).end()
typedef long long ll;
typedef pair<int, int> P;
const ll INF = 1ll << 60;

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

template<int MOD> struct ModInt {
    static const int Mod = MOD; unsigned x; ModInt() : x(0) { }
    ModInt(signed sig) { x = sig < 0 ? sig % MOD + MOD : sig % MOD; }
    ModInt(signed long long sig) { x = sig < 0 ? sig % MOD + MOD : sig % MOD; }
    int get() const { return (int)x; }
    ModInt &operator+=(ModInt that) { if ((x += that.x) >= MOD) x -= MOD; return *this; }
    ModInt &operator-=(ModInt that) { if ((x += MOD - that.x) >= MOD) x -= MOD; return *this; }
    ModInt &operator*=(ModInt that) { x = (unsigned long long)x * that.x % MOD; return *this; }
    ModInt &operator/=(ModInt that) { return *this *= that.inverse(); }
    ModInt operator+(ModInt that) const { return ModInt(*this) += that; }
    ModInt operator-(ModInt that) const { return ModInt(*this) -= that; }
    ModInt operator*(ModInt that) const { return ModInt(*this) *= that; }
    ModInt operator/(ModInt that) const { return ModInt(*this) /= that; }
    ModInt inverse() const { long long a = x, b = MOD, u = 1, v = 0;
        while (b) { long long t = a / b; a -= t * b; std::swap(a, b); u -= t * v; std::swap(u, v); }
        return ModInt(u); }
    bool operator==(ModInt that) const { return x == that.x; }
    bool operator!=(ModInt that) const { return x != that.x; }
    ModInt operator-() const { ModInt t; t.x = x == 0 ? 0 : Mod - x; return t; }
};
template<int MOD> ostream& operator<<(ostream& st, const ModInt<MOD> a) { st << a.get(); return st; };
template<int MOD> ModInt<MOD> operator^(ModInt<MOD> a, unsigned long long k) {
    ModInt<MOD> r = 1; while (k) { if (k & 1) r *= a; a *= a; k >>= 1; } return r; }
typedef ModInt<1000000007> mint;

string K;
int D;
mint dp[100010][2][100];

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

    cin >> K >> D;

    dp[0][0][0] = 1;
    rep(i, 0, K.length()) rep(j, 0, 2) rep(k, 0, D) {
        int lim = j ? 9 : K[i] - '0';
        rep(d, 0, lim + 1) {
            //(dp[i + 1][j || d < lim][(k + d) % D] += dp[i][j][k]) %= mod;
            dp[i + 1][j || d < lim][(k + d) % D] += dp[i][j][k];
        }
    }

    mint rsl = dp[K.length()][0][0] + dp[K.length()][1][0];
    cout << rsl - 1 << endl;
}


Measured memory_bytes: 78464
//http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2242




#include<iostream>
#include<map>
#include<vector>
#include<algorithm>
#include<cmath>
#include<climits>
#include<ctime>
#include<cstring>
#include<numeric>




#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define dump(a) (cerr << #a << "=" << (a) << endl)
#define DUMP(list) cout << "{ "; for(auto nth : list){ cout << nth << " "; } cout << "}" << endl;




using namespace std;




struct Era{




	int from;
	int to;
	string name;




	Era(string era, int w,int g): name(era),from(g - w),to(g){}




	bool isEra(int g){
		return from < g && to >= g;
	}




	void print(int g){
		cout << name << " " << g - from << endl;
	}
};




int main()
{
	int N,Q;
	
	while(cin >> N >> Q && N)
	{
		vector<Era> eras;




		string name;
		int year_w, year_g;
		rep(nth,N)
		{
			cin >> name >> year_w >> year_g;
			eras.push_back(Era(name,year_w, year_g));
		}




		int q;
		rep(nth, Q)
		{
			cin >> q;
			
			bool flag=false;
			rep(i,eras.size())
			{
				if(eras[i].isEra(q))
				{
					eras[i].print(q);
					flag = true;
					break;
				}
			}
			if(!flag){ cout << "Unknown" << endl; }
		}
	}
	return 0;
}

Measured memory_bytes: 1288
#include <bits/stdc++.h>
#define itn int
#define REP(i, n) for (int i = 0; i < n; i++)
#define IREP(i, n) for (int i = n - 1; i >= 0; i--)
#define FOR(a, b) for (int i = a; i < b + 1; i++)
#define all(v) v.begin(), v.end()
#define SENTINEL 2000000000
#define NIL -1
using namespace std;
typedef long long ll;

const ll INF = 1LL << 60;
const ll MOD = 1000000007;
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;}
class UnionFind
{
public:
    vector<ll> par; // 各元の親を表す配列
    vector<ll> siz; // 素集合のサイズを表す配列(1 で初期化)

    // Constructor
    UnionFind(ll sz_) : par(sz_), siz(sz_, 1)
    {
        for (ll i = 0; i < sz_; ++i)
            par[i] = i; // 初期では親は自分自身
    }
    void init(ll sz_)
    {
        par.resize(sz_);
        siz.assign(sz_, 1);
        for (ll i = 0; i < sz_; ++i)
            par[i] = i; // 初期では親は自分自身
    }

    // Member Function
    // Find
    ll root(ll x)
    { // 根の検索
        while (par[x] != x)
        {
            x = par[x] = par[par[x]]; // x の親の親を x の親とする
        }
        return x;
    }

    // Union(Unite, Merge)
    bool merge(ll x, ll y)
    {
        x = root(x);
        y = root(y);
        if (x == y)
            return false;
        // merge technique（データ構造をマージするテク．小を大にくっつける）
        if (siz[x] < siz[y])
            swap(x, y);
        siz[x] += siz[y];
        par[y] = x;
        return true;
    }

    bool issame(ll x, ll y)
    { // 連結判定
        return root(x) == root(y);
    }

    ll size(ll x)
    { // 素集合のサイズ
        return siz[root(x)];
    }
};

int main()
{
    int n,m,k;
    cin >> n >> m >> k;
    UnionFind uf(n);
    vector<int> tomo(n,0);
    REP(i,m){
        int a,b;
        cin >> a >> b;
        uf.merge(a-1,b-1);
        tomo[a-1]++;
        tomo[b-1]++;
    }
    vector<int> ans(n);
    REP(i,n){
        ans[i]=uf.size(i)-1-tomo[i];
    }
    REP(i,k){
        int c,d;
        cin >> c >> d;
        c--;d--;
        if(uf.issame(c,d)){
            ans[c]--;
            ans[d]--;
        }
    }
    REP(i,n){
        cout << ans[i] << " ";
    }
    cout << endl;
}

Measured memory_bytes: 3200