akhauriyash/Code-Regression huggingface dataset:
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define MOD 998244353
#define INF (1<<30)
#define LINF (1LL<<60)
#define endl "\n"
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define reprev(i,n) for(int (i)=(n-1);(i)>=0;(i)--)
#define Flag(x) (1<<(x))
#define Flagcount(x) __builtin_popcount(x)
#define pint pair<int,int>
#define pdouble pair<double,double>
#define plint pair<lint,lint>
typedef unsigned long long int ull;
typedef long long lint;

long long powmod(lint a,lint b){
  return b?powmod(a*a%MOD,b/2)*(b%2?a:1)%MOD:1;
}

int main(void){
    int N;
    cin >> N;
    lint D[N];
    rep(i,N) cin >> D[i];
    if(D[0]!=0){
        cout << 0 << endl;
        return 0;
    }
    sort(D,D+N);
    rep(i,N-1){
        if(D[i+1]-D[i]>1){
            cout << 0 << endl;
            return 0;
        }
    }      
    lint Dcount[N]={};
    rep(i,N){
        Dcount[D[i]]++;
    }
    int last=0;
    if(Dcount[0]!=1) cout << 0 << endl;
    else{
        lint ans=1;
        for(int i=N-1;i>=1;i--) if(Dcount[i]!=0 && Dcount[i-1]==0) ans=0;
        rep(i,N) if(Dcount[i]!=0) last=i;
        for(int i=1;i<=last;i++) ans=(ans*powmod(Dcount[i-1],Dcount[i]))%MOD;
        cout << ans << endl;
    }
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define F first
#define S second
//-std=c++11
#define print(x) printf("%.12f",x);
#define sz(x) (int)x.size()
#define all(x) (x).begin(), (x).end()
#define Red ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define rep(i, n) for(int i =0 ; i < n; ++i)
#define repr(i, n) for(int i=n-1;i>=0;i--)
#define Rep(i,a,b) for(int i=a;i<=b;i++)
#define Repr(i,a,b) for(int i=a;i>=b;i--)
#define pii pair < int, int >
#define iter ::iterator
#define forit(a) for(it=a.begin();it!=a.end();it++)
typedef vector<int> vi;
typedef  long long ll;
const int inf = int(1e9);
const int mod = inf + 7;
const int N = (int)2e5 + 5;
int cnt;
void solve(){
	int n;
	cin>>n;
	int a[n];
	int mn=1e8;
	rep(i,n){
		cin>>a[i];
		mn=min(mn,a[i]);
		cnt+= mn==a[i];
	}
	cout<<cnt<<endl;

}


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

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

using namespace std;

#define PI 3.14159265358979323846
#define MOD 1000000007
#define INF 0x3f3f3f3f
#define mp make_pair
#define pb push_back
#define fi first
#define se second

typedef long long ll;
typedef unsigned long long ull;

int main(){
	int x, a, b;

	scanf("%d%d%d", &x, &a, &b);

	if (abs(x - a) < abs(x - b)){
		printf("A\n");
	}
	else{
		printf("B\n");
	}

	return 0;
}

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

int main(){
    int N;
    cin >> N;
    vector<int> A(N);
    for(int i=0;i<N;i++){
        cin >> A[i];
        A[i]--;
    }
    int cnt = 0;
    rep(i,N){
        if(A[A[i]]==i){
            cnt++;
        }
    }
    cout << cnt/2 << endl;
    return 0;
}

Measured memory_bytes: 640
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<math.h>
#include<map>
using namespace std;
int main() {
    int x,y;
    cin >> x >> y;
    int ans = 0;
    switch (x)
    {
    case 1:
        ans += 300000;
        switch (y)
        {
        case 1:
            ans += 700000;
            break;
        case 2:
            ans += 200000;
            break;
        case 3:
            ans += 100000;
            break;
        }
        break;
    case 2:
        ans += 200000;
        switch (y)
        {
        case 1:
            ans += 300000;
            break;
        case 2:
            ans += 200000;
            break;
        case 3:
            ans += 100000;
            break;
        }
        break;
    case 3:
        ans += 100000;
        switch (y)
        {
        case 1:
            ans += 300000;
            break;
        case 2:
            ans += 200000;
            break;
        case 3:
            ans += 100000;
            break;
        }
        break;
    default:
        switch (y)
        {
        case 1:
            ans += 300000;
            break;
        case 2:
            ans += 200000;
            break;
        case 3:
            ans += 100000;
            break;
        }
    }
    cout << ans << endl;
    return 0;
}

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

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

int main(){
  int n,m;
  cin >> n >> m;
  std::vector<pair<int, int>> p(m);
  rep(i,m) cin >> p[i].first >> p[i].second;
  rep(x,1000) {
    int keta = 1;
    int nx = x / 10;
    std::vector<int> d(1,x%10);
    while (nx) {
      keta++;
      d.push_back(nx%10);
      nx /= 10;
    }
    if (keta != n) continue;
    bool ok = true;
    reverse(d.begin(),d.end());
    rep(i,m) {
      if (d[p[i].first-1] != p[i].second) ok = false;
    }
    if (ok) {
      cout << x << endl;
      return 0;
    }
  }
  cout << -1 << endl;
  return 0;
}


Measured memory_bytes: 3596
package main

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

var sc *bufio.Scanner

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

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

type vertex struct {
	num     int
	prev    *vertex
	visited []bool
}

func findCycle(n int, adj []map[int]struct{}) ([]int, bool) {
	for i := 1; i <= n; i++ {
		queue := make([]vertex, 0)
		queue = append(queue, vertex{i, nil, make([]bool, n+1)})
		for len(queue) > 0 {
			v := queue[0]
			queue = queue[1:]
			for x := range adj[v.num] {
				if v.visited[x] {
					ret := []int{v.num}
					for v.num != x {
						ret = append(ret, v.prev.num)
						v = *v.prev
					}
					return ret, true
				}
				visited := make([]bool, n+1)
				copy(visited, v.visited)
				visited[v.num] = true
				queue = append(queue, vertex{x, &v, visited})
			}
		}
	}
	return []int{}, false
}

func main() {
	sc = bufio.NewScanner(os.Stdin)
	sc.Buffer(make([]byte, 0), 1000000001*3)
	sc.Split(bufio.ScanWords)
	n, m := nextInt(), nextInt()
	adj := make([]map[int]struct{}, n+1)
	for ni := 0; ni <= n; ni++ {
		adj[ni] = make(map[int]struct{})
	}
	for i := 0; i < m; i++ {
		a, b := nextInt(), nextInt()
		adj[a][b] = struct{}{}
	}

	cycle, ok := findCycle(n, adj)
	if !ok {
		fmt.Println(-1)
		return
	}

	for i := 0; ; i++ {
		if i >= len(cycle)-1 {
			break
		}
		for j := i + 1; ; j++ {
			if j >= len(cycle) {
				break
			}
			_, ok := adj[cycle[i]][cycle[j]]
			if ok {
				cycle = cycle[i : j+1]
				i, j = 0, j-i
			}
		}
	}
	fmt.Println(len(cycle))
	for _, c := range cycle {
		fmt.Println(c)
	}
}


Measured memory_bytes: 5504
def check(P, k, n, T):
    res = 0
    for _ in range(k):
        s = 0
        while s + T[res] <= P:
            s += T[res]
            res += 1
            if res == n:
                return n
    return res

n, k = map(int, input().split())
w = [int(input()) for _ in range(n)]

left = 0
right = n * 10000
mid = (left + right) // 2
while right - left > 1:
    v = check(mid, k, n, w)
    if v == n:
        right = mid
    else:
        left = mid
    mid = (left + right) // 2
print(right)


Measured memory_bytes: 9564
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 1e9 + 7;
const ll INF = 1LL << 60;
#define rep(i, a, n) for (ll i = (a); i < (n); i++)
#define debug(x) cerr << #x << ": " << x << endl;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

int main() {
    ll n;
    cin >> n;
    string s;
    cin >> s;
    ll ans=0;
    rep(i, 0, n-2) {
        if(s.substr(i, 3) == "ABC") ans++;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define MAX 1000003
#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define endl "\n"
#define all(a) (a).begin(),(a).end()
#define input(a) for(int i=0;i<a.size();i++) cin>>a[i];
#define test int t; cin>>t; while(t--)
#define vi vector<int>
#define vii vector<pair<int,int>>
#define ii pair<int,int>
#define ff first
#define ss second
using namespace std;

void solve(){
	int n; cin>>n;
	if(n%1000==0) cout<<0;
	else cout<<1000 - n%1000;
}

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

Measured memory_bytes: 3564
// template version 1.14
using namespace std;
#include <bits/stdc++.h>

// varibable settings
#define int long long
const int INF=1e18;
const int MOD=1e9+7;

// define basic macro {{{
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define _rrep(i,n) rrepi(i,0,n)
#define rrepi(i,a,b) for(int i=(int)((b)-1);i>=(int)(a);--i)
#define rrep(...) _overload3(__VA_ARGS__,rrepi,_rrep,)(__VA_ARGS__)
#define each(i,a) for (auto&& i : a)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define pb(a) push_back(a)
#define mp(a, b) make_pair(a, b)
#define mt(a, b, c) make_tuple(a, b, c)
#define ceil(a,b) ((a)+(b)-1)/(b)
#define is_in(x, a, b) ((a)<=(x) && (x)<(b))
#define uni(x) sort(all(x));x.erase(unique(all(x)),x.end())
#define ub upper_bound
#define lb lower_bound
#define posl(A, x) (lower_bound(all(A), x)-A.begin())
#define posu(A, x) (upper_bound(all(A),x)-A.begin())
template<class T> inline void chmax(T &a, const T &b) { if((a) < (b)) (a) = (b); }
template<class T> inline void chmin(T &a, const T &b) { if((a) > (b)) (a) = (b); }

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long double ld;
typedef pair<int,int> pii;
typedef tuple<int,int,int> iii;

template<typename T> using PQ = priority_queue<T, vector<T>, greater<T>>;
struct Fast { Fast(){ std::cin.tie(0); ios::sync_with_stdio(false); } } fast;

#if defined(PCM) || defined(LOCAL)
  #include "lib/dump.hpp"
#else
  #define dump(...) 42
  #define dump_1d(...) 42
  #define dump_2d(...) 42
#endif
//}}}

signed main() {
  int m1,d1,m2,d2;
  cin>>m1>>d1>>m2>>d2;
  if (m1!=m2){
    cout << 1 << endl;
  }
  else{
    cout << 0 << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#![allow(unused_mut)]
#![allow(non_snake_case)]
#![allow(unused_macros)]
#![allow(unused_variables)]
#![allow(unused_imports)]
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
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 mut $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")
    };
}

macro_rules! max {
    ($x: expr) => ($x);
    ($x: expr, $($y: expr),+) => {
        ::std::cmp::max($x, max!($($y),+))
    };
}

macro_rules! min {
    ($x: expr) => ($x);
    ($x: expr, $($y: expr),+) => {
        ::std::cmp::min($x, max!($($y),+))
    };
}

use std::cmp;
use std::collections::{HashSet, BinaryHeap};
fn main() {
    input! {
        Q: usize,
        query: [(usize, usize); Q],
    }

    let like2017_countsum = eratosthenes_variant(100_000);
    for &(l, r) in query.iter() {
        println!("{}", like2017_countsum[r] - like2017_countsum[l-1]);
    }
}

fn eratosthenes_variant(max: usize) -> Vec<usize> {
    let search_bound = (max as f64).sqrt().ceil() as usize;
    let mut like2017_countsum = vec![0; max+1];
    let mut is_primes = vec![true; max+1];
    is_primes[0] = false;
    is_primes[1] = false;

    let mut count = 0;
    for candidate in 2..max+1 {
        if is_primes[candidate] {
            let prime = candidate;
            if prime <= search_bound {
                for no_prime in prime .. max/prime+1 {
                    let no_prime = no_prime * prime;
                    is_primes[no_prime] = false;
                }
            }
            if is_primes[(prime+1)/2] { count += 1; }
        }
        like2017_countsum[candidate] = count;
    }

    like2017_countsum
}


Measured memory_bytes: 6780
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define pb push_back
#define ins insert
#define pqueue(x) priority_queue<x,vector<x>,greater<x>>
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
#define vtpl(x,y,z) vector<tuple<x,y,z>>
#define rev(x) reverse(x);
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
using vpl=vector<pl>;
using vvpl=vector<vpl>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[8]={1,0,-1,0,1,1,-1,-1};
const ll dx[8]={0,-1,0,1,1,-1,1,-1};
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
int main(){
    CST(12);
    double a,b,h,m;cin >> a >> b >> h >>m;
    double radl=2,radm=2;
    radl*=(h/12+m/60/12);
    radm*=(m/60);
    double rad=radl-radm;
    //cout << rad <<endl;
    //if(rad>1)rad-=1;
    //cout << rad <<endl;
    //cout << rad <<endl;
    double ans=a*a+b*b-2*a*b*cos(rad*acos(-1));
    cout << sqrt(ans) <<endl;
}


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

struct Node
{
    int key;
    Node *parent, *right, *left;
};

Node *root; //初めはnullptr

void Insert(int key)
{
    Node *y = nullptr;
    Node *x = root;
    Node *z = new Node;
    z->key = key;

    while (x != nullptr)
    {
        y = x;
        if (z->key < x->key)
        {
            x = x->left;
        }
        else
        {
            x = x->right;
        }
    }

    z->parent = y;
    if (z->parent == nullptr)
    {
        root = z;
    }
    else if (z->key < y->key)
    {
        y->left = z;
    }
    else
    {
        y->right = z;
    }
}

Node *Find(int key)
{
    Node *x = root;
    while (x != nullptr && key != x->key)
    {
        if (key < x->key)
        {
            x = x->left;
        }
        else
        {
            x = x->right;
        }
    }

    return x;
}

void Inorder(Node *u)
{
    if (u == nullptr)
    {
        return;
    }
    Inorder(u->left);
    cout << ' ' << u->key;
    Inorder(u->right);
}

void Preorder(Node *u)
{
    if (u == nullptr)
    {
        return;
    }
    cout << ' ' << u->key;
    Preorder(u->left);
    Preorder(u->right);
}

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

    int num;
    string tmp;
    int key;

    cin >> num;
    for (int i = 0; i < num; i++)
    {
        cin >> tmp;
        if (tmp == "insert")
        {
            cin >> key;
            Insert(key);
        }
        else if (tmp == "find")
        {
            cin >> key;
            if (Find(key) != nullptr)
            {
                cout << "yes" << endl;
            }
            else
            {
                cout << "no" << endl;
            }
        }
        else if (tmp == "print")
        {
            Inorder(root);
            cout << endl;
            Preorder(root);
            cout << endl;
        }
    }

    return 0;
}



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

using namespace std;

typedef vector<int> vi;
typedef pair<int,int> pii;

#define dump(x)  cerr << #x << " = " << (x) << endl
#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back

int data[200][200]={};
int t,n;


int main(){
    while(cin>>t>>n){
        if(t==0 && n==0)break;
        
        rep(i,200)rep(j,200)data[i][j]=100;
        
        rep(i,n){
            int x,y;
            cin>>x>>y;
            x+=100;y+=100;
            data[y][x]=-1;
        }
        int a,b;
        cin>>a>>b;
        a+=100;b+=100;
        data[b][a]=0;
        
        int dx[]={0,1,1,0,-1,-1};
        int dy[]={1,1,0,-1,-1,0};
        
        for(int time=1;time<=t;time++){
            rep(i,200){
                rep(j,200){
                    if(data[i][j]==time-1){
                        rep(k,6){
                            if(data[i+dy[k]][j+dx[k]]!=-1) data[i+dy[k]][j+dx[k]]=min(data[i+dy[k]][j+dx[k]],time);
                        }
                    }
                    
                }
            }
        }
        int c=0;
        rep(i,200){
            rep(j,200){
                if(data[i][j]!=-1 && data[i][j]!=100)c++;
            }
        }
        
        cout<<c<<endl;
    }
    
}

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

// Function Macros:
#define rep(i, n) for(int(i) = 0; (i) < (n); (i)++)
#define all(v) (v).begin(), (v).end()
#define setpre(n) cout << fixed << setprecision(n)

// Type / Class / Struct Definitions:
using namespace std;

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

// Constants:
const int INF = (1ll << 30) - 1;  // approx 1.07e9
const ll INFLL = 1ll << 60;       // approx 1.15e18
const int MOD = 1e9 + 7;          // 998244353
const long double EPS = 1.0e-14;

// Global Variables:

// Prototype Declarations:
int gcd(int, int);
template <class T>
inline bool chmin(T&, T);
template <class T>
inline bool chmax(T&, T);

// ================ Main Loop ================
int main() {
    int n;
    cin >> n;
    if(n % 10 == 7)
        cout << "Yes" << endl;
    else if((n / 10) % 10 == 7)
        cout << "Yes" << endl;
    else if((n / 100) == 7)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    return 0;
}
// ===========================================

// Functions:
int gcd(int a, int b) {
    return b ? gcd(b, a % b) : a;
}

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

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


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

using namespace std;
using ll = long long;

const ll mod = 1e9 + 7;

#define MOD 1000000007
template<int mod>
struct ModInt{
   int x;
   ModInt():x(0){}
   ModInt(long long y):x(y>=0?y%mod:(mod-(-y)%mod)%mod){}
   ModInt &operator+=(const ModInt &p){
       if((x+=p.x)>=mod)x-=mod;
       return *this;
   }
   ModInt &operator-=(const ModInt &p){
       if((x+=mod-p.x)>=mod)x-=mod;
       return *this;
   }
   ModInt &operator*=(const ModInt &p){
       x=(int)(1LL*x*p.x%mod);
       return *this;
   }
   ModInt &operator/=(const ModInt &p){
       *this*=p.inverse();
       return *this;
   }
   ModInt &operator^=(long long p){
       ModInt res = 1;
       for (; p; p >>= 1) {
           if (p & 1) res *= *this;
           *this *= *this;
       }
       return *this = res;
   }
   ModInt operator-()const{return ModInt(-x);}
   ModInt operator+(const ModInt &p)const{return ModInt(*this)+=p;}
   ModInt operator-(const ModInt &p)const{return ModInt(*this)-=p;}
   ModInt operator*(const ModInt &p)const{return ModInt(*this)*=p;}
   ModInt operator/(const ModInt &p)const{return ModInt(*this)/=p;}
   ModInt operator^(long long p)const{return ModInt(*this)^=p;}
   bool operator==(const ModInt &p)const{return x==p.x;}
   bool operator!=(const ModInt &p)const{return x!=p.x;}
   explicit operator int() const { return x; }
   ModInt operator=(const int p) {x = p; return ModInt(*this);}
   ModInt inverse()const{
       int a=x,b=mod,u=1,v=0,t;
       while(b>0){
           t=a/b;
           a-=t*b;
           std::swap(a,b);
           u-=t*v;
           std::swap(u,v);
       }
       return ModInt(u);
   }
   friend std::ostream &operator<<(std::ostream &os,const ModInt<mod> &p){
       return os<<p.x;
   }
   friend std::istream &operator>>(std::istream &is,ModInt<mod> &a){
       long long x;
       is>>x;
       a=ModInt<mod>(x);
       return (is);
   }
};
typedef ModInt<MOD> mint;


int main()
{
    int n, m; cin >> n >> m; vector<int> s(n + 1), t(m + 1); for(int i = 1; i <= n; i++)cin >> s[i];
    for(int i = 1; i <= m; i++)cin >> t[i];
    vector<vector<mint>> dp(n + 1, vector<mint>(m + 1)); // dp[i][j] := s[i], t[j]まで見たときの共通部分列の個数

    for(int i = 1; i <= n; i++) {
        for(int j = 1; j <= m; j++) {
            dp[i][j] = dp[i - 1][j] + dp[i][j - 1] - dp[i - 1][j - 1];

            if(s[i] == t[j]) {
                dp[i][j] += dp[i - 1][j - 1] + 1;
            }
        }
    }
    
    cout << (dp[n][m] + 1) << endl;
}

Measured memory_bytes: 16000
import java.util.Scanner;

public class Main {

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

		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();

		if (a + b == c || a + c == b || b + c == a) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
	}

}


Measured memory_bytes: 35644
s = input()
rm=0
for i in range(len(s)):
    if len(s)%2 !=0:
        s = s[:-1]
        rm += 1
        continue
    if s[0:len(s)//2] == s[len(s)//2:len(s)] and rm > 0:
        break
    else:
        s = s[:-1]
        rm += 1
print(len(s))

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; ++i)
#define ALL(v) v.begin(), v.end()
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1000000007;

int main()
{
	ll n;
	cin >> n;
	vector<ll> a(n);
	rep(i,n)cin >> a[i];
	map<ll ,ll> mp;
	rep(i,n)
	mp[a[i]] ++;
	vector<ll> b,c;
	for(auto i = mp.begin();i != mp.end(); ++i)
	{
		if(i->second>1)b.push_back(i->first);
		if(i->second>3)c.push_back(i->first);
	}
	sort(ALL(b),greater<ll>());
	sort(ALL(c),greater<ll>());
	if(b.size()<2)
	{
		cout<<0<<endl;
	}
	else
	{
		cout<<max(b[0]*b[1],c.size()>0 ? c[0]*c[0]:0)<<endl;
	}
	
	return 0;
}

Measured memory_bytes: 7296
//shan61916
#include <bits/stdc++.h>
  using namespace std;
typedef   long long ll;
typedef   unsigned long long ull ;
typedef   double dll ;

#define   mp make_pair
#define   pb push_back
#define   ff first 
#define   ss second
#define   IOS ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define   endl "\n" 
#define   pll pair<ll, ll>
#define   all(x) x.begin(), x.end()
#define   vll vector<ll> 

const ll inf = (ll)(1e17 + 17);
const ll mod = (ll)(1e9 + 7);


int main(){
 IOS
#ifdef SHAN
    freopen("input.txt" , "r" , stdin);  
#endif
  ll m, k;
  cin >> m >> k;
  ll maxx = (1ll<<m) - 1;
  if(k > maxx) {
    cout << -1;
    return 0;
  }
  if(m == 1) {
    if(k == 0) {
      cout << "0 0 1 1" << endl;
    } else {
      cout << "-1" << endl;
    }
    return 0;
  }
  for(ll i = 0; i <= maxx; i++) {
    if(i == k)continue;
    cout << i << " ";
  }
  cout << k << " ";
  for(ll i = maxx; i >= 0; i--) {
    if(i == k) continue;
    cout << i << " ";
  }
  cout << k << endl;
  return 0;
} //good night.

Measured memory_bytes: 1792
#define dbg(...) fprintf(stderr,__VA_ARGS__)
#define dpr(x) cerr<<#x<<": "<<x<<endl;
#define dprc(c) do{cerr<<#c<<":";for(auto&_i:(c)){cerr<<" "<<_i;}cerr<<endl;}while(0)
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
int INF = 1e9+7;
#define all(c) begin(c), end(c)
#define tr(i,c) for(auto i=begin(c);i!=end(c);i++)
#define rtr(i,c) for(auto i=(c).rbegin();i!=(c).rend();i++)
#define rep(i,b) for(auto i=0;i<(b);i++)
#define pb push_back
#define sz(c) int((c).size())

static int swap_count;

void bubbleSort(vi& A, int N) {
  bool flag = true;
  while (flag) {
    flag = false;
    for (int j = N-1; j > 0; j--) {
      if (A[j] < A[j-1]) {
        swap(A[j], A[j-1]);
        flag = true;
        swap_count++;
      }
    }
  }
}

int main(int argc, char **argv)
{
  int N;
  cin >> N;
  vi A(N);
  for (auto& a:A) {
    cin >> a;
  }
  bubbleSort(A, N);
  string sp = "";
  for (auto& a:A) {
    cout << sp << a;
    sp = " ";
  }
  cout << endl;
  cout << swap_count << endl;

  return 0;
}

Measured memory_bytes: 3144
p = int(input())
a = list(map(int,input().split()))
b = [0]*p
fact = [1]*(p+1)
for i in range(p):
    fact[i+1] = (i+1)*fact[i]
    fact[i+1] %= p
factinv = [1]*p
for i in range(p):
    factinv[i] = pow(fact[i],p-2,p)
powl = [[1]*(p+1) for _ in range(p+1)]
for i in range(p+1):
    for j in range(p):
        powl[i][j+1] = (i*powl[i][j])%p

for i in range(1,p):
    k1 = powl[i][p-2]
    k2 = powl[p-1][p-1-i]
    if a[i]==1:
        for j in range(1,p):
            kj = powl[k1][j]
            b[j] += kj*k2*factinv[i]*factinv[p-1-i]
            b[j] %= p

if a[0]==1:
    b[0] += 1
    b[0] %= p
    b[p-1] += p-1
    b[p-1] %= p

print(*b)

Measured memory_bytes: 115932
#include <bits/stdc++.h>
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define ll long long int
#define pii pair<int,int>
#define pll pair<long long int,long long int>
#define pci pair<char,int
#define mii map<int,int>
#define mll map<long long int,long long int>
#define mci map<char,int>
#define umii unordered_map<int,int>
#define umll unordered_map<long long int,long long int>
#define umci unordered_map<char,int>
#define F first
#define S second
#define pb push_back
#define endl '\n'
#define mod 1000000007
using namespace std;
#define maxval 10003000


int main(){
   IOS;
ll x;cin>>x;
  cout<<1-x;


    
return 0;    
}

Measured memory_bytes: 3608
import scala.io.StdIn.{readLine,readInt}

object Main extends App {
  var w = ""

  def shuffle(cnt:Int, w:String):String =
    if(cnt == 0)  w else { val m = readInt;shuffle(cnt-1, (w drop m)+(w take m)) }

  def exec(w:String):Unit =
    if(w=="-") return else { val n = readInt;println(shuffle(n,w));exec(readLine) }

  exec(readLine.trim)
}

Measured memory_bytes: 43892
#encoding:utf-8 No.0049 2014.10.3
data = []
while gets
  data.push $_.chomp.split(/,/)
end

a,b,ab,o = 0,0,0,0
data.length.times do |i|
  if data[i][1] == "A"
    a += 1
  elsif data[i][1] == "B"
    b += 1
  elsif data[i][1] == "AB"
    ab += 1
  else
    o += 1
  end
end

puts a
puts b
puts ab
puts o

Measured memory_bytes: 6096
package main

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

var stdin = bufio.NewScanner(os.Stdin)

func main() {
	stdin.Split(bufio.ScanWords)
	S := make([]byte, 100000)
	S = []byte(nextStr())
	def := []byte("CODEFESTIVAL2016")
	cnt := 0
	for i, s := range S {
		if s != def[i] {
			cnt++
		}
	}
	fmt.Println(cnt)
}

func nextInt() int {
	stdin.Scan()
	i, err := strconv.Atoi(stdin.Text())
	if err != nil {
		panic(err)
	}
	return i
}

func nextStr() string {
	stdin.Scan()
	return stdin.Text()
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin>>n;
  int d[n];
  for(int i=0;i<n;++i){
    cin>>d[i];
  }
  sort(d,d+n);
  int tem=0,count=0;
  for(int i=0;i<n;++i){
    if(d[i]!=tem){
      count++;
      tem = d[i];
    }
  }
  cout<<count;
  return 0;

}


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

signed main(){
    int A,B,C;
    cin >> A >> B >> C;
    
    if(A == B && B == C) cout << "No" << endl;
    else if(A != B && B != C && A != C) cout << "No" << endl;
    else cout << "Yes" << endl;
    
    return 0;
}



Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp58
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] input = Console.ReadLine().Split(' ');
            int K = int.Parse(input[0]);
            int S = int.Parse(input[1]);
            int count = 0;
            for (int x = 0; x <= K; x++)
            {
                for(int y = 0; y <= K; y++)
                {
                    int z = S - x - y;
                    if(0<=z && z <= K)
                    {
                        count++;
                    }
                }
            }
            Console.WriteLine(count);
        }
    }
}


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

#define FOR(i,s,t) for(int i=s; i < t; i++)
#define REP(i,n) FOR(i,0,n)
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define LL long long
#define SWAP(type,a,b) do{type tmp=a;a=b;b=tmp;} while(0)
#define dump(x) cerr<<#x<<"="<<x<<", "
#define dumpl(x)cerr<<#x<<"="<<x<<endl


#define dump_vec(a)  for(const auto& e : a) {cerr << e << std::endl; }

int main(){

    int K;
    cin >> K;



    if(K%2 ==0 || K%5 ==0){
        cout << "-1" ;
        return(0);
    }

    int L;
    if(K%7 == 0) L = (int) 9*(K/7);
    else L = 9*K;

    int p = 10 % L;
    int i = 1;

    while(true){
        if(p == 1){
            cout << i;
            return(0);
        }

        p *= 10;
        p %= L;
        i++;
    }

    return(0);
}


Measured memory_bytes: 3636
N, A, B = list(map(int,input().split()))
if (B * (N-1) + A) - (B + (N-1) * A) < 0:
  print(0)
elif A == B:
  print(1)
else:
  print((B * (N-1) + A) - (B + (N-1) * A) + 1)

Measured memory_bytes: 3060
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt(), b = sc.nextInt(), c = sc.nextInt() , k = sc.nextInt();
        String s = "a";
        int result = 0;
        
        int minA =  Math.min(a, k);
        result += minA;
        
        k -= minA;
        if (k < 0) {
            System.out.println(result);
            return;
        }
        
        k -= b;
        if (k < 0) {
            System.out.println(result);
            return;
        }

        int minC =  Math.min(c, k);
        result -= minC;

        System.out.println(result);
    }
}

Measured memory_bytes: 27052
#include <iostream>
using namespace std;
int main(void){
  int N;
  int res=0;
  cin >> N;
  int A[N];
  int B[N];
  for(int i=0; i<N; ++i){
    cin >> A[i];
  }
  for(int i=0; i<N; ++i){
    cin >> B[i];
  }
  for(int i=0; i<N; ++i){
    if ((A[i]-B[i]) >=0){
      res = res+A[i]-B[i];
    }
  }
  cout << res;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <iostream>
#include <memory>
#include <memory.h>
#include <fstream>
#include <cmath>
#include <numeric>
#include <vector>
#include <stack>
#include <string>
#include <queue>
#include <sstream>
#include <cstdlib>
#include <cassert>
#include <cstdio>
#include <cstring>
#include <map>
#include <set>
#include <iomanip>
#include <list>
#include <cctype>
#include <algorithm>
#include <complex>
using namespace std;

typedef complex<double> xy_t;
typedef pair<xy_t, xy_t> line;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<double, double> Pd;
typedef pair<int, P> PP;
typedef pair<int, PP> PPP;
const int INF = 1 << 29;
const double EPS = 1E-10;

#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, m, n) for(int i = m; i < n; i++)

int n;
map<int, int> memo[25];
map<int, int> nxt[5];

int dx[] = {1, 0, -1, 0, 1, 1, -1, -1};
int dy[] = {0, -1, 0, 1, 1, -1, 1, -1};
int h(int i, int j){
	return n * i + j;
}

void print(int state, int pos){
	cout << pos / n << " " << pos % n << endl;
	rep(i, n){
		rep(j, n){
			if(state & (1 << h(i, j))) cout << "#";
			else cout << '.';
		}
		cout << endl;
	}
	cout << endl;
}

bool cango(int state, int i, int j){
	int s = state & (1 << h(i, j));
	return (0 <= i && i < n && 0 <= j && j < n && s == 0);
}

int get_next(int state){
	if(nxt[n-1][state]) return nxt[n-1][state] - 1;
	int res = 0;
	int pow = 1;

	rep(i, n)rep(j, n){
		int cnt = 0;
		int s = h(i, j);

		bool f = (state & (1 << s)) ? true : false;
		rep(k, 8){
			int i2 = i + dy[k];
			int j2 = j + dx[k];
			if(0 <= i2 && i2 < n && 0 <= j2 && j2 < n){	
				int s2 = h(i2, j2);
				if(state & (1 << s2)) cnt++;
			}
		}

		if((f && (cnt == 2)) || cnt == 3){
			res += pow;
		}
		pow <<= 1;
	}
	nxt[n-1][state] = res + 1;
	return res;

}

int bfs(int state, int pos){
	rep(i, n * n) memo[i].clear();

	memo[pos][state] = 1;
	queue<P> que;
	que.push(P(state, pos));

	while(!que.empty()){
		P p = que.front();
		que.pop();
		state = p.first;
		pos = p.second;
		
		if(state == 0){
			//cout << "!!!!!!!!!!!!!!" << " " << memo[pos][state] << endl;
			return memo[pos][state] - 1;
		}

//		print(state, pos);
		int i1 = pos / n;
		int j1 = pos % n;
		//cout << nstate << endl;

		rep(i, 8){
				
			int i2 = i1 + dy[i];
			int j2 = j1 + dx[i];
			
			if(cango(state, i2, j2)){
				int nstate = get_next((state | (1 << h(i2, j2)))) & ~(1 << h(i2, j2));
				//print(nstate, h(i2, j2));
				if(memo[h(i2, j2)][nstate] == 0){
					
					memo[h(i2, j2)][nstate] = memo[pos][state] + 1;
					que.push(P(nstate, h(i2, j2)));
				}
			}
			
		}
	}
	return -1;
}

int main(){
	
	while(cin >> n && n){
		int state = 0;
		int pos = 0;
		int pow = 1;
		char c;
		rep(i, n)rep(j, n){
			cin >> c;
			if(c == '#') state += pow;
			else if(c == '.') ;
			else {
				pos = h(i, j);
			}
			pow <<= 1;
		}
		cout << bfs(state, pos) << endl;
	}
	return 0;
}

Measured memory_bytes: 20000
#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define ll long long int
#define pb push_back
typedef pair<ll,ll> ipair;
#define F first
#define S second


int main() {
	ios_base::sync_with_stdio(false);
    std::cin.tie(NULL);
    std::cout.tie(NULL);
    
    
	ll n,i,j,p,k,m,ans=0;
    cin>>n;
    vector<ll> a(n);
    for(i=0;i<n;i++)
    {
        cin>>a[i];
    }
    
    map<ll,ll> mp;
    for(i=0;i<n;i++)
    {
        mp[i+a[i]]++;
    }
    for(i=0;i<n;i++)
    {
        ans+=mp[i-a[i]];
    }
    cout<<ans<<endl;
    
    
    
    
    
    
    // for(i=0;i<n;i++)
    // {
    //     cout<<a[i]<<" ";
    // }
    // cout<<endl;
    
	return 0;
}

Measured memory_bytes: 27464
import java.util.Scanner;


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

		String S = sc.next();
		boolean result = false;
      	String test[] = {"dream", "dreamer", "erase", "eraser"};
		int index = S.length();

		loop: for (int i = 0; i < 20001; i++) {
          	if (index == 0) {
				result = true;
				break;
			}
          	for (int j = 0; j < test.length; j++) {
              	if (index - test[j].length() >= 0
                	&& test[j].equals(S.substring(index - test[j].length(), index))) {
                	index -= test[j].length();
                	continue loop;
                }
            }
			break;
		}

		System.out.println(result ? "YES" : "NO");
	}
}

Measured memory_bytes: 29420
#include <bits/stdc++.h>
#pragma GCC optimize ("Ofast", "unroll-loops")
using namespace std;
#define ll long long
#define int ll
#define FOR(i,a,b) for (int i = (a); i<(b); i++)
#define REP(i,n) FOR(i,0,n)
#define REP1(i,n) FOR(i,1,n+1)
#define RREP(i,n) for (int i=(n)-1; i>=0; i--)
#define f first
#define s second
#define pb push_back
#define ALL(x) x.begin(),x.end()
#define SZ(x) (int)(x.size())
#define SQ(x) (x)*(x)
#define pii pair<int, int>
#define pdd pair<double ,double>
#define endl '\n'
#define PI 3.14159265
//#define TOAD
#ifdef TOAD
#define bug(x) cerr<<__LINE__<<": "<<#x<<" is "<<x<<endl
#define IOS()
#else
#define bug(...)
#define IOS() ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#endif
const ll inf = 1ll<<60;
const int iinf=1ll<<60;
const ll mod = 1e9+7;
const ll maxn=5e3+5;
ll pw(ll x, ll p){
    ll ret=1;
    while (p>0){
        if (p&1){
            ret*=x;
        }
        x*=x;
        x%=mod;
        p>>=1;
    }
    return ret;
}
 
ll inv(ll a, ll b){
    return 1<a ? b - inv(b%a,a)*b/a : 1;
}
 
int dp[405][405];
signed main (){
    IOS();
    int n; cin>>n;
    vector<int> vc(n+1);
    REP1(i,n) cin>>vc[i];
    vector<int> pf(n+1);
    pf[1]=vc[1];
    REP1(i,n-1){
        pf[i+1]=pf[i]+vc[i+1];
    }
    /*REP1(i,n) cout<<pf[i]<<' ';
 
    cout<<endl;
    */
    REP(i,n+1) REP(j,n+1) dp[i][j]=iinf;
    for (int i=n;i>=1;i--) {
        FOR(j,i,n+1){
            if (i==j){
                dp[i][j]=0;
                continue;
            }
            FOR(k,i,j){
                dp[i][j]=min(dp[i][j], dp[i][k]+dp[k+1][j]+pf[j]-pf[i-1]);
            }
            bug(i);
            bug(j);
            bug(dp[i][j]);
        }
    }
 
    cout<<dp[1][n]<<endl;
}

Measured memory_bytes: 4928
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod=1e9+7;
const int INF=1e9+7;
const int maxn=2e5+5;
int a[10]={0,2,5,5,4,5,6,3,7,6};

struct note{
    int i,cost;

    bool operator < (const note & x) const {
        return i>x.i;
    }
}t[100];

int ans[100],tot,flag;
int temp[100],at;
int n,m,mi=99,di;
int l1;

void bi()
{
     int f=0;
     if (tot>at)
     {
         f=1;
     }
     else 
    for( int q=0;q<tot;q++)
    {
        if (ans[q]>temp[q]){
            f=1;
            break;
        }
        else if (ans[q]<temp[q]) break;
    }

    if (f)
    {
        for (int q=0;q<tot;q++)
        temp[q]=ans[q];
        at=tot;
    }
}
void dfs(int yu)
{
    if (yu==0)
    {
        if (flag)
        {
            bi();
        }
        else
        {
            flag=1;
            at=tot;
            for( int q=0;q<tot;q++)
            temp[q]=ans[q];
        }
        return ;
    }

    for (int q=0;q<m;q++)
    {
        if (yu>=t[q].cost)
        {
            yu-=t[q].cost;
            ans[tot++]=t[q].i;
            dfs(yu);
            tot--;
            yu+=t[q].cost;      
        }
    }
}

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

    for (int q=0;q<m;q++)
    {
        scanf("%d",&t[q].i);
        t[q].cost=a[t[q].i];
        if (mi>t[q].cost)
        {
            mi=t[q].cost;
            di=t[q].i;
        }
        else if (mi==t[q].cost)
        {
            di=max(di,t[q].i);
        }
    }

    sort(t,t+m);
    int len=n/mi;
    int yu=n%mi;
    tot=0;
    flag=0;

    if (len>=5)
    {
        len-=5;
        yu+=mi*5;
    }
    else 
    {
        yu+=len*mi;
        len=0;
    }

    dfs(yu);

    tot=at;
    if (flag)
    {
        int l=0;
        for (;l<tot;l++)
        {
            if (temp[l]>di)
            {
                printf("%d",temp[l]);
            }
            else break;
        }

        for (int q=0;q<len;q++) printf("%d",di);
        for (;l<tot;l++)
        printf("%d",temp[l]);
    }

    printf("\n");

}



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

int main() {
  long int X, K, D, x, k, ans;
  cin >> X >> K >> D;
  X = abs(X);
  k = X/D;
  if(K > k){
    if((K-k)%2 == 1) ans = abs(X-(k+1)*D);
    if((K-k)%2 == 0) ans = abs(X-k*D);
  }else{
    ans = X - K*D;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3632
#include<map>
#include<string>
#include<vector>
#include<iostream>

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

using namespace std;

typedef vector< vector<int> > vvi;

const int INF=1<<29;

void GabowDFS(int u,vector<bool> &visited,vector<int> &nodes,const vvi &adj){
	if(visited[u]) return;
	visited[u]=true;
	rep(i,adj[u].size()){
		int v=adj[u][i];
		if(!visited[v]) GabowDFS(v,visited,nodes,adj);
	}
	nodes.push_back(u);
}

vvi GabowSCC(const vvi &adj){
	int n=adj.size();
	vector<int> ord;
	vector<bool> visited(n);
	rep(u,n) GabowDFS(u,visited,ord,adj);

	vvi radj(n);
	rep(u,n) rep(i,adj[u].size()) radj[adj[u][i]].push_back(u);

	vvi sccs;
	rep(u,n) visited[u]=false;
	for(int i=n-1;i>=0;i--){
		int u=ord[i];
		vector<int> scc;
		GabowDFS(u,visited,scc,radj);
		if(scc.size()>0) sccs.push_back(scc);
	}
	return sccs;
}

int main(){
	for(int n;cin>>n,n;){
		int m=0;
		map<string,int> f;

		vvi adj(n);
		int day1[1000],day2[1000];
		rep(i,n){
			string s1,s2;
			int d1,d2; cin>>s1>>d1>>s2>>d2;
			if(f.count(s1)==0) f[s1]=m++;
			if(f.count(s2)==0) f[s2]=m++;

			int u=f[s2],v=f[s1];
			adj[u].push_back(v);
			day1[v]=d1;
			day2[v]=d2;
		}

		vvi scc=GabowSCC(adj);

		int ans=0;
		bool tool[1000]={};
		rep(i,scc.size()){
			int dif=INF;
			bool start=true;
			rep(j,scc[i].size()){
				int u=scc[i][j];
				ans+=day2[u];
				dif=min(dif,day1[u]-day2[u]);
				if(tool[u]) start=false;
			}
			if(start) ans+=dif;

			rep(j,scc[i].size()){
				int u=scc[i][j];
				rep(k,adj[u].size()) tool[adj[u][k]]=true;
			}
		}

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

	return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const int INF = 1e9;
const int MOD = INF+7;
const ll LINF = 1e18;
#define rep(i,N) for(int (i)=0;(i)<(N);++(i))
#define rrep(i,N) for(int (i)=(N-1);(i)>0;--i)
#define FOR(i,j,N) for(int (i)=(j);(i)<(N);++(i))
#define put(n) cout<<(n)<<endl;
#define all(v) v.begin(),v.end()
#define MP make_pair
#define pb(n) push_back(n)


int main(){
    int X;
    cin >> X;
    if(X == 7 || X == 5 || X == 3) cout <<"YES"<< endl;
    else cout <<"NO"<< endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>

typedef long long int int64;

void run(void){
  const int mod=1000000007;
  int n,k;
  scanf("%d%d",&n,&k);
  int *dp=(int *)calloc(2*(k+1),sizeof(int));
  dp[0]=1;
  int now=0;
  while(n--){
    int a;
    scanf("%d",&a);
    int next=now^(k+1);
    int i;
    int local=0;
    for(i=k;i>=k-a;i--) local=(local+dp[now+i])%mod;
    for(i=k;i-a-1>=0;i--){
      dp[next+i]=local;
      local=((int64)local+dp[now+i-a-1]-dp[now+i]+mod)%mod;
    }
    for(;i>=0;i--){
      dp[next+i]=local;
      local=(local-dp[now+i]+mod)%mod;
    }
    now=next;
  }
  printf("%d\n",dp[now+k]);
}

int main(void){
  run();
  return 0;
}


Measured memory_bytes: 896
#include<iostream>
#include<cmath>
#include<algorithm>
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<<#X<<": "<<X<<" ";
#define ARDEB(i,X) cout<<#X<<"["<<i<<"]: "<<X[i]<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define ARDEB(X) {}
#define END {}
#endif
using namespace std;
int main(){
	int n,k,x,y;
	cin>>n>>k>>x>>y;
	if(n>k)cout<<x*k+y*(n-k)<<endl;
	else cout<<x*n<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<limits.h>

#define M 500000

void merge(int *,int,int,int);
void mergeSort(int *,int,int);

int count=0;
int S[M];

int main(){
  int n,i;

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

  mergeSort(S,0,n);

  for(i=0;i<n;i++){
    if(i<n-1) printf("%d ",S[i]);
    else printf("%d\n",S[i]);
  }
  printf("%d\n",count);

  return 0;
}

void merge(int *A,int left,int mid,int right){
  int n1,n2,i,j,k;
  int *L,*R;

  n1 = mid - left;
  n2 = right - mid;

  L = malloc((n1+1)*sizeof(int));
  R = malloc((n2+1)*sizeof(int));

 for(i=0;i<n1;i++){
   L[i]=A[left+i];
 }
 for(i=0;i<n2;i++){
   R[i]=A[mid+i];
 }
 
   L[n1]=INT_MAX;
   R[n2]=INT_MAX;
   i=0;
   j=0;
 
   for(k=left;k<right;k++){
     if(L[i]<=R[j]){
       A[k]=L[i];
       i++;
     }
     else{
       A[k] = R[j];
       j++;
     }
     count++;
   }
 
}

void mergeSort(int *A,int left,int right){
  int mid;

  if(left+1<right) {
    mid = (left+right)/2;

    mergeSort(A,left,mid);
    mergeSort(A,mid,right);
    merge(A,left,mid,right);
  }
}

Measured memory_bytes: 63340
#include<bits/stdc++.h>
using namespace std;
int main() {
    int N; cin>>N;
    int Alice,Bob,ans;Alice=0,Bob=0,ans=0;
    vector<int> a(N);
    for (int i=0;i<N;i++) {//入力
        cin>>a[i];
    }
    sort(a.begin(),a.end());//昇順
    reverse(a.begin(),a.end());//反転

    for(int i=0;i<N;i++){//場合分け
        if(i%2==0){//Alice
        Alice=Alice+a[i];
        }
        else{//Bob
        Bob=Bob+a[i];
        }
    }
    ans=max(Alice,Bob)-min(Alice,Bob);//差分答え
    cout<<ans;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
#define debug(x) cerr<<#x<<' '<<x<<'\n'
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
const int maxn=2e5+10;
const int mod=1e9+7;
const int inf=0x3f3f3f3f;
int book[maxn];
int main()
{
    ios::sync_with_stdio(false);cin.tie(0);
    int n,cnt=0;
    cin>>n;
    rep(i,1,n) cin>>book[i];
    int Min=inf;
    rep(i,1,n) {
        if(book[i]<Min) {
            Min=book[i];
            cnt++;
        }
    }
    cout<<cnt<<'\n';
    return 0;
}



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


int main()
{
    int H, W, N;
    cin >> H >> W >> N;
    int si, sj;
    cin >> si >> sj;
    si --; sj--;
    char S[N], T[N];
    cin >> S;
    cin >> T;
    
    bool flag = true;
    int u = si, d = H-1-si;
    int l = sj, r = W-1-sj;
    // cout << si << ' ' << ' ' << sj << endl;
    // cout << l << ' ' << r << ' ' << u << ' ' << d << ' ' << endl;
    for (int i =0; i < N; i++)
    {
        if (S[i] == 'L')
            l --;
        if (S[i] == 'R')
            r --;
        if (S[i] == 'U')
            u --;
        if (S[i] == 'D')
            d --;
        
        if (l < 0 or r < 0 or u < 0 or d < 0)
        {
            // cout << l << ' ' << r << ' ' << u << ' ' << d << ' ' << endl;
            flag = false;
            break;
        }

        if (T[i] == 'L')
            r ++;
        if (T[i] == 'R')
            l ++;
        if (T[i] == 'U')
            d ++;
        if (T[i] == 'D')
            u ++;

        if (l > W-1) l = W - 1;
        if (r > W-1) r = W - 1;
        if (u > H-1) u = H - 1;
        if (d > H-1) d = H - 1;

        // cout << l << ' ' << r << ' ' << u << ' ' << d << ' ' << endl;
    }
    if (flag)
        cout << "YES"<< endl;
    else
        cout << "NO"<< endl;
    return 0;
}

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

using namespace std;

typedef long long ll;

const ll MOD = 1000000007;

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

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

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    ll n, m; cin >> n >> m;
    string s; cin >> s;
    string t; cin >> t;
    ll ans = lcm(n, m);
    ll bs = ans / n;
    ll bt = ans / m;
    ll iv = lcm(bs, bt);
    for(ll pos=0;pos<ans;pos+=iv){
        ll p = pos * n / ans;
        ll q = pos * m / ans;
        // cout << p << " " << q << endl;
        if(s[p] != t[q]){
            cout << -1 << endl;
            return 0;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
#include<iostream>
using namespace std;
int main(){
  string S;
  cin >> S;
  vector<string> k(4);
  for(int i = 0; i < 4; i++)
    k.at(i) = S[i];
  int check = 0;
  int p = 0;
  for(int i = 1; i < 4; i++){
    if(k.at(0) == k.at(i)){
      check++;
      p = i;
      break;
    }
  }
  int chk = 0;
  for(int i = 1; i < 3; i++){
    if(i == p)
      continue;
    for(int j = i; j < 4; j++){
      if(j == p || i == j)
        continue;
      else{
        if(k.at(i) == k.at(j) && k.at(i) != k.at(0) && k.at(j) != k.at(0))
          chk++;
      }
    }
  }
  if(check && chk)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}

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

int main(void) {
	 
	 int a,b,c,d;
	 
	 cin >>a>>b>>c>>d;
	 
	 if((a*b)>=(c*d))
	 cout<<a*b;
	 else
	 cout<<c*d;
	 
	return 0;
}

Measured memory_bytes: 256