akhauriyash/Code-Regression huggingface dataset:
#include<cstdio>
#include<algorithm>
using namespace std;
const int maxn = 2007;
int n, k, u[maxn], v[maxn], gra, head[maxn];
struct edge {
    int nxt;
    int to;
} e[2000 << 1];
int tp = 0;
void add(int u, int v) {
    e[++gra].to = v;
    e[gra].nxt = head[u];
    head[u] = gra;
    return ;
}
void dfs(int now, int last, int deep) {
    tp++;
    if(!deep)return;
    for(int v, i = head[now]; i; i = e[i].nxt) {
        v = e[i].to;
        if(v != last) dfs(v, now, deep - 1);
    }
}

int main() {
    scanf("%d%d", &n, &k);
    for(int i=1; i<n;i++) {
        scanf("%d%d", &u[i], &v[i]);
        add(u[i], v[i]);
        add(v[i], u[i]);
    }
    int ans = 0;
    if(k % 2 ) {
        for(int i=1; i<n; i++) {
            tp = 0;
            dfs(u[i], v[i], k / 2);
            dfs(v[i], u[i], k / 2);
            ans = max(ans, tp);
        }
    } else {
        for(int i=1; i<n;i++) {
            tp = 0;
            dfs(i, 0, k / 2);
            ans = max(ans, tp);
        }
    }
    printf("%d", n - ans);
    return 0;
}



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

int main(void)
{
    string x;
    cin>>x;
    reverse(x.begin(),x.end());
    string y=x.substr(8,x.length()-7);
    reverse(y.begin(),y.end());
    cout <<y<<endl;
    return 0;
}


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;
using P = pair<int,int>;

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; }
const ll llINF = 1LL << 60;
const int iINF = 1e8;

const double pi = 3.141592653589793;

//---main---------------------------------------------
int main(){
    //main
    int A,B,H,M;
    cin >> A >> B >> H >> M;

    double theta, ans;
    theta = 2*pi*( (60*H+M)/720. - M/60.);

    ans = sqrt(A*A+B*B-2*A*B*cos(theta));
    
    printf("%.10f\n",ans);

    return 0;
}

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


void solve(long long K, long long A, long long B){
    if(A%K==0||B%K==0){puts("OK");return;}
    if(A/K==B/K)puts("NG");
    else puts("OK");
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long K;
    scanf("%lld",&K);
    long long A;
    scanf("%lld",&A);
    long long B;
    scanf("%lld",&B);
    solve(K, A, B);
    return 0;
}


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

int main() {
    int a, b;
    cin >> a >> b;
    int c = a;
    int ans = 1;
    if (b != 1) {
        while (c < b) {
            c += a-1;
            ans++;
        }
    } else {
        ans = 0;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
#include <climits>
#include <sstream>
using namespace std;
static const double EPS = 1e-5;
typedef long long ll;

const int MAX_N=300;

int C[MAX_N];
int w[MAX_N][3];


int dp[MAX_N+1];
int n,m;


int solve(){
	int ret=0;
	for(int k=0;k<3;k++){
		memset(dp,0,sizeof(dp));
		for(int i=0;i<n;i++){
			for(int j=C[i];j<=m;j++){
				dp[j]=max(dp[j],dp[j-C[i]]+w[i][k]);
			}
		}
		ret=max(ret,dp[m]);
	}
	return ret;
}

main(){
	string fin;
	while(getline(cin,fin)){
		stringstream sfin(fin);
		sfin>>n>>m;
		for(int i=0;i<n;i++){
			getline(cin,fin);
			getline(cin,fin);
			stringstream sfin(fin);
			sfin>>C[i]>>w[i][0]>>w[i][1]>>w[i][2];
		}
		cout<<solve()<<endl;
	}
}

Measured memory_bytes: 940
import java.util.*;
import java.io.*;

import static java.lang.Character.isUpperCase;

public class Main {

    public static void main(String[] args) {

        Scanner in = new Scanner(System.in);
        String S = in.next();
        boolean playable = true;

        for(int i =0 ; i<S.length() ; i++)
        {
            int x =  (i+1)%2;

            if(x==1)
            {
                if(S.charAt(i)=='R'|| S.charAt(i)=='U'||S.charAt(i)=='D' )
                {
                }
                else {
                    playable = false;
                }
            }
            else if(x==0)
            {
                if(S.charAt(i)=='L'|| S.charAt(i)=='U'||S.charAt(i)=='D' )
                {
                }
                else {
                    playable=false;
                }
            }


        }
                if(playable==true)
                {
                    System.out.println("Yes");
                }
                else
                    {
                        System.out.println("No");
                    }








        }







    }
















Measured memory_bytes: 35560
#include <bits/stdc++.h>
#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define in(x,y,h,w) x >= 0 && x < h && y >= 0 && y < w
using namespace std;

#define int long long
//typedef    long long          ll;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      P;
 
const int INF=1e+9;
const double EPS=1e-9;
const int MOD=1000000007;
 
const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};

signed main(){
	int n,d[90] = {};
	cin >> n;
	d[0] = 2;
	d[1] = 1;
	for(int i = 2;i <= n;i++) d[i] = d[i - 1] + d[i - 2];
	cout << d[n] << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
  int count =0,n,m,max=-100000;
  string s[101],t[101];
  cin>>n;
  for(int i=0;i<n;i++)cin >> s[i];
  cin>>m;
  for(int i=0;i<m;i++)cin >> t[i];
  for(int i=0;i<n;i++){
    for(int j=0;j<n;j++){
      if(s[i]==s[j])count ++;
    }
    for(int j=0;j<m;j++){
      if(s[i]==t[j])count --;
    }
    if(count >= max)max=count;
    count =0;
  }
  if(max<=0)max=0;
  cout << max;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <limits>
#include <vector>
#include <cstdio>
#include <bits/stdc++.h>
#include <set>
using namespace std;
using ll =long long;

int main (void) {
  int A,B,C;
  cin >> A >> B >> C;
  int t=max({A,B,C});
  int p=t;
  int K,ans;
  cin >> K;
  for (int i=1;i<=K;i++){
    p=p*2;
  }
  ans=p-t+A+B+C;
  cout << ans;
}

Measured memory_bytes: 256
#include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
using namespace std;
#define REP(i, j) for(int i = 0; i < (int)(j); ++i)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define REVERSE(v) reverse((v).begin(), (v).end())
#define curr(P, i) P[i]
#define next(P, i) P[(i+1)%P.size()]
const double EPS = 1e-12;
#define EQ(a,b) (abs((a)-(b)) < EPS)
typedef complex<double> P;
typedef vector<P> G;
 
double cross(const P& a, const P& b) {
  return imag(conj(a)*b);
}
 
double area2(const G &P) {
  double A = 0.0;
  for (int i = 0; i < P.size(); ++i)
    A += cross(curr(P, i), next(P, i));
  return A / 2.0;
}
 
P rotation(P v, double r){
  return P(v.real() * cos(r) - v.imag() * sin(r), v.real() * sin(r) + v.imag() * cos(r));
}
 
double calc(int N){
  G a(N);
  a[0] = P(1, 0);
  double r = 0.0;
  FOR(i, 1, N){
    int d; cin >>d;
    r += d * M_PI / 180.0;
    a[i] = rotation(P(1, 0), r);
  }
  return area2(a);
}
 
int main() {
  int N;
  while(cin >>N && N){
    double a = calc(N);
    cin >>N;
    double b = calc(N);
    cout <<(EQ(a, b) ? 0 : (a > b ? 1 : 2)) <<endl;
  }
  return 0;
}

Measured memory_bytes: 1208
#include <bits/stdc++.h>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep2(i,a,n) for(int i=a;i<n;i++)
#define been(ix) (ix).begin(),(ix).end()
using namespace std;
typedef long long ll; 
typedef vector<int> vi;
typedef vector<long long> vl;
const ll INFL = 1e18;
const int INF = 1001001001; 
typedef pair<int,int> P;
#define foreach(ix,i) for(auto& (ix) : (i))
typedef long double ld;
const int mod =1000000007;
vector<vi> res;int n,m,q;
int cnt  =0;

int main(){
    string s;
    cin>>s;
    int n=s.length();
    int dp [n+1][13];
    rep(i,n+1)rep(j,13)dp[i][j]=0;
    dp[0][0]=1;
    rep(i,n){
        if(s[i]=='?'){
            rep(k,10){
                rep(j,13){
                    dp[i+1][(j*10+k)%13]+=dp[i][j];
                    dp[i+1][(10*j+k)%13]%=mod;
                }
            }
        }
        else{
            int k =s[i]-'0';
            rep(j,13){
                dp[i+1][(10*j+k)%13]+=dp[i][j];
                dp[i+1][(10*j+k)%13]%=mod;
            }
    }
    
    }
    cout<<dp[n][5]<<endl;
    }

Measured memory_bytes: 5504
K = int(input())
d = [1,2,3,4,5,6,7,8,9]

if K <= 9:
  print(K)
  exit()

cnt = 9
while cnt < K:
  _ = d.pop(0)
  matsubi = _%10
  
  if matsubi == 0:
    d.append(_*10+matsubi)
    d.append(_*10+matsubi+1)
    cnt += 2

  elif matsubi == 9:
    d.append(_*10+matsubi-1)
    d.append(_*10+matsubi)
    cnt += 2

  else:
    d.append(_*10+matsubi-1)
    d.append(_*10+matsubi)
    d.append(_*10+matsubi+1)
    cnt += 3
      
ans = -1*(cnt - K + 1)
print(d[ans])

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

void solve()
{
    int k;
    int x, y;
    cin >> k >> x >> y;
    
    int x_sgn = (x < 0) ? -1 : 1;
    int y_sgn = (y < 0) ? -1 : 1;
    x = abs(x);
    y = abs(y);
    
    int a = 0;
    int b = 0;
    
    if ((k % 2 == 0) && ((x + y) % 2 == 1))
    {
        cout << -1 << '\n';
        return;
    }
    
    queue<pair<int, int>> soln;
    while ((x - a) + (y - b) > 2 * k)
    {
        if (x >= a + k)
            a += k;
        else
            b += k;
        soln.push({a, b});
    }
    
    if (abs(x - a) + abs(y - b) == k)
    {
        soln.push({x, y});
        
        cout << soln.size() << '\n';
        while (!soln.empty())
        {
            cout << soln.front().first * x_sgn << ' ' << soln.front().second * y_sgn << '\n';
            soln.pop();
        }
        
        return;
    }
    
    if (((x - a) + (y - b)) % 2 == 1)
    {
        if (abs(x - a - k) + (y - b) > 2 * k)
            b += k;
        else
            a += k;
        soln.push({a, b});
    }
    
    if (abs(x - a) < abs(y - b))
    {
        int lx = x;
        int ly = (b < y) ? (b + (abs(y - b) - abs(x - a)) / 2) : (b - (abs(y - b) - abs(x - a)) / 2);
        
        int lk = k - (abs(x - lx) + abs(y - ly));
        if (a > x)
            lx -= lk;
        else
            lx += lk;
        
        assert(abs(x - lx) + abs(y - ly) == k);
        assert(abs(a - lx) + abs(b - ly) == k);
        soln.push({lx, ly});
    }
    else
    {
        int lx = (a < x) ? (a + (abs(x - a) - abs(y - b)) / 2) : (a - (abs(x - a) - abs(y - b)) / 2);
        int ly = y;
        
        int lk = k - (abs(x - lx) + abs(y - ly));
        if (b > y)
            ly -= lk;
        else
            ly += lk;
        
        assert(abs(x - lx) + abs(y - ly) == k);
        assert(abs(a - lx) + abs(b - ly) == k);
        soln.push({lx, ly});
    }
    
    soln.push({x, y});
    
    cout << soln.size() << '\n';
    while (!soln.empty())
    {
        cout << soln.front().first * x_sgn << ' ' << soln.front().second * y_sgn << '\n';
        soln.pop();
    }
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    
    int tc = 1;
    // cin >> tc;
    for (int i = 1; i <= tc; ++i)
    {
        // cout << "->" << i << '\n';
        solve();
    }
    
    return 0;
}

Measured memory_bytes: 3968
N, K = map(int, input().split())
R, S, P = map(int, input().split())
T = input()

dp = [[0]*3 for _ in range(N+1)]
for i in range(1, N+1):
    if i <= K:
        dp[i][0] = int(T[i-1]=='s') * R
        dp[i][1] = int(T[i-1]=='p') * S
        dp[i][2] = int(T[i-1]=='r') * P
    else:
        dp[i][0] = max(dp[i-K][1], dp[i-K][2]) + int(T[i-1]=='s') * R
        dp[i][1] = max(dp[i-K][0], dp[i-K][2]) + int(T[i-1]=='p') * S
        dp[i][2] = max(dp[i-K][0], dp[i-K][1]) + int(T[i-1]=='r') * P

ans = 0
for d in dp[-K:]:
    ans += max(d)
print(ans)

Measured memory_bytes: 28864
import sys
import math
import collections
import itertools
import array
import inspect

# Set max recursion limit
sys.setrecursionlimit(1000000)


# Debug output
def chkprint(*args):
    names = {
        id(v): k
        for k, v in inspect.currentframe().f_back.f_locals.items()
    }
    print(', '.join(
        names.get(id(arg), '???') + ' = ' + repr(arg) for arg in args))


# Binary converter
def to_bin(x):
    return bin(x)[2:]


def li_input():
    return [int(_) for _ in input().split()]


def gcd(n, m):
    if n % m == 0:
        return m
    else:
        return gcd(m, n % m)


def gcd_list(L):
    v = L[0]

    for i in range(1, len(L)):
        v = gcd(v, L[i])

    return v


def lcm(n, m):
    return (n * m) // gcd(n, m)


def lcm_list(L):
    v = L[0]

    for i in range(1, len(L)):
        v = lcm(v, L[i])

    return v


# Width First Search (+ Distance)
def wfs_d(D, N, K):
    """
    D: 隣接行列(距離付き)
    N: ノード数
    K: 始点ノード
    """

    dfk = [-1] * (N + 1)
    dfk[K] = 0

    cps = [(K, 0)]
    r = [False] * (N + 1)
    r[K] = True
    while len(cps) != 0:
        n_cps = []
        for cp, cd in cps:
            for i, dfcp in enumerate(D[cp]):
                if dfcp != -1 and not r[i]:
                    dfk[i] = cd + dfcp
                    n_cps.append((i, cd + dfcp))
                    r[i] = True

        cps = n_cps[:]

    return dfk


# Depth First Search (+Distance)
def dfs_d(v, pre, dist):
    """
    v:  現在のノード
    pre: １つ前のノード
    dist: 現在の距離

    以下は別途用意する
    D: 隣接リスト(行列ではない)
    D_dfs_d: dfs_d関数で用いる，始点ノードから見た距離リスト
    """

    global D
    global D_dfs_d

    D_dfs_d[v] = dist

    for next_v, d in D[v]:
        if next_v != pre:
            dfs_d(next_v, v, dist + d)

    return


def sigma(N):
    ans = 0
    for i in range(1, N + 1):
        ans += i
    return ans


class Combination:
    def __init__(self, n, mod):

        g1 = [1, 1]
        g2 = [1, 1]
        inverse = [0, 1]
        for i in range(2, n + 1):
            g1.append((g1[-1] * i) % mod)
            inverse.append((-inverse[mod % i] * (mod // i)) % mod)
            g2.append((g2[-1] * inverse[-1]) % mod)
        self.MOD = mod
        self.N = n
        self.g1 = g1
        self.g2 = g2
        self.inverse = inverse

    def __call__(self, n, r):
        if (r < 0 or r > n):
            return 0
        r = min(r, n - r)
        return self.g1[n] * self.g2[r] * self.g2[n - r] % self.MOD


# --------------------------------------------

dp = None


def main():
    N = int(input())
    D = [li_input() for _ in range(N)]

    t, a = 1, 1

    # t = t_rate * x
    # a = a_rate * x
    for t_rate, a_rate in D:
        x = t // t_rate if t % t_rate == 0 else t // t_rate + 1
        y = a // a_rate if a % a_rate == 0 else a // a_rate + 1

        t = t_rate * max(x, y)
        a = a_rate * max(x, y)

    print(a + t)


main()


Measured memory_bytes: 4724
#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;
using   ll=long long;
using   ld=long double;

#define fast          ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ordered_set   tree<pll, null_type,less<pll>, rb_tree_tag,tree_order_statistics_node_update>

#define endl          "\n"
#define pb            push_back
#define mp            make_pair
#define F             first
#define S             second
#define int             long long int

#define ALL(v)        v.begin(),v.end()
#define ALLR(v)       v.rbegin(),v.rend()
#define pii           3.14159265358979323
#define inf         LLONG_MAX
#define ones(x)       __builtin_popcount(x)
#define fill(a,b)     memset(a,b,sizeof(a))
#define mod       998244353

ll mod_pow(ll a,ll b) 
{
    ll res = 1;
    while(b)  
    {
        if(b&1)   
        {
          res=(res*a)%mod;
        }
        a=(a*a)%mod;
        b>>=1;
    }
    return res;
}

ll mod_inverse(ll a) 
{
  return mod_pow(a , mod-2);
}

void solve()
{
  int n;
  
  cin >> n;
  
  int a[n+1];
  
  for(int i = 1; i <= n; ++i) {
    cin >> a[i];
  }
  
  int pre[n+10] {};
  int sre[n+10] {};
  
  for(int i = 1; i <= n; ++i) {
    pre[i] = pre[i-1]^a[i];
  }
  
  for(int i = n; i >= 1; --i) {
    sre[i] = sre[i+1]^a[i];
  }
  
  for(int i = 1; i <= n; ++i) {
    cout << (pre[i-1]^sre[i+1]) << " " ;
  }
}

signed main() {
    fast;
    
    int t = 1;
    
    //cin >> t;
    
    while(t--) {
        solve();
    }
 
    return 0;
}

Measured memory_bytes: 8332
#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 all(x) (x).begin(),(x).end()
using namespace std;
using ll = long long;
using vint = vector<int>;

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

	int s[2], t[2];
	string resu;
	cin >> s[0] >> s[1] >> t[0] >> t[1];
	// 時計回りに一周
	REP(i, t[1] - s[1]) resu += 'U';
	REP(i, t[0] - s[0]) resu += 'R';
	REP(i, t[1] - s[1]) resu += 'D';
	REP(i, t[0] - s[0]) resu += 'L';
	// さらに外を回す
	resu += 'L';
	REP(i, t[1] - s[1] + 1) resu += 'U';
	REP(i, t[0] - s[0] + 1) resu += 'R';
	// 地点の通過
	resu += 'D';
	resu += 'R';
	// 外回って戻る
	REP(i, t[1] - s[1] + 1) resu += 'D';
	REP(i, t[0] - s[0] + 1) resu += 'L';
	resu += 'U';

	cout << resu << "\n";
	return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws NumberFormatException, IOException {

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		String s = br.readLine();

		int count = 0;

		for (int i = 0; i < 4; i++) {
			if (s.charAt(i) == '+') {
				count++;
			} else {
				count--;
			}
		}

		System.out.println(count);

	}

}


Measured memory_bytes: 22612
#include <iostream>
using namespace std;
#define Nmax 100000

int main()
{
	int n = 0;
	int h[Nmax] = { 0 };

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

	int cnt = 0;
	int maxcnt = 0;
	for (int i = 0; i < n - 1; i++) {
		if (h[i] >= h[i + 1]) {
			cnt++;
		}
		else {
			cnt = 0;
		}
		if (cnt >= maxcnt) {
			maxcnt = cnt;
		}
	}

	cout << maxcnt << "\n";

	return 0;
}

Measured memory_bytes: 640
#include<cstdio>
#include<algorithm>
#include<vector>
#define N_ 201000
#define M_ 2010000
#define INF 99999999
using namespace std;
struct Edge {
	int b, e, f;
};
class MaxFlow {
public:
	Edge E[M_ * 2];
	vector<int>G[N_];
	int Level[N_], Q[N_], PV[N_], source, sink, n, EC;
	long long flow;
	void init(int N, int S, int T) {
		n = N, flow = EC = 0;
		for (int i = 0; i <= n; i++)G[i].clear();
		source = S, sink = T;
	}
	void Add_Edge(int a, int b, int f) {
		G[a].push_back(EC);
		G[b].push_back(EC + 1);
		E[EC++] = { a,b,f };
		E[EC++] = { b,a,0 };
	}
	bool GetLevel() {
		int i;
		for (i = 1; i <= n; i++)Level[i] = -1;
		int head = 0, tail = 0;
		Q[++tail] = source, Level[source] = 0;
		while (head < tail) {
			int x = Q[++head];
			for (auto &y : G[x]) {
				if (E[y].f && Level[E[y].e] == -1) {
					Q[++tail] = E[y].e;
					Level[E[y].e] = Level[x] + 1;
				}
			}
		}
		return Level[sink] != -1;
	}
	int BlockFlow(int a, int f) {
		if (a == sink)return f;
		for (int &i = PV[a]; i >= 0; i--) {
			int x = G[a][i];
			if (E[x].f && Level[E[x].e] == Level[a] + 1) {
				int t = BlockFlow(E[x].e, min(f, E[x].f));
				if (t) {
					E[x].f -= t;
					E[x ^ 1].f += t;
					return t;
				}
			}
		}
		return 0;
	}
	void Dinic() {
		int t;
		while (GetLevel()) {
			for (int i = 1; i <= n; i++)PV[i] = G[i].size() - 1;
			while (t = BlockFlow(source, INF)) flow += t;
		}
	}
}G2;
int n, Deg[N_], UF[N_], Res[N_][2];
int Find(int a) {
	if (a == UF[a])return a;
	return UF[a] = Find(UF[a]);
}
vector<int>A[N_], B[N_];
struct point {
	int d, num;
	bool operator < (const point &p)const {
		return d < p.d;
	}
}w[N_];
void Merge(int a, int b) {
	a = Find(a), b = Find(b);
	UF[a] = b;
}
vector<int>TP[N_];
int Num[N_], Q[N_], head, tail, vis[N_];
int main() {
	int i, j, c, a;
	scanf("%d", &n);
	G2.init(n + n + 1, n + n, n + n + 1);
	for (i = 1; i < n; i++) {

		G2.Add_Edge(G2.source, i, 1);
		scanf("%d", &c);
		for (j = 1; j <= c; j++) {
			scanf("%d", &a);
			TP[a].push_back(i);
			if (a != 1) {
				G2.Add_Edge(i, n - 1 + a, 1);
			}
		}
	}
	for (i = 1; i <= n; i++) {
		if(i!=1)G2.Add_Edge(n - 1 + i, G2.sink, 1);
	}
	G2.Dinic();
	if (G2.flow != n - 1) {
		puts("-1");
		return 0;
	}
	for (i = 2; i <= n; i++) {
		for (auto &x : G2.G[n - 1 + i]) {
			Edge tp = G2.E[x];
			if (tp.f) {
				Num[tp.e] = i;
			}
		}
	}
	Q[++tail] = 1;
	while (head < tail) {
		int x = Q[++head];
		for (auto &t : TP[x]) {
			if (!vis[t]) {
				Res[t][0] = x;
				Res[t][1] = Num[t];
				Q[++tail] = Num[t];
				vis[t] = 1;
			}
		}
	}
	if (tail!=n) {
		puts("-1");
		return 0;
	}
	for (i = 1; i < n; i++)printf("%d %d\n", Res[i][0], Res[i][1]);
	return 0;
}

Measured memory_bytes: 50024
using System;

namespace agc002A
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            string[] str = Console.ReadLine().Split();
            int[] A = new int[2];
            A[0] = int.Parse(str[0]);
            A[1] = int.Parse(str[1]);
            Array.Sort(A);
            if (A[0] > 0 && A[1] > 0)
                Console.WriteLine("Positive");
            else if (A[0] == 0 || A[1] == 0)
                Console.WriteLine("Zero");
            else if ((A[0] < 0 && A[1] > 0) || (A[0] > 0 && A[1] < 0))
                Console.WriteLine("Zero");
            else if (A[1] < 0 && (A[1] - A[0]) % 2 == 0)
                Console.WriteLine("Negative");
            else if (A[1] < 0 && (A[1] - A[0]) % 2 == 1)
                Console.WriteLine("Positive");
        }
    }
}


Measured memory_bytes: 11092
string = str(input())
flag = True
for i in range(len(string)):
	if (i+1)%2==0:
		if( string[i]!='L' and string[i]!='U' and string[i]!='D' ):
			# print(string[i],i)
			flag = False
			break
	else:
		if ( string[i]!='R' and string[i]!='U' and string[i]!='D' ):
			flag = False
			# print(string[i],i)
			break
if(flag):
	print("Yes")
else:
	print("No")

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

using namespace std;

int main(){
	int n = 0;
	int color[][2] = {{0, 0}, {2, 3}, {1, 3}, {1, 2}};
	while(cin >> n && n != 0){
		vector<int> line;
		for(int i = 0; i < n; i++){
			int tmp = 0;
			cin >> tmp;
			line.push_back(tmp);
		}

		int minch = n;
		for(int i = 0; i < n; i++){ 
			for(int j = 0; j < 2; j++){
				vector<int> copyline = line;
				if(i == 0){
					if(color[line[i]][j] != line[i+1]) continue;
				}
				else if(i == n-1){
					if(color[line[i]][j] != line[i-1]) continue;
				}
				else if(color[line[i]][j] != line[i+1] && color[line[i]][j] != line[i-1]) continue;
				copyline[i] = color[line[i]][j];
				int count = 1;
				for(int k = 0; k < n-1; k++){
					if(!copyline[k]) continue;
					int progress = 1;
					while(!copyline[k+progress] && k+progress<copyline.size()) progress++;
					if(copyline[k] != copyline[k+progress]){
						if(count >= 4){
							int target = copyline[k];
							for(int l = k; copyline[l] == 0 || copyline[l] == target; l--){
								copyline[l] = 0;
								if(!l) break;
							}
							k = -1;
							count = 1;
						}
						else count = 1;
					}
					else count++;
				}

				if(count >= 4){
					int target = copyline[n-1];
					for(int l = n-1; copyline[l] == 0 || copyline[l] == target; l--){
						copyline[l] = 0;
						if(!l) break;
					}
				}

				int chnum = 0;
				for(int k = 0; k < n; k++){
					if(copyline[k]) chnum++;
				}

				minch = minch > chnum ? chnum : minch;
			}
		}

		cout << minch << endl;
	}
	return 0;
}

Measured memory_bytes: 1324
#include<iostream>


using namespace std;

#define N 100

int memo[N+1][N+1];
int q[N+1];

int main(){
  int n,i,j,k,l,min_memo;

  cin >> n;

  for(i=1;i<=n;i++) cin >> q[i-1] >> q[i];

  for(i=1;i<=n;i++) memo[i][i] = 0;

  for(l=2;l<n+1;l++){
    for(i=1;i<=n-l+1;i++){
      j = i +l -1;
      for(k = i;k<j;k++){
if(k==i) min_memo =  memo[i][k] + memo[k+1][j] + q[i-1]*q[k]*q[j];
    else  min_memo = min(min_memo, memo[i][k] + memo[k+1][j] + q[i-1]*q[k]*q[j]);
      }
      memo[i][j] =min_memo;
    }
  }

  cout << memo[1][n] << endl;

  return 0;
}



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

int main() {
    double a, b, h, m;
    cin >> a >> b >> h >> m;
    double hkaku = (30*h + m/2);
    double mkaku = 6*m;
    double theta = abs(hkaku - mkaku);
    printf("%.12f", sqrt(a*a + b*b - 2*a*b*cos(theta*M_PI/180)));

    return 0;
}

Measured memory_bytes: 4228
#include <stdio.h>

int main (){

    int G, N, D;
    scanf("%d %d %d", &G, &N, &D);

    int tot;

    if(G>=N) {
        if(D%G == 0) {
            tot = D/G;
        } else {
            tot = D/G+1;
        }
    } else {
        if(D%N == 0) {
            tot = D/N;
        } else {
            tot = D/N+1;
        }
    }
    printf("%d", tot);

    return 0;
}

Measured memory_bytes: 1704
#include "bits/stdc++.h"
#define MOD 1000000007
#define inf 0x3f3f3f3f
#define pi acos(-1.0)
#define ri register int
#define Abs(x) ((x) < 0 ? (-(x)) : (x))
#define ls (cur << 1)
#define rs (cur << 1 | 1)
#define mid ((l + r) >> 1)
const int maxn = 5e5 + 10;
inline int Max(int a, int b) { return a > b ? a : b; }
inline int Min(int a, int b) { return a > b ? b : a; }
namespace FastIO {
inline int read()
{
    int f = 1, r = 0;
    char c = getchar();
    while (!isdigit(c)) {
        if (c == '-') {
            f = -1;
        }
        c = getchar();
    }
    while (isdigit(c)) {
        r = 10 * r + c - '0';
        c = getchar();
    }
    return f * r;
}
inline void write(int x)
{
    if (x < 0)
        putchar('-'), x = -x;
    if (x > 9)
        write(x / 10);
    putchar(x % 10 + '0');
}
inline void writesp(int x) { write(x), putchar(' '); }
inline void writeln(int x) { write(x), puts(""); }
};
using namespace FastIO;
int N, seg[maxn << 2], pos[maxn], K, tot, ver[maxn << 2], next[maxn << 2], head[maxn], du[maxn], ans[maxn];
inline void add(int u, int v)
{
    ver[++tot] = v, next[tot] = head[u], head[u] = tot;
}
void update(int l, int r, int pos, int val, int cur)
{
    if (l == r) {
        seg[cur] = val;
        return;
    }
    if (mid >= pos)
        update(l, mid, pos, val, ls);
    else
        update(mid + 1, r, pos, val, rs);
    seg[cur] = Min(seg[ls], seg[rs]);
}
int query(int l, int r, int L, int R, int cur)
{
    if (l >= L && r <= R) {
        return seg[cur];
    }
    int ans = inf;
    if (mid >= L) {
        ans = query(l, mid, L, R, ls);
    }
    if (mid < R) {
        ans = Min(ans, query(mid + 1, r, L, R, rs));
    }
    return ans;
}
std::priority_queue<int, std::vector<int>, std::greater<int>> q;
signed main()
{
    //freopen("C:\Users\hjw\Downloads\testdata (4).in", "r", stdin);
    N = read(), K = read();
    for (ri i = 1; i <= N; ++i) {
        pos[read()] = i;
    }
    memset(seg, 0x3f, sizeof(seg));
    for (ri i = N; i >= 1; --i) {
        int now = pos[i];
        int low = query(1, N, now, Min(N, now + K - 1), 1);
        if (low != inf) {
            du[pos[low]]++, add(now, pos[low]);
        }
        low = query(1, N, Max(1, now - K + 1), now, 1);
        if (low != inf) {
            du[pos[low]]++, add(now, pos[low]);
        }
        update(1, N, pos[i], i, 1);
    }
    for (ri i = 1; i <= N; ++i) {
        if (!du[i])
            q.push(i);
    }
    int cnt = 0;
    while (!q.empty()) {
        int top = q.top();
        ans[top] = ++cnt;
        q.pop();
        for (ri i = head[top]; i; i = next[i]) {
            du[ver[i]]--;
            if (du[ver[i]] == 0) {
                q.push(ver[i]);
            }
        }
    }
    for (ri i = 1; i <= N; ++i) {
        writeln(ans[i]);
    }
    return 0;
}

Measured memory_bytes: 31100
import java.util.Arrays;
import java.util.Scanner;

public class Main {
public static void main(String[] args) {
	
	Scanner keyboard = new Scanner(System.in); 
	
	double N = keyboard.nextDouble();
	double K = keyboard.nextDouble();
	
	double S = 0.0;
	double ans = 0.0;
	
	if(N > K) {
		S = K - 1;
		ans +=  (1.0 / N * (N-K+1));
	}else {
		S = N;
	}
	
	for(int i = 1 ; i <= S; i++) {
		double P = 1.0 / N;
		int Q = i;
		
		while(Q < K) {
			Q = Q * 2;
			P = P * (1.0/2.0);
		}
		ans += P;
	}

	System.out.println(ans);
	keyboard.close();
	}	
}


Measured memory_bytes: 23252
#include "bits/stdc++.h"

using namespace std;

typedef long long ll;
typedef long double ld;

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

    ll x,p;cin>>x>>p;
    if(p==100){
        if(x%2) cout<<1+(x-1)/2<<endl;
        else cout<<x/2<<endl;
    }
    else{
        bool f=false;
        if(x%2){
            x++;
            f=true;
        }
        ld a= x/2*(100.0/p), b=(x-2)/2*(100.0/p);
        if(!f){
            cout<<fixed<<setprecision(10)<<a<<endl;
        }
        else{
            ld res=a*(100.0-p)/100 + b*p/100.0;
            cout<<fixed<<setprecision(10)<<1+res<<endl;
        }
    }
}


Measured memory_bytes: 256
import java.io.PrintWriter;
import java.util.Scanner;

class Main{
    private static final Scanner sc = new Scanner(System.in);
    private static final PrintWriter out = new PrintWriter(System.out);
    public static void main(String[] Args){
        while(true){
            final int h = Integer.parseInt(sc.next());
            final int w = Integer.parseInt(sc.next());
            if(h==0&&w==0) break;
            for(int i = 0; i<h; i++){
                for(int j = 0; j<w; j++){
                    if( ( (i+j)&1)==0) out.print("#");
                    else out.print('.');
                }
                out.println();
            }
            out.println();
        }
        out.flush();
    }
}

Measured memory_bytes: 28760
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		String[] array = new String[n];
		int[] iarray = new int[n];
		sc.nextLine();
		for(int i = 0;i < n;i++){
			array[i] = sc.nextLine();
		}
		Arrays.sort(array);
int count = 0;
int max = 0;
		for(int i = 0;i < n-1;i++){
			if(array[i].equals(array[i+1])){
				count++;
				iarray[i] = count;
				if(i == n-2 && max < count){
					max = count;
				}
			}else{
				if(max < count){
					max = count;
				}
				count = 0;
				iarray[i] = count;
			}
		}

		for(int i = 0;i < n;i++){
			if(iarray[i] == max){
				System.out.println(array[i]);
			}
		}

		}
}

Measured memory_bytes: 180980
//#include<string>
#include<iostream>
#include<cstdio>
#include<string>
using namespace std;


long long ans;

int main(){
    string A;
    cin >> A;
    long long len = A.length();

    ans += 1 + len*(len-1)/2;
    long long char_cnt[26] = {};
    for(int i = 0; i < len; i++){
        char_cnt[A[i]-'a']++;
    }

    for(int i = 0; i < 26; i++){
        ans -= char_cnt[i]*(char_cnt[i]-1)/2;
    }

    cout << ans << endl;
}

Measured memory_bytes: 640
/*Author--Vishwas Agrawal*/
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define vll vector<ll>
#define pb push_back
#define test \
   int t;    \
   cin >> t; \
   while (t--)
#define fio                          \
   ios_base::sync_with_stdio(false); \
   cin.tie(NULL);                    \
   cout.tie(NULL);
#define mod 1000000007LL
#define all(x) x.begin(), x.end()
#define sortall(x) sort(all(x))
#define inc(i, a, n) for (int i = a; i < n; i++)
#define dec(i, a, n) for (int i = n - 1; i >= a; i--)
int main()
{
  ll n,x,t;
  cin>>n>>x>>t;
  if(n%x==0)
  {
     cout<<(n/x)*t<<endl;
  }
  else
  {
     cout<<(n/x+1)*t<<endl;
  }
  
   

   return 0;
}

Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
int n,m;
int main()
{
	scanf("%d%d",&n,&m);
	if(n==13&&m==1) printf("Bob");
	else if(n>m||(n==1&&m==13)) printf("Alice");
	else if(m!=n)printf("Bob");
	else printf("Draw");
}

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

using namespace std;
 
#define PB	push_back
#define ALL(x)	(x).begin(), (x).end()
#define ALLR(x)	(x).rbegin(), (x).rend()
#define MP	make_pair
 
#define debug(_x)		cerr << #_x << '=' << (_x) << endl;
#define debug2(_x, _y)	cerr << #_x << '=' << (_x) << ' ' << #_y << '=' << (_y) << endl;
#define debugn(_a)		cerr << #_a << ": "; for (const auto _x: _a) cerr << (_x) << ' '; cerr << endl;

#define HERE debug(__LINE__);

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

#define int long long int

typedef pair<int, int> ii;
typedef pair<pair<int, int>, int> iii;
typedef vector<int> vi;
typedef vector<iii> viii;
typedef vector<vi> vvi;
typedef vector<ii> vii;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef unsigned long long ull;

const int INF = LONG_LONG_MAX>>1;
const int NINF = LONG_LONG_MIN/2;

//MODULAR ARITHMATIC
const int mmod = 1000000007 ;

//ADD
int add(int a, int b, int m=mmod) {
	a += b;
	a %= m;
	return a;
}

//SUB
int sub(int a, int b, int m=mmod) {
    return (a%m - b%m + m)%m;
}

//MUL
int mul(int a, int b, int m=mmod) {
	return ((a%m) * (b%m) % m);
}

//POW
int pow(int a, int b, int m=mmod) {
    a %= m;
    int r = 1;
    while (b) {
		if (b&1) r = r*a%m;
		b >>= 1;
		a = a*a%m;
    }
    return r;
}

//INV
int inv(int a, int m=mmod) {
	return pow(a, m-2, m);
}

int32_t main() {
	FAST_IO;
	
	int n, k;
	cin >> n >> k;
	
	vi a(n);
	for (int& x: a) cin >> x;
	
	vi dp(k+1);
	
	dp[0] = 1;
	
	for (int i = 0; i < n; i++) {
		vi temp(k+1);
		for (int used = k; used >= 0; used--) {
			int t = dp[used];
			int l = used+1;
			int r = used + min(a[i], k - used);
			if (l <= r) {
				temp[l] = add(temp[l], t);
				if (r+1 <= k)
					temp[r+1] = sub(temp[r+1], t);
			}
		}
		int ps = 0;
		for (int i = 0; i <= k; i++) {
			ps = add(ps, temp[i]);
			dp[i] = add(dp[i], ps);
		}
	}
	
	cout << dp[k] << endl;
}

// g++ -Wall -Wextra -Wshadow -fsanitize=undefined


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

int main() {
  long N, A, B;
  cin >> N >> A >> B;
  if (B < A || N == 1 && A != B) cout << 0 << endl;
  else cout << (B - A) * (N - 2) + 1 << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <list>
#include <set>
#include <queue>
#include <map>
#include <algorithm>
#include <functional>
#include <string>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
using namespace std;

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

typedef long long int ll;
typedef pair<int,int> pii;
typedef vector<int> vint;
typedef vector<pii> vpii;
typedef vector<vint> det1;
typedef vector<vpii> det2;

int main()
{
    int a, b, c;
    cin >> a >> b >> c;

    const bool ok = a == b && a == c && b == c;

    cout << (ok ? "Yes" : "No") << endl;

    return 0;
}


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

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

lcm = C * D // gcd(C, D)
total = B - A + 1
ans = total - ((B // C - (A - 1) // C) + (B // D - (A - 1) // D) - (B // lcm - (A - 1) // lcm))
print(ans)


Measured memory_bytes: 2940
//bit全探索
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, from, to) for (int i = from; i < (to); ++i)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define pb push_back
using ll = long long;
using vin=vector<int>;
using vll=vector<ll>;
using vst=vector<string>;
using P = pair<int, int>;
const int inf=1e9+7;
const ll INF=1e18;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };


int main(){cout<<fixed<<setprecision(10);
		   //greedy　後ろから決めていく 選べる中で最大のものを選ぶ
           int n,m;
           cin>>n>>m;
           vector<P> a(n);
           rep(i,0,n)cin>>a[i].first>>a[i].second;
           ll ans=0;
           rep(i,0,n){
             a[i].first=m-a[i].first;//いつまで選べるか
           }
           sort(all(a));
           reverse(all(a));
           int date=m-1;
           priority_queue<int, vector<int>, less<int>> pq;
           int i=0;
           while(true){
             while(i<n&&date<=a[i].first){
               pq.push(a[i].second);
               i++;
              // cout<<1<<endl;
             }
             if(!pq.empty()){
              ans+=pq.top();
               pq.pop();
             }
               date--;
             if(date==-1)break;
           }
           cout<<ans<<endl;
}

Measured memory_bytes: 4640
from sys import stdin,stdout
LI=lambda:list(map(int,input().split()))
MAP=lambda:map(int,input().split())
IN=lambda:int(input())
S=lambda:input()
import math
def p(a):print(" ".join(list(map(str,a))))
from collections import Counter

a=IN()
print(a+pow(a,2)+pow(a,3))


Measured memory_bytes: 9464
#include<bits/stdc++.h>
using namespace std;
int k, n, a[200005];

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

//    freopen("input.txt","r",stdin);
//    freopen("output.txt","w",stdout);

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

    cout << k - mx << '\n';
}


Measured memory_bytes: 1024
from math import hypot

n = int(input())
for i in range(n):
    xa, ya, ra, xb, yb, rb = map(float, input().split())
    d = hypot(xb - xa, yb - ya)
    if ra + rb < d:
        print(0)
    elif abs(ra - rb) <= d:
        print(1)
    elif rb < ra:
        print(2)
    else:
        print(-2)

Measured memory_bytes: 6820
#include<iostream>
#include <algorithm>
#include <functional>
#include<vector>
#include<math.h>
#include<bitset>
#include<string>
#include <deque>
#include<queue>
#include <iomanip>
#include<map>
#include <random>
#include<type_traits>
#include<stack>
#include <sstream> 
using namespace std;
#define ll long long int
#define all(v) begin(v), end(v)
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define reps(i, s, n) for(int i = (int)(s); i < (int)(n); i++)
//typedef vector<int> V;
//typedef vector<VV> VVV;

template<typename T>
void remove(std::vector<T>& vector, unsigned int index)
{
	vector.erase(vector.begin() + index);
}

int sum_estemater(string s, int p, int q, int r) {
	while (s[0] == '('){
		string new_s = "", if_s = "";
		char enzan_falg = '0';
		int num_flag = 0, mina_flag = 0, s_flag = 0;
		for (int i = 0; i < s.length(); i++) {
			if (s[i] == '(') {
				s_flag = 1;
				new_s += if_s;
				if_s = "";
				if_s += s[i];
				mina_flag = 0;
				enzan_falg = '0';
			}
			else if (s[i] == '-') {
				mina_flag = 1 - mina_flag;
				if_s += s[i];
			}
			else if((s[i]=='P')|| (s[i] == 'Q')|| (s[i] == 'R')|| ((s[i]-'0'<=9)&& (s[i]-'0' >=0 ))){
				if_s += s[i];
				if (s[i] == 'P')s[i] = p+'0';
				if (s[i] == 'Q')s[i] = q + '0';
				if (s[i] == 'R')s[i] = r + '0';
				if (enzan_falg == '0') {
					if (mina_flag == 0) {
						num_flag=s[i]-'0';
					}
					else {
						num_flag = 2 - (s[i] - '0');
						mina_flag = 0;
					}
				}
				else {
					if (mina_flag != 0) {
						s[i] =(2 - (s[i] - '0'))+'0';
					}
					if (enzan_falg == '*') {
						num_flag = min(s[i]-'0', num_flag);
					}
					else {
						num_flag = max(s[i] - '0', num_flag);
					}
				}
			}
			else if (s[i] == ')') {
				if (s_flag == 0) {
					if_s += s[i];
				}
				else {
					s_flag = 0;
					new_s += to_string(num_flag);
					num_flag = 0;
					if_s = "";
				}
			}
			else {
				if_s += s[i];
				enzan_falg = s[i];
			}
		}
		new_s += if_s;
		s = new_s;
		//cout << "s :" << s <<" p :"<<p<<" q :"<<q<<" r :"<<r<< endl;
	}
	return atoi(s.c_str());
}

int main() {
	string s;
	cin >> s;
	while(s != ".") {
		if (s[0] != '(')s = '(' + s + ')';
		int max1 = 0, sum;
		for (int p = 0; p < 3; p++) {
			for (int q = 0; q < 3; q++) {
				for (int r = 0; r < 3; r++) {
					sum = sum_estemater(s, p, q, r);
					if (sum == 2)max1++;
				}
			}
		}
		cout << max1 << endl;
		cin >> s;
	}
}



Measured memory_bytes: 3256
parseInt(x::String) = parse(Int, x)
parseInt(x::SubString{String}) = parse(Int, x)
parseInt(x::Char) = parse(Int, x)
parseInt(x::Float64) = trunc(Int, x)
parseFloat(x::String) = parse(Float64, x)
parseFloat(x::Int) = trunc(Float64, x)
parseFloat(x::SubString{String}) = parse(Float64, x)
parseFloat(x::Char) = parse(Float64, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)

function main()
    s,t=[chomp(readline()) for i in 1:2]
    n=length(s)
    l=length(t)
    cnt=Dict{Char,Vector{Int}}(i=>Vector{Int}() for i in 'a':'z')
    for i in 1:n
        push!(cnt[s[i]],i)
    end
    now,res,ans=0,0,0
    for i in 1:l
        hoge=t[i]
        if !(hoge in s)
            ans=-1
            break
        end
        index=searchsortedfirst(cnt[hoge],now)
        if length(cnt[hoge])+1==index
            res+=1
            now=cnt[hoge][1]
        else
            now=cnt[hoge][index]
        end
        ans=res*n+now
        now+=1
    end
    println(ans)
end
main()

Measured memory_bytes: 181648
#pragma GCC optimize ("O3")
#include <iostream>
#include <iomanip>
#include <istream>
#include <ostream>
#include <sstream>
#include <iterator>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <utility>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <ctime>
#include <cctype>
#include <cstdlib>
#define IINF 10e8
#define INF 1<<30
#define MOD 1000000007
#define mod 1000000007
#define rep(i, a, n) for (ll i = a; i < (ll)(n); i++)
#define Endl endl
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define mmax(x,y)(x>y?x:y)
#define mmin(x,y)(x<y?x:y)
#define chmax(x,y) x=mmax(x,y)
#define chmin(x,y) x=mmin(x,y)
#define all(x) (x).begin(),(x).end()
#define siz(x) (ll)(x).size()
#define PI acos(-1.0)
using namespace std;
//using Int=int_fast64_t;
typedef long long int ll;
typedef long long int LL;
typedef pair<ll,ll>Pll;
typedef pair<int,int>Pin;
template<class T> using V=vector<T>;
long long GCD(long long a, long long b) { return b ? GCD(b, a%b) : a; }
long long LCM(long long a, long long b)  {return a/GCD(a,b)*b;}
int dx[4]={-1,0,1,0};
int dy[4]={0,-1,0,1};
int ddx[8]={-1,0,1,0,1,1,-1,-1};
int ddy[8]={0,-1,0,1,1,-1,1,-1};
char dir[4]={'u','l','d','r'};
ll cmp(pair<ll,ll>a,pair<ll,ll> b){
        if(a.se!=b.se)
        return a.se<b.se;
        else
        return a.fi<b.fi;
}
//---------------------------------------------------------------------------

//---------------------------------------------------------------------------
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    //-------------------------------
    string s;cin>>s;
    if(s.length()%2!=0){
        cout<<"No"<<endl;
        return 0;
    }
    int abc=1;
    for(int i=0;i<s.length();i+=2){
        if(!(s[i]=='h'&&s[i+1]=='i'))
            abc=0;
    }
    if(abc==0){
        cout<<"No"<<endl;
        return 0;
    }
    else cout<<"Yes"<<Endl;
    //-------------------------------
    return 0;
}
//---------------------------------------------------------------------------


Measured memory_bytes: 256
#include<iostream>
#include<climits>
#include<math.h>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<stdio.h>
#include <string>
#include <complex>
#include <functional>
using namespace std;
//typedef pair<string,string> P;
//double dat[100][100];
//int dp[6][1010];//動的計画法
//int prime[10000001];
//char str[1010][1010];
//vector<pair<int,int> > pc[100001];
//int ABS(int a){return max(a,-a);}
//long long num[100000];
int main(){
	long long n;
	cin>>n;
	long long a[n];
	for(int i=0;i<n;i++) {
		cin>>a[i];
	}
	sort(a,a+n);
	long long t1=0,t2=0,p=0;
	for(int i=n;i>=0;i--){
		if(a[i]==p){
			if(t1==0){
				t1=p;
				p=0;
			}else{
				t2=p;
				break;
			}
		}else{
			p=a[i];
		}
	}
	cout<<t1*t2<<endl;
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define in(x,y,h,w) x >= 0 && x < h && y >= 0 && y < w

#define int long long
//typedef    long long          ll;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      P;

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); }
 
const int INF=1e+18;
const double EPS=1e-9;
const int MOD=1000000007;

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

signed main(){
	int n,cnt[26] = {},ans = 0;
	string s;
	cin >> n >> s;
	for(int i = 0;i < n;i++){
		int tmp = 1;
		for(int j = 0;j < 26;j++){
			if(j != s[i] - 'a') tmp = (tmp * (cnt[j] + 1)) % MOD;
		}
		ans = (ans + tmp) % MOD;
		cnt[s[i] - 'a']++;
	}
	cout << ans << endl;
}

Measured memory_bytes: 512
#include "iostream"
using namespace std;
int main()
{
	int N,temp,f;
	f = 0;
	cin >> N;
	temp = N;
	while (temp != 0){ 
		f += temp % 10;
		temp /= 10;
	}
	if (N%f == 0)cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
// 有點不耐煩會破壞偉大的計劃

#include <bits/stdc++.h>

#define append push_back

using namespace std;
using ll = long long;

const int N = 1e5 + 3;
const int M = 1e6 + 7;
const long long MOD = 1e9 + 7;
const long long INF = 1e14 + 9;
const int SM = 1e3 + 5;
const int logN = 22, BL = 400;
const double EPS = 1e-9, PI = acos(-1);
const int dx[] = {1, 0, 0, -1, -1, 1, -1, 1};
const int dy[] = {0, 1, -1, 0, -1, 1, 1, -1};

void debug() {
	cerr << "\n";
}
template<typename Type1, typename... Type2>
void debug(Type1 a, Type2... b) {
    cerr << a << " ";
    debug(b...);
}

int main() {
//    freopen(".in", "r", stdin);
//    freopen(".out", "w", stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);

    long long n; cin >> n;

    vector<long long> a(n), b(n), c(n);

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

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

    for(long long i = 0; i < n; i++) {
        c[i] = i + 1;
    }

    long long x = 0, y = 0, z = 0;
    do {
        z++;
        if(a == c) {
            x = z;
        }
        if(b == c) {
            y = z;
        }
    } while(next_permutation(c.begin(), c.end()));

    cout << abs(x - y);

    return 0;
}


Measured memory_bytes: 3660
from itertools import groupby
N, M  =map(int, input().split())
ps = [[] for i in range(M)]
for i in range(M):
    ps[i] = list(input().split())
if M == 0:
    print(0,0)
    exit()
newps = sorted(ps,key=lambda i:i[0]) 
newpslist = list([list(g) for k, g in groupby(newps, key = lambda i:i[0])])
countAC = 0
counterror = 0
for group in newpslist:
    subcounterror = 0
    for subgroup in group:
        if subgroup[1] == 'WA':
            subcounterror += 1
        else:
            countAC += 1
            counterror += subcounterror
            break    
print(countAC, counterror)


Measured memory_bytes: 83360