akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Linq;

namespace ProblemE
{
    class Program
    {
        static void Main(string[] args)
        {
            int N = GetInt();
            var a = GetLongArray();
            long wholeXOR = 0;

            for(int i = 0; i < N; i++)
            {
                wholeXOR ^= a[i];
            }

            for (int i = 0; i < N; i++)
            {
                if (i == N - 1)
                {
                    Console.Write(wholeXOR ^ a[i]);
                }
                else
                {
                    Console.Write("{0} ", wholeXOR ^ a[i]);
                }
            }
            Console.WriteLine();
        }

        public static int GetInt() => int.Parse(Console.ReadLine());
        public static int[] GetIntArray() => Console.ReadLine().Split().Select(int.Parse).ToArray();
        public static double GetDouble() => double.Parse(Console.ReadLine());
        public static double[] GetDoubleArray() => Console.ReadLine().Split().Select(double.Parse).ToArray();
        public static long GetLong() => long.Parse(Console.ReadLine());
        public static long[] GetLongArray() => Console.ReadLine().Split().Select(long.Parse).ToArray();

    }
}


Measured memory_bytes: 52000
#include <iostream>
#include <vector>
#include <cmath>
#include <string>
#include <algorithm>
#include <set>

using namespace std;

typedef long long ll;

int main(){
    int x, y, z;
    cin >> x >> y >> z;
    cout << z << " " << x << " " << y << endl;
    return 0;
}


Measured memory_bytes: 256
# AOJ 0211: Jogging
# Python3 2018.6.25 bal4u

def lcm(a, b):
	return a // gcd(a, b) * b

def gcd(a, b):
	while b != 0:
		r = a % b
		a, b = b, r
	return a

def ngcd(n, a):  # aが整数のリスト
	if n == 1: return a[0]
	g = gcd(a[0], a[1]);
	for i in range(2, n):
		if g == 1: break
		g = gcd(g, a[i])
	return g;

def nlcm(n, a):  # aが整数のリスト
	if n == 1: return a[0];
	g = gcd(a[0], a[1]);
	c = a[0] //g *a[1]
	for i in range(2, n):
		g = gcd(c, a[i])
		c = c //g * a[i]
	return c

while True:
	n = int(input())
	if n == 0: break
	d, v = [], []
	for i in range(n):
		a, b = map(int, input().split())
		g = gcd(a, b)
		a //= g
		b //= g
		d.append(a)
		v.append(b)
	g = nlcm(n, d);
	for i in range(n): d[i] = (g//d[i])*v[i]
	g = ngcd(n, d)
	for i in range(n): print(d[i]//g)


Measured memory_bytes: 5620
#include <stdio.h>

int main(void)
{
    int num[4];
    int temp;
    int i, j;
    
    scanf("%d %d %d %d", &num[0], &num[1], &num[2], &num[3]);
    
    if(num[1] < num[2] || num[3]<num[0]){
        printf("%d\n", 0);
    }else{
        for(i=0; i<4; i++){
            for(j=i+1; j<4; j++){
                if(num[i] > num[j]){
                    temp = num[i];
                    num[i] = num[j];
                    num[j] = temp;
                }
            }
        }
        printf("%d\n", num[2] - num[1]);
    }
    
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i,n) for(ll i = n;i >= 0;--i)
#define FOR(i,m,n) for(ll i = m, i##_len=(n);i <i##_len; ++i)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
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; }
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
const int INF = 1e9;
const ll LLINF = 1e16;

vector<ll> divisors(ll n) {
    vector<ll> res;
    for(ll i = 1; i*i <= n; ++i) {
        if(n % i != 0) continue;
        res.push_back(i);
        if(n/i == i) continue;
        res.push_back(n/i);
    }
    return res;
}

bool is_prime(ll n) {
    if(n == 1) return false; // 1 は素数ではない。
    for(ll i = 2; i*i <= n; ++i) { // 2 <= i <= sqrt(n) に約数があれば、
        if(n % i == 0) return false; // n は素数ではない
    }
    return true;
}

int main(void)
{
    ll a,b;
    cin >> a >> b;
    vector<ll> prime_div;
    vector<ll> diva = divisors(a);
    vector<ll> divb = divisors(b);
    vector<ll> divab(diva.size() + divb.size());
    sort(all(diva));
    sort(all(divb));
    vector<ll>::iterator it = set_intersection(all(diva), all(divb), divab.begin());
    ll internum = ll(it - divab.begin());

    REP(i,internum){
        if(is_prime(divab[i])){
            prime_div.push_back(divab[i]);
        }
    }

    cout << prime_div.size() + 1<< endl;

    return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#define ALL(obj) (obj).begin(),(obj).end()
#define RALL(obj) (obj).rbegin(),(obj).rend()
#define REP(i, n) for(int i=0;i<(n);++i)
#define RANGE(i, a, b) for(int i=(a);i<(b);++i)
#define RREP(i, n) for(int i=(n)-1;i>= 0;--i)

#define endl '\n'
#define pb push_back
#define eb emplace_back
#define pque priority_queue
#define umap unordered_map
#define uset unordered_set
#define BIG 2000000000
#define VERYBIG 1000000000000000ll
#define dcout cout<<fixed<<setprecision(20)
#define Accepted_MAGIC cin.tie(0);ios::sync_with_stdio(false)

// typedef long long ll;
using Real = long double;
#define int long long

const long long dx[]={1,0,-1,0,1,1,-1,-1}, dy[]={0,-1,0,1,1,-1,1,-1};
const long long MOD = 1e9+7;
constexpr Real eps = 1e-9, pi = acos(-1);

template<typename T> inline T GCD(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template<typename T> inline T LCM(T a,T b){T c=GCD(a,b);a/=c;return a*b;}
template<typename T> inline T nCr(T a,T b){T i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
template<typename T> inline T nHr(T a,T b){return nCr(a+b-1,b);}
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;}

typedef pair<int, int> INTP;
typedef vector<int> INTV;
struct edge2 {int to, cost;};
struct edge3 {int from, to, cost;};

signed main(void){
  Accepted_MAGIC;
  
  int H, W, K; string S[10];
  cin >> H >> W >> K;
  int cnt[10][1010] = {};
  REP(i, H) {
    cin >> S[i];
    REP(j, W){
      cnt[i][j+1] += cnt[i][j];
      if(S[i][j] == '1') cnt[i][j+1]++;
    }
  }
  int ans = BIG;
  REP(bit, (1<<(H-1))){
    int anspre = __builtin_popcount(bit);
    int left = 0;
    REP(j, W){
      int num = 0;
      bool greater = 0;
      REP(i, H){
        num += cnt[i][j+1]-cnt[i][left];
        if((bit>>i) & 1){
          greater |= (num > K);
          num = 0;
        }
      }
      greater |= (num > K);
      if(greater) {
        if(left == j){
          anspre = VERYBIG;
          break;
        }
        anspre++; left = j; j--;
      }
    }
    chmin(ans, anspre);
  }
  cout << ans << endl;
}

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

int count(int a, int b){
  return b - a + 1;
}



int main() {
  int N;
  cin >> N;
  vector<int> vec(N);
  int a,b,total = 0;
  for(int i = 0; i < N; i++){
  cin >> a >> b;
    vec.at(i) = count(a,b);
    total += vec.at(i);
  }
  cout << total <<endl;
}


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

int main(){
    int a,b,k,cnt=0,ans=0;
    cin>>a>>b>>k;

    for(int i=min(a,b);i>0;i--){
        if(a%i==0&&b%i==0){
            cnt++;
            ans=i;
        }
        if(k==cnt) break;
    }

    cout<<ans<<endl;

}


Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<functional>
#include<vector>
#include<queue>
#include<stack>
#include<set>
using namespace std;
#define MOD 1000000007
#define f(i,n) for(int i=0;i<int(n);i++)
#define N 100000


int main(){
	int a[N];
	int n, k;
	long long s, ans;
	ans = 0;
	scanf("%d", &n);
	k = 0;
	f(i, n){
		scanf("%d", &a[i]);
		while (a[i] % 2 == 0){
			ans++;
			a[i] = a[i] / 2;
		}
	}
	printf("%lld\n", ans);

	return 0;
}

Measured memory_bytes: 256
//This is getting accepted!
// I HATE BUG
// God Of The Bugs
// 12/11/2016
#include<bits/stdc++.h>

using namespace std;

#define ms(s, n) memset(s, n, sizeof(s))
#define FI first
#define SE second
#define pb push_back
#define mp make_pair
#define ll long long
#define sz(a) ((int)(a).size())
#define __builtin_popcount __builtin_popcounll
#define ld long double

typedef pair<int, int> pii;
typedef pair<double, double> pdd;
typedef pair<int, pii> ppi;

const double PI = acos(0) * 2;
const double EPS = 1e-8;
const ll MOD = 1e9 + 7;
const int MAXN = 1e5 + 5;
const int oo = 1e9;
const double foo = 1e30;

template<class T> int getbit(T s, int i) { return (s >> i) & 1; }
template<class T> T onbit(T s, int i) { return s | (T(1) << i); }
template<class T> T offbit(T s, int i) { return s & (~(T(1) << i)); }
template<class T> int cntbit(T s) { return __builtin_popcounll(s);}
template<class T> T sqr(T x) { return x * x; }

inline void addmod(int& a, int val, int p = MOD) {if ((a = (a + val)) >= p) a -= p;}
inline void submod(int& a, int val, int p = MOD) {if ((a = (a - val)) < 0) a += p;}
inline int mult(int a, int b, int p = MOD) {return (ll) a * b % p;}

int n,m;
string a[100], b[100];

int main() {
//#ifndef ONLINE_JUDGE
//    freopen("inp.txt", "r", stdin);
////    freopen("out.txt", "w", stdout);
//#endif

	cin >> n >> m;
	for (int i=0; i<n; i++) cin >> a[i];
	for (int i=0; i<m; i++) cin >> b[i];
	for (int i=0; i+m-1<n; i++) {
		for (int j=0; j+m-1<n; j++) {
//			cout << i << " "<< j << endl;
			int ok = 0;
			for (int i1=0; i1<m; i1++) {
				for (int j1=0; j1<m; j1++) {
					if (b[i1][j1] != a[i + i1][j + j1]) {
						ok = 1;
						break;
					}
				}
				if (ok) break;
			}
			if (!ok) {
				cout << "Yes";
				return 0;
			}
		}
	}

	cout << "No";
}


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

#define endl "\n"
#define ll long long int
#define vi vector<int>
#define vll vector<ll>
#define vvi vector < vi >
#define pii pair<int,int>
#define pll pair<long long, long long>
#define MOD 1000000007
#define INF 1000000000000000001;
#define all(c) c.begin(),c.end()
#define mp(x,y) make_pair(x,y) 
#define mem(a,val) memset(a,val,sizeof(a))
#define f first
#define s second
 
int main(){
	ios::sync_with_stdio(false);
	cin.tie(NULL);

	string s;
	cin>>s;
	for (int i = 0; i < s.size(); ++i)
	{
		cout<<"x";
	}

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <math.h>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <deque>
using namespace std;
typedef long long int lo;
#define pb push_back
#define pf push_front
#define ft front
#define mp make_pair
#define st first
#define nd second
#define inf (lo)1e9;
#define FOR for(lo i = 0 ; i < n ; i++)
#define FORV for(lo i = 0 ; i < (lo)v.size() ; i++)
#define ii pair<lo,lo>
#define iii pair<lo, pair<lo,lo> >
lo a,b,c,d,e,n,m,k,t,h,x,y,a1[100005],a2[100005];
char c1[505][505],c2,c3,c4;
string s1,s2,s3,s4;
double d1,d2,d3;
vector <lo> v;
map <lo,lo> mp1;
map <string,lo> mp2;
set <lo> stt;
queue <lo> q;
priority_queue <lo> pq;
lo vis [10000];
deque <lo> dq;
int main() {
    // freopen("gir.gir", "r", stdin);
    // freopen("cik.cik", "w", stdout);
    cin >> a >> b;
    cout << (a * (a - 1)) / 2 + (b * (b - 1)) / 2 << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
typedef long double ld;
const ll INF = 1e+14;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
#define pb push_back
 
void Yes(){
	cout<<"Yes"<<endl;
	exit(0);
}
 
void No(){
	cout<<"No"<<endl;
	exit(0);
}
int main(){
  ll n; cin>>n;
  vector<ll> a;
  rep(i,n){
    ll b; cin>>b;
    a.push_back(b);
  }
  
  sort(a.begin(),a.end());
  ll judge=a[n-1];
  ll key=judge/2;
  
  auto it=lower_bound(a.begin(),a.end(),key);
  ll index=it-a.begin();
  ll ans1=a[index];
  ll d;
  rep(i,n){
    if(a[i]==ans1) {
      d=i; break;
    }
    else continue;
  }
  ll ans2=a[d-1];
 
  ll a1=ans1-key;
  ll a2=key-ans2;
  if(a1<=a2) {
    if(n%2==0&&a1==a2) cout<<judge<<" "<<ans2<<endl;
    else cout<<judge<<" "<<ans1<<endl;
  }
  else cout<<judge<<" "<<ans2<<endl;
}

Measured memory_bytes: 1400
#include <cmath>
#include <iostream>
#include <vector>

using namespace std;

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

    if (N == 0) {
        cout << 0 << endl;
        return 0;
    }

    long long mod = 2;
    long long base = 1;
    vector< int > bin_S;

    while (N != 0) {
        // cout << N << endl;
        if (N % mod == 0)
            bin_S.push_back(0);
        else
            bin_S.push_back(1);
        N -= *(bin_S.end() - 1) * base;
        base *= -2LL;
        mod *= 2LL;
    }

    for (int i = bin_S.size() - 1; i >= 0; i--) {
        cout << bin_S[i];
    }
    cout << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
const int INF = (1<<30)-1;
const long long LINF = (1LL<<62)-1;
const long double PI = acos(-1.0L);
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};
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; }

template< class T >
T extgcd(T a, T b, T &x, T &y) {
  T d = a;
  if(b != 0) {
    d = extgcd(b, a % b, y, x);
    y -= (a / b) * x;
  } else {
    x = 1;
    y = 0;
  }
  return d;
}

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll a, b;
  cin >> a >> b;
  ll x, y;
  extgcd(a, b, x, y);
  cout << x << ' ' << y << endl;
  return 0;
}


Measured memory_bytes: 3208
/*
 * Shubham Jain
 */
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0; i<(n); i++)
#define mem(x,val) memset((x),(val),sizeof(x));
#define rite(x) freopen(x,"w",stdout);
#define read(x) freopen(x,"r",stdin);
#define all(x) x.begin(),x.end()
#define sz(x) ((int)x.size())
#define sqr(x) ((x)*(x))
#define clr clear()
#define ll long long int
#define inf (1<<30)
#define ins insert
#define endl '\n'
#define xx first
#define yy second
#define eps 1e-9
#define FAST_IO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define INF 1000000000000000000
#define mx 0
inline ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }
inline ll lcm(ll a, ll b) { return a * (b / gcd(a, b)); }


int main() {
    FAST_IO
    ll a,b,c,d;
    cin>>a>>b>>c>>d;
    if(a+b>c+d)
        cout<<"Left"<<endl;
    else if(a+b<c+d)
        cout<<"Right"<<endl;
    else
        cout<<"Balanced"<<endl;

return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
    int i;
    scanf("%d", &i);
    if (i >= 195)
        printf("5\n");
    else if (i >= 189)
        printf("4\n");
    else if (i >= 165)
        printf("3\n");
    else if (i >= 135)
        printf("2\n");
    else if (i >= 105)
        printf("1\n");
    else 
        printf("0\n");

    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define LOOP(i,o) for(i=0;i<o;i++)
int main() {
  int n,k;
  cin>>n>>k;
  int y=n-2*k;
  if(y<=0){
    y=0;
  }
  cout<<y<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(void){
    
    //*
    int a, b, c;
    cin >> a >> b >> c ;
    //*/
    
    /*
    vector<int> vec(4);
    cin >> vec.at(0) >> vec.at(1) >> vec.at(2) ;
    
    sort(vec.begin(), vec.end());
    */
    
    ///*
    if(a + b >= c){
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    //*/
    
    //cout << a.at(0) << b.at(1) << c.at(2) << endl;

    return 0; 
}


Measured memory_bytes: 3648
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int main()
{
	int n,k;
	cin>>n>>k;
	int dp[n+1];
	int h[n+1];
	for(int i=1;i<=n;i++)
	cin>>h[i];
	dp[0]=0;
	dp[1]=0;
	dp[2]=abs(h[2]-h[1]);
	int mn;
	for(int i=3;i<=n;i++)
	{
		mn=INT_MAX;
		for(int l=1;l<=k&&i-l>=1;l++)
		{
			if(mn>dp[i-l]+abs(h[i]-h[i-l]))
			mn=dp[i-l]+abs(h[i]-h[i-l]);
		}
		dp[i]=mn;
	}
	cout<<dp[n];
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
using ll         = long long;
constexpr ll MOD = 1000000007;
#define REP(i, n) for (ll i = 0; i < (n); i++)
#define REP2(i, x, n) for (ll i = x; i < (n); i++)
const long long INF = numeric_limits<long long>::max();
template <class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
int main() {
    ll N, C, K;
    cin >> N >> C >> K;
    vector<ll> passengersTime(N);
    for (ll i = 0; i < N; ++i) {
        cin >> passengersTime[i];
    }

    sort(passengersTime.begin(), passengersTime.end());

    ll busNum         = 1;
    ll passengerIndex = 0;
    for (ll i = 1; i < N; i++) {
        bool tooCrowded = (i - passengerIndex) >= C;
        bool isTimeOver = passengersTime[i] > (passengersTime[passengerIndex] + K);

        if (tooCrowded || isTimeOver) {
            busNum++;
            passengerIndex = i;
            // cout << endl << "NextBus:" << passengersTime[passengerIndex] << "+" << K << endl;
        }
        // cout << passengersTime[i] << " ";
    }

    cout << busNum << endl;

    return 0;
}

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

#define ipr pair<int, int>
#define pb push_back
#define ff first
#define ss second
#define fr(i, j, k) for (int i = j; i < k; i++)
#define rf(i, j, k) for (int i = j; i >= k; i--)
#define ll unsigned long long
#define int long long
#define ld long double
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define mp make_pair
#define cnt_ones(x) __builtin_popcountll(x)

#define IOS                           \
    std::ios::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);

const int Maxn = (int)1e6;
const ld pi = acos(-1);
const int mod = (int)1e9 + 7;
const int inf = (int)1e18;

template <class T>
ostream &operator<<(ostream &out, vector<T> &A) {
    fr(i, 0, (int)A.size()) out << A[i] << " ";
    return out;
}

//}

int arr[(int)1e6+1];

int32_t main() {
    IOS int n;  cin>>n;
    int ans = n + n*n + n*n*n;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3604
N= int(input())
X1 = N / 1.08
X = int(X1)
N_calc = int(X*1.08)
N_calc2 = int((X+1)*1.08)
if N_calc == N :
    print(X)
elif N_calc2==N:
    print(X+1)
else :
    print(":(")

Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define fi first
#define se second
#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define rrep(i, n) for (int (i) = 1; (i) <= (n); (i++))
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define pb push_back
#define eb emplace_back
#define yn {puts("Yes");}else {puts("No");}
#define printd(x) printf("%.12f\n", ans);
template<class T> bool chmin(T& a, const T& b) {if (a > b) {a = b; return 1;} return 0;}
template<class T> bool chmax(T& a, const T& b) {if (a < b) {a = b; return 1;} return 0;}
using namespace std;
using ll = long long;
using P = pair<int, int>;

vector<vector<int>> g(105);
vector<bool> visited(105);
vector<int> d(105, -1);
vector<int> f(105);

int nowTime = 0;

int dfs(int s) {
	visited[s] = true;
	nowTime++;
	if (d[s] == -1) d[s] = nowTime;

	for(auto v: g[s]) {
		if (visited[v]) continue;
		dfs(v);
	}
	
	bool ok = true;
	for (auto v: g[s]) {
		if (visited[v]) continue;
		ok = false;
	}
	if (ok) f[s] = nowTime + 1;
	return nowTime++;
}


int main(void) {
	int n;
	cin >> n;
	rep (i, n) {
		int u, k;
		cin >> u >> k;
		u--;
		rep (j, k) {
			int v;
			cin >> v;
			v--;
			g[u].pb(v);
		}
	}

	rep (i, n) if (!visited[i]) dfs(i);

	rep (i, n) cout << i + 1 << " " << d[i] << " " << f[i] << endl;
	return 0;
}


Measured memory_bytes: 3156
void main() {
    int n = readln.chomp.to!int;
    int a = readln.chomp.to!int;
    writeln(n % 500 <= a ? "Yes" : "No");
}

import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.numeric;
import std.container;
import std.typecons;
import std.ascii;
import std.uni;

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#define max(a, b)	(((a) > (b)) ? (a) : (b))		/* ２個の値の最大値 */
#define min(a, b)	(((a) < (b)) ? (a) : (b))		/* ２個の値の最小値 */
#define ENTER		printf("\n")					/* 改行プリント */
int DBG = 1;										/* デバッグプリント 提出時は0 */
/* main *************************************************************/
int main()
{
	int		a,b,c,i,j,k,n,m,x,y,ans = 0;
	float	f;
	
	scanf("%d", &n);
	
	a = (int)( (float)n / 1.08);
	
	if ((int)((float)a * 1.08) == n ) {
		printf("%d\n",a);
	} else if ( (int)((float)(a+1) * 1.08) == n ) {
		printf("%d\n",a+1);
	} else if ( (int)((float)(a-1) * 1.08) == n ) {
		printf("%d\n",a-1);
	} else {
		printf(":(\n");
	}


	return 0;
}


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

const int S = 22;
int dp[S][S][S][S];
char m[S][S];

bool used[S*S];
int mex(const vector<int> &vec)
{
    for(auto x: vec)
        used[x] = true;
    int ans;
    for(int i = 0; ; i++)
        if(!used[i])
        {
            ans = i;
            break;
        }
    for(auto x: vec)
        used[x] = false;
    return ans;
}

int main()
{
    int h, w;
    scanf("%d %d", &h, &w);
    for(int i = 1; i <= h; i++)
        scanf("%s", m[i] + 1);
    for(int i = 0; i < h; i++)
        for(int j = 0; j < w; j++)
            for(int x0 = 1; x0 + i <= h; x0++)
                for(int y0 = 1; y0 + j <= w; y0++)
                {
                    int x1 = x0 + i, y1 = y0 + j;
                    vector<int> vec;
                    for(int x = x0; x <= x1; x++)
                        for(int y = y0; y <= y1; y++)
                            if(m[x][y] == '.')
                                vec.push_back(dp[x0][x-1][y0][y-1]
                                            ^ dp[x+1][x1][y0][y-1]
                                            ^ dp[x0][x-1][y+1][y1]
                                            ^ dp[x+1][x1][y+1][y1]);
                    dp[x0][x1][y0][y1] = mex(vec);
                }
    puts(dp[1][h][1][w] ? "First" : "Second");
}

Measured memory_bytes: 3692
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define PI 3.14159265358979323846
#define int long long
constexpr long long INF = numeric_limits<long long>::max() / 2;
constexpr int MOD = 1000000007;
using Graph = vector<vector<int>>;

int max=100000;

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

    int H,W,K;
    cin>>H>>W>>K;
    string S[H];

    rep(i,H){
        cin>>S[i];
    }
    int sum=0;
    int ans=INF;

    for(int bit=0;bit<(1<<H-1);bit++){
        vector<int> m{};
        m.push_back(0);
        int b=1;
        for(int i=0;i<H-1;i++){
            if(bit&(1<<i)) {
                m.push_back(i+1);
                b++;
            }
        }
        m.push_back(H);
        int n=m.size()-1;
        int c[n][W]{};
        bool z=false;
        rep(i,n){
            for(int k=0;k<W;k++){
                for(int j=m[i];j<m[i+1];j++){
                    if(S[j][k]=='1')c[i][k]++;
                    if(c[i][k]>K)z=true;
                }
            }            
        }
        if(z)continue;
        int p=1;
        int r[n]{};
        for(int i=0;i<W;i++){
            bool ng=false;
            rep(j,n){
                r[j]+=c[j][i];
                if(r[j]>K)ng=true;
            }
            if(ng){
                p++;
                rep(j,n){
                    r[j]=c[j][i];
                }
            }
        }
        ans=min(ans,p+b-2);

    }
    cout << ans << endl;





    



}


Measured memory_bytes: 384
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <functional>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <cassert>
#include <exception>
#include <numeric>
using namespace std;
typedef long long ll;
typedef string str;
typedef pair<ll, ll> P;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<char> vc;
typedef vector<str> vs;
typedef vector<P> vp;
typedef vector<bool> vb;
#define rep(i, a, n) for (ll i = (a); i < (n); ++i)
#define rrep(i, a, n) for (ll i = (a); i > (n); --i)
#define erep(i, a, n) for (ll i = (a); i <= (n); ++i)
#define rerep(i, a, n) for (ll i = (a); i >= (n); --i)
#define all(c) (c).begin(), (c).end()
#define pb push_back
#define mp make_pair
#define sz(x) ((int)x.size())
#define print(X) cout << (X) << "\n"
#define _ << " " <<
static const int INF = 1e+9+7;

int main(){
  int a,b,c;
  cin >> a >> b >> c;
  if(a<b and b<c) print("Yes");
  else print("No");

  return 0;
}





Measured memory_bytes: 3108
// A - T or T

#include <iostream>
#include <vector>
#include <cmath>

int main()
{
    int N, D;
    std::vector<std::vector<int> > v;

    std::cin >> N >> D;
    for (int i = 0; i < N; i++)
    {
        std::vector<int> p;
        for (int j = 0; j < D; j++)
        {
            int val;
            std::cin >> val;
            p.push_back(val);
        }
        v.push_back(p);
    }

    int answer = 0;
    for (int i = 0; i < N - 1; i++)
    {
        for(int j = i + 1; j < N; j++)
        {
            int sum = 0;
            for (int d = 0; d < D; d++)
            {
                int s = (v[i][d] - v[j][d]);
                sum += (s * s);
            }
            int distance = (int)(std::sqrt(sum) + 0.9);
            if ((distance * distance) == sum)
            {
                answer ++;
            }
        }
    }

    std::cout << answer << std::endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int gcd(int a, int b){
    if (b > a){
        int c = a;
        a = b;
        b = c;
    }
    
    while (a % b != 0){
        int c = a % b;
        a = b;
        b = c;
    }
    
    return b;
}

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

    bool flag = true;
    
    if (C % gcd(A, B) != 0){
        flag = false;
    }
    
    if (flag == true){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }
    
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
 
using namespace std;
 
int main(int argc, char const *argv[]) {
    string s;
    int i;
 
    cin >> s;
 
    if (s.substr(0, 1) != "A") {
        cout << "WA";
        return 0;
    }
    
    string subs = s.substr(2, s.size()-3);
    if (subs.find("C") == std::string::npos ||
        subs.find("C") != subs.rfind("C")) {
        cout << "WA";
        return 0;
    }
 
    string lowers = s.erase(s.find("C"), 1).erase(0, 1);
    string copy = lowers.substr(0, lowers.size());
    transform(lowers.begin(), lowers.end(), lowers.begin(), ::tolower);
    if (lowers != copy) {
        cout << "WA";
        return 0;
    }
 
    cout << "AC";
    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#define mod 1000000007
#define inv2 500000004
using namespace std;
int add(int a,int b){a+=b; return a>=mod?a-mod:a;}
int sub(int a,int b){a-=b; return a<0?a+mod:a;}
int mul(int a,int b){return 1ll*a*b%mod;}
int ksm(int a,int b)
{
    int s=1;
    for(;b;b>>=1,a=mul(a,a))
        if(b&1) s=mul(s,a);
    return s;
}
int f[3005][3005][2];
int A[3005],tx[3005],ty[3005],t1[3000][2],t2[3000][2];
int n,m;
int main()
{
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;i++) scanf("%d",&A[i]);
    for(int i=1;i<=m;i++) scanf("%d %d",&tx[i],&ty[i]);
    for(int i=1;i<=n;i++)
        for(int j=i+1;j<=n;j++)
            if(A[i]>A[j]) f[i][j][0]=1;
            else if(A[i]==A[j]) f[i][j][1]=1;
    for(int i=1;i<=m;i++)
    {
        if(tx[i]>ty[i]) swap(tx[i],ty[i]);
        for(int j=1;j<=tx[i];j++) t1[j][0]=f[j][tx[i]][0],t1[j][1]=f[j][tx[i]][1];
        for(int j=tx[i]+1;j<=n;j++) t1[j][0]=f[tx[i]][j][0],t1[j][1]=f[tx[i]][j][1];
        for(int j=1;j<=ty[i];j++) t2[j][0]=f[j][ty[i]][0],t2[j][1]=f[j][ty[i]][1];
        for(int j=ty[i]+1;j<=n;j++) t2[j][0]=f[ty[i]][j][0],t2[j][1]=f[ty[i]][j][1];

        for(int j=1;j<tx[i];j++)
        {
            f[j][tx[i]][0]=mul(inv2,add(f[j][tx[i]][0],t2[j][0]));
            f[j][tx[i]][1]=mul(inv2,add(f[j][tx[i]][1],t2[j][1]));
        }
        for(int j=tx[i]+1;j<ty[i];j++)
        {
            f[tx[i]][j][0]=mul(inv2,add(f[tx[i]][j][0],sub(1,add(t2[j][0],t2[j][1]))));
            f[tx[i]][j][1]=mul(inv2,add(f[tx[i]][j][1],t2[j][1]));
        }
        for(int j=ty[i]+1;j<=n;j++)
        {
            f[tx[i]][j][0]=mul(inv2,add(f[tx[i]][j][0],t2[j][0]));
            f[tx[i]][j][1]=mul(inv2,add(f[tx[i]][j][1],t2[j][1]));
        }

        for(int j=1;j<tx[i];j++)
        {
            f[j][ty[i]][0]=mul(inv2,add(f[j][ty[i]][0],t1[j][0]));
            f[j][ty[i]][1]=mul(inv2,add(f[j][ty[i]][1],t1[j][1]));
        }
        for(int j=tx[i]+1;j<ty[i];j++)
        {
            f[j][ty[i]][0]=mul(inv2,add(f[j][ty[i]][0],sub(1,add(t1[j][0],t1[j][1]))));
            f[j][ty[i]][1]=mul(inv2,add(f[j][ty[i]][1],t1[j][1]));
        }
        for(int j=ty[i]+1;j<=n;j++)
        {
            f[ty[i]][j][0]=mul(inv2,add(f[ty[i]][j][0],t1[j][0]));
            f[ty[i]][j][1]=mul(inv2,add(f[ty[i]][j][1],t1[j][1]));
        }
        f[tx[i]][ty[i]][0]=mul(inv2,add(f[tx[i]][ty[i]][0],sub(1,add(f[tx[i]][ty[i]][0],f[tx[i]][ty[i]][1]))));
    }
    int ans=0;
    for(int i=1;i<=n;i++)
        for(int j=i+1;j<=n;j++)
            ans=add(ans,mul(ksm(2,m),f[i][j][0]));
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 69888
while True:
    n,w,h = map(int,input().split())
    if w == 0:
        break
    ls = [[w,h]]
    for i in range(n):
        p,s = map(int,input().split())
        p -= 1
        pw,ph = ls[p]
        if s%(pw+ph) < pw:
            s %= pw+ph
            ls.extend([[min(s,pw-s),ph],[max(s,pw-s),ph]])
        else:
            s = (s-pw)%(ph+pw)
            ls.extend([[pw,min(s,ph-s)],[pw,max(s,ph-s)]])
        ls.pop(p)
    ans = [hi*wi for wi,hi in ls]
    ans.sort()
    print(' '.join(map(str,ans)))



Measured memory_bytes: 5620
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define ll long long int
#define ld long double
#define ordered_set tree < ll ,  null_type ,  less<ll> ,  rb_tree_tag ,  tree_order_statistics_node_update >
//added two more functions to set
//(1)*(set.find_by_order(k))[kth element in the sorted set] 
//(2)set.order_of_key(k)[count of elements strictly less than k]

typedef vector< int > vi;
typedef vector<long long> lvi;
typedef vector< vector<int> > vvi;
typedef vector< vector<long long> > lvvi;
typedef pair< int,int > ii;
typedef pair< long long,long long > lii;
typedef vector<pair<int,int>> vii;
typedef vector<pair<long long,long long>> lvii;
typedef vector<vector<pair<int,int>>> vvii;
typedef vector<vector<pair<long long,long long>>> lvvii;

#define pb push_back
#define all(c) (c).begin(),(c).end()
#define tr(c,i) for(auto i = (c).begin(); i != (c).end(); i++)//remember i is an iterator
#define tc(t) int (t); cin>>(t);while((t)--)
#define ff first
#define ss second
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " is " << a << endl;
	err(++it, args...);
}

//-----------------------------------------------------------------------------------------------------------------------------------------------------------------
#define mod 1000000007
//-----------------------------------------------------------------------------------------------------------------------------------------------------------------

long long mod_sum() { return 0LL; }
template<typename T, typename... Args>
T mod_sum(T a, Args... args) { return ((a + mod_sum(args...))%mod + mod)%mod; }

long long mod_product() { return 1LL; }
template<typename T, typename... Args>
T mod_product(T a, Args... args) { return (a*mod_product(args...))%mod; }
//-----------------------------------------------------------------------------------------------------------------------------------------------------------------


signed main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);	
	int n;
	cin>>n;
	map<string,int> mp;
	for (int i = 0; i < n; ++i)
	{
		string s;
		cin>>s;
		mp[s]++;
	}
	cout<<"AC x "<<mp["AC"]<<endl;
	cout<<"WA x "<<mp["WA"]<<endl;
	cout<<"TLE x "<<mp["TLE"]<<endl;
	cout<<"RE x "<<mp["RE"]<<endl;
	return 0;
}	

Measured memory_bytes: 3652
//#define __USE_MINGW_ANSI_STDIO 0
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
// #define int ll
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef pair<int, int> PII;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define IN(a, b, x) (a<=x&&x<b)
#define MP make_pair
#define PB push_back
#ifdef int
const int INF = (1LL<<30);
#else
const ll INF = (1LL<<60);
#endif
const double PI = 3.14159265359;
const double EPS = 1e-12;
const int MOD = 1000000007;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }

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

int bit[100010], nn = 100010;

//0からi-1番目までの和
int sum(int i) {
  i++;
  int s = 0;
  while(i > 0) {
    s += bit[i];
    i -= i&-i;
  }
  return s;
}

//i番目(0-index)にxを加える
void add(int i, int x) {
  i++;
  while(i <= nn) {
    bit[i] += x;
    i += i&-i;
  }
}

VVI v;
int ans[100010];
signed main(void)
{
  int n, m;
  cin >> n >> m;
  REP(i, n) {
    int l, r;
    cin >> l >> r;
    ++r;
    v.PB({r-l, l, r});
  }
  sort(ALL(v));

  int idx = 0;
  FOR(i, 1, m+1) {
    int ans = n-idx;
    for(int j=0; j<=m; j+=i) ans += sum(j);
    cout << ans << endl;
    while(idx<n && v[idx][0] <= i) {
      add(v[idx][1], 1);
      add(v[idx][2], -1);
      ++idx;
    }
    // cout << "idx:" << idx << endl;
    // REP(j, m+1) cout << sum(j+1) << " "; cout << endl;
  }

  return 0;
}


Measured memory_bytes: 22700
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <stack>
#include <istream>
#include <map>
#include <set>
#include <queue>
#define rep0(i,n) for (int i = 0; i < (n); ++i)  //0スタート
#define rep1(i,n) for (int i = 1; i < (n); ++i)  //1スタート
#define REP(i,a,b) for (int i = a; i < (b); ++i)  //aからbまで
#define print(x) cout<<x<<endl  //xを改行付きで出力
#define INF 1000000007  //最大値兼MOD
typedef long long ll;
using namespace std;
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() {
cin.tie(0);
ios::sync_with_stdio(false);
/*
./a.exe
*/
int a,b,c;
cin>>a>>b>>c;
print(c / a * b);
return 0;
}


Measured memory_bytes: 256
n, m = map(int, input().split())

a = []
b = []

for i in range(0, n):
    a.append(list(map(int, input().split()))) 

for j in range(0, m):
    b.append(int(input()))

c = []

for i in range(0, n):
    c.append(0)
    
    for j in range(0, m):
        c[i] += a[i][j] * b[j]
    
    print(c[i])

Measured memory_bytes: 7916
// #pragma GCC target ("avx2")
// #pragma GCC optimization ("O3")
// #pragma GCC optimization ("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define mod 998244353
#define int long long
#define inf 2e15
const int minnodes=1005;
#define ll long long

#define EPS 0.000000001
#define N 2000000 

int ndigits(int n)
{
    int ans = 0;
    while(n)
    {
        n /= 10;
        ans++;
    }
    return (ans & 1);
}
 
int32_t main()
{
    IOS;

    int n;
    cin >> n;
    int ans = 0;
    for(int i = 1; i <= n;i++)
        ans += ndigits(i);
    cout << ans;


}
 

Measured memory_bytes: 256
#include <iostream>
#include <string.h>

using namespace std;

int main(void)
{
    int N, M;
    int K, A;
    int *c;
    
    cin >> N >> M;

    c = new int[M+1];

    for (int i = 0; i <= M; i++) {
        c[i] = 0;
    }


    for (int i = 1; i <= N; i++) {
        cin >> K;
        for (int j = 1; j <= K; j++) {
            cin >> A;
            c[A]++;
        }
    }

    int result = 0;
    for (int i = 1; i <= M; i++) {
        if (c[i] == N) {
            result++;
        }
    }

    cout << result << endl;

    return 0;
}

Measured memory_bytes: 256
n=int(input())
s=str(input())
s=list(s)
import collections
c=collections.Counter(s)
values, counts = zip(*c.most_common())
temp=list(counts)
l=len(temp)
ans=1
for i in range(l):
  ans=ans*(temp[i]+1)
print((ans-1)%(10**9+7))

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

int main(){
  int n; 
  cin >> n;
  int max=0;
  int r=0;
  for (int i=0;i<n;i++){
    int h;
    cin >>h;
    if (max<=h){
      max=h;
      r++; 
    }
  }
  cout <<r;
}

Measured memory_bytes: 256
a = [list(map(int, input().split())), list(map(int, input().split())), list(map(int, input().split()))]

def main():
    for i in range(1,3):
        x = a[0][0] - a[0][i] == a[1][0] - a[1][i]== a[2][0] -a[2][i]
        y = a[0][0] - a[i][0] == a[0][1] - a[i][1]== a[0][2] -a[i][2]
        if x is False or y is False:
            return "No"
    return "Yes"

if __name__ == "__main__":
    print(main())

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

using namespace std;
#define rep(x, n)          for (int x = 0; x < n; x++)
#define REP(x, a, b)       for (int x = a; x <= b; x++)
#define all(container)     (container).begin(), container.end()
#define rall(container)    (container).rbegin(), container.rend()
#define sz(container)      (int) (container).size()
#define pb                 push_back
#define eb                 emplace_back

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

#ifdef LOCAL_DEFINE
    #include "DEBUG.hpp"
#else
    #define dmp(...) 0
#endif
template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }
vector<vector<int>> g;
vector<int> ans;
vector<bool> visited;

void bfs() {
    queue<int> Q;
    Q.push(0);
    visited[0]=true;
    while(!Q.empty()) {
        int curr=Q.front();
        Q.pop();
        for(auto&v:g[curr]) {
            if(visited[v]) continue;
            visited[v]=true;
            ans[v]=curr;
            Q.push(v);
        }
    }
}

int main(void) {
    int n,m;
    scanf("%d%d",&n,&m);
    g.resize(n);
    visited.resize(n,false);
    ans.resize(n,-1);
    rep(i,m) {
        int from,to;
        scanf("%d%d",&from,&to);
        --from,--to;
        g[from].pb(to);
        g[to].pb(from);
    }
    bfs();
    bool ok=true;
    REP(i,1,n-1) if(!visited[i]) ok=false;
    if(!ok) puts("No");
    else {
        puts("Yes");
        REP(i,1,n-1) printf("%d\n",ans[i]+1); 
    }
    return 0;
}

Measured memory_bytes: 10108
#include <stdio.h>
 
int main(void)
{
 
  int a, b, r, tmp;
  scanf("%d %d", &a,&b);
  if(a<b){
    tmp = a;
    a = b;
    b = tmp;
  }
  r = a % b;
  while(r!=0){
    a = b;
    b = r;
    r = a % b;
  }
  printf("%d\n", b);
 
  return 0;
}


Measured memory_bytes: 2088
#include <inttypes.h>
#include <math.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(void)
{
    intmax_t N, M, s[5];
    char c[5];
    char ans[4] = {};

    scanf("%jd%jd", &N, &M);
    for (size_t i = 0; i < M; i++) {
        scanf("%jd %c", &s[i], &c[i]);
    }

    for (size_t i = 0; i < M; i++) {
        if (ans[s[i] - 1] == 0) {
            ans[s[i] - 1] = c[i];
        } else {
            if (ans[s[i] - 1] != c[i]) {
                puts("-1");
                return 0;
            }
        }
    }

    if (ans[0] == 0) {
        if (N == 1) {
            ans[0] = '0';
        } else {
            ans[0] = '1';
        }
    }

    if (ans[1] == 0)
        ans[1] = '0';
    if (ans[2] == 0)
        ans[2] = '0';
    ans[N] = '\0';

    if ((N > 1) && (ans[0] == '0')) {
        puts("-1");
        return 0;
    }

    puts(ans);

    return 0;
}


Measured memory_bytes: 128
import sys,itertools,collections,bisect
from collections import deque,Counter,defaultdict
from heapq import heappush,heappop,heapify
read=sys.stdin.readline
sys.setrecursionlimit(10**6)

MOD=10**9+7
N=int(input())
A=list(map(int,input().split()))
cum=[0]*(N+1)
for i in range(N):
    cum[i+1]=(cum[i]+A[i])%MOD

ans=0
for i in range(N):
    res=(cum[N]-cum[i+1]+MOD)%MOD*A[i]%MOD
    ans=(ans+res)%MOD
print(ans)


Measured memory_bytes: 98248
#include<bits/stdc++.h>
#define ll long long 
#define endl "\n"
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
using namespace std;
unordered_map<ll,ll> m;
void primefactors(ll n)
{
    for(ll i=2;i<=sqrt(n);i++)
    {
        if(n%i==0)
        {
            ll c=0;
            while(n%i==0)
            {
                n/=i;
                c++;
            }
            m[i]=c;
        }
    }
    if(n>1)
    {
        m[n]=1;
    }
}
ll check(ll n)
{
    ll c=1,ans=0;
    while(1)
    {
        if(c>n)
        {
            break;
        }
        ans++;
        n-=c;
        c++;
    }
    return ans;
}
int main()
{
    fastio;
    ll n;
    cin>>n;
    ll ans=0;
    primefactors(n);
    for(auto it:m)
    {
        ans+=check(it.second);
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3676
#include <iostream>
using namespace std;
int main(void){
    bool same = true;
    while(same){
        int x,y;
        cin >> x;
        cin >> y;
        if(x == 0 && y == 0){
            same = false;
        }else{
            if(x > y){
                cout<<y<<" "<<x<<endl;
            }else{
                cout<<x<<" "<<y<<endl;
            }
        }
    }
}



Measured memory_bytes: 2976
#include<bits/stdc++.h>
using namespace std;
int main()
{
	long long int n,i,j,ans=10000000000001;
	cin>>n;
	for(i=1;i*i<=n;i++)
	{
		if(n%i==0)
		{
			ans=min(ans,i+n/i);
		}
	}
	cout<<ans-2<<endl;
	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String args[]) {
		Scanner scr = new Scanner(System.in);
		int dotcount =Integer.parseInt(scr.nextLine());
		dots = new int[dotcount][];
		for(int i=0; i<dotcount; i++){
			String[] str = scr.nextLine().split(" ", 0);
			dots[i] = new int[Integer.parseInt(str[1])];
			for(int j=2; j<str.length; j++){
				dots[i][j-2] = Integer.parseInt(str[j])-1;
			}
		}
		step=1;
		//index=0;
		start = new int[dotcount];
		finish = new int[dotcount];
		visited = new boolean[dotcount];
		for(int i=0; i<dotcount; i++){
			visited[i] = false;
		}
		for(int i=0; i<dotcount; i++){
			Visit(i);
		}
		//Visit(0);
		for(int i=0; i<dotcount; i++){
			System.out.println(String.valueOf(i+1) +" "+ start[i] +" "+ finish[i]);
		}
		scr.close();
	}
	static int[][] dots;
	static int step;
	//static int index;
	static boolean[] visited;
	static int[] start;
	static int[] finish;
	static void Visit(int i){
		if(visited[i]) return;
		visited[i] = true;
		start[i] = step;
		step++;
		//System.out.println(step);
		for(int j=0; j < dots[i].length; j++){
			//if(!visited[dots[i][j]])
				Visit(dots[i][j]);
		}
		finish[i] = step;
		step++;
	}
}

Measured memory_bytes: 26820
#include<bits/stdc++.h>
#include<algorithm>
#include<cmath>
#include<climits>
using namespace std;
typedef long long int lli;
typedef vector<int> vi;
typedef vector<long long int> vlli;
typedef pair<int,int> pii;
typedef pair<long long int,long long int> plli;
typedef vector< vi > vvi ;
typedef vector< vlli > vvlli  ;
#define fi(i,a,b) for(int i=a;i<=b;i++)
#define flli(i,a,b) for(long long int i=a;i<=b;i++)
#define bi(i,a,b) for(int i=a;i>=b;i--)
#define blli(i,a,b) for(long long int i=a;i>=b;i--)
#define fast ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define all(x) x.begin(),x.end()
#define sz(x) x.size()
#define pi 2*acos(0.0)
#define pb push_back
#define tr(v,it) for(decltype(v.begin()) it=v.begin();it!=v.end();it++)
#define present(v,num) (v.find(num)!=v.end())
#define cpresent(v,num) (find(v.begin(),v.end(),num)!=v.end())
#define pq priority_queue
#define mp make_pair
const int inf=INT_MAX;
const lli INF =LLONG_MAX;
const lli mod = 998244353;
int main() {
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    fast;
    lli n,k;cin>>n>>k;
    vector<plli> var(k);
    flli(i,0,k-1)
    {
    	lli l,r;cin>>l>>r;
    	var[i].first=l;
    	var[i].second=r;
    }
    sort(all(var));
    vlli ans(n,0);
    vlli presum(n,0);
    ans[0]=1;
    flli(i,0,n-1)
    {
    	if(i!=0)
    		presum[i]=(presum[i]+presum[i-1])%mod;
    	if(i!=0)
    		ans[i]=presum[i];
    	lli lasti=-1;
    	flli(j,0,k-1)
    	{
    		lli curr=i+var[j].first;
    		lli next=i+var[j].second;
    		if(next<=lasti)continue;
    		else curr=max(curr,lasti);
    		if(curr<n)
    			presum[curr]=(presum[curr]+ans[i])%mod;
    		if(next+1<n)
    			presum[next+1]=(presum[next+1]-ans[i]+mod)%mod;
    		lasti=max(lasti,next);
    	}
    }
    cout<<ans[n-1];
    cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
    return 0;
}

Measured memory_bytes: 6360
fun main(args: Array<String>) {
    val s = readLine()!!
    println(when (s) {
        "SUN" -> 7
        "MON" -> 6
        "TUE" -> 5
        "WED" -> 4
        "THU" -> 3
        "FRI" -> 2
        "SAT" -> 1
        else -> throw IllegalStateException()
    })
}

Measured memory_bytes: 29856
#include<cstdio>
#include<algorithm>
using namespace std;
int Q;
long long Pow(long long a, long long b, long long Mod){
    long long r = 1;
    while(b){
        if(b&1)r=r*a%Mod;
        a=a*a%Mod;b>>=1;
    }
    return r;
}
int Phi(int a){
    int i, r = a;
    for(i=2;i*i<=a;i++){
        if(a%i==0){
            r = r/i*(i-1);
            while(a%i==0)a/=i;
        }
    }
    if(a!=1){
        r=r/a*(a-1);
    }
    return r;
}
int gcd(int a, int b){
    return b?gcd(b,a%b):a;
}
long long Calc(int a, int m){
    int i;
  //  printf("%d %d\n",a,m);
    if(m <= 500){
        int s = 1;
        for(i=1;;i++){
            s = 1ll*s*a%m;
            if(s==i%m)return i;
        }
        return -1;
    }
    int p = Phi(m);
    int G = gcd(m,p);
    long long r = Calc(a, G);
    if(r == -1)return -1;
//    printf("%lld %lld\n",r%G, Pow(a,r,G));
//    printf("%lld\n",r);
    long long t = (Pow(a, r, m) + m - r)%m;
//    printf("%lld\n",Pow(a,r,m));
//    printf("%d %lld\n",G,t);
    int p2 = p/G, m2 = m/G;
    long long t2 = t/G;
    int pm = Phi(m2);
    long long ttt = 1ll * Pow(p2, pm - 1, m2) * t2 % m2;
    long long res = ttt * p + r;
    //printf("%lld %lld\n",Pow(a,res,m), res%m);
    return res;
}
int main(){
    int i;
    int a, m;
    scanf("%d",&Q);
    while(Q--){
        scanf("%d%d",&a,&m);
        printf("%lld\n",Calc(a,m));
    }
}

Measured memory_bytes: 128