akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MAXN=1e5+5;
const ll MOD=1e9+7;
const ll MOD1=13;
ll n,dp[MAXN][13];
char str[MAXN];
ll add1(ll x,ll y)
{
    x=(x*10)%MOD1;
    ll ret=x+y;
    if(ret>=MOD1)
    {
        return ret-MOD1;
    }
    return ret;
}
ll add(ll x,ll y)
{
    ll ret=x+y;
    if(ret>=MOD)
    {
        return ret-MOD;
    }
    return ret;
}
void solve()
{
    n=strlen(str+1);
    dp[0][0]=1;
    for(ll i=0;i<n;i++)
    {
        for(ll j=0;j<=12;j++)
        {
            if(str[i+1]=='?')
            {
                for(ll k=0;k<=9;k++)
                {
                    ll nex=add1(j,k);
                    dp[i+1][nex]=add(dp[i+1][nex],dp[i][j]);
                }
            }
            else
            {
                ll num=str[i+1]-'0';
                ll nex=add1(j,num);
                dp[i+1][nex]=add(dp[i+1][nex],dp[i][j]);
            }
        }
    }
    ll ans=0;
    ans=dp[n][5];

    printf("%lld\n",ans);
}
int main()
{
    scanf("%s",str+1);
    solve();
}


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

int main() {
  int n;
  cin >> n;
  vector<int> b(n-1);
  rep(i, n-1) cin >> b[i];
  vector<int> a(n);
  a[0] = b[0];
  rep(i, n-2) {
    a[i+1] = min(b[i+1], b[i]);
  }
  a[n-1] = b[n-2];
  int ans = 0;
  rep(i, n) ans += a[i];
  cout << ans << '\n';
  return 0;
}

Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std ;
using ll=long long ;
int main(){

ll a,b,cont=0 ;
cin >> a >>b ;
for(int i=0;i<a;i++)
{
    ll x , y ;
    cin >> x >> y ;
    if(sqrt(abs(x)*abs(x) + abs(y)*abs(y)) <= b) cont++ ;

}
cout << cont ;

 return 0 ;
}


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

typedef long long ll;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define each(itr,c) for(__typeof(c.begin()) itr=c.begin(); itr!=c.end(); ++itr)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second

int M,W;
int bm[12],bw[12];

inline int calc(int m, int w)
{
    int d=abs(bm[m]-bw[w]);
    return d*(d-30)*(d-30);
}

int dp[13][4100];
int dfs(int x, int mask)
{
    if(dp[x][mask]>=0) return dp[x][mask];
    if(x==M || mask==(1<<W)-1) return 0;

    int ret=dfs(x+1,mask);
    rep(i,W)
    {
        if(mask>>i&1) continue;
        ret=max(ret,dfs(x+1,mask+(1<<i))+calc(x,i));
    }

    return dp[x][mask]=ret;
}

int main()
{
    while(scanf(" %d %d", &M, &W),M)
    {
        rep(i,M) scanf(" %d", &bm[i]);
        rep(i,W) scanf(" %d", &bw[i]);

        memset(dp,-1,sizeof(dp));
        printf("%d\n", dfs(0,0));
    }
    return 0;
}

Measured memory_bytes: 3444
#include<stdio.h>

int p(int a,int b){return a*a+b*b;}
int main()
{
	int W,H,i,j,rh,rw,x,y,z;
	for(;scanf("%d%d",&H,&W),H;)
	{
		rh=151;rw=151;
		for(i=1;i<151;i++)
			for(j=i+1;j<151;j++)
			{
				x=p(i,j);
				y=p(H,W);
				z=p(rh,rw);
				if((x>y||(x==y&&H<i))&&z>x)
				{
					rh=i;rw=j;
				}
			}
		printf("%d %d\n",rh,rw);
	}
	return 0;
}

Measured memory_bytes: 600
#include<bits/stdc++.h>
#define ll long long
#define endl '\n'
#define rep(i,l,r) for(int i=l;i<=r;i++)
#define per(i,r,l) for(int i=r;i>=l;i--)
const int MX=5e5+7;
const int mod=1e9+7;
const double pi=3.1415926535897932384;
double isp=1e-13;
using namespace std;
ll qpow(ll a,ll b,ll MOD=mod){for(ll ans=1;;a=a*a%MOD,b>>=1){if(b&1)ans=ans*a%MOD;if(!b)return ans;}}
ll inv(ll a,ll MOD=mod){return qpow(a,MOD-2,MOD);}
ll __gcm(ll a,ll b){return a*b/__gcd(a,b);}
ll gcd(ll a,ll b){return b==0?a:gcd(b,a%b);}
void add(ll &x,ll y){x=(x+y)%mod;}
ll p[MX];
ll C(ll n,ll m)
{
    return p[n]*inv(p[m]*p[n-m]%mod)%mod;
}
void solve()
{
    int n,m;
    cin>>n>>m;
    p[0]=1;
    for(int i=1;i<=max(n,m);i++)
    {
        p[i]=p[i-1]*i%mod;
    }
    //cout<<p[n]<<endl;
    ll ans=p[n]*C(m,n)%mod;
   // cout<<ans<<endl;
    int op=1;
    for(int i=1;i<=n;i++)
    {
        //cout<<i<<endl;
        op*=-1;
        (ans+=op*p[n-i]*C(m-i,n-i)%mod*C(n,i)%mod+mod)%=mod;
       // cout<<ans<<endl;
    }
  //  cout<<ans<<endl;
    cout<<p[n]*C(m,n)%mod*ans%mod<<endl;
}
int main()
{
  //ios::sync_with_stdio(0),cin.tie(0);
  int t;
 // cin>>t;
  t=1;
  while(t--){
  solve();

  }
}


Measured memory_bytes: 7456
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (long long  i=a;i<n;i++)
#define sz(A) (int)(A.size())
#define all(x) (x).begin(),(x).end()
#define get(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
typedef long long ll;
typedef pair<int, int> PII;
typedef vector<int> VI;

void solve() {
	ll n, x, t;
	cin >> n >> x >> t;
	cout << (n + x - 1) / x*t << endl;
}
int main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int T_ = 1;
	//cin >> T_;
	for (int i = 0; i < T_; i++)solve();
	return 0;
}



Measured memory_bytes: 3648
package main

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

func main(){
	stdin.Split(bufio.ScanWords)
	input1 := getStdin()
	input2 := getStd()

	if(input1%2 == 0){
		word := input2[:input1/2]
		if(input2 == (word+word)){
		fmt.Println("Yes")
		}else{
			fmt.Println("No")
		}
	} else{
		fmt.Println("No")
	}


}

var stdin = bufio.NewScanner(os.Stdin)

func getStdin() int{
	stdin.Scan()
		if err := stdin.Err(); err != nil{
			fmt.Fprintln(os.Stderr, err)
		}
		line, err := strconv.Atoi(stdin.Text())
		if err != nil{
			panic(err)
		}
	return line
}

func getStd() string{
	stdin.Scan()
		if err := stdin.Err(); err != nil{
			fmt.Fprintln(os.Stderr, err)
		}
		line := stdin.Text()
	return line
}

Measured memory_bytes: 640
#include <algorithm>
#include <functional>
#include <iostream>
#include <numeric>
#include <queue>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

using ll = long long;
using ull = unsigned long long;

using vll = vector<ll>;

void solve();

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

  solve();

  return 0;
}

#define ini(...)   \
  int __VA_ARGS__; \
  in(__VA_ARGS__)

#define inl(...)  \
  ll __VA_ARGS__; \
  in(__VA_ARGS__)

#define ins(...)      \
  string __VA_ARGS__; \
  in(__VA_ARGS__);

void in() {}
template <typename T, class... U>
void in(T& t, U&... u) {
  cin >> t;
  in(u...);
}

void out() {
  cout << endl;
}
template <typename T, class... U>
void out(const T& t, const U&... u) {
  cout << t;
  if (sizeof...(u))
    cout << " ";
  out(u...);
}

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

void solve();
#ifndef ONLINE_JUDGE
#include "./lib.hpp"
#endif

void solve() {
    inl(X);

    ll ret = 0;
    ll sum = 0;
    while (sum < X)
        sum += ++ret;
    out(ret);
}


Measured memory_bytes: 3628
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
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)
typedef long long ll;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1000003 ;

int main(){
  string s;
  cin >> s;
  ll ans=inf;
  for(char c='a';c<='z';c++){
    ll temp=-1;
    ll pos=0;
    rep(i,s.size()){
      pos++;
      if(s[i]==c){
        temp=max(temp,pos-1);
        pos=0;
      }
      if(i==s.size()-1)temp=max(temp,pos);
    }
    ans=min(ans,temp);
  }
  cout << ans << endl;
return 0;}

Measured memory_bytes: 256
/* ex 9_2
   cy_an  */

#include <stdio.h>
#include <stdlib.h>
//スタックに格納するデータの最大数
#define SIZE 100000

//スタックの定義
typedef struct stack{
    int size;
    int count;
    char data[SIZE];
    char *top;
} stack;

//スタックの初期化
void initialize_stack(stack *stk){
    stk->count = 0;
    stk->size = SIZE;
    stk->top = &(stk->data[SIZE]);
}

//データの追加
void push(stack *stk, int elem){
    if(stk->count >= stk->size){
        fprintf(stderr, "Error: stack overflow. (x=%c)\n", elem);
        exit(1);
    }
    else{
        stk->top--;
        *(stk->top) = elem;
        stk->count++;
    }
}

//データの取り出し
char pop(stack *stk){
    char latest;
    if(stk->count <= 0){
        fprintf(stdout, "Error: stack underflow.\n");
        exit(1);
    }
    else{
        latest = *(stk->top);
        stk->top++;
        stk->count--;
        return latest;
    }
}

int main(void){
    stack cube;
    char arr[SIZE];
    int i = 0, count = 0;
    
    //スタックを初期化
    initialize_stack(&cube);

    //スタックにデータを追加
    scanf("%s", arr);
    while(arr[i] != '\0'){
        if(arr[i] != *(cube.top) && cube.count > 0){ // 入力とtopが一致しないとき
            pop(&cube);            // topをpop
            count++;
        }else{
            push(&cube, arr[i]);
        }
        i++;
    }
    // 出力
    printf("%d", 2*count);
    return 0;
}

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

using namespace std;

int memo[45];

int fib(int n) {
	if (n <= 1)
		return 1;
	if (memo[n] != 0)
		return memo[n];
	return memo[n] = fib(n-1) + fib(n-2);
}

int fib1(int n) {
	return (int)(pow((1 + sqrt(5)) / 2, n) / sqrt(5) + 0.5);
}

int main() {
	int n;
	cin >> n;
	fill_n(memo, 45, 0);
	cout << fib(n) << endl;
	return 0;
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double db;
#define fi first
#define se second
#define pi pair<ll,ll>
#define pii pair<ll,pi>
#define pb push_back
#define mk make_pair
int main() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	clock_t begin = clock();
	int n, m;
	cin >> n >> m;
	priority_queue<ll>p;
	for (int i = 0; i < n; i++) {
		ll x;
		cin >> x;
		p.push(x);
	}
	for (int i = 0; i < m; i++) {
		ll have = p.top();
		p.pop();
		p.push(have / 2);
	}
	ll ans = 0;
	while (!p.empty()) {
		ans += p.top();
		p.pop();
	}
	cout << ans;
	clock_t end = clock();
	cerr << "Time run: " << (float)(end - begin) / CLOCKS_PER_SEC << " s" << endl;
}

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

#define ll long long 
#define pb push_back
#define mem0(a) memset(a,0,sizeof(a))
#define mem1(a) memset(a,-1,sizeof(a))
#define memf(a) memset(a,false,sizeof(a))
#define all(v) v.begin(),v.end()
#define sz(a) (ll)a.size()
#define F first
#define S second
#define INF 2000000000000000000
#define endl "\n"
#define _time_ 1.0 * clock() / CLOCKS_PER_SEC
#define popcount(x) __builtin_popcountll(x)
#define pll pair<ll,ll> 
#define ld long double

const int M=1000000007;
const int MM=998244353;
const long double PI = acos(-1);

ll power(ll b,ll e,ll m)
{
    if(e==0) return 1;
    if(e&1) return b*power(b*b%m,e/2,m)%m;
    return power(b*b%m,e/2,m);
}
ll power( ll b, ll e)
{
    if(e==0) return 1;
    if(e&1) return b*power(b*b,e/2);
    return power(b*b,e/2);
}
template<typename T, typename U> static inline void amin(T &x, U y){ if(y<x) x=y; }
template<typename T, typename U> static inline void amax(T &x, U y){ if(x<y) x=y; }
template<typename T, typename U> ostream& operator<<(ostream &os, const pair<T, U> &p)
{ 
    return os<<'('<<p.F<< ","<<p.S<<')'; 
}

int _runtimeTerror_()
{
    ll x,k,d;
    cin>>x>>k>>d;
    if(x==0)
    {
        cout<<(k%2?d:0);return 0;
    }
    ll ans=abs(x);
    ll y=abs(x);
    if(y/d>=k)
    {
        cout<<y-k*d<<"\n";return 0;
    }
    k-=y/d;
    y-=y/d*d;
    //cout<<k<<"\n";
    ans=y;
    if(k&1)
        ans=d-y;
    cout<<ans<<"\n";
    return 0;
}

int main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    #ifdef runSieve
        sieve();
    #endif
    #ifdef NCR
        initialize();
    #endif
    int TESTS=1;
    //cin>>TESTS;
    while(TESTS--)
        _runtimeTerror_();
    return 0;
}

Measured memory_bytes: 3644
import heapq

#dg = 10**7#ノード数より多く取る

n,m, S = map(int,input().split()) #n:頂点数　m:辺の数

edge = [[] for i in range(n)]
#edge[i] : iから出る道の[重み,行先]の配列


Cs=[]
Ds=[]
amax=0
for _ in range(m):
    u, v, a, b = map(int,input().split())
    edge[u-1].append([v-1,a,b])
    edge[v-1].append([u-1,a,b])#有向グラフの場合コメント
    amax=max(a,amax)

for _ in range(n):
    c, d = map(int,input().split())
    Cs.append(c)
    Ds.append(d)

dg=(n-1)*amax

def cut(S): 
    return min(S,dg)

S=cut(S)

def dijkstra(start):

    #dijkstra
    # d : minimum distance from s
    d = [[10**20]*(dg+1) for _ in range(n)]
    d[start][cut(S)] = 0
    edgelist = []

    heapq.heappush(edgelist,(Ds[0], 0, cut(S+Cs[0])))

    for e in edge[start]:
        if S-e[1]>=0:
            heapq.heappush(edgelist,(e[2],e[0],S-e[1]))

    while len(edgelist):
        minedge = heapq.heappop(edgelist)
        t,ce,cs = minedge[0],minedge[1],minedge[2]
        #print(t,ce,cs)
        if  d[ce][cs]== 10**20:
            d[ce][cs] = t
            ns=cut(cs+Cs[ce])
            #print(ce,ns)
            if d[ce][ns]==10**20:
                #d[ce][ns]=t+Ds[ce]
                heapq.heappush(edgelist, (t+Ds[ce],ce,ns))

            for e in edge[ce]:
                if cs>=e[1]:
                    #print(e)
                    ne=e[0]
                    ns=cs-e[1]
                    if d[ne][ns]==10**20:
                        #print(ne)
                        heapq.heappush(edgelist, (t+e[2],ne,ns))
    return d

d=dijkstra(start=0)
for x in d[1:]:
    print(min(x))
#print(d)


Measured memory_bytes: 114176
#17:43
n,m,q = map(int,input().split())
imos = [[0 for _ in range(n+1)] for _ in range(n+1)]
for _ in range(m):
  l,r = map(int,input().split())
  r -= 1
  imos[0][r] += 1
  imos[l][r] -= 1
#print(imos)
for i in range(n):
  for j in range(n):
    imos[i][j+1] += imos[i][j]
for j in range(n):
  for i in range(n):
    imos[i+1][j] += imos[i][j]
#print(imos)
for _ in range(q):
  x,y = map(int,input().split())
  x -= 1
  y -= 1
  print(imos[x][y])

Measured memory_bytes: 57816
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<(b);i++)
#define erep(i,a,b) for(int i=a;i<=(int)(b);i++)
#define per(i,a,b) for(int i=(b)-1;i>(a);i--)
#define eper(i,a,b) for(int i=((int)(a));i>=b;i--)
#define pb push_back
#define mp make_pair
#define INF (1<<30)-1
#define MOD 1000000007
using namespace std;
typedef long long ll;
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
int gcd(int a,int b){return b?gcd(b,a%b):a;}

int n, a[100005];
int main() {
 ios::sync_with_stdio ( false );
 cin.tie ( 0 );
    cin >> n;
    rep(i, 0, n) {
        int x; cin >> x;
        x++;
        a[x-1]++;
        a[x+2]--;
    }
    rep(i, 1, 100005) a[i] += a[i-1];
    int ans = 0;
    rep(i, 0, 100005) 
        ans = max(ans, a[i]);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 640
#include <stdio.h>

int main(void)
{
	int n, i, count = 0;	

	scanf("%d%*c", &n);

	for(i=0;i<n;i++) {
		int a, b;

		scanf("%d %d%*c", &a, &b);

		count += b - a + 1;
	}

	printf("%d\n", count);
	
	return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <string>
#define REP(i,k,n) for(int(i)=(k);(i)<(n);(i)++)
using namespace std;

const int MAX_N = 15;
int a[MAX_N];
long res = 0;
int N = 0;

void dfs(int i, long x, long sum)
{
  // グローバル res に加算
  if (i == N - 1) {
    res += a[i] + 10 * x + sum;
    return;
  }
  // i の後ろに + を挟むケース
  // x は加算され、リセット
  dfs(i + 1, 0, a[i] + 10 * x + sum);
  // + を挟まないケース
  dfs(i + 1, 10 * x + a[i], sum);

}

int main()
{
  string S;
  // int a[MAX_N];

  cin >> S;
  N = S.length();
  REP(i,0,N) {
    a[i] = S[i] - '0';
  }

  dfs(0,0,0);
  cout << res << endl;

  return 0;
}


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

constexpr char NL = '\n';
constexpr int MOD = 1e9 + 7;

struct safe_hash {
    static uint64_t splitmix64(uint64_t x) {
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

void solve()
{
    int n, m; cin >> n >> m;

    int sx, sy; cin >> sx >> sy;
    int dx, dy; cin >> dx >> dy;
    --sx; --sy; --dx; --dy;
    
    vector<vector<char>> v(n, vector<char>(m));
    vector<vector<bool>> visited(n, vector<bool>(m, false));
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < m; ++j) {
            cin >> v[i][j];
        }
    }

    deque<pair<pair<int, int>, int>> q;
    q.push_back({{sx, sy}, 0});

    vector<pair<int, int>> coords = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}};

    while (!q.empty()) {
        int cx = q.front().first.first, cy = q.front().first.second, cw = q.front().second;

        if (cx == dx && cy == dy) {
            cout << cw << NL;
            return;
        }

        q.pop_front();

        visited[cx][cy] = true;

        for (int i = 0; i < 4; ++i) {
            int nx = cx + coords[i].first;
            int ny = cy + coords[i].second;

            if (nx < 0 || ny < 0 || nx >= n || ny >= m || visited[nx][ny] || v[nx][ny] == '#') continue;

            q.push_front({{nx, ny}, cw});
        }

        for (int i = -2; i <= 2; ++i) {
            for (int j = -2; j <= 2; ++j) {
                int nx = cx + i;
                int ny = cy + j;

                if (nx < 0 || ny < 0 || nx >= n || ny >= m || visited[nx][ny] || v[nx][ny] == '#') continue;

                q.push_back({{nx, ny}, cw + 1});
            }
        }
    }

    cout << -1 << NL;
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    solve();
    return 0;
}

Measured memory_bytes: 12020
// Daniel Grzegorzewski
// while (clock()<=69*CLOCKS_PER_SEC)
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
// #pragma GCC target ("avx2")
// #pragma GCC optimization ("O3")
// #pragma GCC optimization ("unroll-loops")

#define MP make_pair
#define PB push_back
#define ST first
#define ND second
#define int long long

using namespace __gnu_pbds;
using namespace std;

template <typename T>
using ordered_set =
    tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

//X.find_by_order(k); - zwraca iterator na k-ty element (numeracja od zerowego)
//X.order_of_key(k); - zwraca liczbę elementów ostro mniejszych niż k

typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<PII> VII;
typedef long long LL;

void init_ios() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
}

const int N = 2*(int)1e5 + 3;

int k, n, a[N];

signed main() {
  init_ios();
  cin >> k >> n;
  int mx = 0;
  for (int i = 1; i <= n; ++i) {
    cin >> a[i];
    if (i > 1)
      mx = max(mx, a[i]-a[i-1]);
  }
  mx = max(mx, k-a[n]+a[1]);
  cout<<k-mx<<"\n";
}

Measured memory_bytes: 1792
#include <iostream>
#include <string>
#include <stdio.h>
#include <algorithm>
using namespace std;

int main(){
    string s;
    int n, m;
    while(cin >> s >> n, s != "-"){
        for(int i = 0; i < n; i++){
            cin >> m;
            string t = s.substr(0, m);
            s += t;
            s.erase(0, m);
        }

        cout << s << "\n";
    }
}


Measured memory_bytes: 3228
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cfloat>
#include<climits>
#include<cmath>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>

using namespace std;

using lint = long long;
using P = pair<int, int>;
using LLP = pair<long long, long long>;

#define REP(i, x, n) for(int i = (x), i##_len = (int)(n) ; i < i##_len ; ++i)
#define rep(i, n) for(int i = 0, i##_len = (int)(n) ; i < i##_len ; ++i)
#define reps(i, n) for(int i = 1, i##_len = (int)(n) ; i <= i##_len ; ++i)
#define rrep(i, n) for(int i = (int)(n) - 1 ; i >= 0 ; --i)
#define rreps(i, n) for(int i = (int)(n) ; i > 0 ; --i)
#define SORT(x) sort((x).begin(), (x).end())
#define SORT_INV(x) sort((x).rbegin(), (x).rend())
#define REVERSE(x) reverse((x).begin(), (x).end())
#define TWINS(x) cout << ((x) ? "Yay!" : ":(") << '\n'
#define endl '\n'

constexpr int IINF = (1 << 30) - 1;
constexpr long long LLINF = 1LL << 61;
constexpr double EPS = 1e-10;

constexpr int dx4[] = {1, 0, -1, 0}, dy4[] = {0, 1, 0, -1};
constexpr int dx8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dy8[] = {0, -1, -1, -1, 0, 1, 1, 1};

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

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

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

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

    int m = max(h, w);

    cout << (n+m-1)/m << endl;

    cout << flush;

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include"stdio.h"
#define MAX 500000
#define N 1000000000
using namespace std;

int arr[MAX];
int L[MAX / 2 + 2], R[MAX / 2 + 2];
int c = 0;

void merge(int a[], int left,int middle, int right)
{
	int n1 = middle - left;
	int n2 = right - middle;
	for (int i = 0; i < n1; i++)L[i] = a[left+i];
	L[n1] = N;
	for (int i = 0; i < n2; i++)R[i] = a[middle+i];
	R[n2] = N;
	int l = 0;
	int r = 0;
	for (int i = left; i < right; i++)
	{
		c++;
		if (L[l] > R[r])
		{
			a[i] = R[r];
			r++;
		}
		else
		{
			a[i] = L[l];
			l++;
		}
	}
}
void mergesort(int a[],int left,int right)
{
	if (left + 1 < right)
	{
		int middle = (left + right) / 2;
		mergesort(a, left, middle);
		mergesort(a, middle, right);
		merge(a, left, middle, right);
	}

}


int main()
{
	int n;
	scanf("%d", &n);
	for (int i = 0; i < n; i++)scanf("%d", &arr[i]);
	mergesort(arr, 0, n);
	for (int i = 0; i < n-1; i++)printf("%d ", arr[i]);
	printf("%d\n", arr[n-1]);
	printf("%d\n", c);
	return 0;
}

Measured memory_bytes: 7084
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using P=pair<string,int>;

int main() {
    map<string,int> day{P("SUN",7),P("MON",6),P("TUE",5),P("WED",4),P("THU",3),P("FRI",2),P("SAT",1)};
    string S;cin>>S;
    cout<<day[S]<<endl;
}

Measured memory_bytes: 3644
#include<iostream>
#include<string>
using namespace std;
int main()
{
    string S, T;
    int a[1000], mina, ans;
    for(int i = 0; i < 1000; i++){
        a[i] = 0;
    }
    cin >> S >> T;
    int ss, st;
    ss = S.size();  st = T.size();
    for(int i = 0; i < ss - st + 1; i++){
        for(int j = 0; j < st; j++){
            if(S[i + j] != T[j]){
                a[i] += 1;
            }
        }
    }
    mina = a[0];
    for(int i = 1; i < ss - st + 1; i++){
        mina = (mina <= a[i]) ? mina : a[i];
    }
    cout << mina;
}

Measured memory_bytes: 3636
#include <stdio.h>
int main(int argc, const char *argv[]){
    int a,b,c,x=0;
    
    scanf("%d",&x);
    a = x / 3600;
    b = (x%3600)/60;
    c = x%60;
    
    printf("%d:%d:%d\n",a,b,c);
    return 0;
}

Measured memory_bytes: 592
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
//const ll mod = 1000000007;
//const ll mod = 998244353;
const int inf = 1e9 + 10;
const ll INF = 1e18;
const ld EPS = 1e-10;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }



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

  int x;
  cin >> x;

  cout << !x << '\n';

  
  return 0;
}

Measured memory_bytes: 3580
from collections import*
n=int(input())

d=defaultdict(list)
for i in range(n):
    a=int(input())
    for j in range(a):
        d[i+1].append(list(map(int,input().split())))
        
#print(d)

ans=[]
for i in range(2**n):
    bol=[i>>j&1for j in range(n)]
#    print(bol)
    f=0
    for p,b in enumerate([i>>j&1for j in range(n)]):
        if b:
            for s,t in d[p+1]:
                if bol[s-1]!=t:
                    f=1
    if f==0:
#        print(bol)
        ans.append(sum(bol))
print(max(ans))


Measured memory_bytes: 3700
S = input()
a = int(S[0])
b = int(S[1])
c = int(S[2])
d = int(S[3])

if (a+b+c+d == 7):
  print(str(a)+"+"+str(b)+"+"+str(c)+"+"+str(d)+"=7")
elif (a+b+c-d == 7):
  print(str(a)+"+"+str(b)+"+"+str(c)+"-"+str(d)+"=7")
elif (a+b-c-d == 7):
  print(str(a)+"+"+str(b)+"-"+str(c)+"-"+str(d)+"=7")
elif (a-b-c-d == 7):
  print(str(a)+"-"+str(b)+"-"+str(c)+"-"+str(d)+"=7")
elif (a-b+c+d == 7):
  print(str(a)+"-"+str(b)+"+"+str(c)+"+"+str(d)+"=7")
elif (a-b-c+d == 7):
  print(str(a)+"-"+str(b)+"-"+str(c)+"+"+str(d)+"=7")
elif (a+b-c+d == 7):
  print(str(a)+"+"+str(b)+"-"+str(c)+"+"+str(d)+"=7")
elif (a-b+c-d == 7):
  print(str(a)+"-"+str(b)+"+"+str(c)+"-"+str(d)+"=7")


Measured memory_bytes: 9224
using System;
using System.Collections.Generic;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        public struct Point
        {
            public decimal x;
            public decimal y;
        };


        static void Main(string[] args)
        {
            string s = Console.ReadLine().Trim();
            int data_num = int.Parse(s);



            List<Point> point_list = new List<Point>();

            for (int i = 0; i < data_num; i++)
            {
                string str = Console.ReadLine();

                string[] str_array = str.Split(' ');

                Point point = new Point();
                for (int d_num = 0; d_num < 4; d_num++)
                {
                    point.x = decimal.Parse(str_array[d_num * 2]);
                    point.y = decimal.Parse(str_array[d_num * 2 + 1]);
                    point_list.Add(point);
                }

                Point pos1 = point_list[0];
                Point pos2 = point_list[1];
                Point pos3 = point_list[2];
                Point pos4 = point_list[3];
                decimal p1 = ((pos2.y - pos1.y) * (pos4.x - pos3.x));
                decimal p2 = ((pos4.y - pos3.y) * (pos2.x - pos1.x));

                if (p1 == p2)
                {
                    Console.WriteLine("YES");
                }
                else
                {
                    Console.WriteLine("NO");
                }
                point_list.Clear();
            }
        }
    }
}



Measured memory_bytes: 13912
import collections 
cnt = collections.Counter()
n,m = map(int,input().split())
a = [0] + [int(x) for x in input().split()]
cnt[0] = 1
for i in range(1,n+1):
    a[i] += a[i-1]
    a[i] %= m
    cnt[a[i]]+=1
ans = 0
for k in cnt:
    ans += cnt[k]*(cnt[k]-1)//2
print(ans)

Measured memory_bytes: 14636
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<string> vs;
ll llmax = LLONG_MAX;
vll d1 = {1, 0, -1, 0}, d2 = {0, 1, 0, -1};
string ALP = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
string alp = "abcdefghijklmnopqrstuvwxyz";
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}
void neg() {cout << -1 << endl;}
void sortll(vll &a) {sort(a.begin(), a.end());}
void sortc(string &a) {sort(a.begin(), a.end());}
void sorts(vs &a) {sort(a.begin(), a.end());}

int main() {
  ll n;
  cin >> n;
  for (ll i = n; i > 0; i--) {
    if (sqrt(i) == (ll)sqrt(i)) {
      cout << i << endl;
      return 0;
    }
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <utility>
#include <map>
#include <vector>
#include <algorithm>
#include <queue>
#include <math.h>
#include <stack>
#include <set>
#include <deque>
#include <cmath>
#include <cassert>

using namespace std;
typedef long long ll;
ll mod = 1e9+7;
#define rep(i,n) for(int i = 0; i < (n); ++i)

int main() {
    ll n;
    ll k;
    cin >> n >> k;
    vector<ll> a(n);
    rep(i, n) cin >> a[i];
    vector<vector<ll>> dp(45, vector<ll>(2, -1));
    dp[44][0] = 0;
    for (int i = 43; i >= 0; --i) {
        ll cnt1 = 0;
        rep(j, n) {
            if (a[j] & (1LL<<i)) ++cnt1;
        }
        //cout << cnt1 << endl;
        if (dp[i+1][0] >= 0) {
            if ((k&(1LL<<i))) {
                dp[i][0] = max(dp[i][0], dp[i+1][0] + (n-cnt1) * (1LL<<i));
                dp[i][1] = max(dp[i][1], dp[i+1][0] + cnt1 * (1LL<<i));
            }
            else {
                dp[i][0] = max(dp[i][0], dp[i+1][0] + cnt1 * (1LL<<i));
            }
        }
        if (dp[i+1][1] >= 0) {
            dp[i][1] = max(dp[i][1], dp[i+1][1] + max(cnt1, n-cnt1) * (1LL<<i));
        }
    }
    //for (int i = 44; i >= 0; --i) {
    //    for (auto v: dp[i]) {
    //        cout << v << " ";
    //    }
    //    cout << endl;
    //}
    cout << max(dp[0][0], dp[0][1]) << endl; 
    return 0;
}


Measured memory_bytes: 4056
#include<iostream>
#include<math.h>
#include<string>
#include<algorithm>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)

using namespace std;

int main(){
    int n,m;
    cin>>n>>m;
    int l[100010],r[100010];
    for(int i=0;i<m;++i){
        cin>>l[i]>>r[i];
    }

    int lmax=0,rmin=100010;
    for(int i=0;i<m;++i){
        lmax = max(l[i],lmax);
        rmin = min(r[i],rmin);
    }
    int ans = rmin-lmax+1;
    
    if(ans >= 0)cout<<ans;
    else cout<<"0";
}

Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <vector>
#include <functional>
#include <stack>
#include <utility>
#include <map>
#include <queue>
#include <set>

using namespace std;

typedef long long ll;

int main() {
	ll n, t, st, en, ans = 0;
	cin >> n >> t;
	for (int i = 0; i < n; i++) {
		int a;
		cin >> a;
		if (i == 0) {
			st = a;
			en = a + t;
			continue;
		}
		if (a > en) {
			ans += en - st;
			st = a;
			en = a + t;
		}
		else {
			en = a + t;
		}
	}
	ans += en - st;
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define FLASH ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end))) // rep(i, 1, 5) --> {1,2,3,4} // rep(i, 5, 1) --> {4,3,2,1} // rep(it, end(v), begin(v)) --> *it

using namespace std;

signed main()
{
    int n;
    cin >> n;
    vector<double> v(n);
    rep(i, 0, n)
        cin >> v[i];
    int s = accumulate(begin(v), end(v), 0LL);
    for (int i = 1; i <= n; i += 2)
        s -= 2 * v[i];
    cout << s << " ";
    rep(i, 0, n - 1)
    {
        s = 2 * v[i] - s;
        cout << s << " ";
    }
    return 0;
}

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

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
#define foru(i, a, b) for(int i = a; i <= b; i++) 
#define ford(i, a, b) for(int i = a; i >= b; i--) 
#define endl "\n"
#define scv(a, b, c) #a#b#c
#define com(a,b) a ## b

using namespace std;

typedef long long ll;
typedef double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pii> vii;
typedef vector<pll> v2l;
typedef pair<char, int> pci;
typedef vector<pci> vci;

const int N = 1e6 + 1;
const int NN = 3e3 + 1;
const ll MOD = 998244353;
const ll oo = 1e18 + 7;
const int BASE = 10000;

class solve {
public:
    solve() {
        string s, t;
        cin >> s >> t;
        int n = sz(s);
        s += s;
        vector<vll> next(2 * n, vll(26));
        for (int i = 2 * n - 2; i >= 0; i--) {
            for (int j = 0; j < 26; j++) {
                next[i][j] = next[i+1][j];
            }
            next[i][s[i+1]-'a'] = i + 1;
        }
        ll res = -1;
        for (int i = 0; i < n; i++) {
            if (s[i] == t[0]) {
                res = i;
                break;
            }
        }
        if (res == -1) {
            cout << res;
            return;
        }
        for (int i = 1; i < sz(t); i++) {
            ll pos = res % n;
            if (next[pos][t[i]-'a'] <= pos) {
                cout << -1;
                return;
            }
            res += next[pos][t[i]-'a'] - pos;
        }
        cout << res + 1;
    }
};

int main() {
    #ifdef DEBUG
        com(fre, open) (scv(solve, ., inp), "r", stdin);
        com(fre, open) (scv(solve, ., out), "w", stdout);
    #endif
    ios_base::sync_with_stdio(1);
    cin.tie(nullptr);
    cout.tie(nullptr);
    cout.precision(10);
    solve();
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
    return 0;
}

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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int n;
    string s;
    cin >> n >> s;
    int res=0;
    rep(i,0,n){
        if(s[i]==s[i+1]){
            res++;
        }
    }
    int ans = n-res ;
    cout << ans << "\n";    
}

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

int main() {
  int N;
  cin >> N;
  int v[N];
  for (int i = 0; i < N; i++) cin >> v[i];
  sort(v, v + N);
  double c = v[0];
  for (int i = 1; i < N; i++) c = (c + v[i]) / 2;
  cout << c << endl;
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main()
{
  int n=0,m=0,k=0,t=0;
  scanf("%d%d%d",&n,&m,&k);
  if(n<=m)
  {
  t=n;
  n=m;
  m=t;

  }
  if(k>m&&k<n)
	  printf("Yes\n");
     else if(k<m||k>n)
		 printf("No\n");
return 0;
}

Measured memory_bytes: 128
package main

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

var swap map[int][]int

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	var N, M int
	scanner.Scan()
	fmt.Sscanf(scanner.Text(), "%d", &N)
	scanner.Scan()
	fmt.Sscanf(scanner.Text(), "%d", &M)

	ps := make([]int, N)
	for i := 0; i < N; i++ {
		scanner.Scan()
		fmt.Sscanf(scanner.Text(), "%d", &ps[i])
	}

	swap = make(map[int][]int)
	for i := 0; i < M; i++ {
		var a, b int
		scanner.Scan()
		fmt.Sscanf(scanner.Text(), "%d", &a)
		scanner.Scan()
		fmt.Sscanf(scanner.Text(), "%d", &b)
		swap[a] = append(swap[a], b)
		swap[b] = append(swap[b], a)
	}

	ans := 0
	done := make(map[int]struct{})
	for i := 1; i <= N; i++ {
		if _, e := done[i]; e {
			continue
		}
		conn := make(map[int]struct{})
		connected(i, conn)
		cnt := 0
		for pos, _ := range conn {
			done[pos] = struct{}{}
			if _, e := conn[ps[pos-1]]; e {
				cnt++
			}
		}
		ans = ans + cnt
	}
	fmt.Println(ans)
}

func connected(n int, done map[int]struct{}) {
	done[n] = struct{}{}
	ret := make([]int, 0)
	ret = append(ret, n)
	for _, c := range swap[n] {
		if _, e := done[c]; !e {
			connected(c, done)
		}
	}
}


Measured memory_bytes: 42752
#include <iostream>
#include <string>
#include <cstdlib>
#include <vector>
#include <array>
#include <map>
#include <algorithm>
#include <queue>
#include <stack>
#include <cmath>

using namespace std;
typedef long long int ll;


int main(int argc, char const *argv[])
{
	ll n, x;
	cin >> n >> x;
	vector<ll> l(n);
	for (ll i = 0; i < n; i++)
	{
		cin >> l[i];
	}

	ll d = 0;
	ll ans = 1;

	for (ll i = 0; i < n; i++)
	{
		d += l[i];
		if (d <= x)
		{
			ans++;
		}
	}


	cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>

int main() {
    int i, j, k;
    std::cin >> i >> j >> k;
    if ((i == 5 || i == 7) && (j == 5 || j == 7) && (k == 5 || k == 7) && (i + j + k == 17)) {
        std::cout << "YES" << std::endl;
    } else {
        std::cout << "NO" << std::endl;
    }
    return 0;
}

Measured memory_bytes: 256
import scala.io.Source

object Main {
  def main(args: Array[String]) = {
    val lines = Source.stdin.getLines
    val Array(eachMax, sum) = lines.next.split(" ").map(_.toInt)

    var pattern = 0
    for {
      x <- 0 to (math.min(eachMax, sum))
      y <- 0 to (math.min(eachMax, sum - x)) if ((sum - x - y) <= eachMax)
    } {
      pattern = pattern + 1
    }

    println(pattern)
  }
}


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

using namespace std;

int main(){
      int n, y;
      scanf("%d%d", &n, &y);
      
      for(int i = 0; i <= n; i++){
            for(int j = 0; i + j <= n; j++){
                  int rem = y - 10000 * i - 5000 * j;
                  
                  if(rem >= 0 && rem % 1000 == 0 && rem / 1000 == n - i - j)
                  return 0 * printf("%d %d %d\n", i, j, n - i - j);
            }
      }
      
      printf("-1 -1 -1\n");
}

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

const int inf = (signed) (~0u >> 1);

typedef class Edge {
	public:
		int ed, nx, r;

		Edge() {	}
		Edge(int ed, int nx, int r) : ed(ed), nx(nx), r(r) {	}
} Edge;

typedef class MapManager {
	public:
		int *h;
		vector<Edge> E;

		MapManager() {	}
		MapManager(int n) {
			h = new int[(n + 1)];
			memset(h, -1, sizeof(int) * (n + 1));
		}
		~MapManager() {
			delete[] h;
			E.clear();
		}

		void add_edge(int u, int v, int r) {
			E.emplace_back(v, h[u], r);
			h[u] = (signed) E.size() - 1;
		}
		void add_arc(int u, int v, int r) {
			add_edge(u, v, r);
			add_edge(v, u, 0);
		}
		Edge& operator [] (int p) {
			return E[p];
		}
} MapManager;

typedef class Network {
	public:
		int S, T;
		MapManager g;

		int *d, *h;

		Network(int S, int T) : S(S), T(T), g(T) {
			d = new int[(T + 1)];
			h = new int[(T + 1)];
		}
		~Network() {
			delete[] d;
			delete[] h;
		}

		boolean bfs() {
			queue<int> Q;
			memset(d, -1, sizeof(int) * (T + 1));
			d[S] = 0;
			Q.push(S);
			while (!Q.empty()) {
				int e = Q.front();
				Q.pop();
				for (int i = g.h[e], eu; ~i; i = g[i].nx) {
					eu = g[i].ed;
					if (!g[i].r || ~d[eu])
						continue;
					d[eu] = d[e] + 1;
					Q.push(eu);
				}
			}
			return d[T] != -1;
		}
		
		int dfs(int p, int mf) {
			if (p == T || !mf)
				return mf;
			int flow = 0, f;
			for (int& i = h[p], j, e; ~i; (i != -1) && (i = g[i].nx)) {
				e = g[i].ed, j = i;
				if (g[i].r && d[e] == d[p] + 1 && (f = dfs(e, min(mf, g[i].r))) > 0) {
					g[j].r -= f;
					g[j ^ 1].r += f;
					flow += f;
					mf -= f;
					if (!mf)
						break;
				}
			}
			return flow;
		}

		int dinic() {
			int rt = 0;
			while (bfs()) {
				for (int i = 0; i <= T; i++)
					h[i] = g.h[i];
				rt += dfs(S, inf);
			}
			return rt;
		}

		void add_edge(int u, int v, int r) {
			g.add_arc(u, v, r);
		}

		int find_in_match(int p) {
			for (int i = g.h[p]; ~i; i = g[i].nx) {
				if (!g[i].r) {
					return g[i].ed;
				}
			}
			return -1;
		}
} Network;

const int N = 1e5 + 5;

int n, T;
int A[N], B[N];
boolean vis[N];
vector<int> S[N], G[N];

int main() {
	scanf("%d", &n);
	Network network (0, T = 2 * n - 1);
	for (int i = 1; i < n; i++)
		network.add_edge(0, i, 1);
	for (int i = 1; i < n; i++)
		network.add_edge(n - 1 + i, T, 1);
	for (int i = 1, k; i < n; i++) {
		scanf("%d", &k);
		S[i].resize(k);
		for (auto& x : S[i]) {
			scanf("%d", &x);
			if (x > 1) {
				network.add_edge(i, n - 2 + x, 1);
			}
		}
	}
	int flow = network.dinic();
	if (flow < n - 1) {
		puts("-1");
		return 0;
	}
	for (int i = 1; i < n; i++) {
		A[i] = network.find_in_match(i);
		assert(A[i] >= n);
		A[i] -= n - 2;
	}
	for (int i = 1; i < n; i++) {
		for (auto e : S[i]) {
			if (e ^ A[i]) {
				G[e].push_back(i);
			}
		}
	}
	queue<int> Q;
	Q.push(1);
	while (!Q.empty()) {
		int p = Q.front();
		Q.pop();
		for (auto e : G[p]) {
			if (!B[e]) {
				B[e] = p;
				Q.push(A[e]);
			}
		}
	}
	for (int i = 1; i < n; i++) {
		if (!B[i]) {
			puts("-1");
		}
	}
	for (int i = 1; i < n; i++) {
		printf("%d %d\n", A[i], B[i]);
	}
	return 0;
}



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

typedef long long ll;

using namespace std;

int main() {
    ll n;
    scanf("%lld", &n);
    vector<ll> a(n + 1), d(n + 1);
    for (ll i = 1; i <= n; ++i) scanf("%d", a.begin() + i);
    sort(a.begin(), a.end());
    for (ll i = 1; i <= n; ++i) d.at(i) = d.at(i - 1) + a.at(i);
    auto prev = a.end() - 1;
    while (true) {
        auto now = lower_bound(d.begin(), prev - a.begin() + d.begin(), (*prev + 1) / 2) - d.begin() + a.begin();
        if (now == prev) break;
        prev = now;
    }
    printf("%ld\n", a.end() - prev);
    return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
typedef long long ll;
#define SZ(x) ((int)(x).size())

const ll MOD = 1e9 + 7;

using namespace std;

int main() {

	int A, B;
	cin >> A >> B;

	cout << max(max(A+B,A-B),A*B) << endl;
	

	return 0;
}

Measured memory_bytes: 256
#n, m, k = gets.split.map(&:to_i)

n = gets.to_i

to = []
n.times do to << [] end

(n-1).times do |i|
    a, b = gets.split.map(&:to_i)
    a -= 1
    b -= 1
    to[a] << [b, i]
    to[b] << [a, i]
end

que = []
que << [0, -1]

ans = {}

vcolmax = 1
while que.size != 0
    xx = que.shift
    u = xx[0]
    col = xx[1]
    vcol = 1
    to[u].each do |x|
        v = x[0]
        idx = x[1]
        next if ans[idx] != nil
        vcol += 1 if vcol == col
        ans[idx] = vcol
        que << [v, vcol]
        vcolmax = [vcolmax, vcol].max
        vcol += 1
    end
end

puts vcolmax
ans.to_a.sort.each do |a|
    puts a[1]
end


Measured memory_bytes: 43396
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <functional>
#include <iomanip>
#define vll vector<ll>
#define vvv vector<vvl>
#define vvi vector<vector<int> >
#define vvl vector<vector<ll> >
#define vv(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define vvvl(a, b, c, d) vector<vvl>(a, vvl(b, vll (c, d)));
#define rep(c, a, b) for(ll c=a;c<b;c++)
#define re(c, b) for(ll c=0;c<b;c++)
#define all(obj) (obj).begin(), (obj).end()
typedef long long int ll;
typedef long double ld;
using namespace std;

struct UF{
  std::vector<int> par, dep, sz;
  UF(int n){
    par.resize(n+1), dep.resize(n+1), sz.resize(n+1);
    init(n);
  }
  void init(int nu) {
    for(int iu=0;iu<=nu;iu++){
      par[iu] = iu;
      dep[iu] = 0;
      sz[iu] = 1;
    }
  }
  int find(int xu){
    if(par[xu] == xu) return xu;
    return par[xu] = find(par[xu]);
  }
  void unite(int xu, int yu){
    xu=find(xu);
    yu=find(yu);
    if(xu == yu) return;
    if(dep[xu] < dep[yu]){
      sz[yu] += sz[xu];
      par[xu] = yu;
    }else{
      par[yu] = xu;
      sz[xu] += sz[yu];
      if(dep[xu] == dep[yu]) dep[xu]++;
    }
  }
  bool same(int xu, int yu){
    return find(xu) == find(yu);
  }
};
int main(int argc, char const *argv[]) {
  ll a, b, c, n, m;std::cin >> n >> m;
  UF uf(2*n+1);
  re(i, m){
    std::cin >> a >> b >> c;
    uf.unite(a, b);
  }
  set<ll> s;
  rep(i, 1, n+1) s.insert(uf.find(i));
  std::cout << s.size() << '\n';
  return 0;
}


Measured memory_bytes: 7296
#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;
typedef long long  ll;
typedef long double ld;
typedef pair<ll,ll> pp;
typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> super_set;
typedef tree<ll,null_type,less_equal<ll>,rb_tree_tag,tree_order_statistics_node_update> multi_set;
#define x1 dfds
#define y1 dsfdsfe
#define pb push_back
#define forn(i,n) for(ll i = 1;i<=n;++i)
#define fi first
#define sc second
#define endl '\n'
#define po(x) (1ll<<x)
const ll DIM = 2e5+7;
const ll INF = 1e9;
mt19937_64 rnd(chrono::steady_clock::now().time_since_epoch().count());

ll A[DIM],cnt[DIM];
int main(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    ll n;
    cin>>n;
    forn(i,n){
        cin>>A[i];
        cnt[A[i]]++;
    }
    ll sum = 0;
    forn(i,n){
        sum+=cnt[i]*(cnt[i]-1)/2;
    }
    forn(i,n){
        ll r = sum-cnt[A[i]]*(cnt[A[i]]-1)/2;
        r+=(cnt[A[i]]-1)*(cnt[A[i]]-2)/2;
        cout<<r<<endl;
    }

    return 0;
}



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

#define NMAX 4000

ll dp[NMAX];

void init(){
    rep(i, 0, NMAX) dp[i] = -1;
}

int main(){
    init();
    ll a, b, c, d, e, f;
    cin >> a >> b >> c >> d >> e >> f;
    // dp[i] := 総重量 i <= f で，なおかつ解け残しがない時の最大砂糖溶解量
    dp[0] = 0;
    auto func = [&](ll cur, ll w, ll s) {
        ll weight = cur + 100 * w + s;
        if(weight > f) return false;
        ll sugar = dp[cur] + s;
        ll water = cur + 100 * w - dp[cur];
        // if(water % 100) exit(1);
        if(sugar > e * (water / 100)) return false;
        return true;
    };
    rep(i, 0, f+1) {
        if(dp[i] == -1) continue;
        if(func(i, a, 0)) dp[i + 100 * a] = max(dp[i + 100 * a], dp[i]);
        if(func(i, b, 0)) dp[i + 100 * b] = max(dp[i + 100 * b], dp[i]);
        if(func(i, 0, c)) dp[i + c] = max(dp[i + c], dp[i] + c);
        if(func(i, 0, d)) dp[i + d] = max(dp[i + d], dp[i] + d);
    }

    //rep(i, 0, f+1) cerr << i << " " << dp[i] << endl;
    ll mass = 100*a, sugar = 0;
    rep(i, 1, f+1) {
        if(i * sugar < dp[i] * mass) {
            sugar = dp[i];
            mass = i;
        }
        if(i == 2634) cerr << dp[i] << endl;
    }
    cout << mass << " " << sugar << endl;
    return 0;
}

Measured memory_bytes: 3672
#include<stdio.h>
#include<stdlib.h>
#define N 100
  
int p[N],m[N][N];
 int n;
void matrixChain();
  
int main(){
  
  int i;
  
  scanf("%d",&n);
  for(i=1; i <=n; i++){
    scanf("%d%d",&p[i-1],&p[i]);
  }
   
  
  matrixChain();
printf("%d\n",m[1][n]);
  return 0;
}
  
void matrixChain(){
  int t,k;
  int i,j;
  int l;
  
  for(i=1; i < n; i++){
    m[i][j]=0;
  }
  
  for(l=2; l <= n; l++){
    for(i=1; i <= n-l+1; i++){
      j=i+l-1;
      m[i][j]=1000000;
    for(k=i; k < j; k++){
      t=m[i][k]+m[k+1][j]+p[i-1]*p[k]*p[j];
      if(t < m[i][j]) m[i][j]=t;
    }
  }
  }
}


Measured memory_bytes: 2056
def main17():
    strbuf = "U"
    strbuf2 = "N"
    strbuf3 = "K"
    print(strbuf + strbuf2 + strbuf3)

def main18():
    strbuf = input('');
    num = int(strbuf);
    if(num<1200):
        print("ABC");
    elif(num<2800):
        print("ARC");
    else:
        print("AGC");


if __name__ == '__main__':
    main18()

Measured memory_bytes: 3060
#include <iostream>
#include <vector>

int main() {
    int N;
    std::string S;
    std::cin >> N >> S;
    for (int i = 0; i < S.size(); ++i) {
        std::cout << (char)((int)'A' + (((int)S[i] - (int)'A') + N) % 26);
    }
    std::cout << std::endl;
    return 0;
}


Measured memory_bytes: 1016
use std::io;
use std::cmp;


// read a line(without line feed)
fn read_line() -> String {
    let mut in_str = String::new();
    io::stdin().read_line(&mut in_str).unwrap();
    return in_str.trim().to_string();
}

// read wods on a line
pub fn read_words_in_line() -> Vec<String> {
    let s = read_line();
    return s.split_whitespace().map(|x| x.to_string()).collect::<Vec<String>>()
}

// read type t on a line
pub fn read_t_in_line<T : std::str::FromStr>() -> Vec<T> {
    let mut v : Vec<T> = Vec::new();
    for e in read_words_in_line().iter().map(|x| x.parse::<T>()) {
        if let Ok(r) = e {
            v.push(r);
        }
        else{
            return Vec::new();
        }
    }
    return v;
}

// sort slice
pub fn sort<T : std::cmp::Ord>(slice : &mut [T]) {
    slice.sort();
}
// sort slice by reverse order
pub fn sort_rev<T : std::cmp::Ord>(slice : &mut [T]) {
    slice.sort_by(|x, y| y.cmp(x));
}

pub fn min<T : std::cmp::Ord>(a : T, b : T) -> T{
    return cmp::min(a, b);
}

pub fn max<T : std::cmp::Ord>(a : T, b : T) -> T{
    return cmp::max(a, b);
}


fn main() {
    let b = read_line().chars().collect::<Vec<char>>();
    let sz = b.len();
    let mut max_len = 0;
    for i in 0..sz {
        for j in i..sz {
            let mut ok = true;
            for k in i..(j+1) {
                if !(b[k] == 'A' || b[k] == 'G' || b[k] == 'T' || b[k] == 'C') {
                    ok = false;
                }
            }
            if ok {
                max_len = max(max_len, j - i + 1);
            }
        }
    }
    println!("{}", max_len);
    
}


Measured memory_bytes: 4352