akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

const int INF = 1e+9;
typedef pair<int, int> P;

struct node {
	int c, to, t;
	node(int c, int to, int t) : c(c), to(to), t(t){}
};

bool operator > (const node& n1, const node& n2){
	return (n1.c == n2.c) ? n1.to > n2.to : n1.c > n2.c;  
}

int N, M;
vector<P> G[101];
int d[101][2];

void dijkstra(int s){
	for(int i = 0; i <= N; ++i){
		d[i][0] = INF;
		d[i][1] = INF;
	}
	priority_queue<node, vector<node>, greater<node>> que;
	que.push(node(0, s, 1));
	d[s][1] = 0;
	while(!que.empty()){
		node n = que.top();
		que.pop();
		if(n.c > d[n.to][n.t])
			continue;
		for(auto& u : G[n.to]){
			if(d[u.first][n.t] > d[n.to][n.t] + u.second){
				d[u.first][n.t] = d[n.to][n.t] + u.second;
				que.push(node(d[u.first][n.t], u.first, n.t));
			}
			if(n.t){
				if(G[u.first].empty())
					continue;
				for(auto w : G[u.first]){
					d[w.first][0] = min(d[w.first][0], d[n.to][1]);
					que.push(node(d[w.first][0], w.first, 0));
				}
			}
		}
	}
}

int main() {
	while(cin >> N >> M && (N || M)){
		for(int i = 0; i <= N; ++i)
			G[i].clear();
		int a, b, c;
		for(int i = 0; i < M; ++i){
			scanf("%d%d%d", &a, &b, &c);
			G[a].push_back(P(b, c));
			G[b].push_back(P(a, c));
		}
		dijkstra(1);
		cout << d[N][0] << endl;
	}
	return 0;
}

Measured memory_bytes: 1264
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <cctype>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <functional>

using namespace std;
using ll = long long int;
#define rep(i,n) for(int i = 0; i < n; i++)
#define FOR(i, a, b)  for(int i = (a); i < (b) ; i++)

#define pb push_back
#define SORT(v,n) sort(v, v+n)
#define ALL(x) (x).begin(),(x).end()
#define debug(x) cerr << #x << ": " << x << '\n'
#define elif else if
#define itn ll
#define int ll
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
///                →,↑,←,↓,↗,↖,↙,↘
int dx[8] = { 1, 0, -1, 0, 1, -1, -1, 1 };
int dy[8] = { 0, 1, 0, -1, 1, 1, -1, -1 };
typedef vector<vector<int>> vvi;
typedef vector<vector<vector<int>>> vvvi;


map<string, int> mp;

signed main() {
	ios::sync_with_stdio(false);
	int i, j, k;
	int n, m;
	cin >> n;
	vector<string> s1(n);
	rep(i, n) {
		cin >> s1[i];
		int num = mp[s1[i]];
		mp[s1[i]] = num + 1;
	}
	cin >> m;
	vector<string> s2(m);
	rep(i, m) {
		cin >> s2[i];
		int num = mp[s2[i]];
		if(num != 0)
			mp[s2[i]] = num - 1;
	}
	int mx = 0;
	rep(i, n) {
		mx = max(mx, mp[s1[i]]);
	}

	cout <<  mx << endl;
	return 0;
}

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

using namespace std;

const int N_MAX = 20;
const int Q_MAX = 200;

void printArray(int *S, int n)
{
    for (int i = 0; i < n; i++)
    {
        cout << S[i];
        if (i != n-1)
            cout << " ";
    }
    cout << endl;
}
// 組み合わせを列挙
void rec(int i, int *S, int n)
{
    if (i == n)
    {
        printArray(S, n);
        return;
    }
    S[i] = 0;
    rec(i+1, S, n);

    S[i] = 1;
    rec(i+1, S, n);
}
void makeCombination(int *S, int n)
{
    rec(0, S, n);
}

// i番目以降の要素を使って、mが作れる場合trueを返す。
bool solve(int *A, int n, int i, int m)
{
    if (m == 0)
        return true;
    if (i >= n)
        return false;
    return (solve(A, n, i + 1, m) || solve(A, n, i + 1, m - A[i]));
}

int main(int argc, char *argv[]) {
    cin.tie(0);
    ios::sync_with_stdio(false);

    /* 再帰と組み合わせのサンプル
    int S[3] = { 0 };
    makeCombination(S, 3);
    */

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

    int q;
    cin >> q;
    int M[Q_MAX] = { 0 };
    for (int i = 0; i < q; i++)
    {
        cin >> M[i];
    }

    for (int i = 0; i < q; i++)
    {
        cout << (solve(A, n, 0, M[i]) ? "yes" : "no") << endl;
    }

    return 0;
}


Measured memory_bytes: 3176
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
const int N =2e5+10 , M = 5e5+10, OO = 0x3f3f3f3f ,  MOD = 1e9+7;
const double EPS = 1e-3;
#define M_PI 3.14159265358979323846
#define clr(arr,val) memset(arr , val , sizeof (arr))
#define loop(i,n) for(int i = 0;i < int(n);i++)
#define rloop(i,n) for(int i = int(n)-1;i >= 0;i--)
#define range(i,a,b) for(int i = int(a);i <= int(b);i++)
#define pb push_back
#define F first
#define S second
#define all(v) ((v).begin()) , ((v).end())
#define sz(v)  ((int)((v).size()))
typedef pair <int,int> pii ;
typedef vector < pii > vii ;
int dx[]={1,0,-1,0};int dy[]={0,1,0,-1}; //4 Direction
//int dx[]={1,1,0,-1,-1,-1,0,1};int dy[]={0,1,1,1,0,-1,-1,-1};//8 direction
//int dx[]={2,1,-1,-2,-2,-1,1,2};int dy[]={1,2,2,1,-1,-2,-2,-1};//Knight Direction
//int dx[6]={2,1,-1,-2,-1,1};int dy[6]={0,1,1,0,-1,-1}; //Hexagonal Direction
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);


int a,b;
int arr[5];

int main(){


    //ios_base::sync_with_stdio(0);
    //cin.tie(0);cout.tie(0);



	scanf("%d %d",&a,&b);
	arr[a] = 1;
	arr[b] = 1;
	for(int i = 1 ; i <= 3 ; ++i)
		if(arr[i] == 0)
			return printf("%d\n",i) , 0;



	

    

    return 0;
}

Measured memory_bytes: 256
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input!{
        abc: [usize; 3],
    }
    let mut abc = abc;
    abc.sort();
    println!("{}", if abc == [5, 5, 7] {"YES"} else {"NO"});
}


Measured memory_bytes: 4352
n,a,b,c,d=map(int,input().split())
s=input()
if a<b<c<d:
    if "##" not in s[a-1:d-1]:
        print("Yes")
    else:
        print("No")
elif a<c<b<d:
    if "##" not in s[a-1:c-1] and  "##" not in s[b-1:d-1]:
        print("Yes")
    else:
        print("No")
else:
    if "##" not in s[a-1:c-1] and "..." in s[b-2:d+1]:
        print("Yes")
    else:
        print("No")

Measured memory_bytes: 3636
#include <iostream>
#include <queue>

using namespace std;

int main(){

  int n,t,p,c=0;
  string s;
  cin>>n>>t;
  queue<pair<string,int> >a;

  while(n--){
    cin>>s>>p;
    a.push(make_pair(s,p));
  }
  
  while(!a.empty()){
    pair<string,int>b=a.front();
    a.pop();

    if(b.second<=t){
      c+=b.second;
      cout<<b.first<<' '<<c<<endl;
    }

    else{
      b.second-=t;
      c+=t;
      a.push(b);
    }
  }
}


Measured memory_bytes: 6308
l = '1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51'
s = l.split(', ')
a = int(input())
print(s[a-1])

Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
long long a[3];
int main(){cin>>a[0]>>a[1]>>a[2];sort(a,a+3);cout<<((a[0]&1&a[1]&1&a[2]&1)?a[0]*a[1]:0)<<endl;return 0;}

Measured memory_bytes: 256
def reful(C) :
    new = []
    for i in range(len(C)//2) :
        new.append(C[i])
        new.append(C[i+len(C)//2])
    return new
    
def cut(C, k) :
    new=[]
    for i in range(k, len(C)) :
        new.append(C[i])
    for i in range(k) :
        new.append(C[i])
    return new

n = int(input())
card = []
for i in range(2*n) :
    card.append(i+1)
m = int(input())
for i in range(m) :
    k = int(input())
    if k == 0 :
        card = reful(card)
    else :
        card = cut(card, k)
for i in range(2*n) :
    print(card[i])
    


Measured memory_bytes: 5628
using System;
class Program
{
	static void Main(string[] args)
	{
		// 整数の入力
		string[] input = Console.ReadLine().Split(' ');
		int a = int.Parse(input[0]);
		int b = int.Parse(input[1]);
		String s;
		// 判定
		if((a*b) % 2 == 0){
			s = "Even";
		}else{
			s = "Odd";
		}
		//出力
		Console.WriteLine(s);
	}
}


Measured memory_bytes: 13140
#include<cstdio>

int a, b;

int main() {
	scanf("%d%d", &a, &b);
	if(a>0) printf("Positive\n");
	else if(b>=0) printf("Zero\n");
	else if((b-a)%2) printf("Positive\n");
	else printf("Negative\n");
	
	return 0;
}

Measured memory_bytes: 128
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <valarray>
#include <vector>
using namespace std;

using ll = long long;
using ld = long double;
const int INF = 1e9;
const double EPS = 1e9;
const ll MOD = 1e9 + 7;

ll f(ll n)
{
  if (n % 2 == 1)
  {
    return ((n + 1) / 2) % 2;
  }
  else
  {
    return (((n + 1) / 2) % 2) xor n;
  }
}

int main()
{
  long long A;
  scanf("%lld", &A);
  long long B;
  scanf("%lld", &B);
  cout << (f(B) xor f(max(A - 1, 0LL))) << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
int main(){
  ll N,A;
  cin>>N;
  ll cnt=0, ans=0, m=1e9;
  for(int i=0; i<N; i++){
    cin>>A;
    if(A<0){
      cnt++;
      A*=-1;
    }
    m=min(m,A);
    ans+=A;
  }
  if(cnt%2==1)
    ans-=m*2;
  cout<<ans<<endl;
}

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

#ifdef DEBUG
#define debug(x) cout << #x << ": " << x << endl
#else
#define debug(x)
#endif

#define REP(i, n) for(int i = 0; i < (n); i++)
#define REPS(i, n) for(int i = 1; i <= (n); i++)
#define ALL(v) (v).begin(), (v).end()

#define pb push_back
#define mp make_pair
#define mt make_tuple

using namespace std;

using ll = long long;
using pi = pair<int, int>;
using pl = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;

const ll INF = 1e18;
const ll MOD = 1e9+7;

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

ll comb(ll n, ll r)
{
    if(n < r) return 0;
    ll ret = 1;
    for(ll i = 1; i <= r; i++)
    {
        ret *= n-i+1;
        ret /= i;
    }
    return ret;
}


signed main()
{
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(10);

    ll N, P; cin >> N >> P;
    ll even = 0, odd = 0;
    REP(i, N)
    {
        ll A; cin >> A;
        if(A%2==0) even++;
        else odd++;
    }
    if(P == 0)
    {
        ll ans = 0;
        for(ll i = 0; i <= odd; i+=2) ans += pow(2, even) * comb(odd, i);
        cout << ans << endl;
    }
    else
    {
        ll ans = 0;
        for(ll i = 1; i <= odd; i+=2) ans += pow(2, even) * comb(odd, i);
        cout << ans << endl;
    }
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
    public static void main(String args[]) {
        int i, j;
        int[] num;
        num = new int[100];
        Scanner sc = new Scanner(System.in);
        int length = sc.nextInt();
        for(i=0;i<length;i++){
            num[i] = sc.nextInt();
        }
        for(j=length-1;j>=0;j--){
            if(j==0){
                System.out.printf("%d\n", num[j]);
            }else{
                System.out.printf("%d ", num[j]);
            }
        }
        sc.close();
    }
}


Measured memory_bytes: 26620
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
#include <iomanip>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdlib>
#include <map>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define pie 3.141592653589793238462643383279
#define INF 1000000007
#define ggr getchar(); getchar();return 0;
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
int lcm(int x, int y) {
	return x / gcd(x, y)*y;
}

long long a, b, ans;

signed main() {
	cin >> a >> b;
	long long ta = 0, mu = 0;
	if (b % 2 == 0)ta = b / 2;
	else ta += b / 2 + 1;
	mu = a / 2;
	if ((ta - mu) % 2 == 1)ans += 1;
	long long wa = 2;
	a--;
	while (b >= wa) {
		if (b % (wa * 2) >= wa) {//1
			ta = (b / (wa * 2)*wa) + (((b - wa) % (wa * 2)) + 1);
		}
		else {//0
			ta = (b / (wa * 2))*wa;
		}
		
		if (a < wa)mu = 0;
		else if (a % (wa * 2) >= wa) {
			mu = (a / (wa * 2)*wa) + (((a - wa) % (wa * 2)) + 1);
		}
		else {
			mu = (a / (wa * 2))*wa;
		}

		if ((ta - mu) % 2 == 1)ans += wa;
		wa *= 2;
	}
	cout << ans << endl;
}

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

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

const double PI = acos(-1);
const int inf = 2e9;
const ll INF = 2e18;
const ll MOD = 1e9+7;

#define sz(s) (s).size()
#define pb push_back
#define fi first
#define se second
#define REP(i,n) for (int i = 0; i<n; i++)
#define ALL(a) begin(a), end(a)

int main (void) {
    int H,W;
    cin >> H >> W;
    vector<string> S(H);
    REP(i,H) cin >> S[i];
    vector<vector<int>> b(H,vector<int>(W));
    REP(i,H) {
        int n = 0;
        REP(j,W) {
            if (S[i][j] == '#') {
                b[i][j] = -1;
            }
            else {
                n++;
                if (j == W-1) {
                    b[i][j] = n;
                    n = 0;
                }
                else if (j != W-1 && S[i][j+1] == '#') {
                    b[i][j] = n;
                    n = 0;
                }
            }
        }
        int t = 0;
        for (int j=W-1; j>=0; j--) {
            if (b[i][j] == -1) t = 0;
            else if (t == 0) {
                t = b[i][j];
            }
            else {
                b[i][j] = t;
            }
        }
    }
    int ans = 0;
    REP(j,W) {
        int lm = 0;
        int hi = 0;
        REP(i,H) {
            if (b[i][j] == -1) {
                ans = max(ans,lm+hi-1);
                lm = 0;
                hi = 0;
            }
            else {
                lm = max(lm, b[i][j]);
                hi++;
            }
        }
        ans = max(ans, hi+lm-1);
    }
    cout << ans << endl;
    /*
    REP(i,H) {
        REP(j,W) {
            cout << b[i][j] << " \n"[j==W-1];
        }
    }
    */
    return 0;
}

Measured memory_bytes: 20096
import java.util.Scanner

object Main {
  def main(args: Array[String]): Unit = println(solve(new Scanner(System.in)))

  def solve(in: String): String = solve(new Scanner(in))

  def solve(sc: Scanner): String = {
    val ABC = Array.fill(3)(sc.nextInt)
    val K = sc.nextInt

    var (n, i) = ABC.zipWithIndex.maxBy(_._1)
    val rest = ABC.zipWithIndex.filter(_._2 != i).map(_._1).sum
    for (i <- 1 to K) {
      n *= 2
    }
    (rest + n).toString
  }
}


Measured memory_bytes: 27344
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int max_n=1100005;
typedef pair<ll,int> P;
const ll inf=0x3f3f3f3f3f3f3f3f;

struct edge{
    int u,v;
    ll w;
    int next;
}G[max_n*2];
int head[max_n];
int tot;
void add_edge(int u,int v,ll w=1){
    G[tot]={u,v,w,head[u]};
    head[u]=tot++;
}
void init(int n){
    tot=2;
    for(int i=0;i<=n;i++)head[i]=0;
}

ll d[max_n];
void dijkstra(int s){
    priority_queue<P,vector<P>,greater<P> > q;
    memset(d,0x3f,sizeof(d));
    
    d[s]=0;
    q.push(P(0,s));
    P p;
    int u,v;
    while(!q.empty()){
        p=q.top();
        q.pop();
        u=p.second;
        if(d[u]<p.first)continue;
        for(int i=head[u];i;i=G[i].next){
            v=G[i].v;
            if(d[v]>d[u]+G[i].w){
                d[v]=d[u]+G[i].w;
                q.push(P(d[v],v));
            }
        }
    }
}
int k;
int main(){
    scanf("%d",&k);
    init(k+1);
    for(int i=1;i<=9;i++)add_edge(k+1,i%k,i);
    for(int i=0;i<k;i++){
        for(int j=0;j<=9;j++)add_edge(i,(i*10+j)%k,j);
    }
    dijkstra(k+1);
    printf("%lld\n",d[0]);
    return 0;
}

Measured memory_bytes: 41200
n, y = map(int, input().split())
a={}
j=True


for th in range(0, n+1) :
    for fh in range(0, n-th+1) :
        if th * 10000 + fh * 5000 + (n-fh-th) * 1000 == y :
            print (th, fh, n-fh-th)
            j = False
            break
    else :
        continue
    break

if j == True:
    print(-1, -1, -1)

Measured memory_bytes: 3064
use std::io::*;

fn permutation(n: usize, p: &mut Vec<usize>, used: &mut Vec<bool>, all: &mut Vec<Vec<usize>>) {
    if p.len() == n {
        all.push(p.to_vec());
        return;
    }
    for i in 0..n {
        if !used[i] {
            p.push(i);
            used[i] = true;
            permutation(n, p, used, all);
            p.pop();
            used[i] = false;
        }
    }
}

fn main() {
    let mut s: String = String::new();
    std::io::stdin().read_to_string(&mut s).ok();
    let mut itr = s.trim().split_whitespace();
    let n: usize = itr.next().unwrap().parse().unwrap();
    let a: Vec<(f64, f64)> = (0..n)
        .map(|_| {
            (
                itr.next().unwrap().parse().unwrap(),
                itr.next().unwrap().parse().unwrap(),
            )
        })
        .collect();

    let mut used = vec![false; n];
    let mut p = Vec::new();
    let mut all = Vec::new();
    permutation(n, &mut p, &mut used, &mut all);

    let mut ans = 0.0;
    for i in all {
        for j in 0..i.len() - 1 {
            ans += ((a[i[j + 1]].0 - a[i[j]].0) * (a[i[j + 1]].0 - a[i[j]].0)
                + (a[i[j + 1]].1 - a[i[j]].1) * (a[i[j + 1]].1 - a[i[j]].1))
                .sqrt();
        }
    }
    for i in 1..n + 1 {
        ans /= i as f64;
    }
    println!("{}", ans);
}


Measured memory_bytes: 8444
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long ll;
typedef pair<ll,ll> P;
const ll mod=1000000007;
const ll LINF=1LL<<60;
const int INF=1<<30;

int main(){
	string s,t;
	cin >> s >> t;
	int n = s.size();
	int m = t.size();
	int i,j,k,l;
	string ans(n,'z');
	for(i = 0; i < n - m + 1; i++) {
		string tmp(n,'#');
		for(j = 0; j < i; j++) {
			tmp[j] = '#';
		}
		for(k = j; k < m + i; k++) {
			tmp[k] = t[k - j];
		}
		// for(int z = 0; z < n; z++) {
		// 	cout << tmp[z];
		// }
		// cout  << endl;
		int flag = 0;
		for(int q = 0; q < n; q++) {
			if (s[q] != '?'){
				if (tmp[q] != '#' && s[q] != tmp[q]){
					flag = 1;
					break;
				}
				else{
					tmp[q] = s[q];
				}
			}
		}
		if (flag == 0 && ans > tmp){
			for(int w = 0; w < n; w++) {
				ans[w] = tmp[w];
			}
		}
	}
	string judge(n,'z');
	if (ans == judge){
		cout << "UNRESTORABLE" << endl;
	}
	else{
		for(int i = 0; i < n; i++) {
			if(ans[i] != '#'){
				cout << ans[i];
			}
			else{
				cout << 'a';
			}
		}
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {
    static List<Integer> list;
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        list = new ArrayList<>();
        int n = Integer.parseInt(sc.next());
        StringBuilder tmp = new StringBuilder();
        for (int i = 0; i < n; i++) {
            tmp.append(sc.next());
        }
        int p = Integer.parseInt(tmp.toString());
        tmp = new StringBuilder();
        for (int i = 0; i < n; i++) {
            tmp.append(sc.next());
        }
        int q = Integer.parseInt(tmp.toString());

        tmp = new StringBuilder();
        for (int i = 0; i < n; i++) {
            tmp.append(i+1);
        }
        permutation(tmp.toString(), "");
        System.out.println(Math.abs((list.indexOf(p)+1) - (list.indexOf(q)+1)));
    }

    private static void permutation(String str, String ans) {
        if (str.isEmpty()) {
            list.add(Integer.parseInt(ans));
            return;
        }
        for (int i = 0; i < str.length(); i++) {
            char c = str.charAt(i);
            permutation(str.substring(0, i) + str.substring(i + 1), ans + c);
        }
    }
}


Measured memory_bytes: 44036
import sys
sys.setrecursionlimit(10 ** 9)
input = sys.stdin.readline
from itertools import permutations,  combinations, accumulate
from functools import *
from collections import deque, defaultdict, Counter
from heapq import heapify, heappop, heappush, heappushpop

INF = float('inf')
NIL = - 1


N = int(input())
S = input().rstrip()

ret = 0
for i in range(N):
    for j in range(i + 1, N):
        k = 2 * j - i
        if k >= N:
            break
        if S[i] != S[j] and S[j] != S[k] and S[k] != S[i]:
            ret += 1

print(S.count('R') * S.count('G') * S.count('B') - ret)


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

int main() {
  uint32_t q = 0;
  std::cin >> q;
  while (q > 0) {
    q--;
    std::string X, Y;
    std::cin >> X >> Y;

    std::vector<std::vector<uint32_t>> dp(
        X.size() + 1, std::vector<uint32_t>(Y.size() + 1, 0));
    for (size_t i = 1; i < X.size() + 1; i++) {
      for (size_t j = 1; j < Y.size() + 1; j++) {
        dp[i][j] =
            (X[i - 1] == Y[j - 1] ? dp[i - 1][j - 1] + 1
                                  : std::max(dp[i][j - 1], dp[i - 1][j]));
      }
    }

    std::cout << dp.back().back() << std::endl;
  }

  return 0;
}


Measured memory_bytes: 6920
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>

using namespace std;
using ll = long long;
using ull = unsigned long long;

#ifndef __MACRO_H__
#define __MACRO_H__

#define all(collection)  (collection).begin(), (collection).end()		// begin to end
#define rep(i, begin, end) for (ll i = begin; i < end; i++)					// repeat
#define repr(i, begin, end) for (ll i = begin - 1; end <= i; i--)		// repeat reverse

std::chrono::system_clock::time_point  start;

void TimeStart(void)
{
	start = std::chrono::system_clock::now();
}

void TimeEnd(void)
{
	auto time = std::chrono::system_clock::now() - start;
	auto msec = std::chrono::duration_cast<std::chrono::milliseconds>(time).count();
	cerr << endl << msec << " msec " << endl;
}

#endif


int main(void)
{
	ll a; cin >> a;
	ll b; cin >> b;

	
	if (13 <= a)
		cout << b;
	else if (6 <= a)
		cout << b / 2;
	else
		cout << 0;

	return 0;

}

Measured memory_bytes: 256
n = int(input())
# a: 長さnの値不明の整数列
b = [int(i) for i in input().split()]

# b1 >= max(a1,a2)
# b2 >= max(a2,a3)
# ...
# bn-1 >= max(an_1,an)

# この条件を満たす最大のa1,a2,...を求める
# sum_i{bi}がなにか使えそうなきはする 

# [ex1]
# b = [2,5,5]
# a = [2,2,5,1]
#     [2,2,5,5] *

# [ex2]
# b = [0,153, 10,10,23]
# a = [0,  0,153,10,10,23] ... false!
#     [0,  0, 10,10,10,23] ... true

# [ex3]
# b = [  0,153,10,10,5]
# a = [  0,  0,10,10,5,5]

# [ex4]
# b = [3,1]
# a = [3,1,1]

# [ex5]
# b = [3,1,3]
# a = [3,1,1,3]

# [ex6]
# b = [1,4,2,5,3,6]
# a = [1,1,2,2,3,3,6]

# [ex7]
# b = [4,1,5,2]
# a = [4,1,1,2,2]

# a1 = b1
#   if b2 <= b1
#      a2 = b2
# elif b2 > b1
#      a2 = b1
# an = bn-1

a = [] 
a.append(b[0])
for i in range(1,len(b)):
    if b[i] <= b[i-1]:
        a.append(b[i])
    else:
        a.append(b[i-1])
a.append(b[-1])

ans = sum(a)
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const int MOD = 1000000007;

int main()
{
    string t;
    cin >> t;
    rep(i, t.length())
    {
        if (t[i] == '?')
            t[i] = 'D';
    }
    cout << t << endl;
}

Measured memory_bytes: 3764
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const double pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
REP(i,v.size()){if(i)os<<" ";os<<v[i];}return os;}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
REP(i,v.size()){if(i)os<<endl;os<<v[i];}return os;}

int main()
{
	string S;
	cin >> S;

	int tmp = 0;
	int ans = 0;
	int L   = S.length();
	for (int i = 0; i < L; ++i)
	{
		if (S[i] == 'A' || S[i] == 'G' || S[i] == 'C' || S[i] == 'T')
		{
			++tmp;
		}
		else
		{
			ans = max(ans, tmp);
			tmp = 0;
		}
	}

	ans = max(ans, tmp);
	
	cout << ans << endl;



	
}

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

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

vector<pair<long long, long long>> prime_factorize(long long n) {
  vector<pair<long long, long long>> res;
  for (long long p = 2; p*p <= n; p++) {
    if (n % p != 0) continue;
    int num = 0;
    while (n % p == 0) { num++; n /= p; }
    res.push_back(make_pair(p, num));
  }
  if (n != 1) res.push_back(make_pair(n, 1));
  return res;
}

int main() {
  long long A, B;
  cin >> A >> B;
  vector<pair<long long, long long>> pf = prime_factorize(gcd(A, B));
  cout << (int)pf.size() + 1 << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>#include<bits/stdc++.h>
using namespace std;
bool cmp(int x,int y)
{
	return x>y;
}
int n,m,a[100005],ans,c[100005];
int main(){
	cin>>n>>m;
	for(int i=1;i<=m;i++) cin>>a[i];
	sort(a+1,a+1+m);
	for(int i=1;i<m;i++) c[i]=a[i+1]-a[i],ans+=c[i];
	sort(c+1,c+m,cmp);
	for(int i=1;i<=n-1;i++) ans-=c[i];
	cout<<ans;
	return 0;
}

Measured memory_bytes: 1024
//#pragma GCC optimize("-Ofast")
#include <bits/stdc++.h>
using namespace std;
#define AC 0
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int n, m;
	cin >> n >> m;
	vector< vector<int> > t(n);
	vector<int> dp(n, 1), ans(n);
	for (int i = 0, x, y; i < n - 1; i++) {
		cin >> x >> y;
		t[x - 1].push_back(y - 1);
		t[y - 1].push_back(x - 1);
	}
	function<void(int, int)> dfs = [&](int u, int p) {
		for (int i = 0; i < t[u].size(); i++)
			if (t[u][i] != p) {
				dfs(t[u][i], u);
				dp[u] = 1ll * dp[u] * (dp[t[u][i]] + 1) % m;
			}
	};
	dfs(0, -1);
	function<void(int, int, int)> solve = [&](int u, int p, int up) {
		ans[u] = 1ll * dp[u] * up % m;
		vector<int> child;
		for (int i = 0; i < t[u].size(); i++)
			if (t[u][i] != p)
				child.push_back(t[u][i]);
		vector<int> pre(child.size() + 1, 1), suf(child.size() + 1, 1);
		for (int i = 0; i < child.size(); i++) pre[i + 1] = 1ll * pre[i] * (dp[child[i]] + 1) % m;
		for (int i = child.size() - 1; i >= 0; i--) suf[i] = 1ll * suf[i + 1] * (dp[child[i]] + 1) % m;
		for (int i = 0; i < child.size(); i++) solve(child[i], u, (1ll * up * pre[i] % m * suf[i + 1] + 1) % m);
	};
	solve(0, -1, 1);
	for (int i = 0; i < n; i++) cout << ans[i] << '\n';
	return AC;
}

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

int p[1300],size;

bool isPrime(int x){
	for(int i=0;i<size && p[i]<=sqrt(x);i++)if(x%p[i]==0)return false;
	return true;
}

int main(void){
	int n;

	p[0] = 2;
	size = 1;
	for(int i=3;i<10010;i+=2)if(isPrime(i))p[size++]=i;

	while(cin>>n && n){
		int ans = 0;
		for(int i=0;p[i]<=n;i++){
			int sum = 0;
			for(int j=i;sum<n;j++) sum += p[j];
			if(sum == n) ans++;
		}
		cout<<ans<<endl;
	}

	return 0;
}

Measured memory_bytes: 0
#include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <climits>
#include <cmath>
#include <complex>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <cstdint>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
#define MP make_pair
#define PB push_back
#define inf 1000000007
#define mod 1000000007
#define rep(i,n) for(int i = 0; i < (int)(n); ++i)
#define all(x) (x).begin(),(x).end()

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

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

int main(){
    int h,a;
    cin >> h >> a;
    cout << (h+a-1)/a << endl;
    return 0;
}

Measured memory_bytes: 256
s = input()
words = ["dreamer", "dream", "eraser", "erase"]
while len(s) > 0:
    judge = [s.endswith(word) for word in words]
    if any(judge):
        s = s[:-len(words[judge.index(True)])]
        if len(s)==0:
            print("YES")
            break
    else:
        print("NO")
        break


Measured memory_bytes: 3188
#include<bits/stdc++.h>
using namespace std;
vector <long long> v;
void fill(){
    int sum=0;
    for(int i=1;i<=999;i++){
        sum+=i;
        v.push_back(sum);
    }
}
int main(){
    fill();
    long long a,b;
    cin>>a>>b;
    for(int i=0;i<v.size()-1;i++){
        //cout<<1<<endl;
        if((v[i+1]-v[i])==(b-a)){
            cout<<v[i+1]-b;
            return 0;
        }
    }
    return 0;
}

Measured memory_bytes: 256
package main

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

var sc = bufio.NewScanner(os.Stdin)
var out = bufio.NewWriter(os.Stdout)

func solve(a int64, b int64) int64 {
	a1 := (a * 100 + 7)/ 8 - 13
	b1 := (b * 100 + 9)/ 10 - 10
	c := int64(1)
	if c < a1 {
		c = a1
	}
	if c < b1 {
		c = b1
	}
	for i := c; i <= c + 13; i++ {
		if i * 8/ 100 == a && i * 10/ 100 == b {
			return i
		}
	}
	return -1
}

func main() {
	sc.Split(bufio.ScanWords)
	defer out.Flush()

	a := nextInt()
	b := nextInt()
	res := solve(a, b)
	fmt.Fprintln(out, res)
}

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextStringAsBytes(n int64) []byte {
	sc.Scan()
	return []byte(sc.Text())
}

func nextInt() int64 {
	a, _ := strconv.ParseInt(next(), 10, 64)
	return a
}

func nextFloat() float64 {
	a, _ := strconv.ParseFloat(next(), 64)
	return a
}

func nextInts(n int64) []int64 {
	ret := make([]int64, n)
	for i := int64(0); i < n; i++ {
		ret[i] = nextInt()
	}
	return ret
}

func nextFloats(n int64) []float64 {
	ret := make([]float64, n)
	for i := int64(0); i < n; i++ {
		ret[i] = nextFloat()
	}
	return ret
}
func nextStrings(n int64) []string {
	ret := make([]string, n)
	for i := int64(0); i < n; i++ {
		ret[i] = next()
	}
	return ret
}

func containStr(arr []string, target string) bool {
	for _, v := range arr {
		if v == target {
			return true
		}
	}
	return false
}

func PrintOut(src interface{}, joinner string) {
	switch reflect.TypeOf(src).Kind() {
	case reflect.Slice:
		s := reflect.ValueOf(src)
		for idx := 0; idx < s.Len(); idx++ {
			fmt.Fprintf(out, "%v", s.Index(idx))
			if idx < s.Len()-1 {
				fmt.Fprintf(out, "%s", joinner)
			} else {
				fmt.Fprintln(out)
			}
		}
	default:
		fmt.Fprintln(out, "orz")
	}
}

// mapからkeysとvaluesを返す
func splitKeyValue(m map[interface{}]interface{}) (keys, values []interface{}) {
	switch reflect.TypeOf(m).Kind() {
	case reflect.Map:
		s := reflect.ValueOf(m)
		for _, v := range s.MapKeys() {
			keys = append(keys, v)
			values = append(values, s.MapIndex(v))
		}
	default:
		fmt.Fprintln(out, "orz")
	}
	return
}


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

int main() {
	int a,b,c,d;
	cin>>a>>b>>c>>d;
	int x=c-a;int y=d-b;
	cout<<c-y<<" "
	<<d+x<<" "
	<<a-y<<" "
	<<b+x<<endl;
	return 0;
}

Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; ++i)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = int64_t;
using ld = long double;
using P = pair<int, int>;
using vs = vector<string>;
using vi = vector<int>;
using vvi = vector<vi>;
template<class T> using PQ = priority_queue<T>;
template<class T> using PQG = priority_queue<T, vector<T>, greater<T> >;
const int INF = 100010001;
const ll LINF = (ll)INF*INF*10;
template<typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) {return a < b && (a = b, true);}
template<typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) {return a > b && (a = b, true);}
template<typename T1, typename T2>
istream &operator>>(istream &is, pair<T1, T2> &p) { return is >> p.first >> p.second;}
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) { return os << p.first << ' ' << p.second;}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, m;
    cin >> n;
    set<int> a, b, c;
    rep(i, n) {
        int aa;
        cin >> aa;
        a.insert(aa);
    }
    cin >> m;
    rep(i, m) {
        int bb;
        cin >> bb;
        b.insert(bb);
    }
    set_symmetric_difference(all(a), all(b), inserter(c, c.begin()));
    for(int x:c) {
        cout << x << endl;
    }
}


Measured memory_bytes: 40624
n,m=map(int,input().split())
class WarshallFloyd:
#O(V^3)で任意２頂点の最短距離
    def __init__(self,n,_first_index=0):
        self.v = n
        self._first_idx=_first_index
        self.d = [[1e100]*(n+_first_index) for _ in range(n+_first_index)]
        for i in range(n+_first_index):
            self.d[i][i] = 0

    def path(self,x,y,c):
        if x == y:
            return False
        self.d[x][y] = c
        self.d[y][x] = c
        return True

    def build(self):
        f=self._first_idx
        for k in range(f,self.v+f):
            for i in range(f,self.v+f):
                for j in range(f,self.v+f):
                    self.d[i][j] = min(self.d[i][j], self.d[i][k] + self.d[k][j])
        return self.d
w=WarshallFloyd(n,1)
l=[]
for i in range(m):
    x,y,c=map(int,input().split())
    w.path(x,y,c)
    x,y=sorted([x,y])
    l.append([x,y,c])
d=w.build()
ans=0
for a,s,c in l:
    f=1
    for y in range(1,n+1):
        if d[y][s]==d[y][a]+c:f=0;break
    ans+=f
print(ans)

Measured memory_bytes: 3444
x,y = (int(i) for i in input().split())
groupA = [1,3,5,7,8,10,12]
groupB = [4,6,9,11]
groupC = [2]
if x in groupA and y in groupA:
  print('Yes')
elif x in groupB and y in groupB :
  print('Yes')
else:
  print('No')

Measured memory_bytes: 3060
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<set>
#include<map>
#include<queue>
#include<cmath>
#define REP(i,a) for (int i = 0;i < (a);++i)
#define FOR(i,a,b) for (int i = (a);i < (b); ++i)
#define FORR(i,a,b) for (int i = (a);i >= (b); --i)
#define ALL(obj) (obj).begin(),(obj).end()
#define SORT(list) sort(ALL((list)));
#define MOD 1000000007
using namespace std;
using ll = long long;
int main(){
    ll x,k,d;
    cin >> x >> k >> d;
    if(log10(k)+log10(d) <16 and k*d <= llabs(x)){
        cout << llabs(x) - k*d << endl;
        return 0;
    }
    else{
        if(llabs((x/d)%2) == k%2){
            cout << llabs(x%d) << endl;
        }else{
            cout << llabs(llabs(x%d) - d) << endl;
        }
    }
    return 0;
}

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

int main(){
  int n; cin >> n;
  ll k; cin >> k;
  vector<int> a(n), f(n);
  rep(i, n) cin >> a[i];
  rep(i, n) cin >> f[i];

  sort(a.begin(), a.end());
  sort(f.rbegin(), f.rend());

  ll left = -1, right = 1e12, mid;

  while(left + 1 < right){

    mid = (left + right) / 2;
    ll sum = 0;
    rep(i, n){
      sum += max(a[i] - mid / f[i], 0LL);
    }
    if(sum <= k){
      right = mid;
    }
    else{
      left = mid;
    }
  }
  cout << right << endl;


  return 0;
}


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

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

    bool can = false;
    for (int i = 1; i < 10; i++)
    {
        for (int j = 1; j < 10; j++)
        {
            if (i * j == N)
            {
                can = true;
            }
        }
    }

    if (can)
    {
        cout << "Yes" << endl;
    }

    else
    {
        cout << "No" << endl;
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
char maze[21][21];
#define r(z,x) for(int z=0;z<x;z++)
int ans;
void dfs(int x,int y){
	int dx[4]={0,-1,0,1};
	int dy[4]={1,0,-1,0};
	maze[x][y]='#';
	ans++;
	r(i,4)if(maze[x+dx[i]][y+dy[i]]=='.')dfs(x+dx[i],y+dy[i]);
}
int main(){
	int a,b;
	while(cin>>a>>b,a||b){
		ans=0;
		fill(maze[0],maze[20],'#');
		r(i,b)r(j,a)cin>>maze[i][j];
		r(i,b)r(j,a)if(maze[i][j]=='@')dfs(i,j),cout<<ans<<endl;
	}
}

Measured memory_bytes: 3068
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstring>
using namespace std;
const int INF = 1e9;

struct edge{
  int to, cap, rev;
  edge(int t, int c, int r){
    to = t; cap = c; rev = r;
  }
};

void add_edge(int from, int to, int cap, vector< vector<edge> > &g){
  g[from].push_back( edge(to,cap,g[to].size()) );
  g[to].push_back( edge(from,0,g[from].size()-1) );
}

int dfs(int v, int t, vector< vector<edge> > &g, vector<int> &used){
  if(v==t)return INF;
  used[v] = 1;
  for(int i=0;i<(int)g[v].size();i++){
    edge &e = g[v][i];
    if(!used[e.to] && e.cap>0){
      int d = min(e.cap, dfs(e.to,t,g,used));
      if(d>0){
	e.cap -= d;
	g[e.to][e.rev].cap += d;
	return d;
      }
    }
  }
  return 0;
}

int max_flow(int s, int t, vector< vector<edge> > &g){
  int flow = 0;
  while(1){
    vector<int> used(g.size(),0);
    int f = dfs(s,t,g,used);
    if(f==0)return flow;
    flow += f;
  }
}

int gcd(int a,int b){
  if(!b)return a;
  return gcd(b,a%b);
}

int main(){
  int m,n;
  while(1){
    cin >> m >> n;
    if(!m && !n)break;

    vector<int> b(m),r(n);
    for(int i=0;i<m;i++)cin >> b[i];
    for(int i=0;i<n;i++)cin >> r[i];

    vector< vector<edge> > g(n+m+2);
    for(int i=1;i<=m;i++)add_edge(0,i,1,g);
    for(int i=m+1;i<=m+n;i++)add_edge(i,m+n+1,1,g);

    for(int i=0;i<m;i++){
      for(int j=0;j<n;j++){
	if(gcd(b[i],r[j])>1)add_edge(i+1,m+j+1,1,g);
      }
    }

    cout << max_flow(0,m+n+1,g) << endl;
  }
}

Measured memory_bytes: 5648
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const int INF=1001001001;

int main(void){
    string S;
    int n;
    cin>>n>>S;
    int ans=0;
    for(int i=0;i<n-2;i++){
        if(S[i]=='A'){
            if(S[i+1]=='B'&&S[i+2]=='C'){
                ans++;
            }
        }
        
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<map>
#include<algorithm>
#include<cmath>
#include<string>
#include<cstdlib>

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

using namespace std;
 
typedef long long int ll;

const ll INF=(ll)1e18;

int main(){
    int H,W;

    cin >> H >> W;

    int c[10][10];

    REP(i,10)REP(j,10){
        int tmp;
        cin >> tmp;
        c[i][j] = tmp; 
    }


    REP(i,10)REP(j,10)REP(k,10){
        c[j][k] = min(c[j][k], c[j][i] + c[i][k]);
    }
    // REP(i,10)REP(j,10){
    //     printf("%d %d: %d\n",i,j,c[i][j]);
    // }
    int ans = 0;
    REP(i,H)REP(j,W){
        int a;
        cin >> a;
        if(a != -1 && a != 1){
            ans += c[a][1];
        }
    }

    cout << ans << endl;

}

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

void solve(){
unordered_map<long long,unordered_map<long long,long long>> dp;
long long n;
cin>>n;
vector<vector<long long>> v(n,vector<long long>(3,0));
for(long long i=0;i<n;i++){
	long long a,b,c;
	cin>>a>>b>>c;
	v[i][0]=a;
	v[i][1]=b;
	v[i][2]=c;	
}
dp[0][0]=v[0][0];
dp[0][1]=v[0][1];
dp[0][2]=v[0][2];
for(long long i=1;i<n;i++){

	dp[i][0]=max(dp[i-1][1],dp[i-1][2])+v[i][0];
	
	dp[i][1]=max(dp[i-1][0],dp[i-1][2])+v[i][1];
	
	dp[i][2]=max(dp[i-1][1],dp[i-1][0])+v[i][2];
}
cout<<max(dp[n-1][0],max(dp[n-1][1],dp[n-1][2]));
return ;
}



int main() {
solve();


}



Measured memory_bytes: 28580
#[allow(unused_imports)]
use std::cmp::{max, min, Ordering};
#[allow(unused_imports)]
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};
#[allow(unused_imports)]
use std::io::{stdin, stdout, BufWriter, Write};
#[allow(unused_imports)]
use std::iter::FromIterator;
mod util {
    use std::fmt::Debug;
    use std::io::{stdin, stdout, BufWriter, StdoutLock};
    use std::str::FromStr;
    #[allow(dead_code)]
    pub fn line() -> String {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        line.trim().to_string()
    }
    #[allow(dead_code)]
    pub fn chars() -> Vec<char> {
        line().chars().collect()
    }
    #[allow(dead_code)]
    pub fn gets<T: FromStr>() -> Vec<T>
    where
        <T as FromStr>::Err: Debug,
    {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        line.split_whitespace()
            .map(|t| t.parse().unwrap())
            .collect()
    }
    #[allow(dead_code)]
    pub fn with_bufwriter<F: FnOnce(BufWriter<StdoutLock>) -> ()>(f: F) {
        let out = stdout();
        let writer = BufWriter::new(out.lock());
        f(writer)
    }
}
#[allow(unused_macros)]
macro_rules ! get { ( [ $ t : ty ] ) => { { let mut line : String = String :: new ( ) ; stdin ( ) . read_line ( & mut line ) . unwrap ( ) ; line . split_whitespace ( ) . map ( | t | t . parse ::<$ t > ( ) . unwrap ( ) ) . collect ::< Vec < _ >> ( ) } } ; ( [ $ t : ty ] ; $ n : expr ) => { ( 0 ..$ n ) . map ( | _ | get ! ( [ $ t ] ) ) . collect ::< Vec < _ >> ( ) } ; ( $ t : ty ) => { { let mut line : String = String :: new ( ) ; stdin ( ) . read_line ( & mut line ) . unwrap ( ) ; line . trim ( ) . parse ::<$ t > ( ) . unwrap ( ) } } ; ( $ ( $ t : ty ) ,* ) => { { let mut line : String = String :: new ( ) ; stdin ( ) . read_line ( & mut line ) . unwrap ( ) ; let mut iter = line . split_whitespace ( ) ; ( $ ( iter . next ( ) . unwrap ( ) . parse ::<$ t > ( ) . unwrap ( ) , ) * ) } } ; ( $ t : ty ; $ n : expr ) => { ( 0 ..$ n ) . map ( | _ | get ! ( $ t ) ) . collect ::< Vec < _ >> ( ) } ; ( $ ( $ t : ty ) ,*; $ n : expr ) => { ( 0 ..$ n ) . map ( | _ | get ! ( $ ( $ t ) ,* ) ) . collect ::< Vec < _ >> ( ) } ; }
#[allow(unused_macros)]
macro_rules ! debug { ( $ ( $ a : expr ) ,* ) => { eprintln ! ( concat ! ( $ ( stringify ! ( $ a ) , " = {:?}, " ) ,* ) , $ ( $ a ) ,* ) ; } }
const BIG_STACK_SIZE: bool = true;
#[allow(dead_code)]
fn main() {
    use std::thread;
    if BIG_STACK_SIZE {
        thread::Builder::new()
            .stack_size(32 * 1024 * 1024)
            .name("solve".into())
            .spawn(solve)
            .unwrap()
            .join()
            .unwrap();
    } else {
        solve();
    }
}
#[allow(dead_code)]
fn read<T>() -> Vec<T>
where T:
    std::str::FromStr,
    T::Err: std::fmt::Debug {

    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();
    buf.split_whitespace()
        .map(|s| s.trim().parse().unwrap())
        .collect()
}

fn solve() {
    let (t,x) = get!(f64, f64);
    println!("{}", t/x);
}


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

using namespace std;

int main()
{
	long long ans, D, N;

	cin >> D >> N;

	if (N == 100)
	{
		N++;
	}

	ans = pow(100, D) * N;

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

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

        if (x >= 400 && x <= 599) {
            System.out.println(8);
        } else if (x >= 600 && x <= 799) {
            System.out.println(7);
        } else if (x >= 800 && x <= 999) {
            System.out.println(6);
        } else if (x >= 1000 && x <= 1199) {
            System.out.println(5);
        } else if (x >= 1200 && x <= 1399) {
            System.out.println(4);
        } else if (x >= 1400 && x <= 1599) {
            System.out.println(3);
        } else if (x >= 1600 && x <= 1799) {
            System.out.println(2);
        } else if (x >= 1800 && x <= 1999) {
            System.out.println(1);
        } 
    }
}


Measured memory_bytes: 27076
#include <bits/stdc++.h>
template<class T> inline bool chmin(T&a, T b){if(a > b){a = b; return true;}else{return false;}}
template<class T> inline bool chmax(T&a, T b){if(a < b){a = b; return true;}else{return false;}}
#define ll long long
#define double long double
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mod (ll)(1e9+7)
#define inf (ll)(3e18+7)
#define pi (double) acos(-1.0)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
using namespace std;

int main() {
    ll n;
    cin >> n;
    vector<ll> a(n);
    map<ll, ll> mp;
    rep(i, n){
        cin >> a[i];
        mp[a[i]]++;
    }
    ll q, sum = accumulate(all(a), 0LL);
    cin >> q;
    rep(i, q){
        int b, c;
        cin >> b >> c;
        sum -= mp[b] * b;
        sum += mp[b] * c;
        mp[c] += mp[b];
        mp[b] = 0;
        cout << sum << endl;
    }
}

Measured memory_bytes: 9880