akhauriyash/Code-Regression huggingface dataset:
import sys
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int,sys.stdin.readline().rstrip().split())


def floor_sum(n,m,a,b):  # sum((A*i+B)//M for i in range(N))
    res = 0
    if a >= m:
        res += (a//m)*n*(n-1)//2
        a %= m
    if b >= m:
        res += (b//m)*n
        b %= m
    y_max = (a*n+b)//m
    if y_max == 0:
        return res
    x_max = m*y_max-b
    res += (n+(-x_max)//a)*y_max
    res += floor_sum(y_max,a,m,(x_max+a-1)//a*a-x_max)
    return res


T = I()
for i in range(T):
    n,m,a,b = MI()
    print(floor_sum(n,m,a,b))


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

int main() {
	vector<P>v;
	rep(i, 3) {
		vector<P>h;
		rep(j, 8) {
			int p; double t; cin >> p >> t;
			h.push_back(P(t, p));
		}
		sort(h.begin(), h.end());
		printf("%d %.2lf\n%d %.2lf\n", h[0].second, h[0].first, h[1].second, h[1].first);
		for (auto iter = h.begin() + 2; iter != h.end(); iter++)v.push_back(*iter);
	}
	sort(v.begin(), v.end());
	printf("%d %.2lf\n%d %.2lf\n", v[0].second, v[0].first, v[1].second, v[1].first);
}

Measured memory_bytes: 3184
// Contest: AtCoder Beginner Contest 165 (https://atcoder.jp/contests/abc165)
// Problem: D: Floor Function (https://atcoder.jp/contests/abc165/tasks/abc165_d)


// region {{{ boilerplate
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <chrono>
#include <cstdint>
#include <deque>
#include <exception>
#include <forward_list>
#include <functional>
#include <initializer_list>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

#if __cplusplus >= 201703L
#   include <optional>
#   include <string_view>
#   include <variant>
#endif

using namespace std;

#if __cplusplus >= 201703L
#   define all(a)      begin(a),end(a)
#   define sz(x)       ((int)size(x))
#else
#   define all(a)      (a).begin(),(a).end()
#   define sz(x)       ((int)(x).size())
#endif

#define rep(a, b)      for(int a = 0; a < (b); ++a)
#define reps(a, b, c)  for(int a = (b); a < (c); ++a)
#define trav(a, b)     for(auto& a : b)

using ll = long long;
using ld = long double;
using u64 = uint64_t;
using u32 = uint32_t;

using pi = pair<int, int>;
using pl = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vpi = vector<pi>;

#if __cplusplus >= 201703L
#   define MAYBE_UNUSED [[maybe_unused]]
#else
#   define MAYBE_UNUSED
#endif

MAYBE_UNUSED static constexpr int INF = (int)1e9 + 5;
MAYBE_UNUSED static constexpr ll INFL = (ll)1e18 + 5;
MAYBE_UNUSED static mt19937 rng((u32)chrono::duration_cast<chrono::nanoseconds>(chrono::high_resolution_clock::now().time_since_epoch()).count());
//endregion }}}

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

    ll a, b, n; cin >> a >> b >> n;
    if (n < b)
        cout << ((a * n) / b) << '\n';
    else {
        ll x = (n / b) * b - 1;
        cout << ((a * x) / b - a * (x / b)) << '\n';
    }

    return 0;
}

Measured memory_bytes: 3656
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define mst(a,b) memset((a),(b),sizeof(a))
#define pi acos(-1)
#define pii pair<int,int>
const int INF = 0x3f3f3f3f;
const double eps = 1e-6;
const int MAXN = 1e2 + 10;
const int MAXM = 2e6 + 10;
const ll mod = 1e9 + 7;
 
ll a[3][110],suml[3][110],sumr[3][110];
 
int main()
{
#ifdef local
    freopen("data.txt","r",stdin);
//    freopen("data.txt","w",stdout);
#endif
    mst(suml,0);
    mst(sumr,0);
    int n;
    scanf("%d",&n);
    for(int i=1; i<=2; i++)
        for(int j=1; j<=n; j++) {
            scanf("%lld",&a[i][j]);
            suml[i][j] = suml[i][j-1] + a[i][j];
        }
    for(int i=1; i<=2; i++)
        for(int j=n; j>=1; j--)
            sumr[i][j] = sumr[i][j+1] + a[i][j];
    ll ans = 0;
    for(int i=1; i<=n; i++) {
        ll sum = suml[1][i-1] + sumr[2][i+1] + a[1][i] + a[2][i];
        ans = max(ans,sum);
    }
    printf("%lld\n",ans);
    return 0;
}

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

typedef long long ll;

#define pb push_back
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()

int maxHappiness(int n, int arr[][3])
{
  //arr will be of size n X 3
    int dp[3] = {0};
    dp[0] = arr[0][0];
    dp[1] = arr[0][1];
    dp[2] = arr[0][2];
    for (int i = 1;i < n;i++)
    {
        int t1,t2,t3;
        t1 = arr[i][0] + max(dp[1], dp[2]);
        t2 = arr[i][1] + max(dp[0], dp[2]);
        t3 = arr[i][2] + max(dp[0], dp[1]);
        dp[0] = t1;
        dp[1] = t2;
        dp[2] = t3;
    }
    return max(dp[0], max(dp[1], dp[2]));
}

int main()
{

  int n;
  cin >> n;
  int arr[n][3] = {0};

  for (int i = 0;i < n;i++)
  {
    cin >> arr[i][0] >> arr[i][1] >> arr[i][2];

  }
  cout << maxHappiness(n, arr) << "\n";


  return 0;
}


Measured memory_bytes: 1408
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#include<cmath>



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

using namespace std;
int n;

int main(){
  int ans = 0;
  cin >> n;
  REP(i,n){
    int a,b;
    cin >> a >> b;
    ans += b-a+1;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define forn(i, n) for(int i = 0; i < int(n); i++)
#define fore(i, l, r) for(int i = int(l); i < int(r); i++)
#define pb push_back
#define all(x) x.begin(), x.end()
#define sz(a) int((a).size())
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef pair<int, int> pii;
const int mod = 1e9 + 7;
template<class T, class U> inline void add_self(T &a, U b){a += b;if (a >= mod) a -= mod;if (a < 0) a += mod;}
template<class T, class U> inline void min_self(T &x, U y) { if (y < x) x = y; }
template<class T, class U> inline void max_self(T &x, U y) { if (y > x) x = y; }

#define _deb(x) cout<<x;
void _print() {cerr << "]\n";} template <typename T, typename... V>void _print(T t, V... v) {_deb(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#define deb(x...) cerr << "[" << #x << "] = ["; _print(x)
template <class T, class U> void print_m(const map<T,U> &m, int w=3){if(m.empty()){cout<<"Empty"<<endl; return;}for(auto x: m)cout<<"("<<x.first<<": "<<x.second<<"),"<<endl;cout<<endl;}
template<class T, class U>void debp(const pair<T, U> &pr, bool end_line=1){cout<<"{"<<pr.first<<" "<<pr.second<<"}"; cout<<(end_line ? "\n" : ", ");}
template <class T> void print_vp(const T &vp, int sep_line=0){if(vp.empty()){cout<<"Empty"<<endl; return;}if(!sep_line) cout<<"{ ";for(auto x: vp) debp(x,sep_line);if(!sep_line) cout<<"}\n";cout<<endl;}
template <typename T>void print(const T &v, bool show_index = false){int w = 2;if(show_index){for(int i=0; i<sz(v); i++)cout<<setw(w)<<i<<" ";cout<<endl;}for(auto &el: v) cout<<setw(w)<<el<<" ";cout<<endl;}
template <typename T>void print_vv(const T &vv){if(sz(vv)==0) {cout<<"Empty"<<endl; return;} int w = 3;cout<<setw(w)<<" ";for(int j=0; j<sz(*vv.begin()); j++)cout<<setw(w)<<j<<" ";cout<<endl;int i = 0;for(auto &v: vv){cout<<i++<<" {";for(auto &el: v) cout<<setw(w)<<el<<" ";cout<<"},\n";}cout<<endl;}

int main(){
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    ll n;
    while(cin>>n){
        map<ll,ll> m;
        ll x;
        ll sum = 0;
        forn(i,n){
            cin>>x; 
            m[x]++;
            sum+=x;
        }

        int q; cin>>q;
        forn(i,q){
            ll b,c;
            cin>>b>>c;
            ll ps = b*m[b];
            ll ns = c*m[b];
            m[c]+=m[b];
            m[b] = 0;
            sum = sum - ps + ns;
            cout<<sum<<"\n";
        }
        
    }
    return 0;
}

Measured memory_bytes: 9596
#import<ios>
main()
{
	int a,b,x,y,z;
	scanf("%d%d",&a,&b);
	x=a+b;
	y=a-b;
	z=a*b;
	x=x>y?x:y;
	x=x>z?x:z;
	printf("%d",x);
}

Measured memory_bytes: 128
#include<stdio.h>

#define NUMBER_IN 4
#define NUMBER_OUT 2
#define HIT 0
#define BLOW 1

void initialize(int array[]);
int check_hit(int array1[], int array2[]);
int check_blow(int array1[], int array2[]);

main()
{
	int input1[NUMBER_IN];
	int input2[NUMBER_IN];
	int result[NUMBER_OUT];
	
	initialize(input1); //初期化
	initialize(input2);
	result[HIT] = 0, result[BLOW] = 0;
	
	while(1)
	{
		//scanf("%d %d %d %d", &input1[0], &input1[1], &input1[2], &input1[3]);
		if(scanf("%d %d %d %d", &input1[0], &input1[1], &input1[2], &input1[3]) == EOF)
		{
			break;
		}
		scanf("%d %d %d %d", &input2[0], &input2[1], &input2[2], &input2[3]);
		
		result[HIT] = check_hit(input1, input2);
		result[BLOW] = check_blow(input1, input2);
		
		printf("%d %d\n", result[HIT], result[BLOW]);
		
		initialize(input1); //初期化
		initialize(input2);
		result[HIT] = 0, result[BLOW] = 0;
	}
	
	return 0;
}
void initialize(int array[])
{
	short i = 0;
	for(i = 0; i < NUMBER_IN; i++)
	{
		array[i] = 0;
	}
}
int check_hit(int array1[], int array2[])
{
	short i = 0, flag = 0;
	for(i = 0; i < NUMBER_IN; i++)
	{
		if(array1[i] == array2[i])
		{
			flag++;
		}
	}
	return flag;
}
int check_blow(int array1[], int array2[])
{
	short i = 0, j = 0, flag = 0;
	for(i = 0; i < NUMBER_IN; i++)
	{
		for(j = 0; j < NUMBER_IN; j++)
		{
			if((array1[i] == array2[j]) && (i != j))
			{
				flag++;
			}
		}
	}
	return flag;
}

Measured memory_bytes: 592
#include<iostream>
#include<algorithm>
#include<map>
#include<cstdio>
#define ll long long
#define lson (rt<< 1)
#define rson (rt<< 1 | 1)
#define gmid ((l+r)>> 1 )
using namespace std;

const int maxn=20000050;
int main()
{
	int n;
	cin>>n;
	cout<<n+n*n+n*n*n<<endl; 
}


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

using namespace std;

#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define REV(i,n) for(ll (i) = (n) - 1;(i) >= 0;--i)
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {REP(WW,n)cerr << v[WW] << ' ';cerr << endl << endl;}
#define SHOW2d(v,WW,HH) {REP(W_,WW){REP(H_,HH)cerr << v[W_][H_] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL
#define MOD 1000000007

typedef long long ll;
typedef pair<ll,ll> P;

string str;
ll n,ans,place;

ll check(int l, int r, vector<ll> &v,vector<char> op){
    ll ret = 0;
    ll tmp = 0;
     
    for(int i = l;i <= r;i++) {
        if(i == l){
            tmp = v[i];
        }
        else {
            if(op[i-1] == '+'){
                ret += tmp;
                tmp = v[i];
            }
            else{
                tmp *= v[i];
            }
        }
        if(ret + tmp > INF)return INF + 1;
    }
    return ret + tmp;
}

ll dfs(){
	place++;
	vector<ll> v;
	vector<char> op;
	vector<ll> mul;
	vector<ll> it;
	vector<ll> sum(1,0);
	while(1){
		if(str[place] == '('){
			ll tmp = dfs();
			if(tmp == 1 && op.size() > 0 && op.back() == '*' && v.back() == 1){
				op.pop_back();
				mul.back()++;
			}
			else{
				v.EB(tmp);
				it.EB(sum.size()-1);
				mul.EB(1);
			}
		}
		if(isdigit(str[place])){
			if(str[place] == '1' && op.size() > 0 && op.back() == '*' && v.back() == 1){
				op.pop_back();
				mul.back()++;
			}
			else{
				v.EB(str[place] - '0');
				it.EB(sum.size()-1);
				mul.EB(1);
			}
		}
		else if(str[place] == '*'){
			op.EB(str[place]);
		}
		else if(str[place] == '+'){
			op.EB(str[place]);
			sum.EB(0);
		}
		else {
			break;
		}
		place++;
	}
	place++;
	int r = 1;
	ll now = v[0];
	sum[0] = v[0];

	REP(i,v.size()){
		if(i > r){
			now = v[i];
			sum[it[i]] = v[i];
			r = i + 1;
		}
		while(now < n && r < v.size() && now + max(sum[it[r]] * v[r], v[r]) - sum[it[r]] <= n){
			now -= sum[it[r]];
			sum[it[r]] = max(sum[it[r]] * v[r], v[r]);
			now += sum[it[r]];
			r++;
			if(now == n)break;
		}
		if(now == n){
			if(n == 1)ans += max(mul[i] * (mul[i] + 1) / 2,(ll)1);
			else if(it[i] == it[r - 1])ans += mul[i];
			else ans += mul[i] * mul[r-1];
			if(r < v.size() && op[r-1] == '*' && v[r] == 1)ans += mul[i] * mul[r];
		}
		now -= sum[it[i]];
		if(it[i] != it[i+1] || i + 1 == r)sum[it[i]] = 0;
		else sum[it[i]] /= v[i];
		now += sum[it[i]];
	}
	return check(0,v.size() - 1,v,op);
}

int main(){
	
	while(cin >> n,n){
		ans = 0;
		place = 0;
		cin >> str;
		str = "(" + str + ")";
		dfs();
		cout << ans << endl;
	}
	
	return 0;
}



Measured memory_bytes: 50716
#include <iostream>
 
using namespace std;
 
int main() {
  int A,B;
  cin >> A>> B;
  if(A%3==0&&A!=0){
    cout <<"Possible"<<endl;
    return 0;
  }
  if(B%3==0&&B!=0){
    cout <<"Possible"<<endl;
    return 0;
  }
  if((A+B)%3==0&&(A+B)!=0){
    cout <<"Possible"<<endl;
    return 0;
  }
  if(A%3!=0&&B%3!=0&&(A+B)%3!=0){
    cout <<"Impossible"<<endl;
  }
  if(A==0&&B==0){
    cout <<"Impossible"<<endl;
  }
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
#define INT long long
#define oo (int)(1e9)+1
using namespace std;

int x, y, z;

int main()
{
    ios::sync_with_stdio(false);
    cin>>x>>y>>z;
    x-=z;
    cout<<max(0, x/(y+z))<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(long long i=0; i<n; i++)
#define REPR(i, n) for(long long i=n-1; i>=0; i--)
#define FOR(i, m, n) for(long long i=m; i<=n; i++)
#define FORR(i, m, n) for(long long i=m; i>=n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define VSORTR(v) sort(v.rbegin(), v.rend());
#define ALL(v) (v).begin(),(v).end()
#define FIN ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

using namespace std;
using ll = long long;
using ull = unsigned long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;
const ll mod = 1e9+7;
const ll inf = 1e15;
ll power(ll a,ll b){return b?power(a*a%mod,b/2)*(b%2?a:1)%mod:1;}

//c
int main(){FIN
    ll k;cin>>k;
    // ll ans=-1;
    ll a = 7%k;
    if(a==0){
        cout<<1<<endl;
        return 0;
    }
    set<ll> st;
    st.insert(a);
    ll cnt=1;
    while(1){
        a = (10*a+7) % k;
        cnt++;
        ll size = st.size();
        if(a==0) {
            cout<<cnt<<endl;
            return 0;
        }
        st.insert(a);
        if (st.size()==size) {
            cout<<-1<<endl;
            return 0;
        }

    }
    return 0;
}


Measured memory_bytes: 50488
n = int(input())

ans = 0
for i in range(1, n + 1 ,2):
    divisor_count = 0
    for j in range(1, i + 1):
        if i % j == 0:
            divisor_count += 1
    if divisor_count == 8:
        ans += 1

print(ans)


Measured memory_bytes: 9144
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define MOD 1000000007
#define PI 3.141592653589793

int main(){
    int x, a, b;
    cin >> x >> a >> b;
    cout << (abs(x-a) < abs(x-b) ? 'A':'B') << endl;
}


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

int main ()
{
	char op;
	int a, b;
	
	while (cin >> a >> op >> b) 
	{
		
	switch (op)
	{
		case '+':
			cout << a+b << endl;
			break;
		
		case '-':
			cout << a-b << endl;
			break;
			
		case '*':
			cout << a*b << endl;
			break;
			
		case '/':
			cout << a/b << endl;
			break;
		
		case '?':
			return 0;		
	}
}
	return 0;
}

Measured memory_bytes: 3060
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<sstream>
#include<unordered_map>
#include<unordered_set>
#include<vector>
using namespace std;
using uint = unsigned int;
using ll = long long;
const int M = 1e9 + 7;
const ll MLL = 1e18L + 9;
#pragma unused(M)
#pragma unused(MLL)
#ifdef LOCAL
#include"rprint.hpp"
#else
template <ostream& out = cout, class... T> void prints(T&&...){ }
template <ostream& out = cout, class... T> void printd(T&&...){ }
template <ostream& out = cout, class... T> void printb(T&&...){ }
template <ostream& out = cout, class... T> void printArr(T&&...){ }
#endif

int main(){
    int n, m;
    cin >> n >> m;
    vector<ll> as(n);
    for(int i = 0; i < n; i++){
        cin >> as[i];
    }
    ll acc = 0;
    vector<ll> buf(m + 10);
    for(int i = 1; i < n; i++){
        int f = as[i - 1], t = as[i];
        printd(buf);
        if(f < t){
            acc += t - f;
            if(f + 1 < t){
                buf[f + 2] += 1;
                buf[t + 1] += - (t - f);
                buf[t + 2] += t - f - 1;
            }
        }else{
            acc += m + t - f;
            if(!(f == m && t == 1)){
                int t2 = m;
                if(f + 1 < t2){
                    buf[f + 2] += 1;
                    buf[t2 + 1] += - (t2 - f);
                    buf[t2 + 2] += t2 - f - 1;
                }
                int v = m - f, v2 = m + t - f;
                if(t == 1){
                    buf[1] += v;
                    buf[2] += - 2 * v;
                    buf[3] += v;
                }else{
                // if(1 + 1 < t){
                    buf[1] += v;
                    buf[2] += - (v - 1);
                    buf[t + 1] += - v2;
                    buf[t + 2] += v2 - 1;
                }
            }
        }
    }
    printd(buf);
    for(int i = 0; i < 2; i++){
        for(int j = 1; j < m + 9; j++){
            buf[j] += buf[j - 1];
        }
        printd(buf);
    }
    ll maxi = *max_element(buf.begin() + 1, buf.begin() + m + 1);
    cout << acc - maxi << '\n';
    return 0;
}


Measured memory_bytes: 1792
import java.util.*;
class Main{
  public static void main(String[] args){
    Scanner scan=new Scanner(System.in);
    String[] s=scan.nextLine().split("");
    for(int i=0;i<s.length-1;i++){
      if(s[i].equals(s[i+1])){
        System.out.println("Bad");
        System.exit(0);
      }
    }
    System.out.println("Good");
  }
}

Measured memory_bytes: 21588
#include<iostream>
#include<cstdio>
#include<sstream>
#include<string>
using namespace std;



int main(){
  string s;
  getline(cin,s);
  for(int i=0;i<s.length();i++)if(s[i] == ',' || s[i] == '.')s[i] = ' ';
  stringstream ss;
  string ans[1024];
  ss << s;
  int cnt = 0;
  while(cnt < (ss.str()).size())
    ss >> ans[cnt++];

  string rans;
  
  for(int i=0;i<cnt;i++){
    if(!(ans[i].size() >= 3 && ans[i].size() <= 6))continue;
    rans += " " + ans[i];
  }
  cout << rans.substr(1,rans.length()-1) << endl;
 
  return 0;
}

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

#define CO const
#define IN inline
typedef long long int64;

template<class T> IN T read(){
	T x=0,w=1;char c=getchar();
	for(;!isdigit(c);c=getchar())if(c=='-') w=-w;
	for(;isdigit(c);c=getchar()) x=x*10+c-'0';
	return x*w;
}
template<class T> IN T read(T&x){
	return x=read<T>();
}

CO int N=1e3+10,M=2e5+10;
struct edge {int v,id;};
vector<edge> to[N];
pair<int,int> E[M];
int f[N][N][2],vis[N],T;

void dfs(int u,int src,int id,int type){
	f[src][u][type]=id,vis[u]=T;
	for(CO edge&e:to[u])if(vis[e.v]!=T)
		dfs(e.v,src,id,type);
}
void work(int src){
	++T,vis[src]=T;
	for(CO edge&e:to[src])if(vis[e.v]!=T) // edit 1: vis check
		dfs(e.v,src,e.id,0);
	reverse(to[src].begin(),to[src].end());
	++T,vis[src]=T;
	for(CO edge&e:to[src])if(vis[e.v]!=T)
		dfs(e.v,src,e.id,1);
}
int main(){
	int n=read<int>(),m=read<int>();
	for(int i=1;i<=m;++i){
		int u=read<int>(),v=read<int>();
		to[u].push_back({v,i});
		E[i]={u,v};
	}
	for(int i=1;i<=n;++i) work(i);
	for(int i=1;i<=m;++i){
		int u=E[i].first,v=E[i].second;
		puts((f[v][u][0]!=0)^(f[u][v][0]!=i or f[u][v][1]!=i)?"diff":"same");
	}
	return 0;
}


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

#define ul unsigned long int
#define ull unsigned long long
#define li long long int


int main()
{
  ul a,b;
  cin>>a>>b;
  cout << a/b<<" "<<a%b<<" ";
  cout << fixed;
  cout << setprecision(16)<<(double)a/(double)b<<endl;

  //cout <<setprecision(16) << r * r * M_PI << " " << 2 * r * M_PI << endl;
  ;

  return 0;
}



Measured memory_bytes: 3256
#include<algorithm>
#include<cstring>
#include<string>
#include<cassert>
#include<cmath>
#include<climits>
#include<iomanip>
#include<stack>
#include<unordered_map>
#include<bitset>
#include<limits>
#include<complex>
#include<array>
#include <iostream>

using namespace std;
#define rep(i,m,n) for(int (i)=(int)(m);i<(int)(n);i++)
#define REP(i,n) rep(i,0,n)
#define ll long long
int main()
{
  string s,t;
  cin >> s >> t;
  bool flag =false;
  if(s.size()+1 == t.size())
  {
    bool flag2 = true;
    for(int i=0;i < s.size();i++)
      if(s[i] != t[i])
        flag2 = false;
    if(flag2) flag=true;
        
  }
  if(flag) cout << "Yes" << endl;
  else cout << "No" << endl;
}



Measured memory_bytes: 3628
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <stdio.h>
#include <string.h>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cmath>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
using namespace std;

int main(){
  int N;
  cin >> N;
  vector<int> level(N);
  for(int i = 0;i < N;i++){
    cin >> level.at(i);
  }
  sort(level.begin(),level.end());
  cout << level.at(N/2) - level.at(N/2 - 1) << endl;
}


Measured memory_bytes: 3740
#include<cstdio>
int a[25];

int getRes(){
    fflush(stdout);
    char s[2];
    scanf("%s",s);
    return s[0]=='Y';
}

int main(){
    int find = -1;
    for(int i = 0; i <= 11; i++){
        printf("? 1");
        for(int j = 1; j <= i; j++) printf("0");
        printf("\n");
        fflush(stdout);
        if(getRes()) continue;
        else{
            find = i;
            break;
        }
    }
    if(find==-1){
        int len = -1;
        for(int i = 1; i <= 11; i++){
            printf("?");
            for(int j = 1; j <= i; j++) printf("9");
            printf("\n");
            if(getRes()){
                len = i;
                break;
            }
        }
        printf("! 1");
        for(int i = 1; i <= len-1; i++) printf("0");
        printf("\n");
    }
    else{
        int len = find;
        for(int i = 1; i <= len; i++){
            int L = 0, R = 9;
            if(i==1) L++;
            int res = -1;
            while(L<=R){
                int M = (L+R)/2;
                printf("? ");
                for(int j = 1; j <= i-1; j++) printf("%d",a[j]);
                if(i==len) printf("%d1\n",M);
                else printf("%d\n",M);
                if(i!=len){
                    if(getRes()){
                        res = M;
                        L = M+1;
                    }
                    else R = M-1;
                }
                else{
                    if(getRes()){
                        res = M;
                        R = M-1;
                    }
                    else L = M+1;
                }
            }
            a[i] = res;
        }
        printf("! ");
        for(int i = 1; i <= len; i++) printf("%d",a[i]);
        printf("\n");
    }
    return 0;
}


Measured memory_bytes: 3660
use std::io::prelude::*;

fn input<T>() -> T
where
    T: std::str::FromStr,
{
    let stdin = std::io::stdin();
    let token: String = stdin
        .lock()
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}

fn main() {
    let n: usize = input();
    let m: usize = input();
    let ab: Vec<Vec<i64>> = (0..m)
        .map(|_| {
            let a = input();
            let b = input();
            vec![a, b]
        })
        .collect();

    let mut ans = 0;
    for i in 0..m {
        let mut uf = UnionFind::new(n);
        for j in 0..m {
            if i == j {
                continue;
            }

            uf.connect(ab[j][0] - 1, ab[j][1] - 1);
        }
        if uf.size(0) < n {
            ans += 1;
        }
    }

    println!("{}", ans);
}

struct UnionFind {
    parent: Vec<i64>,
}

impl UnionFind {
    fn new(n: usize) -> UnionFind {
        UnionFind {
            parent: vec![-1; n],
        }
    }

    fn root(&mut self, i: i64) -> i64 {
        if self.parent[i as usize] < 0 {
            i
        } else {
            let p = self.parent[i as usize];
            self.parent[i as usize] = self.root(p);
            self.parent[i as usize]
        }
    }

    fn connect(&mut self, i: i64, j: i64) {
        let i = self.root(i);
        let j = self.root(j);
        if i == j {
            return;
        }

        if i < j {
            self.parent[i as usize] += self.parent[j as usize];
            self.parent[j as usize] = i;
        } else {
            self.parent[j as usize] += self.parent[i as usize];
            self.parent[i as usize] = j;
        }
    }

    fn size(&mut self, i: i64) -> usize {
        let ri = self.root(i);
        (-self.parent[ri as usize]) as usize
    }
}


Measured memory_bytes: 4352
import Data.List
import qualified Data.ByteString.Char8 as BS
import Data.Char

main = do
  li <- BS.getLine
  let Just (n,_) = BS.readInt li
  co <- BS.getContents
  let [as,bs] = transpose $ map (unfoldr (BS.readInt . BS.dropWhile isSpace)) $ BS.lines co
  let ans = compute n as bs
  print ans

-- pureforeverearthのコード
-- https://atcoder.jp/contests/abc169/submissions/13847654
-- をコピーしたもの。これで答えが求まる理屈は理解できていない

compute :: Int -> [Int] -> [Int] -> Int
compute n as bs
  | odd n = b1 - a1 + 1
  | True  = b0 + b1 - a0 - a1 + 1
  where
    a0:a1:_ = drop n21 $ sort as
    b0:b1:_ = drop n21 $ sort bs
    n21 = pred $ div n 2

Measured memory_bytes: 90512
#include <stdio.h>

int main(int argc, const char * argv[]) {
    int i,n,b,f,r,v,j,k;
    int x[4][3][10] = {0};
    scanf("%d",&n);
    for(i=0;i<n;i++){
        scanf("%d %d %d %d",&b,&f,&r,&v);
        x[b-1][f-1][r-1]+=v;
    }
    for(i=0;i<4;i++){
        for(j=0;j<3;j++){
            for(k=0;k<10;k++){
                printf("%2d",x[i][j][k]);
            }
            printf("\n");
        }
        if(i!=3){
            printf("####################\n");
        }
    }

        return 0;
}

Measured memory_bytes: 620
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int INF = 1e9;
const int MOD = 1e9 + 7;

int main(void)
{
    string s;
    cin >> s;
    if(s == "Sunny")
    {
        cout << "Cloudy" << endl;
    }
    if(s == "Cloudy")
    {
        cout << "Rainy" << endl;
    }
    if(s == "Rainy")
    {
        cout << "Sunny" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<queue>
#include<vector>
#include<set>
#include<cmath>
#include<algorithm>
using namespace std;
#define REP(i,b,n) for(int i=b;i<n;i++)
#define rep(i,n)   REP(i,0,n)

const double eps = 1e-7;

#define MAX 250
#define INF (1<<21)
double edge[MAX][MAX];
int cap[MAX][MAX];
int tcap[MAX][MAX];
bool visited[MAX];
int parent[MAX];
int flow[MAX][MAX];
int layer[MAX];


void make_layer(int n,int s,int t){
  queue<int> Q;
  Q.push(s);
  layer[s]=0;
  while(!Q.empty()){
    int now = Q.front();
    Q.pop();
    rep(i,n){
      if ( cap[now][i]-flow[now][i] >0 && layer[i] ==-1){
	layer[i]=layer[now]+1;
	Q.push(i);
      }
    }
  }
}

int augment(int now,int t,int n,int f){
  if (now == t || f == 0)return f;
  if ( visited[now] == true)return 0;
  rep(i,n){
    if (layer[now]<layer[i]){
      int tmp= augment(i,t,n,min(f,cap[now][i]-flow[now][i]));
      if( tmp>0){
	flow[now][i]+=tmp;
	flow[i][now]=-flow[now][i];
	visited[now]=false;
	return tmp;
      }
    }
  }
  return 0;
}


int dinic(int n,int s,int t,double time){
  int ansflow=0;
  bool flag=true;
  rep(i,n){
    rep(j,n){
      if( edge[i][j]<eps+time)cap[i][j]=tcap[i][j],flow[i][j]=0;
      else cap[i][j]=0,flow[i][j]=0;
    }
  }



  while(flag){
    fill(layer,layer+n,-1);
    fill(visited,visited+n,false);
    make_layer(n,s,t);
    if ( layer[t] == -1)break;
   
    for(int f=1;f;flag=true){
      f=augment(s,t,n,INF);
      if ( f == 0)break;
      ansflow+=f;
    }
  }
  return ansflow;
}


#define SUPERSOURCE 0
#define SUPERSINK   1

double solve(int n,vector<double> &v,int m){
 int l=0,r=v.size()-1,ret=-1;
  while(l<=r){
    int mid = (r+l)/2;
    if ( dinic(n,SUPERSOURCE,SUPERSINK,v[mid])==m )r=mid-1,ret=mid;
    else l=mid+1;
  }
  return v[ret];
}

class Double{
public:
  double b;
  bool operator<(const Double & a)const{
    if ( abs(b-a.b)<eps)return false;
    else return b < a.b;
  }
};

inline double calc_dist(double x,double y,double v){
  return sqrt(x*x+y*y)/v;
}




main(){
  int n,m;
   while(cin>>n>>m && n){
    double xt[n],yt[n],v[n],xbase[n],ybase[n];
    rep(i,n)cin>>xt[i]>>yt[i]>>v[i];
    rep(i,m)cin>>xbase[i]>>ybase[i];
    int node = 2+n+m;
    rep(i,node)rep(j,node)edge[i][j]=INF,tcap[i][j]=0;
    set<Double> S;
    vector<double> in;
    rep(i,n){
      rep(j,m){
	int src=2+i,dst=2+n+j;
	edge[src][dst]=calc_dist(xt[i]-xbase[j],yt[i]-ybase[j],v[i]);
	tcap[src][dst]=1;
	Double tmp={edge[src][dst]};
	if ( S.find(tmp)==S.end())in.push_back(tmp.b),S.insert(tmp);
      }
    }
    rep(i,n){
      tcap[SUPERSOURCE][2+i]=1;
      edge[SUPERSOURCE][2+i]=-1;
    }
    rep(j,n){
      tcap[2+n+j][SUPERSINK]=1;
      edge[2+n+j][SUPERSINK]=-1;
    }
    sort(in.begin(),in.end());
    printf("%.9lf\n",solve(node,in,m));
   }
   
}

Measured memory_bytes: 2476
#include<iostream>
#include<vector>
#include<algorithm>
#include<utility>
#include<map>
#include<set>
#include<queue>
#define N (998244353)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll,P> Q;

int p[200010];



int main(void){
    string s;
    int k;
    cin>>k>>s;
    if(k>=s.length())cout<<s<<endl;
    else{
        for(int i=0;i<k;i++)cout<<s[i];
        cout<<"..."<<endl;
    }
    return 0;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
typedef long long ll;
const ll zoz = 1e9 + 7;
int n, m, a[N];
ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a%b); }
ll lcm(ll a, ll b) { return a / gcd(a, b)*b; }
int main() {
	cin >> n >> m;
	for (int i = 0; i < n; ++i) cin >> a[i];
	ll lc = a[0] / 2;
	for (int i = 1; i < n; ++i) {
		lc = lcm(lc, 1LL * a[i] / 2);
		lc = min(lc, zoz);
	}
	if (lc <= m) {
		bool busted = 0;
		for (int i = 0; i < n; ++i) {
			ll y = lc / (a[i] / 2);
			if (y % 2 == 0) {
				busted = 1;
				break;
			}
		}
		if (busted) {
			cout << 0 << endl;
		}
		else {
			ll mval = 1LL * m / lc;
			cout << (mval + 1) / 2 << endl;
		}
	}
	else cout << 0 << endl;
}

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

int main(){
  int N;
  cin >> N;
  string S;
  cin >> S;

  int Ans = 0;

  for (int i=1; i<N; i++) {
    int cnt = 0;

    for (char c='a'; c<='z'; c++) {
      bool left = false, right = false;

      for (int j=0; j<i; j++) {
        if (S[j] == c) left = true;
      }

      for (int j=i; j<N; j++) {
        if (S[j] == c) right = true;
      }

      if (left && right) cnt++;
    }

    if (Ans < cnt) Ans = cnt;
  }

  cout << Ans << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<bitset>
#include<iomanip>
#include<list>
#include<deque>
using namespace std;
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define DEB2(X) cout<<X<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define DEB2(X) {}
#define END {}
#endif
typedef long long ll;
#define int ll
#define uset unordered_set
#define umap unordered_map
//typedef std::pair<int,int> P;
struct edge{int to,cost;};
const int INF=100000000000000000;
const int INF2=9223372036854775807;
const int MOD=1000000007;
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define min(X,Y) (((int)(X)<(int)(Y))?(X):(Y))
#define max(X,Y) (((int)(X)>(int)(Y))?(X):(Y))
#define NP(X,Y) next_permutation(X,Y)
#define setdouble(X,Y) cout<<fixed<<setprecision(X)<<Y
int ceil2(int a,int b){if(a%b==0){return a/b;}else{return a/b+1;}}
int pow2(int a,int b){int r=1;for(int i=1;i<=b;i++){r*=a;}return r;}
int Log2(int a){int t=0;while(1){if(a==0||a==1){break;}a/=2;t++;}return t;}

int N;
int A[110];

signed main(){
	cin>>N;
	REP(i,N){
		cin>>A[i];
	}
	int ans=0;
	REP(i,N){
		if(i%2==0&&A[i]%2==1){
			ans++;
		}
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 3600
#include<bits/stdc++.h>
using namespace std;
using i64 = int_fast64_t;

i64 mod_pow(i64 x, i64 n, i64 MOD = 1e9 + 7){
    i64 res = 1;
    while(n > 0){
        if(n & 1) res = (res * x) % MOD ;
        x = (x * x) % MOD;
        n >>= 1;
    }
    return res;
}

i64 mod_inv(i64 x, i64 MOD = 1e9 + 7){
    return mod_pow(x, MOD - 2, MOD);
}

int main(){
    i64 N;
    cin >> N;
    vector<i64> X(N);
    for(int i = 0; i < N; i++) cin >> X[i];
    
    const i64 MOD = 1e9 + 7;
    i64 inv_s = 0;
    i64 ans = 0;
    for(int i = 0; i < N-1; i++){
        inv_s = (inv_s + mod_inv(i+1)) % MOD;
        ans = (ans + (X[i+1] - X[i]) * inv_s) % MOD;
    }
    for(int n = 1; n < N; n++) ans = (ans * n) % MOD;
    cout << ans << endl;
}

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

int ctj = 0, cto = 0;
string s;
int n, a, b;

void prt(int x) {
    if (x == 0)
        printf("No\n");
    else
        printf("Yes\n");
}

int main() {
    cin >> n >> a >> b;
    cin >> s;
    for (int i = 0; i < n; ++i) {
        if (s[i] == 'c') {
            prt(0); continue;
        } if (s[i] == 'a') {
            if (ctj < a+b) {
                ctj++; prt(1); continue;
            } else {
                prt(0); continue;
            }
        } if (s[i] == 'b') {
            if (ctj < a+b && cto < b) {
                ctj++; cto++;prt(1); continue;
            } else {
                prt(0); continue;
            }
        }
    }
}

Measured memory_bytes: 896
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <string>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n) - 1; i >= 0; i--)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (a); i > (b); i--)
#define ALL(a) (a).begin(), (a).end()

int main() {
    int N, A, B;
    cin >> N >> A >> B;
    cout << min(A, B) << " " << max(0, A + B - N) << endl;
    return 0;
}

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

int main(){
    int a,b;
    cin >> a >> b;
    cout << a*b;
}

Measured memory_bytes: 3624
#include <iostream>
#include <cmath>
#include <string>
#include <set>
#include <vector>
#include <map>
#include <list>
#include <stack>
using namespace std;
typedef long long ll;

int main(void) {
    int N;
    cin >> N;
    int i;
    int ans=N;
    for(i=0; i<=N; i++) {
        int t=i;
        int cnt=0;
        while(t>0) {
            cnt += t%6;
            t /= 6;
        }
        t = N-i;
        while(t>0) {
            cnt += t%9;
            t /= 9;
        }
        ans = min(ans, cnt);
    }
    cout << ans << endl;
}


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

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

int main() {
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	string s,t; cin>>s>>t;
	reverse(t.begin(), t.end());
	cout << (s==t ? "YES" : "NO") << endl;
	return 0;
}


Measured memory_bytes: 256
let split str delim =
  let open String in
  let rec doit s acc =
    match
      try Some (rindex s delim) with _ -> None
    with
    | None -> s :: acc
    | Some i -> doit (sub s 0 i) (sub s (i + 1) (length s - i - 1) :: acc) in
  doit str []

let parent i = int_of_float ((float_of_int (i - 1)) /. 2.)

let left i = 2*i + 1

let right i = 2*i + 2

let to_pow_of_2 n =
  let rec doit i =
    if i >= n then i
    else doit (i * 2) in
  doit 1

let update (s : int array) n i x =
  let j = n + i - 1 in
  s.(j) <- x;
  let rec doit j =
    if j > 0 then begin
      let j = parent j in
      s.(j) <- if s.(left j) < s.(right j) then s.(left j) else s.(right j);
      doit j
    end in
  doit j

let find s n a b =
  let rec doit a b k l r =
    if r <= a || b <= l then 2147483647
    else if a <= l && r <= b then s.(k)
    else min (doit a b (left k) l ((l + r) / 2)) (doit a b (right k) ((l + r) / 2) r) in
  doit a b 0 0 n

let solve n q =
  let n = to_pow_of_2 n in
  let s = Array.make (2*n-1) 2147483647 in
  let rec doit i =
    if i < q then begin
      begin match List.map int_of_string (split (read_line ()) ' ') with
      | 0 :: x :: y :: _ -> update s n x y
      | 1 :: x :: y :: _ -> Printf.printf "%d\n" (find s n x (y + 1))
      | _ -> ()
      end;
      doit (i + 1)
    end in
  doit 0

let () =
  match List.map int_of_string (split (read_line ()) ' ') with
  | [n; q] -> solve n q
  | _ -> ()

Measured memory_bytes: 6488
#include <bits/stdc++.h>
using namespace std;
#define int long long
using ll=long long;
using vi=vector<int>;
using vl=vector<long long>;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
#define ITR(v,c) for(auto v=begin(c);v!=end(c);++v)
#define FORE(x,c) for(auto &x:c)
#define FOR(v,a,n) for(int v=a;v<(int)(n);++v)
#define REP(v,n) FOR(v,0,n)
#define RREP(v,n) for(int v=((int)(n)-1);v>=0;--v)
#define ALL(c) begin(c),end(c)
#define RALL(c) rbegin(c),rend(c)
#define SZ(c) ((int)c.size())
#define dump(...)
const int DX[9]={0,1,0,-1,1,1,-1,-1,0}, DY[9]={-1,0,1,0,-1,1,1,-1,0};
const int INF=1e9; const long long INFLL=1e18;
template<class T> ostream& operator << (ostream &os, const vector<T> &v) {
    ITR(i,v) os<<*i<<(i==end(v)-1?"":" "); return os; }
template<class T> istream& operator >> (istream &is, vector<T> &v) {
    ITR(i,v) is>>*i; return is; }
//------------------------------------------------------------------------------

struct UnionFind {
	vector<int> data;
	UnionFind(int size) : data(size, -1) { }
    void unite(int x, int y) {
	    x = root(x); y = root(y);
        if(x != y) {
            if(data[y] < data[x]) swap(x, y);
            data[x] += data[y]; data[y] = x;
        }
	}
	bool same(int x, int y) {
	    return root(x) == root(y);
    }
	int root(int x) {
        return data[x] < 0 ? x : data[x] = root(data[x]);
    }
    int size(int x) {
        return -data[root(x)];
    }
};
signed main() {
    int N,M;
    cin>>N>>M;
    vector<vi> L(N);
    vector<vi> S(M);
    REP(i,N) {
        int k;
        cin>>k;
        L[i].resize(k);
        REP(j,k) {
            cin>>L[i][j];
            L[i][j]--;
            S[L[i][j]].push_back(i);
        }
    }
    
    UnionFind uf(N+M);//0~M-1:言語,M~M+N-1:人
    REP(i,M) {
        REP(j,SZ(S[i])) {
            uf.unite(i,S[i][j]+M);
        }
    }

    int root=uf.root(M+0);
    REP(i,N) {
        if(uf.root(i+M)!=root) {
            cout<<"NO"<<endl;
            return 0;
        }
    }
    cout<<"YES"<<endl;
    return 0;
}


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

typedef long long ll;

const int Maxn = 200005;

int n;
int L[Maxn], R[Maxn];

int main()
{
    scanf("%d", &n);
    for (int i = 0; i < n; i++)
        scanf("%d %d", &L[i], &R[i]);
    sort(L, L + n);
    sort(R, R + n);
    if (n % 2)
        printf("%d\n", R[n / 2] - L[n / 2] + 1);
    else {
        int lef = (L[(n - 1) / 2] + L[n / 2]);
        int rig = (R[(n - 1) / 2] + R[n / 2]);
        printf("%d\n", rig - lef + 1);
    }
    return 0;
}


Measured memory_bytes: 5320
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

const ll mod = 1000000007;

int main() {
    string s;
    cin >> s;
    rep(i,3){
        if(s[i+1] == s[i]){
            cout << "Bad" << endl;
            return 0;
        }
    }
    cout << "Good" << endl;
    return 0;
}


Measured memory_bytes: 3608
#include <bits/stdc++.h>
#define ll long long
#define double long double
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mod (ll)(1e9+7)
#define inf (ll)(3e18+7)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(x) x.begin(),x.end()
using namespace std;

int main() {
  string s, before, c;
  cin >> s;
  before = s[0];
  vector<string> ans;
  ans.push_back(before);
  for(int i = 1; i < s.size(); i++) {
    int j=0;
    c = s[i];
    if(c == before){
      while(i+j < s.size()-1) {
        j++;
        c += s[i+j];
        if(before != c) {
          before = c;
          ans.push_back(before);
          break; 
        }  
      }
    }else{
      before = s[i];
      ans.push_back(before) ;
    }
    i += j; 
  }
  if(ans.at(ans.size()-1) != c) ans.push_back(c);
  cout << ans.size();     
}

Measured memory_bytes: 10996
n,m = map(int,input().split())
K = []
A = []

for _ in range(n):
    tmp = list(map(int,input().split()))
    A += tmp[1:]

ans = 0
from collections import Counter
cnt = Counter(A)
for k,v in cnt.items():
    if v == n:
        ans += 1
print(ans)

Measured memory_bytes: 3316
/*  ex2_3
    hangan2020 */
 
#include <stdio.h>
 
int main(void){
    int N, A; 
    //NとAの入力
    scanf("%d", &N);
    scanf("%d", &A);
    //条件付け
    if( N < 1 || 100 <= N || A < 0 || A > N*N){
        fprintf(stderr, "Valid input should satisfy the following conditions:\n 1 <= N <= 100\n 0 <= A <= N^2");
        return 1;
    }
    //Answerの計算
    printf("%d\n", N*N - A);
    return 0;
}

Measured memory_bytes: 128
A, B, C, X, Y = map(int,input().split())
s1 = 2*C*max(X, Y)
s2 = 2*C*min(X, Y) + A*(X-min(X,Y)) + B*(Y-min(X,Y))
s3 = A*X + B*Y
print(min(s1,s2,s3))

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

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

    //good luck kittu!
    string s; cin>>s;
    int n = s.size();
    for(int i = 0; i<n-1; i++) if(s[i]==s[i+1]) return cout<<i+1<<" "<<i+2<<"\n", 0;
    for(int i = 0; i<n-2; i++) if(s[i]==s[i+2]) return cout<<i+1<<" "<<i+3<<"\n", 0;
    cout<<"-1 -1\n";
    return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <math.h>
#include <stdlib.h>
#include <functional>
#include <vector>
#include <list>
#include <deque>
#include <stack>
#include <bitset>
#include <set>
#include <queue>
#include <map>
using namespace std;
int main(){
	int a,b,c;
	cin>>a>>b>>c;
	int k=0;
	if(a!=b){
		k++;
	}
	if(a!=c){
		k++;
	}
	if(b!=c){
		k++;
	}
	if(k==0){
		k++;
	}
	cout<<k<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<stack>
#include<queue>
#include<deque>
#include<map>
#include<set>
using namespace std;
typedef long long ll;
typedef vector<int> VI;
#define FOR(i,n) for(int (i)=0;(i)<(n);(i)++)
#define FOR1(i,n) for(int (i)=1;(i)<(n);(i)++)
#define eFOR(i,n) for(int (i)=0;(i)<=(n);(i)++)
#define eFOR1(i,n) for(int (i)=1;(i)<=(n);(i)++)
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i) sort((i).begin(),(i).end(), greater<int>());
#define YES(i) cout << ((i) ? "Yes" : "No") << endl;
constexpr auto INF = 1000000000;
constexpr auto LLINF = 1LL << 60;
constexpr auto mod = 1000000007;
template<class T> inline bool chmax(T & a, T b) { if (a < b) { a = b; return 1; }return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; }return 0; }


int main() {

	int n, m;
	cin >> n >> m;
	vector<vector<pair<int, ll>>> g(n);
	FOR(i, m) {
		int a, b;
		ll c;
		cin >> a >> b >> c;
		a--; b--;
		g[a].push_back({ b,c });
	}

	vector<ll> ans(n, -LLINF);
	ans[0] = 0;
	FOR(cnt, n) {
		FOR(i, n) {
			for (auto e : g[i]) {
				if (chmax(ans[e.first], ans[i] + e.second)) {
					if (cnt == n - 1 && e.first == n - 1) {
						cout << "inf" << endl;
						return 0;
					}
				}
			}
		}
	}
	cout << ans[n - 1] << endl;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
#define ll long long
#define For(i,j,k) for (int i=(int)(j);i<=(int)(k);i++)
using namespace std;
const int N=45;
int n;
char e[N][N];
ll f[N][N][N];
ll g[N][N][N],ans;
int main(){
	scanf("%d",&n); n*=2;
	For(i,1,n) scanf("%s",e[i]+1);
	For(i,1,n) For(j,1,n) e[i][j]-='0';
	For(i,1,n) f[i][i][i]=1;
	for (int l=1;l<=n;l+=2)
		for (int i=1;i+l-1<=n;i++){
			int j=i+l-1;
			for (int k=i;k<=n;k+=2)
				for (int l=j;l>k;l-=2){
					ll S=0;
					For(p1,l,j) S+=g[i][k][p1]*f[l][j][p1];
					For(p1,k+1,l-1)	f[i][j][p1]+=f[k+1][l-1][p1]*S;
				}
			For(p1,i,j) For(p2,j+1,n)
				if (e[p1][p2]) g[i][j][p2]+=f[i][j][p1]; 
		}
	For(i,2,n)
		if (e[1][i])
			ans+=f[2][n][i];
	printf("%lld\n",ans);
}

Measured memory_bytes: 1152
#include <iostream>
#include <string>
#include <map>
#include <queue>
#include <algorithm>
#include <vector>
#include <math.h>
#include <bitset>
#include <cmath>
#include <set>

#define rep(i,s,n)for(int i = s;i<n;i++)
#define repe(i,s,n)for(int i = s;i<=n;i++)
#define rep_r(i,s,n)for(int i = n-1;i>=s;i--)
#define rep_re(i,s,n)for(int i = n;i>=s;i--)
using namespace std;
typedef long long ll;
static const ll MOD = 1e9 + 7;
static const ll INF = 1e25;
static const ll MAX_M = 100001;

ll a[100001] = {};
ll s[100001] = {};
int main() {
	ll n; cin >> n;
	repe(i, 1, n)cin >> a[i];
	sort(a + 1, a + 1 + n);

	repe(i, 1, n) s[i] += s[i - 1] + a[i];

	ll k = 0;
	repe(i, 1, n) {
		if (2 * s[i] < a[i + 1]) {
			k = i;
		};
	}

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

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,m;
	cin>>n>>m;
	int sum =0;
	if(n>=2&&m>=2)
	sum += n*(n-1)/2 + m*(m-1)/2;
	else if(n>=2&&m<2)
	sum += n*(n-1)/2;
	else  if(m>=2&&n<2)
	sum += m*(m-1)/2;
	cout<<sum<<endl;
	return 0;
}

Measured memory_bytes: 256
n = int(input())
pat = 1
mod = 10**9+7
l = []
for _ in range(n):
  a = int(input())
  l.append((a,0))
for _ in range(n):
  a = int(input())
  l.append((a,1))
l.sort()
cur = {0:0, 1:0}
for x in l:
  if cur[1-x[1]]:
    pat = pat*cur[1-x[1]]%mod
    cur[1-x[1]] -= 1
  else:
    cur[x[1]] += 1
print(pat)

Measured memory_bytes: 24512
A=list(input().split())
L=len(A)
MAX1=0
MAX2=0
for i in range(L):
    s=A.count(A[i])
    if s>MAX1:
        MAX1=s
        x=A[i]
    else:
        pass
    
    l=len(A[i])
    if l>MAX2:
        MAX2=l
        y=A[i]
    else:
        pass
    
print(x,y)


Measured memory_bytes: 5556
using System;
using System.Collections.Generic;

namespace Project
{
	class MainClass
	{
		public static void Main(string[] args)
		{
			string s = Console.ReadLine();
			int count = 0;
			for (int i = 0; i < s.Length - 1; i++)
			{
				if (s[i] != s[i + 1]) count++;
			}
			Console.WriteLine(count);

		}

	}
}


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

const int N=105;

int L,n,m,bin[N],a[N];
struct data{int x,y,w;}ans[N];

void add(int x,int y,int w)
{
    m++;
    ans[m].x=x;ans[m].y=y;ans[m].w=w;
}

int main()
{
    scanf("%d",&L);
    n=20;
    bin[0]=1;
    for (int i=1;i<=20;i++) bin[i]=bin[i-1]*2;
    for (int i=n-1;i>=2;i--) add(i,i+1,bin[n-i-1]),add(i,i+1,0);
    int top=0,sum=0;
    while (L>=262144) add(1,2,sum),sum+=262144,L-=262144;
    while (L) a[++top]=L%2,L/=2;
    for (int i=top;i>=1;i--)
    {
        if (!a[i]) continue;
        add(1,n-i+1,sum);
        sum+=bin[i-1];
    }
    printf("%d %d\n",n,m);
    for (int i=1;i<=m;i++) printf("%d %d %d\n",ans[i].x,ans[i].y,ans[i].w);
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstdio>

using namespace std;
typedef long long ll;

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

  for (int i = 0; i <= N / 4; i++) {
    for (int j = 0; j <= N / 7; j++) {
      if (4 * i + 7 * j == N) {
        cout << "Yes" << endl;
        return 0;
      }
    }
  }

  cout << "No" << endl;
}


Measured memory_bytes: 256