akhauriyash/Code-Regression huggingface dataset:
import sys
n = int(input())
k = int(input())
n_keta = len(str(n))
memo_ls = [[[0 for _k in range(2)] for j in range(k+2)] for i in range(n_keta + 1)] #フラグ1は小さいこと確定
memo_ls[0][0][0] = 1
for i, base in enumerate(str(n), 1):
    base = int(base)
    for j in range(10):
        for _k in range(k+1):
            if j > base:
                memo_ls[i][_k+1][1] += memo_ls[i-1][_k][1]
            elif j == base:
                if j == 0:
                    memo_ls[i][_k][0] += memo_ls[i-1][_k][0]
                    memo_ls[i][_k][1] += memo_ls[i - 1][_k][1]
                else:
                    memo_ls[i][_k+1][1] += memo_ls[i-1][_k][1]
                    memo_ls[i][_k+1][0] += memo_ls[i-1][_k][0]
            else:
                if j == 0:
                    memo_ls[i][_k][1] += memo_ls[i-1][_k][1] + memo_ls[i - 1][_k][0]
                else:
                    memo_ls[i][_k+1][1] += memo_ls[i-1][_k][1] + memo_ls[i-1][_k][0]
print(sum(memo_ls[-1][k]))

Measured memory_bytes: 40304
#include<iostream>
#include<vector>
#include<set>

int main(void){
    int n;
    long long k;
    std::set<int> b;
    std::cin >> n >> k;
    std::vector<int> a(n), t(n);
    for(int i = 0; i < n; i++){
	std::cin >> a[i];
	a[i]--;
    }
    int time = 0;
    int cur = 0;
    t[cur] = 0;
    b.insert(cur);
    while(true){
	cur = a[cur];
	time++;
	if(b.find(cur) != b.end()){
	    break;
	}else{
	    t[cur] = time;
	    b.insert(cur);
	}
    }

    std::vector<int> c;
    int start = cur;
    while(true){
	c.push_back(cur);
	cur = a[cur];
	if(cur == start){
	    break;
	}
    }
    int ans;

    if(k < t[start]){
	ans = 0;
	for(int i = 0; i < k; i++){
	    ans = a[ans];
	}
    }else{
	ans = c[(k - t[start]) % c.size()];
    }
    std::cout << ++ans << std::endl;

    return 0;
}



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

int main() {
  
  int N, K; cin >> N >> K; int ans = 0;
  
  vector<bool> vec(N, false);
  
  for (int i = 0; i < K; i++) {
    
    int d; cin >> d;
    
    for (int j = 0; j < d; j++) {
      
      int A; cin >> A;
      
      vec[A - 1] = true;
      
    }
    
  }
  
  for (int i = 0; i < N; i++) {
    
    if (vec[i]) continue;
    
    ans++;
    
  }
  
  cout << ans << endl;
  
}

Measured memory_bytes: 3644
#include<stdio.h>
int main(){
	int x,y,d,r;
	double f;
	scanf("%d %d",&x,&y);
	d=x/y;
	r=x%y;
	f=(double)x/y;
	printf("%d %d %lf\n",d,r,f);
return 0;
}

Measured memory_bytes: 2652
N, A, B = gets.chomp.split.map(&:to_i)
hps = []
N.times{ hps << gets.chomp.to_i }
additional_damage = A - B
times = (hps.max/A)..[(hps.max/B+1),(hps.max/(B+additional_damage/N)).ceil+N].min
answer = times.bsearch do |t|
  additional_times = 0
  hps.each do |hp|
    additional_times += [hp - (B * t), 0].max.fdiv(additional_damage).ceil
  end
  additional_times <= t
end
puts answer

Measured memory_bytes: 3068
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())
#define ALL(x) (x).begin(),(x).end()
const long long MOD = 1000000007;
const long long INF = 1LL << 60;

int main(){
	int N;
	cin >> N;
	vector<int> A(N);
	vector<int> B(N);
	vector<int> C(N - 1);
	rep(i, N)cin >> A[i];
	rep(i, N)cin >> B[i];
	rep(i, N - 1)cin >> C[i];
	
	int sum = 0;
	
	rep(i, N){
		sum += B[i];
		if(i != N - 1 && A[i + 1] == A[i] + 1){
			sum += C[A[i] - 1];
		}
	}
	
	cout << sum << endl;
}

Measured memory_bytes: 256
import sys
from collections import deque

input = sys.stdin.readline

def main():    
    for i in range(N-1):
        a, b, c = map(int, input().split())
        a -= 1; b -= 1
        g[a].append((b, c))
        g[b].append((a, c))
        
    Q, K = map(int, input().split())
    K -= 1
        
    q = deque([(K, 0, -1)])

    while q:
        v, c, p = q.popleft()
        
        dist[v] = c
        for u, d in g[v]:
            if u == p: continue
            q.append((u, c+d, v))
    
    for i in range(Q):
        x, y = map(int, input().split())
        print(dist[x-1]+dist[y-1])
 
if __name__ == '__main__':
    N = int(input())
    g = [[] for i in range(N)]
    dist = [0] * N
    main()

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

using namespace std;
#define all(x) (x).begin(), (x).end()
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<vector<bool>> vvb;
typedef vector<vector<int>> vvi;
typedef vector<vector<long long>> vvl;
typedef pair<int,int> pii;
typedef long long ll;
void debugF(ostream &os) {os << endl;}
template <typename Head, typename... Tail>
void debugF(ostream &os, Head H, Tail... T) { os << " " << H; debugF(os, T...); }
#define debug(...) cout << "[" << #__VA_ARGS__ << "]:", debugF(cout, __VA_ARGS__)
template<typename T> istream &operator>>(istream &is, vector<T> &v){ for (auto &x : v) is >> x; return is; }
template<typename T> ostream &operator<<(ostream &os, vector<T> &v){ for(int i = 0; i < v.size(); os << (i>0 ? " ":"") << v[i++]); return os;}

vi dx = {0,1,0,-1};
vi dy = {1,0,-1,0};
vvi dist;
vvi rem;
int n;
void dfs(int x, int y){
    for(int j=0;j<4;j++){
        int xx = x + dx[j];
        int yy = y + dy[j];
        if(xx < 0 || xx >= n || yy < 0 || yy >= n) continue;
        if(dist[xx][yy] > dist[x][y] + (1-rem[xx][yy])){
            dist[xx][yy] = dist[x][y] + (1-rem[xx][yy]);
            dfs(xx,yy);
        }
    }
};

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> n;
    int i, j;
    dist = vvi(n, vi(n));
    rem = vvi(n, vi(n,0));
    for(i=0;i<n;i++){
        for(j=0;j<n;j++){
            int dd = min({i, n-1-i, j, n-1-j});
            dd++;
            dist[i][j] = dd;
        }
    }
    int ans = 0;
    for(i=0;i<n*n;i++){
        int pos; cin >> pos;
        pos--;
        int r,c;
        r = (pos)/n;
        c = (pos)%n;
        ans += (dist[r][c] - 1);
        rem[r][c] = 1;
        dist[r][c]--;
        dfs(r,c);
    }
    cout << ans << "\n";

    return 0;
}

Measured memory_bytes: 20568
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
#define all(v) v.begin(), v.end()
#define sz(v) v.size()
#define INF 100000000000000 //10^14
template <typename T>
bool chmax(T &a, const T& b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <typename T>
bool chmin(T &a, const T& b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

int main()
{
    ll N;
    cin >> N;
    vector<ll> A(N);
    rep(i, N) cin >> A.at(i);
    sort(all(A));
    ll p = N;
    rep(i, N){
      if(A.at(i) > 0){
        p = i;
        break;
      }
    }
    ll M = 0;
    M += A.at(N-1);
    M -= A.at(0);
    rep(i, N-2){
      if(i+1 >= p){
        M += A.at(i+1);
      }
      else{
        M -= A.at(i+1);
      }
    }
    cout << M << endl;
    ll x = A.at(0);
    if(p == 0){
      p++;
    }
    if(p == N){
      p--;
    }
    rep2(j, p, N-1){
      cout << x << " " << A.at(j) << endl;
      x -= A.at(j);
    }
    ll y = A.at(N-1);
    rep2(i, 1, p){
      cout << y << " " << A.at(i) << endl;
      y -= A.at(i);
    }
    cout << y << " " << x << endl;
}

Measured memory_bytes: 4048
#include <iostream>
#include <string>
using namespace std;
int main(void){
    // Your code here!
    
    int n, k;
    cin >> n >> k;
    string s;
    cin >> s;
    
    for(int i = 0; i < s.size(); i ++){
        cout << (char)((i == k-1) ? (s[i]+'a'-'A') : s[i]);
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define rrep(i,n) for(int i=(n)-1; i>=0; i--)
#define FOR(i,a,b) for(int i=(a); i<(b); i++)
#define RFOR(i,a,b) for(int i=(b-1); i>=(a); i--)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define pb push_back
using ll = long long;
using D = double;
using LD = long double;
using P = pair<int, int>;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int main(){
    int d,t,s; cin >> d >> t >> s;
    if(t*s >= d) cout << "Yes" << endl;
    else cout << "No" << endl;
}


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

using namespace std;
 
/*int BinarySearch(vector <int>v3,int n, int x){
      int low=0;
      int high=(n-1);
      while(low<=high){
         int mid=low+(high-low)/2;
          if(x==v3[mid]) return mid;
          if(x<v3[mid]) high=mid-1;
          if(x>v3[mid]) low=mid+1;
      }
    return -1;
}*/
/*long long int Power10(int q){
    long long int o,t=1;
    for(o=0;o<q;o++)
        {t*=10;}
    return t;
}*/
/*int digit(char ch){
    return(ch - '0');
}*/
/*int Search(vector<long long int> v1,long long int x1){
    long long int j;
    for(j=0;j<v1.size();j++){
        if(x1==v1[j]){return j;}
        else{continue;}
    }
    return -1;
}*/
/*int Search2(long long int v[],long long int x,long long int n){
    long long int i;
    for(i=0;i<n;i++){
        if(x==v[i]){return 1;}
        else{continue;}
    }
    return -1;
}*/
typedef map<char,int> mapsi;
int main(){
    long long int m,c=0,count=0,p=0,s=0,j,a=0,b=0,i,e,r=0,g,pts,y,t,d=0,q,x,n,h,mr=17,ms=17,w,l,k,cnt=500,countA=0,sum,sumt,countB=0,countC=0,a1,a2,countD=0;
    long long int min[100000];
    set<long long int> s2;
    vector<long long int> v;
    vector<long long int> v2;
    string str1,str2;
    mapsi mp;
    cin>>n>>k>>x>>y;
    if(n<=k){cout<<x*n;}
    if(n>k){cout<<(n-k)*y+k*x;}
    return 0;
}


Measured memory_bytes: 256
#include <set>
#include <iostream>
#include <cstdio>
#define REP(i,n) for(int i=0; i<(int)(n); i++)

#define FOR(i,c) for(__typeof((c).begin()) i=(c).begin(); i!=(c).end(); i++)

#define print(x) printf("%d\n",x)

using namespace std;

char b[512][512];
int w, h;
char memo[4][500][500];

#define LEFT (0)
#define RIGHT (1)
#define DOWN (2)
#define UP (3)

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


char iter(int y, int x, int d){
  if(y >= h) return '.';
  if(x >= w) return '.';
  if(y <  0) return '.';
  if(x <  0) return '.';

  if(memo[d][y][x]) return memo[d][y][x];
  if(b[y][x] != '.') return b[y][x];

  return memo[d][y][x] = iter(y + dy[d], x + dx[d], d);
}
void update(int y, int x, int d){
  if(memo[d][y][x] == 0 && b[y][x] == '.')
    memo[d][y][x] = iter(y + dy[d], x + dx[d], d);
}

void debug(){
  REP(i,h) puts(b[i]); puts("");
}

int main(){
  scanf("%d%d", &h, &w);

  REP(i, h) scanf("%s", b[i]);
  
  REP(d, 4) REP(i, h) REP(j, w) if(b[i][j] == '.'){
    if(memo[d][i][j] == 0){
      update(i, j, d);
    }
  }

  int ans = 0;
  bool ok = true;

  while(ok){
    ok = false;

    REP(i,h) REP(j,w) if(b[i][j] == '.'){
      set<int> deld;
      
      REP(d, 4){
	for(int e = d + 1; e < 4; e++){
	  if(memo[d][i][j] != '.' && memo[d][i][j] == memo[e][i][j]){
	    deld.insert(e);
	    deld.insert(d);
	  }
	}
      }
      
      if(deld.size()){
	//printf("%d %d : %c %c %c %c\n", i, j, memo[0][i][j], memo[1][i][j], memo[2][i][j], memo[3][i][j]);
	ok = true;
	FOR(it, deld){
	  int y = i;
	  int x = j;
	  int d = *it;

	  while(true){
	    if(b[y][x] != '.'){
	      b[y][x] = '.';
	      break;
	    }
	    y += dy[d];
	    x += dx[d];
	    if(y >= h) break;
	    if(x >= w) break;
	    if(y <  0) break;
	    if(x <  0) break;
	  }
	}

	REP(d,4){
	  REP(y,h) REP(x,w)
	    memo[d][y][x] = 0;

	  REP(y,h) REP(x,w)
	    update(y,x,d);
	}

	ans += deld.size();

	// debug();
      }
    }

  }

  printf("%d\n", ans);

  return 0;
}

Measured memory_bytes: 2132
def main():
    from math import ceil

    A, B = map(int, input().split())

    la, ra = ceil(A * 12.5), ceil((A + 1) * 12.5)
    lb, rb = B * 10, (B + 1) * 10

    L, R = max(la, lb), min(ra, rb)  # [L,R)

    if L >= R:
        print(-1)
        return

    print(L)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main()
{
    while (true) {
        int N;
        cin >> N;
        if (N == 0) { break; }
        if (N == 1) {
            cin >> N;
            cout << N << endl;
            continue;
        }
        using P = pair<char, ll>;
        auto f = [](const P& p, const ll n) { return P{p.first, p.first == '+' ? p.second + n : p.second * n}; };
        auto conv = [](const P& p1, const P& p2) { return P{p1.first, p1.first == '+' ? p1.second + p2.second : p1.second * p2.second}; };
        stack<P> st;
        for (int i = 0, l = 0; i < N; i++) {
            string s;
            cin >> s;
            for (l = 0; l < s.size() and s[l] == '.'; l++) {}
            for (; l < st.size();) {
                const auto e1 = st.top();
                st.pop();
                const auto e2 = st.top();
                st.pop();
                st.emplace(conv(e2, e1));
            }
            if (isdigit(s[l])) {
                const auto e = st.top();
                st.pop();
                st.emplace(f(e, stoll(s.substr(l, s.size() - l))));
            } else {
                st.push({s[l], s[l] == '+' ? 0LL : 1LL});
            }
        }
        for (; st.size() > 1;) {
            const auto e1 = st.top();
            st.pop();
            const auto e2 = st.top();
            st.pop();
            st.push(conv(e2, e1));
        }
        cout << st.top().second << endl;
    }
    return 0;
}



Measured memory_bytes: 3160
#include <bits/stdc++.h>
using namespace std;
#ifdef __DEBUG__
    void debug_out() { cerr << endl; } 
    template <typename Head, typename... Tail>
    void debug_out(Head H, Tail... T) {cerr << " " << H; debug_out(T...);}
    #define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
    #define debug(...) 
#endif

using ll = long long int;


inline void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); };
template<typename T> inline ostream& operator<<(ostream& os, const vector<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline vector<T> fetch_vec(int sz) { vector<T> ret(sz); for (auto& elem : ret) cin >> elem; return ret; }

int N;
vector<ll> A;
inline void input(){
    fast_io();
    cin >> N;
    A = fetch_vec<ll>(N+1);
}

map< int64_t, int > prime_factor(int64_t n) {
  map< int64_t, int > ret;
  for(int64_t i = 2; i * i <= n; i++) {
    while(n % i == 0) {
      ret[i]++;
      n /= i;
    }
  }
  if(n != 1) ret[n] = 1;
  return ret;
}

vector< bool > prime_table(int n) {
  vector< bool > prime(n + 1, true);
  if(n >= 0) prime[0] = false;
  if(n >= 1) prime[1] = false;
  for(int i = 2; i * i <= n; i++) {
    if(!prime[i]) continue;
    for(int j = i + i; j <= n; j += i) {
      prime[j] = false;
    }
  }
  return prime;
}


bool isok(ll p){
    if(A[0]%p) return false;
    if(p<=N){
        vector<ll> AP(p,0);
        for (int i = 0; i <= N; i++) AP[i%(p-1)] += A[i];
        for (int i = 0; i < p; i++) if(AP[i]%p) return false;
    }
    else{
        for (int i = 0; i <= N; i++) if(A[i]%p) return false;
    }
    return true;
}

inline void chmax(ll &a, ll b){if(a<b) a=b;}

int solve(){
    set<ll> ans;
    reverse(A.begin(),A.end());
    // ll f1 = accumulate(A.begin(),A.end(),0LL);
    // if(f1==0) f1 = abs(A[0]);
    // if(f1!=0){
    //     auto pf = prime_factor(abs(f1));
    //     for(auto [p,c]:pf){
    //         if(isok(p)) ans.insert(p);
    //     }
    // }
    // else{
        auto pt = prime_table(N);        
        for (int i = 2; i <= N; i++)
        {
            if(!pt[i]) continue;
            if(isok(i)) ans.insert(i);
        }

        auto pf = prime_factor(abs(A[N]));
        for(auto [p,c]:pf){
            if(isok(p)) ans.insert(p);
        }
    // }

    for(auto a:ans) cout << a << endl;
    if(ans.empty()) cout << endl;
    return 0;
}   

int main()
{
    input();
    solve();
    return 0;
}


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

using namespace std;

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

	int ans = 0;
	for (int i = 0; i < n; i++)
	{
		cin >> a >> b;
		if (a >= h && b >= w) ans++;
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
import java.util.*;
import java.util.Collections;
import java.util.ArrayList;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);

        String w = sc.next();
        int l = w.length();
        int a = 1;
        ArrayList<String> list = new ArrayList<String>();

        for(int i=0; i<l; i++){
            list.add(String.valueOf((char)w.charAt(i)));
        }

        Collections.sort(list);

        if(l==1){
            System.out.println("No");
        }

        for(int i=1; i<l; i++){
            if(list.get(i).equals(list.get(i-1))){
                a += 1;
            }
            else if(!list.get(i).equals(list.get(i-1))){
                if(a%2!=0){
                    System.out.println("No");
                    break;
                }
                a = 1;
            }

            if(i==l-1){
                System.out.println("Yes");
            }
        }
    }
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
#define P(x) cout << (x) << endl
#define p(x) cout << (x)
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define vv(type, c, m, n, i) vector<vector<type>> c(m, vector<type>(n, i));
#define rep(i,a,n) for(int i=(a), i##_len=(n); i<i##_len; ++i)
#define rrep(i,a,n) for(int i=(a); i>n; --i)
#define len(x) ((int)(x).size())
#define mp make_pair
#define eb emplace_back
typedef long long ll;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<long long> vll;
typedef vector<string> vs;
typedef vector<bool> vb;
bool dp[20][2001];
int main() {
	int n; cin >> n;
	vi v(n); rep(i, 0, n) { cin >> v[i]; dp[i][v[i]] = dp[i][0] = true; }
	rep(j, 1, n) {
		rep(k, 0, 2001){
			dp[j][k] |= dp[j - 1][k];
			if(v[j] < k) dp[j][k] |= dp[j - 1][k - v[j]];
		}
	}
	int m; cin >> m;
	int q;
	rep(i, 0, m) {
		cin >> q;
		P(dp[n - 1][q] ? "yes" : "no");
	}
	return 0;
}

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

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

    int n;
    cin >> n;

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

    for (int i = 1; i < 100002; i++) {
        b[i] += b[i - 1];
    }

    int c = 0, d;
    for (int i = 3; i < 100002; i++) {
        int y = b[i] - b[i - 3];
        if (y > c) {
            c = y;
            d = i;
        }
    }

    cout << c << endl;

    return 0;
}

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

int main(){
  int N,M;
  cin>>N>>M;
  bool AC[100100];
   int WA[100100];
  for(int i=0;i<100100;++i){
    AC[i]=false;
    WA[i]=0;
  }
  
  int p;
  string S;
  int numWA=0;
  for(int i=0;i<M;++i){
    cin>>p>>S;
    if(S=="AC"){AC[p-1]=true;}
    if(AC[p-1]==false && S=="WA"){WA[p-1]++;}
  }
  int numAC=0;
  for(int i=0;i<N+1;++i){
    if(AC[i]==true){
      numAC++;
      numWA+=WA[i];
    }
  }
  
  cout<<numAC<<' '<<numWA<<endl;
}


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

using namespace std;

using ll =  long long;

constexpr int V_MAX = 100000;
constexpr int E_MAX = 100000;

vector<int> outdegree(V_MAX, 0);

class Edge {
    public:
    int to, rev, is_used;
    Edge(int to, int rev, int is_used): to(to), rev(rev), is_used(is_used) {}
};

vector<Edge> graph[V_MAX];

void dfs(int node, int par) {
    for(Edge &child_edge: graph[node]) {
        if(child_edge.to == par) continue;
        if(child_edge.is_used != 1 && graph[child_edge.to][child_edge.rev].is_used != 1) continue;
        dfs(child_edge.to, node);
        if(outdegree[child_edge.to] % 2) {
            child_edge.is_used = 1-child_edge.is_used;
            graph[child_edge.to][child_edge.rev].is_used = 1-graph[child_edge.to][child_edge.rev].is_used;
            outdegree[node] = 1-outdegree[node];
            outdegree[child_edge.to] = 1-outdegree[child_edge.to];
        }
    }
}

namespace kruskal {
    class UnionFind {
        public:
        int n;
        vector<int> par, rank, size;  //親, 深さ, その木の要素数

        UnionFind(int n): n(n) {
            for(int i=0;i<n;++i){
                par.push_back(i);
                rank.push_back(0);
                size.push_back(1);
            }
        }

        //根を求める
        int find(int x){
            if(par[x] == x){
                return x;
            }else{
                int p = find(par[x]);
                size[x] = size[p];
                return par[x] = p;
            }
        }

        //xとyの属する集合の併合
        void unite(int x, int y){
            x = find(x);
            y = find(y);
            if(x == y) return;
            
            size[x] += size[y];
            size[y] = size[x];
            if(rank[x] < rank[y]){
                par[x] = y;
            }else{
                par[y] = x;
                if(rank[x] == rank[y]) rank[x]++;
            }
        }

        //同じ集合に属するか否か
        bool is_same(int x, int y){
            return find(x) == find(y);
        }
    };

    class Edge {
        public:
        int from, to, idx;
        Edge(int from, int to, int idx): from(from), to(to), idx(idx) {}
    };

    vector<kruskal::Edge> edges;

    void kruskal(int V){
        UnionFind uf = UnionFind(V);
        for(Edge &e: edges){
            if(uf.is_same(e.from, e.to)){
                graph[e.from][e.idx].is_used = -1;
                graph[e.to][graph[e.from][e.idx].rev].is_used = 0;
            } else {
                uf.unite(e.from, e.to);
            }
        }
    }
}

int main() {
    int n,m,a,b;
    cin >> n >> m;

    for(int i=0;i<m;++i){
        cin >> a >> b;
        --a; --b;
        graph[a].push_back(Edge(b, graph[b].size(), 1));
        graph[b].push_back(Edge(a, graph[a].size()-1, 0));
        kruskal::edges.push_back(kruskal::Edge(a, b, graph[a].size()-1));
        outdegree[a] = 1-outdegree[a];
    }
    if(m % 2) {
        cout << -1 << endl;
        return 0;
    }

    kruskal::kruskal(n);
    
    dfs(0, -1);

    for(int i=0;i<n;++i) {
        for(Edge e: graph[i]) {
            if(e.is_used) cout << i+1 << " " << e.to+1 << endl;
        }
    }
}


Measured memory_bytes: 13860
from enum import Enum, auto
import sys

class NodeType(Enum):
    LEAF = auto()
    INTERNAL_NODE = auto()
    ROOT = auto()

class BinaryTreeNode():
    def __init__(self, parent=None, left=None, right=None):
        self.parent = parent
        self.left = left
        self.right = right
        self.sibling = None
        self.degree = None
        self.depth = None
        self.height = None
        self.type = None

n = int(input())
nodes = [BinaryTreeNode() for i in range(n)]
for i in range(n):
    id, left, right = list(map(int, input().split(' ')))
    degree = 0
    if left != -1:
        degree += 1
        nodes[id].left = left
        nodes[left].parent = id
        nodes[left].sibling = right
    if right != -1:
        degree += 1
        nodes[id].right = right
        nodes[right].parent = id
        nodes[right].sibling = left
    nodes[id].degree = degree
    if degree == 0:
        nodes[id].type = NodeType.LEAF
    else:
        nodes[id].type = NodeType.INTERNAL_NODE

root = 0
for i in range(n):
    if nodes[i].parent == None:
        root = i
        nodes[i].type = NodeType.ROOT

def set_depth(u, d):
    nodes[u].depth = d
    if nodes[u].left != None: set_depth(nodes[u].left, d+1)
    if nodes[u].right != None: set_depth(nodes[u].right, d+1)

def set_height(u):
    h1, h2 = 0, 0
    if nodes[u].left != None:
        h1 = set_height(nodes[u].left) + 1
    if nodes[u].right != None:
        h2 = set_height(nodes[u].right) + 1
    nodes[u].height = h1 if h1 > h2 else h2
    return nodes[u].height

set_depth(root, 0)
set_height(root)

for i in range(n):
    parent = -1 if nodes[i].parent == None else nodes[i].parent
    sibling = -1 if nodes[i].sibling == None else nodes[i].sibling
    type = ''
    if nodes[i].type == NodeType.INTERNAL_NODE:
        type = 'internal node'
    elif nodes[i].type == NodeType.LEAF:
        type = 'leaf'
    elif nodes[i].type == NodeType.ROOT:
        type = 'root'
    print('node %d: parent = %d, sibling = %d, degree = %d, depth = %d, height = %d,'%(i, parent, sibling, nodes[i].degree, nodes[i].depth, nodes[i].height), type)



Measured memory_bytes: 6356
//#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <iomanip>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <climits>
#include <set>
#include <cassert>

using namespace std;

const int SIZE = 1 << 10;
int pointer = SIZE;
char buffer[SIZE];

char Advance() {
    if (pointer == SIZE) {
        fread(buffer, 1, SIZE, stdin);
        pointer = 0;
    }
    return buffer[pointer++];
}

int Read() {
    int answer = 0, sign = 1;
    char ch = Advance();
    while (!isdigit(ch) && ch != '-')
        ch = Advance();
    if (ch == '-') {
        ch = Advance();
        sign = -1;
    }
    while (isdigit(ch)) {
        answer = answer * 10 + ch - '0';
        ch = Advance();
    }
    return answer * sign;
}

const int BASE = 10;

int cost[BASE][BASE];

void RoyFloyd() {
    for (int i = 0; i < BASE; i++)
        for (int j = 0; j < BASE; j++)
            scanf("%d", &cost[i][j]);
    for (int k = 0; k < BASE; k++)
        for (int i = 0; i < BASE; i++)
            for (int j = 0; j < BASE; j++)
                cost[i][j] = min(cost[i][j], cost[i][k] + cost[k][j]);
}

int main() {
    //freopen("tema.in", "r", stdin);
    //freopen("tema.out", "w", stdout);
    int n, m;
    scanf("%d%d", &n, &m);
    RoyFloyd();
    int answer = 0;
    for (int i = 1; i <= n * m; i++) {
        int x;
        scanf("%d", &x);
        if (x != -1)
            answer += cost[x][1];
    }
    printf("%d\n", answer);
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#include <string>
using namespace std;
int intinput() {
	int x;
	cin >> x;
	return x;
}
vector<int> forintinput(int n) {
	vector<int> x(100000);
	for(int i = 0;i < n;i++) cin >> x[i];
	return x;
}
int main(){
	string s;
	string t;
	cin >> s;
	cin >> t;
	t.erase(t.size() -1);
	if(s == t){
		cout << "Yes" << endl;
	}else{
		cout << "No" << endl;
	}
}

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


public class A
{
	public static void Main()
	{
		string[] args = Console.ReadLine().Split(' ');
		int A = Int32.Parse(args[0]);
		int B = Int32.Parse(args[1]);
		int X = Int32.Parse(args[2]);

		Console.WriteLine(((A <= X) && (X <= A + B)) ? "YES" : "NO");
	}
}





Measured memory_bytes: 13140
#include<stdio.h>
int cmp[100010],r=0,f[10010]={0};
int Ta[110],To[1010],Co[1010],Nt[1010];
void sdfs(int e,int s,int k,int *ta,int *to,int *nt,int *id){
  int i;
  f[s]++;
  for(i=ta[s];i+1;i=nt[i]){
    if(i<e&&k<0&&f[to[i]]<0||i>=e&&k>=0&&!f[to[i]])sdfs(e,to[i],k,ta,to,nt,id);
  }
  k<0?(id[r++]=s):(cmp[s]=k);
}
void scc(int v,int e,int *a,int *b){
  int ta[10010],to[60010],nt[60010],id[10010],i,k;
  for(i=0;i<v;i++)f[i]=ta[i]=-1;
  for(i=0;i<e;i++){
    nt[i  ]=ta[to[i+e]=a[i]];
    nt[i+e]=ta[to[i  ]=b[i]];
    ta[a[i]]=i;
    ta[b[i]]=i+e;
  }
  for(i=k=0;i<v;i++){
    if(f[i]==-1)sdfs(e,i,-1,ta,to,nt,id);
  }
  for(i=r;i;i--){
    if(f[id[i-1]]==0)sdfs(e,id[i-1],id[i-1],ta,to,nt,id);
  }
}
int mca(int v,int e,int k,int *a,int *b,int *c){
  int i,j,t,r,s,p=0,mi[110],q[10010],bk[110]={0};
  for(i=0;i<v;i++)Ta[i]=mi[i]=-1;//??£??\??????????????????
  for(i=0;i<e;i++){
    Nt[i]=Ta[a[i]];
    Co[Ta[a[i]]=i]=c[i];
    bk[a[i]]=bk[To[i]=b[i]]=1;
  }
  for(i=0;i<v;i++)p+=bk[i];
  for(i=0;i<e;i++){//?????????MIN???????±???????
    if(mi[To[i]]==-1||Co[mi[To[i]]]>Co[i])mi[To[i]]=i;
  }
  mi[q[t=0]=k]=-1;
  for(r=1;r-t;t++){
    for(j=Ta[q[t]];j+1;j=Nt[j]){
      if(mi[To[j]]==j){
	q[r++]=To[j];
	s+=Co[j];
      }
    }
  }
  if(r==p)return s;
  for(i=r=0;i<v;i++){
    bk[i]=0;
    for(j=Ta[i];j+1;j=Nt[j]){
      if(mi[b[r]=To[j]]==j)a[r++]=i;
    }
  }
  scc(v,r,a,b);//?????£?????????????§£??§???????????????????????????
  for(i=0;i<v;i++)bk[cmp[i]]++;
  for(i=r=s=0;i<v;i++){
    for(j=Ta[i];j+1;j=Nt[j]){
      if((a[r]=cmp[i])==(b[r]=cmp[To[j]])){
	if(j==mi[To[j]])s+=Co[j];
      }
      else c[r++]=bk[cmp[To[j]]]-1?Co[j]-Co[mi[To[j]]]:Co[j];
    }
  }
  return mca(v,r,k,a,b,c)+s;
}
	 
int main(){
  int n,m,k,i,a[10010],b[10010],c[10010];
  scanf("%d %d %d",&n,&m,&k);
  for(i=0;i<m;i++)scanf("%d %d %d",&a[i],&b[i],&c[i]);
  printf("%d\n",mca(n,m,k,a,b,c));
  return 0;
}

Measured memory_bytes: 688
// Problem : C - Step
// Contest : AtCoder - AtCoder Beginner Contest 176
// URL : https://atcoder.jp/contests/abc176/tasks/abc176_c
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;

/* DEBUGGING */
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define deb(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define deb(x...)
#endif

/* MACROS */ 
typedef long long int ll;
 
typedef pair<int, int> pii;
typedef pair<ll,ll> pll;
 
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;

typedef map<int,int> mii;

#define  ff          first
#define  ss          second
#define  pb          push_back
#define  IOS         ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define  lb          lower_bound
#define  ub          upper_bound
#define  all(x)      (x).begin(), (x).end()
#define  ps(x,y)     fixed<<setprecision(y)<<x
#define  setbit(x)   __builtin_popcountll(x)
#define  rep(i,a,b)  for(int i=a ; i<b ; ++i)
#define  repr(i,a,b) for(int i=a ; i>=b ; --i)

/* CONSTANTS */ 
#define PI 3.141592653589793
const ll MOD = 1e9 + 7;
const ll INF = 1000000000;
const ll MAX_N = 2e5 + 2;

// #define cerr if(false)cerr
/* CODE STARTS HERE */

void solve(){
    int n; cin >> n;
    vi v(n);
    rep(i,0,n) cin >> v[i];
    
    ll sum = 0;
    int mn = v[0];
    
    rep(i,0,n){
        if(v[i] > mn){
            mn = v[i];
        }
        sum += abs(v[i] - mn);
    }
    
    cout << sum;
}

int main(){
    IOS;
    solve();
}

Measured memory_bytes: 3988
#include <iostream>
#include <string>

int main()
{
	std::string str; std::cin >> str;
	std::string ans("YES");
	while(!str.empty())
	{
		if(str.size() < 5)
		{
			ans = "NO";
			break;
		}
		std::string s = str.substr(str.size()-3);
		if(s=="eam")//dream
		{
			if(str.substr(str.size()-5)=="dream") str.erase(str.size()-5, 5);
			else
			{
				ans = "NO";
				break;
			}
		}
		else if(s=="mer")//dreamer
		{
			if(str.size() < 7)
			{
				ans = "NO";
				break;
			}
			if(str.substr(str.size()-7)=="dreamer") str.erase(str.size()-7, 7);
			else
			{
				ans = "NO";
				break;
			}
		}
		else if(s=="ase")//erase
		{
			if(str.substr(str.size()-5)=="erase") str.erase(str.size()-5, 5);
			else
			{
				ans = "NO";
				break;
			}
		}
		else if(s=="ser")//eraser
		{
			if(str.size() < 6)
			{
				ans = "NO";
				break;
			}
			if(str.substr(str.size()-6)=="eraser") str.erase(str.size()-6, 6);
			else
			{
				ans = "NO";
				break;
			}
		}
		else
		{
			ans = "NO";
			break;
		}
	}
	std::cout << ans << std::endl;
	return 0;
}

Measured memory_bytes: 512
// ABC 083

// inputに入力データ全体が入る
function Main(input) {
  input = input.split(" ");
  const N = parseInt(input[0],10);
  const A = parseInt(input[1],10);
  const B = parseInt(input[2],10);

  var arr = new Array() //A以上B以下の数値を一時的に入れる配列

  for(var n=0;n<=N;n++) {
    var tmp = n.toString().split(""); //一桁ごとに抽出
    var number = 0;

    // 抽出した値を一桁ずつ加算
    for(var t=0;t<tmp.length;t++) {
      number += parseInt(tmp[t],10);
    }

    if(number >= A && number <= B) arr.push(n);
  }

  var sum = 0; //合計の値
  for(var a=0;a<arr.length;a++) {
    sum += arr[a];
  }

  console.log(sum);
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 17068
#include<bits/stdc++.h>
using namespace std;
#pragma region atcoder
/*#include <atcoder/all>
using namespace atcoder;
//These are for segment tree
/*int op(int a, int b){return max(a, b);}
int e(){return -1;}
int target;
bool f(int v){ return v < target;}
*/
#pragma endregion
#pragma region macros
using ll = long long;
using vi = vector<int>;
using vs = vector<string>;
using vl = vector<ll>;
using vb = vector<bool>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rrep(i, n) for(int i = n - 1; i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
template<class T>bool chmax(T &a, const T b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T b) { if (b<a) { a=b; return 1; } return 0; }
#pragma endregion
#pragma region debug for var, v, vv
#define debug(var)  do{std::cout << #var << " : ";view(var);}while(0)
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){cout << endl;int cnt = 0;for(const auto& v : vv){cout << cnt << "th : "; view(v); cnt++;} cout << endl;}
#pragma endregion
const ll mod = 1000000007;
const int inf = 1001001001;
const ll INF = 1001001001001001001;
const int MAX = 2000005;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

ll modpow(ll a, ll p){
	ll ret = 1;
	while(p){
		if(p & 1) ret = ret * a % mod;
		a = a * a % mod;
		p >>= 1;
	}
	return ret;
}

int main() {
	cin.tie(0);
   	ios::sync_with_stdio(false);
	ll n; cin >> n;
	ll ans = modpow(10, n);
	ans = ((ans + 3 * mod) - 2 * modpow(9,n))%mod;
	ans += modpow(8, n);
	cout << ans % mod << endl;
} 


Measured memory_bytes: 3656
#include <bits/stdc++.h>
#define rep(i, a, b) for(ll i = ll(a); i < ll(b); i++)
#define rer(i, a, b) for(ll i = ll(a) - 1; i >= ll(b); i--)
#define sz(v) (int)(v).size()
#define pb push_back
#define sc second
#define fr first
#define sor(v) sort(v.begin(),v.end())
#define rev(s) reverse(s.begin(),s.end())
#define lb(vec,a) lower_bound(vec.begin(),vec.end(),a)
#define ub(vec,a) upper_bound(vec.begin(),vec.end(),a)
#define uniq(vec) vec.erase(unique(vec.begin(),vec.end()),vec.end())
using namespace std;
typedef long long int ll;
typedef pair <int, int> P;

const ll MOD=1000000007;
int N;
vector<ll> A;
ll dp[100000][2];
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin>>N;
    A.resize(N);
    rep(i,0,N) cin>>A[i];
    dp[1][0]=abs(A[0]+A[1]);
    dp[1][1]=abs(A[0]-A[1]);
    rep(i,2,N){
        dp[i][0]=max(A[i]+dp[i-1][0], -A[i]+dp[i-1][1]);
        dp[i][1]=max(-A[i]+dp[i-1][0], A[i]+dp[i-1][1]);
    }
    cout <<dp[N-1][0]<<"\n";
}

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

int main()
{
	int A[100][100] = {}, B[100][100] = {};
	long long C[100][100] = {};
	int i, j, k;
	int n, m, l;
	int x;
	cin >> n >> m >> l;
	for (i = 0;i < n;i++)
		for (j = 0;j < m;j++)
			cin >> A[i][j];
	for (j = 0;j < m;j++)
		for (k = 0;k < l;k++)
			cin >> B[j][k];
	for (i = 0;i < n;i++) {
		for (k = 0;k < l;k++) {
			for (j = 0;j < m;j++)
				C[i][k] += A[i][j] * B[j][k];
		}
	}
	for (i = 0;i < n;i++) {
		for (k = 0;k < l;k++) {
			cout << C[i][k];
			if (k != l - 1) cout << ' ';
		}
		cout << endl;
	}
		return 0;
	}


Measured memory_bytes: 3248
#include<iostream>
#include<algorithm>
#include<functional>
#include<vector>
#include<queue>
#include<tuple>

using namespace std;

typedef long long ll;
typedef tuple<ll, int, int> T3;

int N, M;
ll S;

struct Edge {
	int to;
	int fee;
	ll time;
	Edge(int a, int b, ll c) { to = a, fee = b, time = c; }
};

vector<vector<Edge>> E;
pair<ll, ll> ryogae[50 + 10];//量　時

ll d[50][5010];

void djk() {
	for (int i = 0; i < 50; i++)for (int j = 0; j <= 5001; j++)d[i][j] = 1e18;

	priority_queue<T3, vector<T3>, greater<T3>> pq;
	d[0][S > 5000 ? 5001 : S] = 0;
	pq.push(make_tuple(0, 0, S > 5000 ? 5001 : S));
	while (pq.size()) {
		auto nw = pq.top(); pq.pop();
		int pos = get<1>(nw);
		int haveCoins = get<2>(nw);
		if (d[pos][haveCoins] < get<0>(nw))continue;

		for (int i = 0; i < E[pos].size(); i++) {
			int nxt = E[pos][i].to;
			ll fee = E[pos][i].fee;
			ll time = E[pos][i].time;

			if (haveCoins <= 5000) {
				//有限の場合
				if (haveCoins >= fee) {
					//金が足りるのなら
					if (d[nxt][haveCoins - fee] > d[pos][haveCoins] + time) {
						d[nxt][haveCoins - fee] = d[pos][haveCoins] + time;
						pq.push(make_tuple(d[nxt][haveCoins - fee], nxt, haveCoins - fee));
					}
				}

				ll nxtCoins = haveCoins + ryogae[pos].first;//今ここで1回分両替する。
				ll addtime = ryogae[pos].second;
				
				if (nxtCoins <= 5000) {
					if (d[pos][nxtCoins] > d[pos][haveCoins] + addtime) {
						d[pos][nxtCoins] = d[pos][haveCoins] + addtime;
						pq.push(make_tuple(d[pos][nxtCoins], pos, nxtCoins));
					}
				}
				else {
					if (d[pos][5001] > d[pos][haveCoins] + addtime) {
						d[pos][5001] = d[pos][haveCoins] + addtime;
						pq.push(make_tuple(d[pos][5001], pos, 5001));
					}
				}

			}
			else {
				//銀貨をいくら使ってもいい場合
				if (d[nxt][5001] > d[pos][haveCoins] + time) {
					d[nxt][5001] = d[pos][haveCoins] + time;
					pq.push(make_tuple(d[nxt][5001], nxt, 5001));
				}
			}
		}
	}
}

int main() {
	cin >> N >> M >> S;
	E.resize(N);
	for (int i = 0; i < M; i++) {
		int u, v, a;
		ll b;
		cin >> u >> v >> a >> b;
		u--, v--;
		E[u].push_back(Edge(v, a, b));
		E[v].push_back(Edge(u, a, b));
	}

	for (int i = 0; i < N; i++) {
		cin >> ryogae[i].first >> ryogae[i].second;
	}


	djk();

	for (int i = 1; i < N; i++) {
		ll ans = 1e18;
		for (int j = 0; j <= 5001; j++) {
			ans = min(ans, d[i][j]);
		}
		cout << ans << "\n";
	}

	return 0;
}

Measured memory_bytes: 9368
#include <bits/stdc++.h>
using namespace std;
int main(void){
  int A[3],i,ans;
  for(i=0;i<3;i++)  cin>>A[i];
  sort(A,A+3);
  ans=0;
  for(i=0;i<2;i++){
    ans+=abs(A[i+1]-A[i]);
  }
  cout<<ans;
}


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

 public class Main{
// taking inputs
static BufferedReader s1;
static BufferedWriter out;
static String read() throws IOException{String line="";while(line.length()==0){line=s1.readLine();continue;}return line;}
static int int_v (String s1){return Integer.parseInt(s1);}
static long long_v(String s1){return Long.parseLong(s1);}
static int[] int_arr() throws IOException{String[] a=read().split(" ");int[] b=new int[a.length];for(int i=0;i<a.length;i++){b[i]=int_v(a[i]);}return b;}
static long[] long_arr() throws IOException{String[] a=read().split(" ");long[] b=new long[a.length];for(int i=0;i<a.length;i++){b[i]=long_v(a[i]);}return b;}
static void assign(){s1=new BufferedReader(new InputStreamReader(System.in));out=new BufferedWriter(new OutputStreamWriter(System.out));}
static long Modpow(long a,long p,long m){long res=1;while(p>0){if((p&1)!=0){res=(res*a)%m;}p >>=1;a=(a*a)%m;}return res;}
static long Modmul(long a,long b,long m){return ((a%m)*(b%m))%m;}
static long ModInv(long a,long m){return Modpow(a,m-2,m);}
static long nck(int n,int r,long m){if(r>n){return 0l;}return Modmul(f[n],ModInv(Modmul(f[n-r],f[r],m),m),m);}
static long[] f;
static long mod=(long)1e9+7;
//......................................@uthor_Alx..............................................

   public static void main(String[] args) throws  IOException{
	        		  assign();
	        		  	int n=int_v(read());
	        		  	Map<String,Integer> map=new HashMap<>();
	        		  	map.put("AC",0);
	        		  	map.put("WA",0);
	        		  	map.put("TLE",0);
	        		  	map.put("RE",0);
	        		  	for(int i=0;i<n;i++){
	        		  		String s=read();
	        		  		map.put(s,map.getOrDefault(s,0)+1);
	        		  	}
	        		  	out.write("AC x "+map.get("AC")+"\n");
	        		  	out.write("WA x "+map.get("WA")+"\n");
	        		  	out.write("TLE x "+map.get("TLE")+"\n");
	        		  	out.write("RE x "+map.get("RE")+"\n");
	        		  	
                      	out.flush();
	        		 
	}
}
	       


Measured memory_bytes: 44736
#if loc||local
#define _GLIBCXX_DEBUG
#endif

#include<bits/stdc++.h>
using namespace std;

#define rep(i,n) for(ll i=0;i<(n);++i)
using ll = int_fast64_t;
using pll = pair<ll,ll>;
constexpr ll INF = 1LL<<60;
constexpr ll MOD = 1e9+7;
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;}
#if loc||local
template<class T>void dump(T&& t){cerr<<t<<endl;}
template<class T,class... Ts> void dump(T&& h, Ts&&... t){cerr<<h<<", ";dump(forward<Ts>(t)...);}
#else
void dump(){}
template<class T,class... Ts> void dump(T&& h, Ts&&... t){}
#endif
template<class T> istream &operator>>(istream&is,vector<T>&v){for(auto &elemnt:v)is>>elemnt;return is;}
template<class T,class U> istream &operator>>(istream&is,pair<T,U>&p){is>>p.first>>p.second;return is;}
template<class T> ostream &operator<<(ostream& os,vector<T>const& v){for(auto const& vi:v)os<<vi<<" ";return os;}
template<class T,class U> ostream &operator<<(ostream& os,pair<T,U>const& p){os<<p.first<<","<<p.second;return os;}
template<class T>vector<T> vec(size_t a){return vector<T>(a);}
template<class T, class... Ts>auto vec(size_t a, Ts... ts){return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...));}

signed main(){

  ll k;
  cin>>k;

  ll x = 7;
  int ans = 1;
  ll limit = 1e7;
  bool f = false;
  while(limit--){
    x %= k;
    if(x==0){f=true;break;}
    x *= 10;
    x += 7;
    ans++;
  }
  if(f)cout<<(ans)<<endl;
  else cout<< -1 <<endl;

}

Measured memory_bytes: 3628
N = int(input())
S = input()
L = len(S)

listr = []
listg = []
listb = []
listc = [0]*L
ans = 0

for i in range(L):
    if(S[i] == "R"):
        listr.append(i)
        listc[i] = 0
    elif(S[i] == "G"):
        listg.append(i)
        listc[i] = 1
    else:
        listb.append(i)
        listc[i] = 2
if(listr == [] or listg == [] or listb == []):
    print(0)
else:
    for i in listr:
        for j in listg:
            div = abs(j - i)
            ans += len(listb)
            mi = min(i,j) - div
            ma = max(i,j) + div
            if(div%2 == 0):
                k = min(i,j) + div//2
                if(listc[k] == 2):
                    ans -= 1
                if(mi >= 0):
                    if(listc[mi] == 2):
                        ans -= 1
                if(ma < L):
                    if(listc[ma] == 2):
                        ans -= 1
            else:
                if(mi >= 0):
                    if(listc[mi] == 2):
                        ans -= 1
                if(ma < L):
                    if(listc[ma] == 2):
                        ans -= 1
    print(ans)

Measured memory_bytes: 9280
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for (int i = 0; i< (n); ++i)
const long long INF = 1LL<<58;

// aを常に小さい値にする　大きい値にする
template<class T> bool chmin(T &a, T b){
    if(a>b) {
        a = b;
        return true;
    }
    return false;

}
template<class T> void chmax(T &a, T b){ if(a<b) a = b; }

// 二分探索 前方のindexを返すもの（自分自身を含む） 前方: -INF側のこと
template<class T> int former(const vector<T> &v, T x){
    return upper_bound(v.begin(), v.end(), x) - v.begin() -1; // upper_bound : keyより大きい要素の内の一番左側のイテレータを返す
}
// 二分探索 後方のindexを返すもの（自分自身を含む）後方: INF側のこと
template<class T> int latter(const vector<T> &v, T x){
    return lower_bound(v.begin(), v.end(), x) - v.begin(); // lower_bound : key以上の要素の内の一番左側のイテレータを返す
}

/*
 *
 * */

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

    double res = N * 2 * 3.14159265;
    cout << res << endl;
}

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

int main(){
  int N;
  cin >> N;
  vector<int> d(N);
  for (int i =0;i<N;i++){
  cin >> d.at(i);
  }
  
  int count = 0;
  for (int i =0;i<N;i++){
    for (int j=0;j<N;j++){
      count += d.at(i)*d.at(j);
    }
    
  }
  for(int i=0;i<N;i++){
      count -= d.at(i)*d.at(i);
    }
  cout << count/2 << endl;
}

Measured memory_bytes: 256
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

import numpy as np
import time
import random
start = time.time()
D = int(input())
Cs = np.array(list(mapint()))
Ss = np.array([list(mapint()) for _ in range(D)], dtype=np.float64)
last = np.zeros(26, dtype=np.float64)
last += D

lis = []
for i in range(D):
    last_2 = last-i
    last_2.astype(np.float64)
    arr = Ss[i] + Cs*last_2
    idx = np.argmax(arr)
    last[idx] = i+1
    lis.append(idx+1)

def check(Ts):
    last_day = np.zeros(26)
    sati = 0
    for i in range(D):
        t = Ts[i]-1
        sati += Ss[i][t]
        last_day[t] = i+1
        sati += sum((last_day-(i+1))*Cs)
    return sati

now = check(lis)
while time.time()-start<1.7:
    lis_2 = lis[:]
    for i in range(2):
        num = random.randint(1, 26)
        num2 = random.randint(0, 364)
        if num==num2:
            continue
        lis_2[num2] = num
    nx = check(lis_2)
    if nx>now:
        lis = lis_2
        now = nx

for d in lis:
    print(d)

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

bool formula(string& s, unsigned int& p)
{
  if (s[p] == 'T') {
    ++p;
    return true;
  } else if (s[p] == 'F') {
    ++p;
    return false;
  } else if (s[p] == '-') {
    ++p;
    return !formula(s, p);
  } else if (s[p] == '(') {
    ++p;
    bool lhs = formula(s, p);
    if (s[p] == '*') {
      ++p;
      bool rhs = formula(s, p);
      ++p;
      return lhs && rhs;
    } else if (s[p] == '+') {
      ++p;
      bool rhs = formula(s, p);
      ++p;
      return lhs || rhs;
    } else {
      p += 2;
      bool rhs = formula(s, p);
      ++p;
      if (lhs && !rhs)
	return false;
      return true;
    }
  }
}

bool equation(string& s, unsigned int& p)
{
  bool lhs = formula(s, p);
  ++p;
  bool rhs = formula(s, p);
  if (lhs == rhs)
    return true;
  return false;
}

int main()
{
  string s;
  while (cin >> s) {
    if (s == "#")
      break;

    bool ans = true;
    for (int S = 0; S < (1 << 11); ++S) {
      string t = s;
      for (unsigned int j = 0; j < t.size(); ++j) {
	if ('a' <= t[j] && t[j] <= 'k') {
	  if (S & (1 << (t[j] - 'a')))
	    t[j] = 'T';
	  else
	    t[j] = 'F';
	}
      }
      
      unsigned int p = 0;
      if (!equation(t, p))
	ans = false;
    }

    if (ans)
      cout << "YES" << endl;
    else
      cout << "NO" << endl;
  }
  return 0;
}

Measured memory_bytes: 928
#include<bits/stdc++.h> 
#define LL long long
LL S;
int x1,y2;

int main()
{
	int i;
  scanf("%lld",&S);
  int x1=sqrt(S),y2=S/x1;
  if((LL)x1*x1==S) printf("0 0 %d 0 0 %d\n",x1,x1);
  else printf("0 0 %d %d %d %d",x1+1,1,-S+(LL)(x1+1)*(x1+1),x1+1);
}

Measured memory_bytes: 256