akhauriyash/Code-Regression huggingface dataset:
#include <map>
#include <set>
#include <cmath>
#include <ctime>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#define ci cin
#define co cout
#define ed endl
#define vc vector
#define sr string
#define pb push_back
#define st(a,n) sort(a,a+n)
#define ms(a) memset(a,0,sizeof(a))
#define fr(i,k,n) for(int i=k;i<=n;++i)
#define FR(i,n,k) for(int i=n;i>=k;--i)
#define inf 0x3f3f3f3f
#define exp 1e-6
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
const int mod =1e9+7;
const int maxn = 2e5+10;
int main()
{
    int n;
    scanf("%d",&n);
    ll ans=0,mx=1000000010;
    int flag=1;
    while(n--)
    {
        ll a,b;
        scanf("%lld%lld",&a,&b);
        if(a!=b) flag=0;
        ans+=a;
        if(a>b) mx=min(mx,b);
    }
    if(flag) co<<0<<ed;
    else co<<ans-mx<<ed;
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <string>
#include <iostream>
using namespace std;
int n;
string s;
int main(){
    scanf("%d",&n);
    cin>>s; 
    if (n&1) {
        printf("No\n");
        return 0;
    }

    for (int x=0;x<(n>>1);x++){
        if (s[x]!=s[x+(n>>1)]){
            printf("No\n");
            return 0;
        }
    }

    printf("Yes\n");
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int c = sc.nextInt();
        int[] b = new int[m];
        int[][] a = new int[n][m];
        for (int i = 0; i < m; i++) {
            b[i] = sc.nextInt();
        }
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                a[i][j] = sc.nextInt();
            }
        }
        int count = 0;
        for (int i = 0; i < n; i++) {
            int sum = 0;
            for (int j = 0; j < m; j++) {
                sum += a[i][j] * b[j];
            }
            sum += c;
            if (sum > 0) {
                count++;
            }
        }
        System.out.println(count);
    }

}


Measured memory_bytes: 23124
process.stdin.on('data', function(chunk) {
  var inputs = chunk.toString().trim().split(' ');
  var a = Number(inputs[0]);
  var b = Number(inputs[1]);
  if(a < b){
console.log('a < b');
  }else if (a > b){
console.log('a > b');
  }else {
console.log('a == b')
  }
  // ????????????????????????
});
process.stdin.resume();
process.stdin.setEncoding('utf8');

Measured memory_bytes: 15520
/*
    飲んだ魔剤で家が建つ。
    created at: 2020-05-10 20:53:28
*/

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

#define all(x) (x).begin(),(x).end()
#define MOD 1000000007
#define INF 1000000000

int main()
{
    string s, t;
    cin >> s >> t;

    int n = s.length();
    int ok = 1;
    for (int i = 0; i < n; i++) {
        if (s[i] != t[i]) ok = 0;
    }

    if (ok) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}


Measured memory_bytes: 3628
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Main main = new Main();
		main.run();
	}

	void run() {
		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();

		int[] A = new int[N];

		int ans=0;
		for (int i = 0; i < N; i++) {
			ans += sc.nextInt()-1;
		}

		System.out.println(ans);


	}

	//以下テンプレート

	public static int[] extgcd(int a, int b) {

		int x0 = 1;
		int x1 = 0;

		int y0 = 0;
		int y1 = 1;

		while (b != 0) {
			int q = a / b;
			int r = a % b;

			int x2 = x0 - q * x1;
			int y2 = y0 - q * y1;

			a = b;
			b = r;

			x0 = x1;
			x1 = x2;

			y0 = y1;
			y1 = y2;
		}

		return new int[] { a, x0, y0 };

	}

	static int gcd(int a, int b) {

		if (b == 0)
			return a;

		if (a < b) {
			int t = a;
			a = b;
			b = t;
		}

		return gcd(b, a % b);

	}

	static int lcm(int a, int b) {
		return a * b / gcd(a, b);
	}

	static void swap(int[] a) {
		int t;

		t = a[0];
		a[0] = a[1];
		a[1] = t;

		return;
	}

	static <T> void output(List<T> list) {

		for (int i = 0; i < list.size(); i++) {
			System.out.print(list.get(i));

			if (i != list.size() - 1) {
				System.out.print(" ");
			} else {
				nl();
			}
		}

	}

	static void output(String[][] str) {

		for (int i = 0; i < str.length; i++) {
			for (int j = 0; j < str[i].length; j++) {
				print(str[i][j]);
			}

			nl();
		}

	}

	static void output(boolean flg, String Yes, String No) {

		if (flg) {
			pln(Yes);
		} else {
			pln(No);
		}

	}

	static void output(String[][] str, int digit) {

		String dig = "%" + String.valueOf(digit) + "s";

		for (int i = 0; i < str.length; i++) {
			for (int j = 0; j < str[i].length; j++) {
				System.out.printf(dig, str[i][j]);
			}
			nl();
		}

	}

	static void pln(String str) {
		System.out.println(str);
	}

	static void pln(int x) {
		System.out.println(x);
	}

	static void print(String str) {
		System.out.print(str);
	}

	static void print(int x) {
		System.out.print(x);
	}

	static void print(String str, int times) {
		for (int i = 0; i < times; i++) {
			print(str);
		}
	}

	static void print(int x, int times) {
		for (int i = 0; i < times; i++) {
			print(x);
		}
	}

	static void nl() {
		System.out.println();
	}

}


Measured memory_bytes: 25424
#include<bits/stdc++.h>
#define ll long long int
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL);
using namespace std;
ll dp[3]={0};
int main()
{
    fast;
    ll n,i,j,sum=0,k;
    cin>>n;
    for(i=0;i<n;i++)
    {
        ll z[3]={0},nw[3]={0};
        for(j=0;j<3;j++)
        {
            cin>>z[j];
        }
        for(j=0;j<3;++j)
        {
            for(k=0;k<3;++k)
            {
                if(j!=k)
                nw[k]=max(nw[k],dp[j]+z[k]);
            }
        }
        for(j=0;j<3;j++)
        dp[j]=nw[j];
    }
    cout<<max(dp[0],max(dp[1],dp[2]));
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<cmath>
#include<algorithm>
#include<functional>
#include<numeric>
#include<queue>
#include<stack>
#include<map>
#include<unordered_map>
#include<set>
#include<bitset>
#include<random>

#pragma region
using namespace std;
#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define rep(i,n) FOR(i,0LL,n)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define rrep(i,n) RFOR(i,0LL,n)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define COUNT(a,y,x) upper_bound(all(a), y) - lower_bound(all(a), x)
#define UNIQUE(a) sort(all(a)); a.erase(unique(all(a)), a.end())
#define pb push_back
typedef long long int ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef vector<string> vs;
typedef map<ll, ll> MAP;
const ll inf = 1LL << 61;
const ll mod = 1000000007LL;
//const ll mod = 998244353LL;

ll n = 0, m = 0, ans = 0, tmp = 0, ma = -inf, mi = inf;
string s;
bool ok;
ll dx[9] = { 0,1,0,-1,0,1,1,-1,-1 }, dy[9] = { 0,0,1,0,-1,1,-1,1,-1 };
#define endl '\n'
#pragma endregion
#define MAX 222222





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


  cin >> n;
  vll v, a, b;
  rep(i, n) {
    cin >> tmp;
    v.pb(tmp);
  }
  sort(rall(v));
  b.pb(v[n - 1]);
  ans = v[0] - v[n - 1];
  FOR(i, 1, n - 1) {
    if (v[i] > 0) {
      a.pb(v[i]);
      ans += v[i];
    }
    else {
      b.pb(v[i]);
      ans -= v[i];
    }
  }
  tmp = v[0];
  cout << ans << endl;
  ll cur = b[0];
  rep(i, a.size()) {
    cout << cur << " " << a[i] << endl;
    cur -= a[i];
  }
  cout << tmp << " " << cur << endl;
  cur = tmp - cur;
  FOR(i, 1, b.size()) {
    cout << cur << " " << b[i] << endl;
    cur -= b[i];
  }
  

  return 0;
}

Measured memory_bytes: 4340
nim,mike = map(int,input().split())
a = set()
b = set()
for i in range(mike):
    a_,b_ = map(int,input().split())
    if a_ == 1:
        a.add(b_)
    if b_ == nim:
        b.add(a_)
print("POSSIBLE" if a&b else "IMPOSSIBLE")

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

ll invmod(ll p) {
	ll q = base-2, r = 1;
	while (q) {
		if (q&1) r = r*p%base;
		p = p*p%base;
		q >>= 1;
	}
	return r;
}

void dfs(int v, int p, vector<vector<int>> &edge, vector<int> &cnt_c) {
	for (int i = 0; i < edge[v].size(); ++i) {
		int nxt = edge[v][i];
		if (nxt == p) continue;
		++cnt_c[v];
		dfs(nxt, v, edge, cnt_c);
		cnt_c[v] += cnt_c[nxt];
	}
}

void dfs2(int v, int p, vector<vector<int>> &edge, vector<ll> &pat,
		vector<int> &cnt_c, vector<ll> &fact, vector<ll> &invfact) {
	pat[v] = 1;
	int cnt = cnt_c[v];
	for (int i = 0; i < edge[v].size(); ++i) {
		int nxt = edge[v][i];
		if (nxt == p) continue;
		dfs2(nxt, v, edge, pat, cnt_c, fact, invfact);
		pat[v] = pat[v]*pat[nxt]%base;
		int ncnt = cnt_c[nxt]+1;
		pat[v] = pat[v]*fact[cnt]%base*invfact[cnt-ncnt]%base*invfact[ncnt]%base;
		cnt -= ncnt;
	}
}

void dfs3(int v, int p, int n, vector<vector<int>> &edge, vector<ll> &pat,
		vector<int> &cnt_c, vector<ll> &fact, vector<ll> &invfact) {
	for (int i = 0; i < edge[v].size(); ++i) {
		int nxt = edge[v][i];
		if (nxt == p) continue;
		ll pv = pat[v]*invmod(pat[nxt])%base;
		int cnt = n-1, ncnt = cnt_c[nxt]+1;
		pv = pv*invfact[cnt]%base*fact[cnt-ncnt]%base*fact[ncnt]%base;
		int cv = n - cnt_c[nxt] - 1;
		pat[nxt] = pat[nxt]*pv%base;
		pat[nxt] = pat[nxt]*fact[cnt]%base*invfact[cnt-cv]%base*invfact[cv]%base;
		dfs3(nxt, v, n, edge, pat, cnt_c, fact, invfact);
	}
}

int main() {
	int n; cin >> n;
	vector<vector<int>> edge(n, vector<int>());
	for (int i = 0; i < n-1; ++i) {
		int a, b; cin >> a >> b; --a; --b;
		edge[a].emplace_back(b);
		edge[b].emplace_back(a);
	}

	vector<int> cnt_c(n);
	dfs(0, -1, edge, cnt_c);

	vector<ll> fact(n+1), invfact(n+1);
	fact[0] = invfact[0] = 1;
	for (int i = 1; i <= n; ++i) {
		fact[i] = fact[i-1]*i%base;
		invfact[i] = invfact[i-1]*invmod(i)%base;
	}
	vector<ll> pat(n);
	dfs2(0, -1, edge, pat, cnt_c, fact, invfact);
	dfs3(0, -1, n, edge, pat, cnt_c, fact, invfact);

	for (int k = 0; k < n; ++k) {
		cout<< pat[k] << endl;
	}
}

Measured memory_bytes: 19444
n = int(input())
s = input()

nowR = s.count("R")
nowG = s.count("G")
nowB = s.count("B")

ans = 0
for i in range(n-1):
    R = nowR
    G = nowG
    B = nowB
    now = s[i]
    if now == "R":
        R -= 1
    elif now == "G":
        G -= 1
    else:
        B -= 1
    nowR = R
    nowG = G
    nowB = B
    for j in range(i+1,n):
        now2 = s[j]
        if now == "R":
            if now2 == "G":
                G -= 1
                ans += B
                if 2*j-i < n and s[2*j-i] == "B":
                    ans -= 1
            elif now2 == "B":
                B -= 1
                ans += G
                if 2*j-i < n and s[2*j-i] == "G":
                    ans -= 1
        elif now == "G":
            if now2 == "R":
                R -= 1
                ans += B
                if 2*j-i < n and s[2*j-i] == "B":
                    ans -= 1
            elif now2 == "B":
                B -= 1
                ans += R
                if 2*j-i < n and s[2*j-i] == "R":
                    ans -= 1
        elif now == "B":
            if now2 == "G":
                G -= 1
                ans += R
                if 2*j-i < n and s[2*j-i] == "R":
                    ans -= 1
            elif now2 == "R":
                R -= 1
                ans += G
                if 2*j-i < n and s[2*j-i] == "G":
                    ans -= 1
print(ans)

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

class Program {
    static Graph G;

    public struct Graph {
        public HashSet<int>[] points;

        public Graph (int n) {
            points = new HashSet<int>[n];
            for (int i = 0; i < n; i++) {
                points[i] = new HashSet<int> ();
            }
        }

        public void AddLine (int a, int b) {
            points[a].Add (b);
            points[b].Add (a);
        }

        public void AddDirectionalLine (int a, int b) {
            points[a].Add (b);
        }
    }

    static void Main (string[] args) {
        string[] str = Console.ReadLine ().Split (' ');
        int N = int.Parse (str[0]);
        int M = int.Parse (str[1]);
        int[] ans = new int[N];
        G = new Graph (N);
        for (int i = 0; i < M; i++) {
            string[] temp = Console.ReadLine ().Split (' ');
            G.AddLine (int.Parse (temp[0]) - 1, int.Parse (temp[1]) - 1);
        }
        Console.WriteLine ("Yes");
        ans = BFS (G, N, ans);
        for (int i = 1; i < N; i++) {
            Console.WriteLine (ans[i] + 1);
        }
    }

    static int[] BFS (Graph graph, int nodeNum, int[] ans) {
        int[] dist = new int[nodeNum];
        var que = new Queue<int> ();
        for (int i = 0; i < nodeNum; i++) {
            dist[i] = -1;
        }
        dist[0] = 0;
        que.Enqueue (0);

        while (que.Count > 0) {
            int nowPoint = que.Dequeue ();
            foreach (int nextPoint in graph.points[nowPoint]) {
                if (dist[nextPoint] != -1) continue;

                ans[nextPoint] = nowPoint;
                dist[nextPoint] = dist[nowPoint] + 1;
                que.Enqueue (nextPoint);
            }
        }

        return ans;
    }
}
//dotnet run --project test

Measured memory_bytes: 71444
#include<iostream>
using namespace std;
int L[110];
long long int D[110];
int main() {
    int N,X;
    cin >> N >> X;
    for (int i=1; i<=N; i++) cin >> L[i];
    
    for (int i=2; i<=(N+1); i++) {
        if (i==1) D[i]=0;
        else D[i]=D[i-1]+L[i-1];
    }

    int cnt=0;
    for (int i=1; i<=(N+1); i++) {
        if (D[i] <= X) cnt++;
        else break;
    }
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 256
#define LOCAL
#define _USE_MATH_DEFINES
#include <array>
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>
#include <functional>
#include <random>
#include <ctime>

using namespace std;

template <typename A, typename B>
ostream& operator <<(ostream& out, const pair<A, B>& a) {
  out << "(" << a.first << "," << a.second << ")";
  return out;
}
template <typename T, size_t N>
ostream& operator <<(ostream& out, const array<T, N>& a) {
  out << "["; bool first = true;
  for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
  return out;
}
template <typename T>
ostream& operator <<(ostream& out, const vector<T>& a) {
  out << "["; bool first = true;
  for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
  return out;
}
template <typename T, class Cmp>
ostream& operator <<(ostream& out, const set<T, Cmp>& a) {
  out << "{"; bool first = true;
  for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "}";
  return out;
}
template <typename U, typename T, class Cmp>
ostream& operator <<(ostream& out, const map<U, T, Cmp>& a) {
  out << "{"; bool first = true;
  for (auto& p : a) { out << (first ? "" : ", "); out << p.first << ":" << p.second; first = 0;} out << "}";
  return out;
}
#ifdef LOCAL
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
#else
#define trace(...) 42
#endif
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}

typedef long long int64;
typedef pair<int, int> ii;
#define SZ(x) (int)((x).size())
const int INF = 1 << 29;
const int MOD = 1e9 + 7;
mt19937 mrand(random_device{}());
int rnd(int x) { return mrand() % x; }

struct fast_ios {
  fast_ios() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
  };
} fast_ios_;

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> a(n), b(n);
  for (int i = 0; i < n; ++i) {
    cin >> a[i] >> b[i];
  }
  int64 ret = 0;
  for (int i = 0; i < n; ++i) {
    if ((m & a[i]) == a[i]) ret += b[i];
  }
  for (int k = 29; k >= 0; --k) {
    int x = (m >> k) & 1;
    if (x == 0) continue;
    int t = ((m >> k) << k) - 1;
    // trace(k, t);
    int64 cur = 0;
    for (int i = 0; i < n; ++i) {
      if ((t & a[i]) == a[i]) cur += b[i];
    }
    ret = max(ret, cur);
  }
  cout << ret << '\n';
  return 0;
}


Measured memory_bytes: 3672
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
using namespace std;
typedef long long int ll;

int main(){
	string s,t; cin >> s >> t;
	bool ok=true;
	map<char,char> S,T;
	for(int i=0;i<s.size();i++){
		if(S.count(s[i])){
			if(S[s[i]]!=t[i])ok=false;
		}
		if(T.count(t[i])){
			if(T[t[i]]!=s[i])ok=false;
		}
		S[s[i]]=t[i],T[t[i]]=s[i];
	}
	cout << (ok?"Yes":"No") << endl;
}

Measured memory_bytes: 776
N,M = map(int,input().split())
A = list(map(int,input().split()))
BC = [list(map(int,input().split())) for _ in range(M)]

A.sort()
BC.sort(reverse=True,key = lambda x:x[1])

pt,card,index = 0,BC[0][1],0
while True:
    for i in range(BC[index][0]):
        if pt < N:
            A[pt] = max(A[pt],card)
        else:
            break
        pt += 1

    index += 1
    if index < M:
        card = BC[index][1]
    else:
        break

print(sum(A))


Measured memory_bytes: 32964
import java.util.Scanner;
class Main{
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);

        String S = scan.next();
        if(S.equals("zyxwvutsrqponmlkjihgfedcba")){
            System.out.println(-1);
            return;
        }
        boolean used[] = new boolean[26];
        char alpha[] = new char[26];
        alpha[0]='a';
        for(int i=0;i<25;++i)alpha[i+1]=(char)(alpha[i]+1);
        if(S.length()==26){
            for(int i=24;i>=0;--i){
                if(S.charAt(i)<S.charAt(i+1)){
                    for(int j=i;j<26;++j)used[S.charAt(j)-'a']=true;
                    for(int j=S.charAt(i)-'a'+1;j<26;++j)if(used[j]){
                        System.out.println(S.substring(0,i)+alpha[j]);
                        return;
                    }
                }
            }
        }else{
            for(int i=0;i<S.length();++i)used[S.charAt(i)-'a']=true;
            for(int i=0;i<26;++i)if(!used[i]){
                S+=alpha[i];
                System.out.println(S);
                return;
            }
        }


    }
}

Measured memory_bytes: 22356
from collections import defaultdict

def main():
    n = int(input())
    d = defaultdict(int)
    for i in range(1, n+1):
        s = str(i)
        a = s[0]
        b = s[-1]
        d[a, b] += 1
    ans = 0
    d_items = list(d.items())
    for (a, b), v in d_items:
        ans += v * d[b,a]
    print(ans)
    
if __name__ == '__main__':
    main()

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

int main() {
	// your code goes here
	
	
	
	string s;
	cin>>s;
	int n;
	n=s.length();
	int ans[n];
	memset(ans,0,sizeof(ans));
	
	int i=0,j=0;
	int cntr=0,cntl=0;
	
	while(i<n){
		
		while( i<s.length() && s[i]=='R'){
			cntr++;
			i++;
		}
	
		j=i;
		
		i--;
	
		while( j<s.length() && s[j]=='L'){
			cntl++;
			j++;
		}
		
		ans[i+1] = (cntl+1)/2 + cntr/2;
		ans[i] = (cntr+1)/2 + cntl/2;
		
		i=j;
		cntr=0;
		cntl=0;
		
	}
	
	for(int i=0;i<n;i++)
		cout<<ans[i]<<" ";
	return 0;
}

Measured memory_bytes: 1024
M=998244353
n,m,k=map(int,input().split())
p,c=[m],[1]
for i in range(1,n):
  p+=[p[-1]*(m-1)%M]
  c+=[c[-1]*(n-i)*pow(i,M-2,M)%M]
print(sum(p[n-i-1]*c[i] for i in range(k+1))%M)

Measured memory_bytes: 25028
import java.util.*;

public class Main{

    static long gcd(long a,long b){
        if(b==0)return a;
        return gcd(b,a%b);
    }

    static long lcm(long a,long b){
        return a/gcd(a,b)*b;
    }
    public static void main(String[] srgs){
        Scanner sc=new Scanner(System.in);

        int n=sc.nextInt(),m=sc.nextInt();
        int[][] in=new int[n][m];
        for(int i=0;i<n;i++){
            for(int j=0;j<m;j++){
                in[i][j]=sc.nextInt();
            }
        }
        for(int i=0;i<n;i++){
            for(int j=0;j<m;j++){
                in[i][j]-=sc.nextInt();
            }
        }
        int[][][] dp=new int[n+1][m+1][7000];
        dp[0][0][0]=1;
        for(int i=0;i<n;i++){
            for(int j=0;j<m;j++){
                for(int k=0;k<7000;k++)if(dp[i][j][k]==1){
                    int a=k,b=in[i][j];
                    int c=Math.abs(a+b);
                    if(c<7000){
                        dp[i+1][j][c]=1;
                        dp[i][j+1][c]=1;
                    }
                    c=Math.abs(a-b);
                    if(c<7000){
                        dp[i+1][j][c]=1;
                        dp[i][j+1][c]=1;
                    }
                }
            }
        }
        for(int i=0;i<7000;i++)if(dp[n][m-1][i]==1){
            System.out.println(i);
            break;
        }
    }
}


Measured memory_bytes: 243724
N = int(input())
A = list(map(int,input().split()))
self_front = [0]*(2*(10**5)+3)
for i in range(N):
    if(i-A[i] >= 0):
        self_front[i-A[i]] += 1
cnt = 0
for i in range(N):
    if(i+A[i] < 2*(10**5)+3):
        cnt += self_front[i+A[i]]
print(cnt)

Measured memory_bytes: 32380
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
typedef long long ll;

using namespace std;

int main()
{
	char c[2][4];
	int ans=0;
	
	cin>>c[0];
	cin>>c[1];
	if(c[0][0]==c[1][2]&&c[0][1]==c[1][1]&&c[0][2]==c[1][0])
	{
		cout<<"YES"<<endl;
	}else{
		cout<<"NO"<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<deque>
#include<stack>
#include<set>
#include<map>
#include<bitset>
#define mod 1000000007
typedef long long ll;
using namespace std;

int main(){
  int n,m; cin >> n >> m;
  int s[10],c[10];
  for(int i=0;i<m;i++) cin >> s[i] >> c[i];
  
  if(n == 1){
    for(int i=0;i<=10;i++){
      bool flag = true;
      for(int j=0;j<m;j++){
        if(c[j] != i) flag = false;
      }
      if(flag){
        cout << i << endl;
        return 0;
      }
    }
    cout << -1 << endl;
    return 0;
  }else if(n == 2){
    for(int i=10;i<100;i++){
      bool flag = true;
      int d1 = i / 10;
      int d2 = i % 10;
      for(int j=0;j<m;j++){
        if(s[j] == 1 && c[j] != d1) flag = false;
        else if(s[j] == 2 && c[j] != d2) flag = false;
      }
      if(flag){
        cout << i << endl;
        return 0;
      }
    }
    cout << -1 << endl;
    return 0;
  }else if(n == 3){
    for(int i=100;i<1000;i++){
      bool flag = true;
      int t = i;
      int d3 = t % 10;
      t /= 10;
      int d2 = t % 10;
      t /= 10;
      int d1 = t;
      for(int j=0;j<m;j++){
        if(s[j] == 1 && c[j] != d1) flag = false;
        else if(s[j] == 2 && c[j] != d2) flag = false;
        else if(s[j] == 3 && c[j] != d3) flag = false;
      }
      if(flag){
        cout << i << endl;
        return 0;
      }
    }
    cout << -1 << endl;
    return 0;
  }
}

Measured memory_bytes: 256
N, W = map(int, input().split())
items = [list(map(int, input().split())) for _ in range(N)]

dp = [[0 for _ in range(W+10)] for _ in range(N+10)]

for i, (item_weight, item_value) in enumerate(items):
    for total_weight in range(W+1):
        if (total_weight-item_weight) >= 0:
            dp[i+1][total_weight] = max(dp[i][total_weight-item_weight] + item_value, dp[i+1][total_weight])
        dp[i+1][total_weight] = max(dp[i+1][total_weight], dp[i][total_weight])
        
print(dp[N][W])

Measured memory_bytes: 181640
#include <bits/stdc++.h>
using namespace std;
#define rep0(i,n) for(int (i) = 0; (i) < (n); ++(i))
#define rrep0(i,n) for(int (i) = (n) - 1; (i) >= 0; --(i))
#define rep1(i,n) for(int (i) = 1; (i) < (n); ++(i))
#define rrep1(i,n) for(int (i) = (n) - 1; (i) >= 1; --(i))
#define nfor(i,a,b) for(int (i) = (a); (i) < (b); ++(i))
#define ll long long
#define mod (1000000007)
#define YES cout << "YES" << endl;
#define Yes cout << "Yes" << endl;
#define yes cout << "yes" << endl;
#define NO cout << "NO" << endl;
#define No cout << "No" << endl;
#define no cout << "no" << endl;
#define all(x) (x).begin(),(x).end()

ll gcd(ll a,ll b){
    if(b == 0) return a;
    return gcd(b,a%b);
}

ll lcm(ll a,ll b){
    ll g = gcd(a,b);
    return a / g * b;
}

int main()
{
    ll n,ans;
    cin >> n;
    vector<ll> p(5);
    rep0(i, 5)cin >> p[i];
    sort(all(p));
    ans = ceil((double)n/p[0]);
    ans += 4;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#ifdef LOCAL_BUILD
#include "pch.h"
#define DLOG(msg) cout << "#" << __LINE__ << ":" << msg << endl;
#define DLOG_V(var) \
  cout << "#" << __LINE__ << ":" << #var << " : " << var << endl;
#else
#include <bits/stdc++.h>
#define DLOG(msg)
#define DLOG_V(var)
#endif
using namespace std;

struct Dict {
  Dict() : buf_(initial_buf_size, list<string>()) {}

  void Insert(const string& s) {
    auto h = StrHash(s) % buf_.size();
    auto& slot = buf_[h];
    if (!FindInternal(slot, s)) {
      slot.push_front(s);
    }
  }

  bool Find(const string& s) const {
    auto h = StrHash(s) % buf_.size();
    auto& slot = buf_[h];
    return FindInternal(slot, s);
  }

 private:
  constexpr static auto initial_buf_size = 1024 * 1024;

  bool FindInternal(const list<string>& slot, const string& s) const {
    return find_if(slot.begin(), slot.end(),
                [&](const string& s0) { return !s0.compare(s); }) != slot.end();
  }

  static size_t StrHash(const string& s) {
    size_t hash = 17;
    for (auto&& c : s) {
      hash += (hash * 23) + static_cast<size_t>(c) * 7;
    }
    return hash;
  }

  vector<list<string>> buf_;
};

int main() {
  int n;
  cin >> n;
  Dict dic;
  for (int i = 0; i < n; ++i) {
    string cmd;
    string str;
    cin >> cmd >> str;
    if (!cmd.compare("insert")) {
      dic.Insert(str);
    } else {
      cout << (dic.Find(str) ? "yes" : "no") << endl;
    }
  }
}

Measured memory_bytes: 44024
//minamoto
#include<bits/stdc++.h>
#define R register
#define inline __inline__ __attribute__((always_inline))
#define fp(i,a,b) for(R int i=(a),I=(b)+1;i<I;++i)
#define fd(i,a,b) for(R int i=(a),I=(b)-1;i>I;--i)
#define go(u) for(int i=head[u],v=e[i].v;i;i=e[i].nx,v=e[i].v)
template<class T>inline bool cmax(T&a,const T&b){return a<b?a=b,1:0;}
template<class T>inline bool cmin(T&a,const T&b){return a>b?a=b,1:0;}
using namespace std;
const int P=1e9+7;
inline void upd(R int &x,R int y){(x+=y)>=P?x-=P:0;}
inline int add(R int x,R int y){return x+y>=P?x+y-P:x+y;}
inline int dec(R int x,R int y){return x-y<0?x-y+P:x-y;}
inline int mul(R int x,R int y){return 1ll*x*y-1ll*x*y/P*P;}
int ksm(R int x,R int y){
	R int res=1;
	for(;y;y>>=1,x=mul(x,x))(y&1)?res=mul(res,x):0;
	return res;
}
const int N=3005;
char s[N];int f[2][N],n,t,res;
int main(){
	scanf("%d%s",&n,s+1);
	f[t=0][1]=1;
	fp(i,1,n-1){
		if(s[i]=='<'){
			f[t^1][1]=0;
			fp(j,2,i+1)f[t^1][j]=add(f[t][j-1],f[t^1][j-1]);
		}
		else{
			f[t^1][i+1]=0;
			fd(j,i,1)f[t^1][j]=add(f[t][j],f[t^1][j+1]);
		}
		t^=1;
	}
	fp(i,1,n)res=add(res,f[t][i]);
	printf("%d\n",res);
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <algorithm>
#include <vector>
#include <cstring>
#include <stack>
#include <cctype>
#include <utility>
#include <map>
#include <string>
#include <climits>
#include <set>
#include <sstream>
#include <utility>
#include <ctime>
#include <cassert>
#include <fstream>
using namespace std;
typedef long long LL;
#define MS(A) memset(A, 0, sizeof(A))
#define MSV(A,a) memset(A, a, sizeof(A))
#define MP make_pair
#define PB push_back
#define getcx getchar_unlocked
#define INF (int(1e9))
#define INFL (LL(1e18))
#define EPS 1e-12
#define chkbit(s, b) (s & (1<<b))
#define setbit(s, b) (s |= (1<<b))
#define chk(a) cerr << endl << #a << " : " << a << endl
#define chk2(a,b) cerr << endl << #a << " : " << a << "\t" << #b << " : " << b << endl
#define chk3(a,b,c) cerr << endl << #a << " : " << a << "\t" << #b << " : " << b << "\t" << #c << " : " << c << endl
#define chk4(a,b,c,d) cerr << endl << #a << " : " << a << "\t" << #b << " : " << b << "\t" << #c << " : " << c << "\t" << #d << " : " << d << endl
#define rep(i, a, n) for(i=a;i<n;i++)
#define rev(i, a, n) for(i=a;i>=n;i--)
#define rep_itr(itr, c) for(itr = (c).begin(); itr != (c).end(); itr++)
#define MOD 1000000007
#define MAX 1000000

int main() {

	int a,b,c,d,e, i;
	cin>>a>>b>>c>>d>>e;

	if(a == 0) {
		cout<<1<<endl;
	}

	if(b == 0) {
		cout<<2<<endl;
	}

		if(c == 0) {
		cout<<3<<endl;
	}
		if(d == 0) {
		cout<<4<<endl;
	}
		if(e == 0) {
		cout<<5<<endl;
	}




	return 0;
}

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

#define MOD 1000000007

void factorize(map<long long, long long> &factor, long long x)
{
    for (long long i = 2; i * i <= x; i++)
    {
        while (x % i == 0)
        {
            x /= i;
            factor[i]++;
        }
        if (x == 1)
        {
            break;
        }
    }
    if (x != 1)
    {
        factor[x]++;
    }
}

long long mul_mod(long long x, long long y, long long mod)
{
    return (x * y) % mod;
}

long long inv_mod(long long x, long long mod)
{
    long long y = mod;
    long long u = 1;
    long long v = 0;
    while (y)
    {
        long long t = x / y;
        x -= t * y;
        swap(x, y);
        u -= t * v;
        swap(u, v);
    }
    u %= mod;
    if (u < 0)
        u += mod;
    return u;
}

long long div_mod(long long x, long long y, long long mod)
{
    return mul_mod(x, inv_mod(y, mod), mod);
}

long long calcPermutation(long long x, long long y, long long mod)
{
    long long ans = 1;
    for (long long i = 0; i < y; i++)
    {
        ans = mul_mod(ans, x - i, mod);
    }
    return ans;
}

long long calcCombination(long long x, long long y, long long mod)
{
    if ((x - y) < y)
    {
        y = x - y;
    }
    long long ans = calcPermutation(x, y, mod);
    while (y > 0)
    {
        ans = div_mod(ans, y, mod);
        y--;
    }
    return ans;
}

long long calcPatarn(long long fact, long long n, long long mod)
{
    long long ans;
    if (fact > 0)
    {
        ans = calcCombination(fact + (n - 1), fact, mod);
    }
    else
    {
        ans = 1;
    }
    return ans;
}

int main()
{
    long long N, M;
    cin >> N >> M;
    map<long long, long long> factor;
    factorize(factor, M);
    long long ans = 1;
    for (auto x : factor)
    {
        ans = mul_mod(ans, calcPatarn(x.second, N, MOD), MOD);
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ALL(c) (c).begin(),(c).end()
#define EACH(i,c) for(auto i=(c).begin();i!=(c).end();++i)
using namespace std;
#define int long long


void solve(long long N){
	int a = 111;
	while(a < N) {
		a += 111;
	}
	cout << a << endl;
}

signed main(){
    long long N;
    scanf("%lld",&N);
    solve(N);
    return 0;
}


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

signed main(){
  int N;
  cin>>N;
  vector<int> A(N);
  rep(i,N)cin>>A[i];
  int ans=0;
  rep(i,N){
    while(A[i]%2==0){
      ans+=1;
      A[i]/=2;
    }
  }
  cout<<ans<<endl;
}

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

int main() {
  long a,b,c=0;
  cin >> a >> b;
  vector<long> aaa;
  vector<long> bbb;

  if(b<a) swap(a,b);
  for(long i=1;i*i<=a;i++) {
    if(a%i==0) aaa.push_back(i);
    if(a%i==0&&i*i!=a) aaa.push_back(a/i);
  }
  for(long i=0;i<aaa.size();i++) {
    if(b%aaa[i]==0)c=max(c,aaa[i]);
  }
  for(long i=2;i*i<c;i++) {
    if(c%i==0) {
      bbb.push_back(i);
      c/=i;
      while(c%i==0) c/=i;
    }
  }
  if(c!=1) bbb.push_back(1);
  bbb.push_back(c);
  cout << bbb.size() << endl;
}

Measured memory_bytes: 384
package main

import "fmt"

func main() {
	var n, m int
	fmt.Scan(&n, &m)
	a := make([]string, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&a[i])
	}
	for i := 0; i < n; i++ {
		fmt.Println(a[i])
		fmt.Println(a[i])
	}
}


Measured memory_bytes: 512
#include<stdio.h>

int main(){
  long n,m;
  scanf("%ld", &n);
  scanf("%ld", &m);

  if(n>m){
    long tmp = n;
    n = m;
    m = tmp;
  }

  if(n>=3 && m>=3){
    printf("%ld\n", (m-2)*(n-2));
    return 0;
  }

  if(n==m){
    if(n==1){
      printf("%ld\n", 1);
      return 0; 
    }

    if(n==2){
      printf("%ld\n", 0);
      return 0; 
    }
  }

  if(n==1){
    printf("%ld\n", m-2);
    return 0; 
  }

  if(n==2){
    printf("0\n");
    return 0; 
  }

  return 0;
}


Measured memory_bytes: 128
#include <cstdio>

int main()
{
	long long num;

	scanf("%lld", &num);

	int digit = 1;	
	long long start = 1;	
	long long niroku = 26;	

	for (;;) {
		if (start <= num && num < start + niroku)
			break;
		else {
			digit++;
			start += niroku;
			niroku *= 26;
		}
	}

	num -= start;
	niroku /= 26;

	//fprintf(stderr, "dig: %d num: %lld", digit, num);
	
	int i;	
	for (i = 0; i < digit; i++) {
		putchar('a' + num / niroku);
		num %= niroku;
		niroku /= 26;
	}

	printf("\n");

	return 0;
}


Measured memory_bytes: 1624
n = gets.to_i
n.times do |i|
  x = gets.to_i
  res = 0

  xs = x.to_s
  while xs.size > 1 do
    maxx = 0

    xs.size.times do |j|
      tmpx = xs[(0...j + 1)].to_i * xs[j + 1...xs.size].to_i
      maxx = [tmpx, maxx].max
    end

    xs = maxx.to_s
    res += 1
  end
  p res
end

Measured memory_bytes: 8812
import java.io.*;
import java.util.*;
public class Main
{
	
	private void solve()throws IOException
	{
		int n=nextInt();
		while(n>0)
		{
			if(n%10==7)
			{
				out.println("Yes");
				return;
			}
			n=n/10;
		}
		out.println("No");
	}

	 
	///////////////////////////////////////////////////////////

	public void run()throws IOException
	{
		br=new BufferedReader(new InputStreamReader(System.in));
		st=null;
		out=new PrintWriter(System.out);

		solve();

		br.close();
		out.close();
	}
	public static void main(String args[])throws IOException{
		new Main().run();
	}
	BufferedReader br;
	StringTokenizer st;
	PrintWriter out;
	String nextToken()throws IOException{
		while(st==null || !st.hasMoreTokens())
		st=new StringTokenizer(br.readLine());
		return st.nextToken();
	}
	String nextLine()throws IOException{
		return br.readLine();
	}
	int nextInt()throws IOException{
		return Integer.parseInt(nextToken());
	}
	long nextLong()throws IOException{
		return Long.parseLong(nextToken());
	}
	double nextDouble()throws IOException{
		return Double.parseDouble(nextToken());
	}
}

Measured memory_bytes: 32924
#include <iostream>
#include <cmath>
#include <queue>
#include <algorithm>
#include <vector>
using namespace std;

typedef pair<int,int> P;

const int INF = 100000000;
int H,W;
vector<vector<char>> maze;
vector<vector<int>> d;

vector<int> dx = {1,0,-1,0};
vector<int> dy = {0,1,0,-1};

int bfs(){
  queue<P> que;
  que.push(P(0,0));
  d.at(0).at(0) = 0;
  
  while(que.size()){
    P p = que.front();
    que.pop();
    if(p.first == W-1 && p.second == H-1) break;
    for(int i=0;i<4;i++){
      int nx = p.first + dx.at(i);
      int ny = p.second + dy.at(i);
      
      if(0<= nx && nx < W && 0 <= ny && ny < H &&
          maze.at(ny).at(nx) == '.' && d.at(ny).at(nx) == INF){
        que.push(P(nx,ny));
        d.at(ny).at(nx) = d.at(p.second).at(p.first) + 1;
      }
    }
  }
  return d.at(H-1).at(W-1);
}

int main() {
  int init_black=0;
  cin >> H >> W;
  for(int i=0;i<H;i++){
    vector<char> tmpvec;
    vector<int> tmpvec_i;
    for(int j=0;j<W;j++){
      char tmp;
      cin >> tmp;
      init_black += (tmp == '#') ? 1 : 0;
      tmpvec.push_back(tmp);
      tmpvec_i.push_back(INF);
    }
    maze.push_back(tmpvec);
    d.push_back(tmpvec_i);
  }
  
  int result = bfs();
  int score;
  if(result == INF){
    score = -1;
  }else{
    score = H*W - init_black - result - 1;
  }
  cout << score << endl;
  
  return 0;
}

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

struct stone { int color, st, en; };

int main() {
	int n;
	while (cin >> n, n) {
		stack<stone>s;
		int a;
		cin >> a;
		stone e = { a,1,1 };
		s.push(e);
		for (int i = 1;i < n;i++) {
			int b;
			cin >> b;
			if (i % 2 == 0) {
				stone t = s.top();
				if (t.color == b) {
					s.pop();
					t.en++;
					s.push(t);
				}
				else {
					s.push({ b,i + 1,i + 1 });
				}
			}

			else {
				stone t = s.top();
				if (t.color == b) {
					s.pop();
					t.en++;
					s.push(t);
				}
				else {
					s.pop();
					if (s.empty()) {
						s.push({ b, 1, i + 1 });
					}
					else {
						stone x = s.top();
						s.pop();
						s.push({ b,x.st,i + 1 });
					}
				}
			}

		}
		int c = s.size();
		int ans = 0;
		for (int i = 0;i < c;i++) {
			stone d = s.top();
			s.pop();
			if (d.color == 0)ans += (d.en - d.st + 1);
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 3080
#include <stdio.h>

int main() {
    int n, count = 0;
    scanf("%d", &n);
    int nums[n];
    for (int i = 0; i < n; i++) {
        scanf("%d", &nums[i]);
    }

    for (int i = 1; i < n - 1; i++) {
        if ((nums[i] > nums[i - 1] && nums[i] < nums[i + 1]) || (nums[i] < nums[i - 1] && nums[i] > nums[i + 1])) {
            count++;
        }
    }

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

Measured memory_bytes: 128
#include <algorithm>
#include <string.h>
#include <iostream>
#include <stdio.h>

using namespace std;

typedef long long ll;

const ll K = 1e6 + 10;

bool h[K];
ll k;
ll t;
ll c;

int main() {
	cin >> k;

	while (true) {
		t = t * 10 + 7;
		c++;
		t %= k;
		
		if (t == 0) {
			cout << c << endl;
			return 0;
		}
		else {
			if (h[t]) {
				cout << "-1" << endl;
				return 0;
			}
			h[t] = true;
		}
	}

	return 0;
}

Measured memory_bytes: 4528
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <complex>
using namespace std;

using ll = long long;
using ull = uint64_t;
using P = pair<int, int>;
constexpr double EPS = 1e-9;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

template<class T>
inline bool chmax(T& x, T y){
    if(x < y){
        x = y;
        return true;
    }
    return false;
}
template<class T>
inline bool chmin(T& x, T y){
    if(x > y){
        x = y;
        return true;
    }
    return false;
}

struct LazySegmentTree{
    vector<int> data;
    vector<int> lazy;
    int sz;

    LazySegmentTree(int n){
        sz = 1;
        while(sz < n)   sz <<= 1;
        data.assign(sz << 1, 0);
        lazy.assign(sz << 1, 0);
    }

    void set(int k, const int& x) { data[sz + k] = x; }
    void build(){
        for(int k = sz - 1; k >= 0; --k){
            data[k] = min(data[k], data[k << 1 | 1]);
        }
    }

    void propagate(int k){
        if(lazy[k] != 0){
            data[k] += lazy[k];
            if(k < sz){
                lazy[k << 1] += lazy[k];
                lazy[k << 1 | 1] += lazy[k];
            }
            lazy[k] = 0;
        }
        return;
    }

    int update(int a, int b, const int& x, int k = 1, int l = 0, int r = -1){
        if(r == -1) r = sz;
        propagate(k);
        if(b <= l || r <= a)    return data[k];
        else if(a <= l && r <= b){
            lazy[k] += x;
            propagate(k);
            return data[k];
        }
        else{
            return data[k] = min(update(a, b, x, k << 1, l, (l + r) >> 1),
                                update(a, b, x, k << 1 | 1, (l + r) >> 1, r));
        }
    }

    int query(int a, int b, int k = 1, int l = 0, int r = -1){
        if(r == -1) r = sz;
        propagate(k);
        if(b <= l || r <= a)    return INF;
        else if(a <= l && r <= b)   return data[k];
        else{
            return min(query(a, b, k << 1, l, (l + r) >> 1),
                        query(a, b, k << 1 | 1, (l + r) >> 1, r));
        }
    }
};

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

    int n, q;
    cin >> n >> q;
    LazySegmentTree seg(n);
    for(int i = 0; i < q; ++i){
        int com;
        cin >> com;
        if(!com){
            int s, t, x;
            cin >> s >> t >> x;
            seg.update(s, t + 1, x);
        }
        else{
            int s, t;
            cin >> s >> t;
            cout << seg.query(s, t + 1) << '\n';
        }
    }
}


Measured memory_bytes: 4928
///
// File:  alds1_11_b.cpp
// Author: ymiyamoto
//
// Created on Wed Oct 18 00:19:44 2017
//

#include <cstdint>
#include <iostream>

using namespace std;

static uint32_t n;
static uint32_t graph[100][100];
static uint32_t count = 0;
static uint32_t d[100];
static uint32_t f[100];

static void dfs(uint32_t index)
{
  count++;
  d[index] = count;
  for (uint32_t i = 0; i < n; i++) {
    if (d[i] == 0 && graph[index][i] == 1) {
      dfs(i);
    }
  }
  count++;
  f[index] = count;
}

int32_t main()
{
  cin >> n;

  for (uint32_t i = 0; i < n; i++) {
    uint32_t id, k;
    cin >> id >> k;
    for (uint32_t j = 0; j < k; j++) {
      uint32_t v;
      cin >> v;
      graph[id - 1][v - 1] = 1;
    }
  }

  for (uint32_t i = 0; i < n; i++) {
    if (d[i] == 0) {
      dfs(i);
    }
  }

  for (uint32_t i = 0; i < n; i++) {
    cout << i + 1 << " " << d[i] << " " << f[i] << endl;
  }

  return 0;
}

Measured memory_bytes: 3104
#include <bits/stdc++.h>
using namespace std;
 
#define FASTIO  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define ll long long int
#define ld long double
#define vll vector<ll>
#define pll pair<ll,ll>
#define vl(p) vector<p>
#define W while
#define For(i,s,x) for(i=s;i<x;i++)
#define Fore(i,s,x) for(i=s;i<=x;i++)
#define FOR(i,x) for(i=0;i<x;i++)
#define Rof(i,s,x) for(i=s;i>=x;i--)
#define all(v) v.begin(),v.end()
#define it(r,v) for(auto r=v.begin();r!=v.end();r++)
#define pb push_back
#define in insert
#define sz size()
#define F first
#define S second
#define nl cout<<"\n"
#define pr(a) cout<<a<<" "
#define pr2(a,b) cout<<a<<" "<<b<<"\n"
#define pr3(a,b,c) cout<<a<<" "<<b<<" "<<c<<"\n"
#define mod 1000000007
#define mp make_pair

  int main()
  {
    char s[3],i;
    cin>>s;
    if(s[0]=='A'&&s[1]=='R'&&s[2]=='C')
    cout<<"ABC";
    else
    cout<<"ARC";
     }

Measured memory_bytes: 3632
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		String S = sc.next();
		StringBuilder sb = new StringBuilder(S);

		char[] ch = S.toCharArray();
		if(ch.length>9) {
			System.out.println("NO");
			return;
		}
		String akb = new String("AKIHABARA");

		for(int i=0;i<9;i++)
		{
			if(sb.length()>i){
			if(akb.charAt(i)==sb.charAt(i)){
				continue;
			}
			}
			sb.insert(i, "A");
			if(akb.charAt(i)==sb.charAt(i)){
				continue;
			}else{
				System.out.println("NO");
				System.exit(0);
			}
		}

		System.out.println("YES");

	}
}


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


void cc_env() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	//
#endif
}



int main() {
	// cc_env();
	// input part

	int a, b;
	cin >> a >> b;
	cout << a*b << endl;

}


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

using namespace std;

int main(){
  
  long int sum=0;
  int n;

  cin >> n;

  for(int i=1;i<=n;i++){
    if(i%3!=0&&i%5!=0) sum+=i;
  }

  cout << sum << endl;

  return 0;

}


Measured memory_bytes: 3632
/**
 *    author:  FromDihPout
 *    created: 2020-05-30
**/

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

int beat(char c) {
    if (c == 'r') return 2;
    if (c == 's') return 0;
    if (c == 'p') return 1;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int n, k, points[3];
    cin >> n >> k >> points[0] >> points[1] >> points[2];
    string s;
    cin >> s;
    int ans = 0;
    vector<int> used(n);
    for (int i = 0; i < n; i++) {
        if (i - k < 0) {
            used[i] = beat(s[i]);
            ans += points[used[i]];
        }
        else if (used[i-k] != beat(s[i])) {
            used[i] = beat(s[i]);
            ans += points[used[i]];
        }
        else {
            used[i] = -1;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 848
#include <iostream>
#include <vector>
#include <algorithm>
#include <tuple>

using namespace std;

#define rep(i, n) for(int i = 0; i < (n); ++i)
#define rep1(i) for(int i = -1; i < 2; ++i)

typedef long long ll;
typedef vector<tuple<ll, ll, ll>> vl;

int main(){
  int n, m;
  cin >> n >> m;
  vl v;
  ll x, y, z;
  rep(i, n){
    cin >> x >> y >> z;
    v.emplace_back(x, y, z);
  }
  ll ans = 0;
  rep1(i){
    rep1(j){
      rep1(k){
        vector<ll> s;
        for (auto x : v){
          s.push_back(get<0>(x) * i + get<1>(x) * j + get<2>(x) * k);
        }
        ll tmp = 0;
        sort(s.begin(), s.end(), greater<ll>());
        rep(i, m) tmp += s[i];
        ans = max(ans, tmp);
      }
    }
  }
  cout << ans << endl;
}

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

using namespace std;
using LL = long long;
using P = pair<int, int>;

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

#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()

const int INF = (int)1e9;
const LL INFL = (LL)1e18;
const int MOD = 1e9 + 7;

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

    string s;
    cin >> s;

    map<char, bool> mp;
    REP(i, 26) mp[(char)(i + 'a')] = false;
    REP(i, s.size()) mp[s[i]] = true;
    string ans = "";
    for(auto x : mp){
        if(!x.second){
            cout << x.first << endl;
            return 0;
        }
    }

    cout << "None" << endl;
}


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

using namespace std;

#define INF ((1<<30)-1)  //int32_t
#define MOD 1000000007
#define MOD2 

#define all(a)  (a).begin(),(a).end()

#define mkp make_pair
#define pb push_back

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

int main(){

    bool flag=true;

    ll ans=0,sum=0;
    
    int n,k;
    string s;
    cin >>n>>s>>k;

    for (int i = 0; i < s.length(); i++)
    {
        if(s[i] != s[k-1])s[i]='*';
    }
    
    

    //cout <<fixed<<setprecision(16)<< << endl;
    cout << s << endl;

    //if(flag)cout << "Yes" <<endl;
    //else cout << "No" <<endl;
    
    return 0;
}


Measured memory_bytes: 256
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def TUPLE(): return tuple(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7 
#mod = 998244353
from decimal import *
#import numpy as np
#decimal.getcontext().prec = 10


def C(n, r):
	if n < r:
		return 0
	else:
		return factorial(n)//factorial(n-r)//factorial(r)

N = input()
K = INT()

n = len(N)

ans = 0
if K <= n-N.count("0"):
	ans += 1

for i in range(n):
	if N[i] != "0" and 0 < K:
		ans += (int(N[i])-1) * 9**(K-1) * C(n-i-1, K-1) + C(n-i-1, K) * 9**K
		K -= 1

print(ans)


Measured memory_bytes: 10608