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

#define Fast           ios_base::sync_with_stdio(0);cin.tie(0),cout.tie(0)
#define FO             freopen("in.txt", "r", stdin)
#define FC             freopen("out.txt", "w", stdout)
#define aise           cout<<"aise"<<endl
#define pb             push_back
#define pf             push_front
#define ppb            pop_back
#define ppf            pop_front
#define mp             make_pair
#define ll             long long
#define all(x)         x.begin(), x.end()
#define mset(v, a)     memset(v, a, sizeof(v))
#define pll            pair< ll, ll >
#define pd             pair< double, double >
#define ff             first
#define ss             second
#define pi             acos(-1.0)
#define mxN            2010
#define inf            1e14
#define mod            1000000007

//NCR iterative
/*voidcomb_table(intN)
{
    for(inti=0; i<=N; ++i)
    {
        for(intj=0; j<=i; ++j)
        {
            if(j==0or j==i)
            {
                C[i][j]=1LL;
            }
            else
            {
                C[i][j]=(C[i-1][j-1]+C[i-1][j]);
            }
        }
    }
}*/


//NCR recursive
/*ll dp[55][55];

ll NCR(ll n,ll r)
{

    if(n==r)
        return dp[n][r]=1;
    if(r==0)
        return dp[n][r]= 1;
    if(r==1)
        return dp[n][r]=n ;
    if(dp[n][r] != -1)
        return dp[n][r];
    return dp[n][r] = NCR(n-1,r)+NCR(n-1,r-1);
}*/

//Sieve:
/*bool Flag[1000010];
vector<ll> Prime;

void sieve()
{

    ll val=sqrt(1000010);
    for(ll i=4;i<=1000005; i+=2) Flag[i]=1;
    for(ll i=3;i <= val;i+=2)
    {

        if(Flag[i]==0)
        {

            for(ll j=i*i;j<=1000005;j+=i) Flag[j]=1;
        }
    }
    Flag[1]=1;
    for(ll i=1;i<=1000000;i++)
        if(Flag[i]==0) Prime.pb(i);
}*/


//Conversion
/*string bin(ll x)
{

    string ret;
    while(x)
    {

        ll t=x%2;
        char c;
        if(t==1)
            c='1';
        else
            c='0';
        ret.pb(c);
        x/=2;
    }
    reverse(all(ret));
    return ret;
}*/

/*ll lcm(ll x, ll y)
{

    ll ret=__gcd(x,y);
    return (x*y)/ret;
}*/

/*ll dx[]= {0,0,1,-1};
ll dy[]= {1,-1,0,0};*/

vector<ll> adj[10];
ll vis[10];
ll n,m;

ll call(ll node, ll cnt)
{

    if(vis[node]==1) return 0;
    if(cnt==n) return 1;
    vis[node]=1;
    ll ans=0;
    for(ll i=0;i<adj[node].size();i++)
        ans+=call(adj[node][i],cnt+1);
    vis[node]=0;
    return ans;
}

int main()
{

    cin >> n >> m;
    for(ll i=0;i<m;i++)
    {

        ll x,y;
        cin >> x >> y;
        adj[x].pb(y);
        adj[y].pb(x);
    }
    mset(vis,0);
    ll ans=call(1,1);
    cout << ans;
}


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

int a, b;

int main() {
  cin >> a >> b;
  // 数値結合
  int union_int = stoi(to_string(a) + to_string(b));
  int range = pow(union_int, 0.5);
  for (int i = 1; i <= range; ++i) {
    if (pow(i, 2) == union_int) {
      cout << "Yes" << endl;
      return 0;
    } 
  }
  cout << "No" << endl;
  
  return 0;
}

Measured memory_bytes: 384
import Control.Applicative
import qualified Data.IntMap as Map

main = do
  [target,_] <- map (read :: String -> Int) . words <$> getLine
  coins <- map (read :: String -> Int) . words <$> getLine
  print $ (resolve target coins (Map.fromList (zip [0..target] [0,0..]))) Map.! target

resolve :: Int -> [Int] -> Map.IntMap Int -> Map.IntMap Int
resolve target (n:ns) tagMap
  |null ns   = dp n tagMap
  |otherwise = resolve target ns (dp n tagMap)
  where
    dp :: Int -> Map.IntMap Int -> Map.IntMap Int
    dp n tagMap
      | n > target = tagMap
      | otherwise  = dp' n tagMap 0
    dp' :: Int -> Map.IntMap Int -> Int -> Map.IntMap Int
    dp' n tagMap x
      | (x + n) > target = tagMap
      | x == 0  = ins
      | oldcoins == 0 = dp' n tagMap  (x+1)
      | oldcoins + 1 < newcoins = ins
      | newcoins == 0 = ins
      | otherwise    = dp' n tagMap (x+1)
      where
        newcoins = tagMap Map.! (n+x)
        oldcoins :: Int
        oldcoins = tagMap Map.! x
        ins :: Map.IntMap Int
        ins = (dp' n (Map.insert (x+n) (oldcoins + 1) tagMap) (x+1))

Measured memory_bytes: 16400
#include<stdio.h>
#include<math.h>

int test(int N){
    
  int i=3;
if(N==2)return 1;

if(N<2 || N%2==0)return 0;

while(i<=sqrt(N)){
  if(N%i==0)return 0;
  i=i+2;
}
return 1;
}
int main(void){
int N;
int n,i;
int t=0;

while(1){
scanf("%d",&n);
if(n>=1 && n<=10000)break;
}
for(i=0 ; i<n ; i++){
    
  while(1){
  scanf("%d",&N);
  if(N>=2 && N<=100000000)break;
  }
  t+=test(N);
}

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

return 0;
}


Measured memory_bytes: 2028
#include <iostream>
#include <vector>
using namespace std;
int main(){
    int k;
    cin >> k;
    int s,x,y,z,ans=0;
    cin >> s;
    for(x = 0;x<=k;x++){
        for(y = 0;y<=k;y++){
            if((s-x-y<=k)&&(s-x-y>=0) ){
                ans ++;
            }
        }
    }
    cout << ans;
    return 0;
}

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

using namespace std;
vector<string> ans;

int main(){
	int n;
	cin >> n;
	string mem[256];
	for(int i = 0;i < n;i++){
		cin >> mem[i];
	}
	int m;
	cin >> m;
	bool door = false;
	for(int i = 0;i < m;i++){
		string id;
		cin >> id;
		bool tid = false;
		string mes;
		for(int j = 0;j < n;j++){
			if(id == mem[j]){
				tid = true;
				if(door){
					mes = "Closed by ";
					mes += id;
					door = false;
				}else{
					mes = "Opened by ";
					mes += id;
					door = true;
				}
				break;
			}
		}
		if(!tid){
			mes = "Unknown ";
			mes += id;
		}
		ans.push_back(mes);
	}
	for(int i = 0;i < ans.size();i++) cout << ans[i] << endl;
	return 0;
}

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

using namespace std;
 
using ll = long long;
using ull = unsigned long long;
using ldouble = long double;
 
const ll inf = 1ll << 60;
const ll mod = (ll)1e9 + 7;

#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define print(s) cout << s;
#define println(s) cout << s << endl;
#define printd(s) cout << fixed << setprecision(10) << s << endl;

string res;

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

    res = "No";
    for (char c : n)
    {
        if (c == '9')
        {
            res = "Yes";
        }
    }

    println(res);
}

Measured memory_bytes: 3584
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		double w = sc.nextDouble();
		double h = sc.nextDouble();
		double x = sc.nextDouble();
		double y = sc.nextDouble();
		
		double area = w * h / 2.0;
		int mlt = x * 2 == w && y * 2 == h ? 1 : 0;
		System.out.printf("%f %d\n", area, mlt);
		
		sc.close();
	}
}




Measured memory_bytes: 29008
N = int(input())
S = [int(input()) for _ in range(N)]

S.sort()

s = sum(S)

if s % 10 == 0:
    for ss in S:
        if (s - ss) % 10 != 0:
            print(s - ss)
            exit()

    print(0)

else:
    print(s)

Measured memory_bytes: 9084
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();
		int cnt5 = 0;
		int cnt7 = 0;
		if(a==5){
			cnt5 += 1;
		}else if(a==7){
			cnt7 += 1;
		}
		if(b==5){
			cnt5 += 1;
		}else if(b==7){
			cnt7 += 1;
		}
		if(c==5){
			cnt5 += 1;
		}else if(c==7){
			cnt7 += 1;
		}

		sc.close();
		System.out.println((cnt5==2&&cnt7==1) ? "YES":"NO");
	}
}

Measured memory_bytes: 20564
#include <iostream>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <utility>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>

using namespace std;

#define rep(i,n) for(int i=0; i<(n); i++)
#define repc(i,s,e) for(int i=(s); i<(e); i++)
#define pb(n) push_back((n))
#define mp(n,m) make_pair((n),(m))
#define all(r) r.begin(),r.end()
#define fi first
#define se second

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<ll> vl;
typedef vector<vl> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

set<string> se;
string s, t, u, v;
int ans;


void calc() {
	v = u + t;
	if (se.count(v) == 0) {
		ans++;
		se.insert(v);
		//cout << v << endl;
	}
	v = t + u;
	if (se.count(v) == 0) {
		ans++;
		se.insert(v);
		//cout << v << endl;
	}
}


int main() {
	int n;
	cin >> n;
	rep(i, n) {
		cin >> s;
		se.clear();
		ans = 0;
		rep(j, s.size()) {
			t = s.substr(0, j);
			u = s.substr(j, s.size());
			calc();
			reverse(all(t));
			calc();
			reverse(all(u));
			calc();
			reverse(all(t));
			calc();
		}
		cout << ans << endl;
	}
}

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

int main(void) {
	
	int n, c;
	long d, j;
	
	scanf("%d", &n);
	
	c = 0;
	while (n-- != 0) {
		scanf("%ld", &d);
		if (d & 1) {
			for (j = 3; j * j < d; j += 2) {
				if (0 == d % j) {
					break;
				}
			}
			if (j * j > d) {
				c++;
			}
		} else {
			if (d == 2) {
				c++;
			}
		}
	}
	printf("%d\n", c);

	return 0;
}

Measured memory_bytes: 596
#include<iostream>
#include<string.h>
#include<ctype.h>
#include<string>
#include<math.h>
#define pi 3.141592653589
#include<iomanip>
using namespace std;
#include<algorithm>
#define rep(i,a,n) for(int i=a;i<n;i++)
#define INF 1e9
#define ll long long
 
 
 
 
 
int main(){
    
    ll n,k,a,b;
    ll cnt[100000]={},sum=0;
    
    cin>>n>>k;
    rep(i,0,n){
        cin>>a>>b;
        cnt[a-1]+=b;
    }
    rep(i,0,100000){
        sum+=cnt[i];
        if(sum>=k){
            cout<<i+1<<endl;
            break;
        }
    }
    
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
using ll = long long;
ll a, b, v, w, t;
int main(){
	scanf("%lld%lld%lld%lld%lld", &a, &v, &b, &w, &t);
	a = abs(a-b);
	v = v-w;
	if(v * t >= a) puts("YES");
	else puts("NO");
}

Measured memory_bytes: 3688
dic = [False for i in range(26)]
txt = input()
for i in txt:
  dic[ord(i) - 97] = True
for i in range(26):
  if not dic[i]:
    print(txt + chr(i + 97))
    break
else:
  for j in range(25):
    if txt[24 - j] < txt[25 - j]:
      
      last = txt[24-j] #以降の文字列を修正
      txt = txt[:24 - j]
      
      dic = [False for i in range(26)]
      for k in txt:
        dic[ord(k) - 97] = True
      txt += chr(dic[ord(last) - 96:].index(False) + ord(last) + 1)

      print(txt)
      break

  else:
    print(-1)

Measured memory_bytes: 9048
n = int(input())
info = [list(map(int, input().split())) for i in range(n)]

ans1 = []
ans2 = []
for i in range(n):
    x, y = info[i]
    ans1.append(x + y)
    ans2.append(x - y)
    
ans1 = sorted(ans1)
ans2 = sorted(ans2)
ans = max(abs(ans1[0] - ans1[-1]), abs(ans2[0] - ans2[-1]))
print(ans)

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

int main() {
  string A,B,C;
  cin >> A >> B >> C;
  
  int X = A.size();
  int Y = B.size();
  
  if(A.at(X-1)==B.at(0) && B.at(Y-1)==C.at(0))
    cout << "YES" << endl;
  else 
    cout << "NO" << endl;
    
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <limits.h>
using namespace std;
int main()
{
    long long a, b, x;
    while(cin>>a>>b>>x){
        long long cnt=0;
        long long pa=a%x, na;
        if(pa==0){
            cnt+=1;
            na=a;
        }
        else {
            cnt+=1;
            na=a+x-pa;
        }
        if(na<=b){
            cnt+=(b-na)/x;
        }
        else cnt=0;
        cout<<cnt<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<unordered_set>
#include<unordered_map>
using namespace std;
int main(){
	int n;
	cin>>n;
	vector<int> h(n);
	for(int i=0;i<n;i++)
		cin>>h[i];
	vector<int> dp(n);
	dp[0] = 0;
	dp[1] = abs(h[1]-h[0]);
	for(int i=2;i<n;i++)
		dp[i] = min(dp[i-1]+abs(h[i]-h[i-1]),dp[i-2]+abs(h[i]-h[i-2]));
	cout<<dp[n-1];
	return 0;
}



Measured memory_bytes: 3952
////////////////////////////////////////////
///                                      ///
///        Template ver. 1.2. rapel      ///
/// Fear is Temporary, Regret is Forever ///
///          Must Try and Get AC         ///
///                                      ///
////////////////////////////////////////////
#include <stdio.h>
#include <iostream>
#include <sstream>
#include <iomanip>

#include <algorithm>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <utility>

#include <math.h>
#include <complex>

#include <assert.h>
#include <time.h>
#include <chrono>
#include <random>

#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <queue>
#include <stack>
#include <list>
#include <bitset>

#define F first
#define S second
#define pb push_back
#define pf push_front
#define pob pop_back
#define pof pop_front
#define endl '\n'
using namespace std;

typedef long long ll;
typedef unsigned long long ull;

//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

void desperate_optimization(int precision){
  	ios_base::sync_with_stdio(false);
  	cin.tie(0);
  	cout.tie(0);
  	cout.setf(ios::fixed);
  	cout.setf(ios::showpoint);
  	cout.precision(precision);
}

const int N = 1e5;
ll a[N + 5];
ll ssum[N + 5];

void hora(int tc) {
	int n;
	cin>>n;
	for(int i = 0;i <= n;i++) cin>>a[i];
	if(n == 0) {
		if(a[0] == 1) cout<<1<<endl;
		else cout<<-1<<endl;
		return ;
	}
	for(int i = n;i >= 0;i--) ssum[i] = ssum[i + 1] + a[i];
	ll cur = 1;
	bool bisa = true;
	for(int i = 0;i <= n;i++) {
		cur -= a[i];
		if(cur < 0) bisa = false;
		if(cur < 1e14) cur *= 2;
	}
	if(bisa == false) {
		cout<<-1<<endl;
		return ;
	}
	ll tot = 1;
	cur = 1;
	for(int i = 0;i < n;i++) {
		cur -= a[i];
		if(cur * 2 <= ssum[i + 1]) {
			tot += cur * 2;
			cur *= 2;
		} else {
			tot += ssum[i + 1];
			cur = ssum[i + 1];
		}
	}
	cur -= ssum[n];
	assert(cur == 0);
	cout<<tot<<endl;
}

int main(){
	desperate_optimization(10);
	int ntc = 1;
	//cin>>ntc;
	for(int tc = 1;tc <= ntc;tc++) hora(tc);
	return 0;
}


Measured memory_bytes: 5172
#include <bits/stdc++.h>
using namespace std;
#define ll long long 
#define endl "\n"
#define pb push_back
#define f(i,n) for(i=0;i<n;i++)
#define F(i,a,b) for(i=a;a<=b;i++)
#define arr(a,n) for( i=0;i<n;i++)cin>>a[i];
#define fi first
#define se second
#define mp make_pair
#define mod 1000000007
#define YES cout<<"YES"<<endl;
#define Yes cout<<"Yes"<<endl;
#define NO cout<<"NO"<<endl;
#define No cout<<"No"<<endl;
#define yes cout<<"yes"<<endl;
#define no cout<<"no"<<endl;
#define vi vector<ll>
#define ed end()
#define bg begin()
#define sz size()
#define ln length()
#define s() sort(a,a+n);
#define sr() sort(a,a+n,greater<ll>());
#define v()  sort(v.begin(),v.end());
#define vr() sort(v.begin(),v.end(),greater<ll>());
#define mod 1000000007
#define fast() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
ll gcd(ll a, ll b){if(!b)return a;return gcd(b, a % b);}
ll power(ll x,ll y,ll p){ll res=1;x%=p;while(y>0){if(y&1)res=(res*x)%p;y=y>>1;x=(x*x)%p;}return res;}
int main() {
   /* #ifndef ONLINE_JUDGE
        // for getting input from input.txt
        freopen("input.txt", "r", stdin);
        // for writing output to output.txt
        freopen("output.txt", "w", stdout);
    #endif*/
        /* 
        Ofcourse it's Hard.
        It's supposed to be Hard.
        If it's easy everyone would do it.
        HARD IS WHAT MAKES IT GREAT

        YESTERDAY U SAID TOMORROW

        SLOWLY BECOMING THE PERSON I 
        SHOULD HAVE BEEN A LONG TIME AGO

        SAME TASK CAN'T BE FOUND DIFFICULT TWICE

        BTBHWSITW

        SPRH TU KAB P

        CP IS ALL ABOUT THINKING 
        YOU HAVE MUCH MORE POTENTIAL THAN U THINK

        AJIT SHIDDAT 10

        UR DAILY ROUTINE 


        */

fast();
//ll t;cin>>t;while(t--)
{
    string s,t;
    cin>>s>>t;
    ll f=0,n=0,m,count=0;
    n=s.length();
    m=t.length();
    map<char,char>ss,tt;
    set<char>sett;
    if(n!=m)
      No
    else
    {
    for(int i=0;i<m;i++)
    {
      if(!ss[s[i]])
        ss[s[i]]=t[i];
      else if(ss[s[i]]!=t[i])
        f=1;
      if(!tt[t[i]])
        tt[t[i]]=s[i];
      else if(tt[t[i]]!=s[i])
        f=1;


    }

    
    

    if(f)
      No
    else
      Yes
  }
}
return 0;
}

Measured memory_bytes: 916
import math

N = int(input())

p = 2
counter = 0
while N != 1:
 if p > math.sqrt(N):
  counter += 1
  break
 ind = 0
 n = -1
 while N % p == 0:
  N //= p
  ind += 1
 if ind == 0:
  p += 1
  continue
 while (n+1)*(n+2)//2 <= ind:
  n += 1
 counter += n
 p += 1

print(counter)

Measured memory_bytes: 9192
S = input()
hantei1 = 0
hantei2 = 0

S1 = int(S[0] + S[1])
S2 = int(S[2] + S[3])

if S1 > 0 and S1 <13 :
    hantei1 = 1
if S2 > 0 and S2 <13 :
    hantei2 = 1

if hantei1 == 1 and hantei2 == 1:
    print("AMBIGUOUS")
elif hantei1 == 1 and hantei2 == 0:
    print("MMYY")
elif hantei1 == 0 and hantei2 == 1:
    print("YYMM")
else:
    print("NA")

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int main(){
    long long int a,b,c,d;
    cin>>a>>b>>c>>d;
    long long int max=a*c;
    if(max<a*d)
    max=a*d;
    if(max<b*c)
    max=b*c;
    if(max<b*d)
    max=b*d;
    cout<<max<<endl;
}

Measured memory_bytes: 3620
#include <iostream>
#include<math.h>
#include<algorithm>
#include<string>
#include<vector>
#include<iomanip>
using namespace std;
#define FOR(i,n) for(int (i)=0;(i)<(n);(i)++)

int retl(int K,int L){
    int tmp=0;
    while(pow(2,tmp) * L < K){
        tmp++;
    }
    return tmp;
}

struct A{
    string s;
    int p;
    int order;
};


int main(){
    string S;

    cin >>S;
    bool x=true;
    FOR(i,3){
        if(S[i+1]==S[i]){
            x=false;
        }
    }
    if(x){
        cout <<"Good"<<endl;
    }else{
        cout <<"Bad"<<endl;
    }

  

    //cout<<ans<< endl;

    return 0;
}

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

int N, K;
string S;

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

  char p = S[K - 1];

  for (int i = 0; i < N ; ++i) {
    if (S[i] != p) S[i] = '*';
  }
  cout << S << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>  // sort, 二分探索, etc
#include <iomanip>  // setprecision (浮動小数点の出力の誤差)
#include <map>
#include <queue>
#include <set>
#include <stack>

#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=a,i##_len=(b);i<i##_len;++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define cauto const auto&
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define SIZE(x) ((ll)(x).size()) // sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x))
#define INF 1000000000000
#define MOD 1000000007
#define perm(c) sort(all(c));for(bool c##p=1;c##p;c##p=next_permutation(all(c)))

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

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

const char newl = '\n';

ll qp(ll a,ll b){ll ans=1;do{if(b&1)ans*=a;a*=a;}while(b>>=1);return ans;}
ll qp(ll a,ll b,ll mod){ll ans=1;do{if(b&1)ans=ans*a%mod;a=a*a%mod;}while(b>>=1);return ans;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll comb(int n, int r) {
    vector<vector<ll> > v(n+1, vector<ll>(r+1, 0));
    for(int i=0;i<n+1;i++) {v[i][0]=1; if(i < r+1)v[i][i]=1; }
    for(int i=1;i<n+1;i++) {for(int j=1;j<min(i,r+1);j++) {v[i][j]=v[i-1][j-1]+v[i-1][j];}}
    return v[n][r];
}

// INT_MAX   = 2.1e+09 (2147483647)
// LONG_MAX  = 9.2e+18 (9223372036854775807)
// LLONG_MAX = 9.2e+18 (9223372036854775807)


int main() {
    int n;
    cin >> n;
    vector<ll> vec;
    map<ll, ll> mp;
    rep(i, n) {
        ll x;
        cin >> x;
        vec.push_back(x);
        mp[i - x] += 1;
    }

    ll total = 0;
    rep(i, n) {
        ll left = vec[i] + i;
        total += mp[left];
    }

    cout << total << newl;

    return 0;
}


Measured memory_bytes: 27184
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++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(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<long double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

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

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }

#define INF 1LL<<60

int main() {
    ll N, W;
    cin >> N >> W;
    vector<ll> w(N), v(N);
    FOR(i, 0, N-1) cin >> w[i] >> v[i];

    // dp[i][j]: i番目までのアイテムを用いて価値をjにするのに必要な最小の重さ
    ll max_value = N * 1e3;
    vector<vector<ll>> dp(N, vector<ll>(max_value+1, INF));
    
    dp[0][v[0]] = w[0];
    FOR(i, 0, N-1) dp[i][0] = 0;
    for(ll i=1; i<N; i++){
        for(ll j=1; j<=max_value; j++) {
            if( v[i] <= j ) {
                dp[i][j] = min(dp[i-1][j-v[i]] + w[i], dp[i-1][j]); 
            } else {
                dp[i][j] = dp[i-1][j];
            }
        }
    }

    ll ans = 0;
    for(ll j=max_value; j>=0; j--){
        if(dp[N-1][j] <= W) {
            ans = j;
            break;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 79488
#include<bits/stdc++.h>
using namespace std;
#define IO ios_base::sync_with_stdio(false)
#define ll long long
string s;
int vs[200000],a[200000];
map<int, int>mp;
int main()
{
        IO;
        ll i, j=0, n, m, k=1, l=0, r, t,x,y,mx; ll sum=1;
        cin>>n;
        for(i=1; i<=n; i++){
            cin>>a[i];
            l+=mp[i-a[i]];
            mp[i+a[i]]++;
        }
        cout<<l<<endl;

    return 0;
}


Measured memory_bytes: 21436
#!/usr/bin/env python3
S = input()
ans = 0
for l in range(len(S)):
    for r in range(1, len(S) + 1):
        if l < r and all(S[k] in list('ACGT') for k in range(l, r)):
            ans = max(ans, r - l)
print(ans)


Measured memory_bytes: 3060
t1,t2 = list(map(int, input().split()))
a1,a2 = list(map(int, input().split()))
b1,b2 = list(map(int, input().split()))

ptr1 = (b1 - a1) * t1
ptr2 = ptr1 + (b2 - a2) * t2
ptr3 = ptr2 + (b1 - a1) * t1
ptr4 = ptr3 + (b2 - a2) * t2

if ptr2 == 0:
  ans = 'infinity'
elif ptr1 * ptr2 > 0:
  ans = 0
else:
  ans = 1 + 2 * (abs(ptr1) // abs(ptr2))
  if abs(ptr1) % abs(ptr2) == 0:
    ans -= 1

print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define fi first
#define se second
int main(){
    int n,ans=1,max;
    cin >> n;
    vector<int> v(n);
    for(int i=0;i < n;i++)
    {
        cin >> v.at(i);
    }
    
    max = v.at(0);
    for(int i=1;i < n;i++)
    {
        if(v.at(i)>=max){
            ans++;
            max=v.at(i);
        }
    }
    cout << ans << endl;
}



Measured memory_bytes: 256
s=input()
n=len(s)
for x in range(n-1):
    if s[x]==s[x+1]:print(x+1,x+2,sep=" ");exit()
for i in range(n-2):
    if s[i]==s[i+2]:
        print(i+1,i+3,sep=" ");exit()

print("-1 -1")

Measured memory_bytes: 3188
n=int(input())
h=list(map(int,input().split()))
x=0
max=0

for i in range(0,n-1):
  if h[i]>=h[i+1]:
    x=x+1
  else:
    if x>max:
      max=x
    x=0
if x>max:
  max=x
print(max)

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

#define rep(i,n) for (ll i = 0; i < (n); ++i)
#define All(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()   //reverse
#define strall(v) (v).cbegin(),(v).cend() //const_itterator
#define IN(a, b, x) (a<=x&&x<b)
using namespace std;
using ll = long long;
using Pair = pair<int,int>;
using Graph = vector<vector<ll>>;
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
template<typename t, typename u, typename Comp=less<>>
bool chmax(t& xmax, const u& x, Comp comp={}) { if(comp(xmax, x)) { xmax = x; return true; } return false;}
template<typename t, typename u, typename Comp=less<>>
bool chmin(t& xmin, const u& x, Comp comp={}) { if(comp(x, xmin)) { xmin = x; return true;} return false;}
const int INF = 1e9;
const ll infl = ll(1e18)+5;

/*
*ios::sync_with_stdio(false);
*cin.tie(0);
*/

int main(){
   int a,b;
   cin >> a >> b;
   cout << a*b << endl;
}

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


int main (void) {
int A,B,res;
scanf("%d",&A);
scanf("%d",&B);
for (int i=1;i<=3;i++){
    if (i!=A && i!=B) {res=i;}
}
printf("%d",res);
return EXIT_SUCCESS;
}

Measured memory_bytes: 128
#include<stdio.h>
#include<math.h>
#include <stdlib.h>

int compare_int(const void *a, const void *b)
{
    return *(int*)a - *(int*)b;
}

main()
{
  int a,b,c;
    scanf("%d%d%d",&a,&b,&c);

    if(a==b){
        if(a!=c){
            printf("Yes");
        }
        else{
            printf("No");
        }
    }
    else if(a==c){
        printf("Yes");
    }
    else{
        if(b==c){
            printf("Yes");
        }
        else{
            printf("No");
        }
    }


   // int data[] = {4, 2, 3, 6, 3, 2, 1, 3, 5, 7};
   // int i;

    //when you use sort
    /*qsort(data, 10, sizeof(int), compare_int);
    for (i = 0; i < 10; i++) {
        printf("%3d", data[i]);
    }
    printf("\n");
    */


}


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



int main(){
while(true){
	int n, m;
	double g[205][205];
	double dp[205][205];
	cin >> n >> m;
	if(n == 0 && m == 0) return 0;
	std::memset(g, 0.0, sizeof(g));
	std::memset(dp, 0.0, sizeof(dp));
	for(int i = 0; i < n; i++){
		for(int j = 0; j < n; j++){
			cin >> g[j][i];
		}
	}
	for(int i = 0; i < n; i++){
		dp[1][i] = 1.0;
	}
	for(int i = 2; i <= m; i++){
		for(int j = 0; j < n; j++){
			for(int k = 0; k < n; k++){
				dp[i][j] = max(dp[i][j], dp[i - 1][k] * g[j][k]);
			}
		}
	}
	double res = 0.0;
	for(int i = 0; i < n; i++){
		res = max(res, dp[m][i]);
	}
	printf("%.2lf\n",res);
}
}



Measured memory_bytes: 3860
// {{{ by shik
#include <bits/stdc++.h>
#pragma GCC diagnostic ignored "-Wunused-result"
#pragma GCC diagnostic ignored "-Wunused-function"
#define SZ(x) ((int)(x).size())
#define ALL(x) begin(x), end(x)
#define REP(i, n) for (int i = 0; i < int(n); i++)
#define REP1(i, a, b) for (int i = (a); i <= int(b); i++)
#define MP make_pair
#define PB push_back
using namespace std;
typedef int64_t LL;
typedef pair<int, int> PII;
typedef vector<int> VI;

namespace { namespace shik {

template<class T> void _R(T &x) { cin >> x; }
void _R(int &x) { scanf("%d", &x); }
void _R(int64_t &x) { scanf("%" SCNd64, &x); }
void _R(double &x) { scanf("%lf", &x); }
void _R(char &x) { scanf(" %c", &x); }
void _R(char *x) { scanf("%s", x); }
void R() {}
template<class T, class... U> void R(T &head, U &... tail) { _R(head); R(tail...); }

template<class T> void _W(const T &x) { cout << x; }
void _W(const int &x) { printf("%d", x); }
void _W(const int64_t &x) { printf("%" PRId64, x); }
void _W(const double &x) { printf("%.16f", x); }
void _W(const char &x) { putchar(x); }
void _W(const char *x) { printf("%s", x); }
template<class T> void _W(const vector<T> &x) { for (auto i = x.begin(); i != x.end(); _W(*i++)) if (i != x.cbegin()) putchar(' '); }
void W() {}
template<class T, class... U> void W(const T &head, const U &... tail) { _W(head); putchar(sizeof...(tail) ? ' ' : '\n'); W(tail...); }

#ifdef SHIK
#include "dump.hpp"
#else
#define dump(...)
#endif

template<class T, class F = less<T>> void sort_uniq(vector<T> &v, F f = F()) { sort(begin(v), end(v), f); v.resize(unique(begin(v), end(v)) - begin(v)); }
template<class T> inline T bit(T x, int i) { return (x >> i) & 1; }
template<class T> inline bool chkmax(T &a, const T &b) { return b > a ? a = b, true : false; }
template<class T> inline bool chkmin(T &a, const T &b) { return b < a ? a = b, true : false; }
template<class T> using MaxHeap = priority_queue<T>;
template<class T> using MinHeap = priority_queue<T, vector<T>, greater<T>>;

// }}}

const int N=2e5+10;

int n,m,r[N][2];
char s[N];
VI e[N];
bool vis[N];

void main() {
    R(n,m);
    scanf("%s",s+1);
    REP(i,m) {
        int a,b;
        R(a,b);
        e[a].PB(b);
        e[b].PB(a);
    }
    REP1(i,1,n) sort_uniq(e[i]);
    REP1(i,1,n) for ( int j:e[i] ) r[i][s[j]-'A']++;
    queue<int> q;
    auto push=[&]( int x ) {
        vis[x]=1;
        q.push(x);
    };
    REP1(i,1,n) if ( r[i][0]==0 || r[i][1]==0 ) push(i);
    while ( !q.empty() ) {
        int p=q.front(); q.pop();
        for ( int i:e[p] ) if ( !vis[i] && --r[i][s[p]-'A']==0 ) push(i);
    }
    bool ans=count(vis+1,vis+n+1,true)<n;
    W(ans?"Yes":"No");
}

// {{{ main
}}
int main() { shik::main(); return 0; }
// }}}


Measured memory_bytes: 12544
#include <stdio.h>
int main(void) {
    int a, b, c, i, divisor;
    divisor = 0;
    scanf("%d %d %d", &a, &b, &c);
    for (i = a; i < b + 1; i ++) {
        if (c % i == 0) divisor ++;
    }
    printf("%d\n", divisor);
    return 0;
}

Measured memory_bytes: 596
# -*- coding: utf-8 -*-

import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

class ModTools:
    """ 階乗たくさん使う時用のテーブル準備 """

    def __init__(self, MAX, MOD):
        """ MAX：階乗に使う数値の最大以上まで作る """
        
        MAX += 1
        self.MAX = MAX
        self.MOD = MOD
        # 階乗テーブル
        factorial = [1] * MAX
        factorial[0] = factorial[1] = 1
        for i in range(2, MAX):
            factorial[i] = factorial[i-1] * i % MOD
        # 階乗の逆元テーブル
        inverse = [1] * MAX
        # powに第三引数入れると冪乗のmod付計算を高速にやってくれる
        inverse[MAX-1] = pow(factorial[MAX-1], MOD-2, MOD)
        for i in range(MAX-2, 0, -1):
            # 最後から戻っていくこのループならMAX回powするより処理が速い
            inverse[i] = inverse[i+1] * (i+1) % MOD
        self.fact = factorial
        self.inv = inverse
    
    def nCr(self, n, r):
        """ 組み合わせの数 (必要な階乗と逆元のテーブルを事前に作っておく) """

        if n < r: return 0
        # 10C7 = 10C3
        r = min(r, n-r)
        # 分子の計算
        numerator = self.fact[n]
        # 分母の計算
        denominator = self.inv[r] * self.inv[n-r] % self.MOD
        return numerator * denominator % self.MOD

    def div(self, x, y):
        """ MOD除算 """

        return x * pow(y, self.MOD-2, self.MOD) % self.MOD

r1, c1, r2, c2 = MAP()

mt = ModTools(r2+c2+2, MOD)
def calc(r, c):
    return mt.div(((r+2) * mt.nCr(c+r+2, r+2) - c - 1), (c + 1))

ans = calc(r2, c2) - calc(r2, c1-1) - calc(r1-1, c2) + calc(r1-1, c1-1)
print(ans%MOD)


Measured memory_bytes: 161268
#include <bits/stdc++.h>
using namespace std;
int main() {
    double w, h, x, y;
    cin >> w >> h >> x >> y;
    int ishalf = (x*2 == w && y*2 == h) ? 1 : 0;
    double ret = w*h/2.0; 
    cout << ret << " " << ishalf << endl; 
    return 0;
}

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

#define mod 1000000007;
//vector<int> dp;
vector<vector<double>> dp;

int main() {
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int n,i,j;
    double ans = 0.0;
    cin >> n;
    vector<double> a(n);
    for(i=0;i<n;i++){
        cin >> a[i];
    }
    dp.resize(n+1,vector<double> (n+1));
    dp[1][0] = 1 - a[0];
    dp[1][1] = a[0];
    for(i = 2;i <= n;i++){
        for(j = 0;j <= i;j++){
            if(j == 0){
                dp[i][j] = dp[i-1][j]*(1-a[i-1]);
            }
            else if(i == j){
                dp[i][j] = dp[i-1][j-1]*a[i-1];
            }
            else{
                dp[i][j] = dp[i-1][j]*(1-a[i-1]) + dp[i-1][j-1]*a[i-1];
            }
        }
    }
    
    for(i = n/2+1;i <= n;i++){
        ans += dp[n][i];
    }
    cout<<setprecision(10)<<fixed<< ans;
    dp.clear();

    return 0;
}


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

int Sqrt(int n) {
	int x = sqrt(n);
	while (x * x <= n) ++x;
	while (x * x > n) --x;
	return x;
}

int main() {
	int n, P;
	scanf("%d%d", &n, &P);
	vector<int> val(3 * n), id(3 * n);
	for (int i = 0; i < n; ++i)
		val[i] = Sqrt(n * n - i * i - 1) + 1;
	for (int i = 0; i < 2 * n; ++i)
		val[n + i] = min(2 * n - 1, Sqrt(4 * n * n - i * i)) + 1;
	for (int i = 0; i < 3 * n; ++i)
		id[i] = i;
	sort(id.begin(), id.end(), [&](int x, int y) { return val[x] < val[y] || (val[x] == val[y] && x > y); });
	int ans = 0;
	for (int k = 0; k <= n; ++k) {
		vector<int> f(k + 1);
		f[0] = 1;
		int cnt = 0;
		for (int i = 0; i < 2 * n; ++i) {
			if (id[i] < n) {
				for (int j = k; j >= 0; --j)
					if (f[j] || f[j - 1])
						f[j] = ((j == 0 ? 0 : 1ll * f[j - 1] * max(0, val[id[i]] - j + 1 - cnt)) + 1ll * f[j] * max(0, val[id[i] + n] - (n + k + n - 1 - id[i] - j))) % P;
			} else {
				for (int j = 0; j <= k; ++j)
					if (f[j]) f[j] = 1ll * f[j] * max(0, val[id[i]] - (cnt + j)) % P;
				++cnt;
			}
		}
		ans = (ans + (k & 1 ? -1 : 1) * f[k]) % P;
	}
	printf("%d\n", (ans + P) % P);
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(void){
  int i,j;
  int key;
  int A[100];
  int N;

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

    for(i=0;i<N;i++){
      if(i>0)printf(" ");
      printf("%d",A[i]);
    }

    printf("\n");

  for(j=1;j<N;j++){
    key=A[j];
    i=j-1;

    while(1){
      if(i>=0 && A[i]>key){
	A[i+1]=A[i];
	i=i-1;
      }
      else break;
    }

    A[i+1]=key;

    for(key=0;key<N;key++){
      if(key>0)printf(" ");
      printf("%d",A[key]);
    }

    printf("\n");

  }
  return 0;

}

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

int main() {
    string S;
    cin >> S;
    int c=0;
    for (int i = 0; i < S.length()-1; ++i) {
        if(S.at(i) != S.at(i+1)){
            c++;
        }
    }
    if(c > 0){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = s; i < (int)(n); i++)
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

using namespace std;
using ll = long long;
using pii = pair<int, int>;

//const ll INF = 1e18L + 5;
//const int INF = 1e9 + 5;
//const double pi = 3.14159265358979323846;

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

	ll a, b, c, x, y;
	cin >> a >> b >> c >> x >> y;

	c *= 2;
	ll ans = 0;
	if (c < a + b) {
		ll z = min(x, y);
		ans += c * z;
		x -= z; y -= z;
		if (x) {
			cout << ans + min(a, c) * x << endl;
		} else {
			cout << ans + min(b, c) * y << endl;
		}
	} else {
		cout << x * a + y * b << endl;
	}
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <limits>
#include <map>
#define REP(i,n) for(long (i)=0;(i)<(n);(i)++)
#define REPI(i,a,b) for(long (i)=(a);(i)<(b);(i)++)
#define INF numeric_limits<double>::infinity()
constexpr long MOD = 1e9 + 7;
using namespace std;
using P = pair<long, long>;
using VI = vector<long>;

int main() {
    vector<P> v;
    long n, k;
    cin >> n >> k;
    REP(i,n) {
        long a, b;
        cin >> a >> b;
        v.push_back(P(a,b));
    }
    
    sort(v.begin(), v.end());
    int i = 0;
    long cnt = 0;
    while (cnt < k) {
        cnt += v[i].second;
        i++;
    }
    i--;
    cout << v[i].first << endl;
}


Measured memory_bytes: 2420
#include <iostream>

int main(void){
    std::string S, ans="";
    std::cin >> S;
    bool flg = false;
    for (int i = -1; i < 2; i += 2){
        for (int j = -1; j < 2; j += 2){
            for (int k = -1; k < 2; k += 2){
                int a = S.at(0) - '0';
                int b = S.at(1) - '0';
                int c = S.at(2) - '0';
                int d = S.at(3) - '0';
                if (a + b * i + c * j + d * k == 7){
                    ans += std::to_string(a);
                    if (i < 0) ans += '-';
                    else ans += '+';
                    ans += std::to_string(b);
                    if (j < 0) ans += '-';
                    else ans += '+';
                    ans += std::to_string(c);
                    if (k < 0) ans += '-';
                    else ans += '+';
                    ans += std::to_string(d) + "=7";
                    flg = true;
                    break;
                }
            }
            if (flg) break;
        }
        if (flg) break;
    }

    std::cout << ans << std::endl;

    return 0;
}


Measured memory_bytes: 3668
import itertools


def calc(s):
    ret = 24
    for i in range(1, len(s)):
        ret = min(ret, s[i] - s[i-1])
    return ret


def main():
    N = int(input())
    D = list(map(int, input().split()))
    if D.count(0) >= 1 or D.count(12) >= 2:
        print(0)
        return
    cnt = [0] * 13
    for d in D:
        cnt[d] += 1
    fixed = [0, 24]
    variable = []
    for i in range(1, 12):
        if cnt[i] >= 3:
            print(0)
            return
        elif cnt[i] == 2:
            fixed.append(i)
            fixed.append(24-i)
        elif cnt[i] == 1:
            variable.append(i)
    if cnt[12] == 1:
        fixed.append(12)
    ans = 0
    for p in itertools.product((False, True), repeat=len(variable)):
        s = list(fixed)
        for i in range(len(variable)):
            if p[i]:
                s.append(variable[i])
            else:
                s.append(24-variable[i])
        s.sort()
        ans = max(ans, calc(s))
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 42604
ENV[Z='RUBY_THREAD_VM_STACK_SIZE']||exec({Z=>?5*8},'ruby',$0)
ch=Hash.new{|h,k|h[k]=Hash.new 0};cnt=1
dfs=->x,d{x>0?dfs[ch[x][0],d-1]^dfs[ch[x][1],d-1]:d&-d}
n,m=gets.split.map &:to_i
n.times{
    s=gets.chomp
    q=1
    s.bytes{|b|c=b-48;ch[q][c]<1&&ch[q][c]=cnt+=1;q=ch[q][c]}
}
puts dfs[1,m+1]!=0 ? :Alice : :Bob

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


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

    int P=0;
    int W=0;
    int G=0;
    int Y=0;
    string IN;

    for (int i=0; i<N; i++) {
        cin >> IN;

        if (IN == "P") P=1;
        if (IN == "W") W=1;
        if (IN == "G") G=1;
        if (IN == "Y") Y=1;

    }

    int result = P+W+G+Y;

    if (result == 3) cout << "Three" << endl;
    else cout << "Four" << endl;


}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
int main(){
	ll n, m; cin >> n >> m;
	vector<vector<ll>> adj(n);
	vector<ll> indeg(n);
	for(ll i = 0; i < m; i++){
		ll a,b; cin >> a >> b;
		a--; b--;
		adj[a].push_back(b);
		indeg[b]++;
	}
	stack<ll> zero;
	vector<ll> dp(n);
	for(ll i = 0; i < n; i++) if(!indeg[i]) zero.push(i);
	while(!zero.empty()){
		ll cur = zero.top();
		zero.pop();
		for(auto a : adj[cur]){
			dp[a] = max(dp[a], dp[cur] + 1);
			if(--indeg[a] == 0) zero.push(a);
		}
	}
	ll res = 0;
	for(ll a : dp) res = max(a, res);
	cout << res << endl;
}


Measured memory_bytes: 7296
import numpy as np
from numba import njit
 
 
@njit('f8(i8,i8,i8,i8,f8[:,:,:])', cache=True)
def get_expv(N, i, j, k, expv):
    result = 0.0
    if expv[i][j][k] != -1:
        return expv[i][j][k]
    nonlp = 1.0 - (N-i-j-k) / N
    result += 1
    if i != 0:
        result += get_expv(N, i-1, j, k, expv) * (i / N)
    if j != 0:
        result += get_expv(N, i+1, j-1, k, expv) * (j / N)
    if k != 0:
        result += get_expv(N, i, j+1, k-1, expv) * (k / N)
    result /= nonlp
    expv[i][j][k] = result
    return result
 
def main():
    N = int(input())
 
    sushi_count = {1:0, 2:0, 3:0}
    for a in map(int, input().split()):
        sushi_count[a] += 1
    sh = (N+1, N-sushi_count[1]+1, sushi_count[3]+1)
    expv = np.full(sh, -1.0)
 
    expv[0][0][0] = 0.0
 
    print(get_expv(N, sushi_count[1], sushi_count[2], sushi_count[3], expv))
 
if __name__ == '__main__':
    main()

Measured memory_bytes: 318288
import java.util.Scanner;

public class Main{

	/**
	 * @param args
	 */
	
	void doIt(){
		Scanner sc = new Scanner(System.in);
		int A, B, C;
		int N = sc.nextInt();
		int[] topping = new int[N];
		A = sc.nextInt();
		B = sc.nextInt();
		C = sc.nextInt();
		for(int i=0; i<N; i++){
			topping[i] = sc.nextInt();
		}
		sort_down00(topping, N);
		for(int i=0; i<N; i++){
			if((C/A) <= ((C+topping[i])/(A+B))){
				C += topping[i];
				A += B;
			}
			else{
				break;
			}
		}
		System.out.println((int)C/A);


	
	}

	static void sort_down00(int[] data, int n){
		int i;
		int idx;
		int work;
		for(i=0; i<n; i++){
			idx = max_idx00(data, i, n);
			work = data[i];
			data[i] = data[idx];
			data[idx] = work;
		}
		return;
	}
	
	static int max_idx00(int[] data, int from, int to){
		int i;
		int idx = from;
		for(i=from; i<to; i++){
			if(data[idx] < data[i]){
				idx = i;
			}
		}
		return idx;
	}

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		
		new Main().doIt();
			
	}
		
		


}

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


int main(){
  //string S;
  
  int N;
  
  cin >> N;
  
  int a = N/500;
  int b = N%500;
  int c = b/5;
  
  cout << 1000*a + c*5 << endl;
  

  return 0;
}

Measured memory_bytes: 3588
'''
    Auther: ghoshashis545 Ashis Ghosh
    College: jalpaiguri Govt Enggineerin College
    Date:07/06/2020

'''
from os import path
import sys
from functools import cmp_to_key as ctk
from collections import deque,defaultdict as dd 
from bisect import bisect,bisect_left,bisect_right,insort,insort_left,insort_right
from itertools import permutations
from datetime import datetime
from math import ceil,sqrt,log,gcd
def ii():return int(input())
def si():return input()
def mi():return map(int,input().split())
def li():return list(mi())
abc='abcdefghijklmnopqrstuvwxyz'
abd={'a': 0, 'b': 1, 'c': 2, 'd': 3, 'e': 4, 'f': 5, 'g': 6, 'h': 7, 'i': 8, 'j': 9, 'k': 10, 'l': 11, 'm': 12, 'n': 13, 'o': 14, 'p': 15, 'q': 16, 'r': 17, 's': 18, 't': 19, 'u': 20, 'v': 21, 'w': 22, 'x': 23, 'y': 24, 'z': 25}
mod=1000000007
#mod=998244353
inf = float("inf")
vow=['a','e','i','o','u']
dx,dy=[-1,1,0,0],[0,0,1,-1]

        

def solve():
    
    a,b=mi()
    print(a*b)
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
if __name__ =="__main__":
    if path.exists('input.txt'):
        sys.stdin=open('input.txt', 'r')
        sys.stdout=open('output.txt','w')
    else:
        input=sys.stdin.readline
    solve()


Measured memory_bytes: 68408
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef double D;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
typedef long double ld;

#define rd(x) scanf("%d",&x)
#define rd2(x,y) scanf("%d %d",&x,&y)
#define rd3(x,y,z) scanf("%d %d %d",&x,&y,&z)
#define rl(x) scanf("%lld",&x)
#define rl2(x,y) scanf("%lld %lld",&x,&y)
#define rl3(x,y,z) scanf("%lld %lld %lld",&x,&y,&z)
#define wd(x) printf("%d" ,x)
#define wd2(x,y) printf("%d %d",x,y)
#define wl(x) printf("%lld",x)
#define wl2(x,y) printf("%lld %lld",x,y)
#define PC(x) putchar(x)
#define GC() getchar()
#define NL printf("\n")
#define SP printf(" ")
 
#define SZ(a) (int)a.size()
#define ALL(a) a.begin(), a.end()
#define ITER(it,a) for (__typeof(a.begin()) it = a.begin(); it != a.end(); it++)
#define FILL(a,value) memset(a, value, sizeof(a))

#define F first
#define S second
#define MP make_pair
#define PB push_back

#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL)
#define fr(i,s,e) for(int i=s;i<e;i++)
#define frl(i,s,e) for(ll i=s;i<e;i++)
#define frr(i,s,e) for(int i=s-1;i>=e;i--)
#define frv(i,a) for(int i = 0;i<(int)a.size();i++)
#define frvr(i,a) for(int i = a.size()-1;i>=0;i--)
#define tr(i,a) for(typeof(a.begin()) i = a.begin(); i != a.end();i++)

#define inf 10000000000000
#define mod 1000000007
#define maxn 100009
#define maxr 100009

void solve()
{
	ll n;
	rl(n);
	VL arr(n);
	fr(i,0,n)
	{
		rl(arr[i]);

	}
	ll sum=accumulate(ALL(arr),0);
	ll nt=0,ans=1e18;
	fr(i,0,n-1)
	{
		nt+=arr[i];
		sum-=arr[i];
		ans=min(ans,abs(nt-sum));
	}
	wl(ans);
	NL;
	return;
}
int main(){
	//sstd::ios::sync_with_stdio(false); cin.tie(NULL);
	solve();
	return 0;
}

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

int f() {

}
int main() {
   char n[10];
   cin >> n;
   ll ans = 0;
   for(int bit = 0;bit < (1 << strlen(n)-1);bit++) {
      ll a = n[0] - '0';
      rep(i, strlen(n)-1) {
         ll j = n[i] - '0';
         if(bit & (1<<i)) {
            ans += a;
            a = n[i+1]- '0';
         }else {
            a = a *10 + (n[i+1]-'0');
         }
         
      }
      ans += a;
   }
   cout << ans << endl;
}

Measured memory_bytes: 3636
n,a,b,c = map(int, input().split())
m = {'A':a, 'B':b, 'C':c}

ss = [input() for _ in range(n)]


ans = []
def _t(s0, s1):
    m[s0] = m[s0] + 1
    m[s1] = m[s1] - 1
    ans.append(s0)


if a+b+c == 0:
    print('No')
    exit(0)


elif a+b+c == 1:
    for k, v in m.items():
        if v == 1:
            o = k

    for s in ss:
        if o not in s:
            print('No')
            exit(0)
        o = s.strip(o)
        ans.append(o)

elif a+b+c == 2:
    for i, s in enumerate(ss):
        if m[s[0]] + m[s[1]] == 0:
            print('No')
            exit(0)
        if m[s[0]] > m[s[1]]:
            _t(s[1], s[0])
        elif m[s[0]] < m[s[1]]:
            _t(s[0], s[1])
        else:
            if i < len(ss)-1 and s[0] in ss[i+1]:
                _t(s[0], s[1])
            else:
                _t(s[1], s[0])

else:
    for s in ss:
        if m[s[0]] + m[s[1]] == 0:
            print('No')
            exit(0)
        if m[s[0]] > m[s[1]]:
            _t(s[1], s[0])
        else:
            _t(s[0], s[1])

print('Yes')
for a in ans:
    print(a)


Measured memory_bytes: 17096
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip> 
#include <complex> 
#include <string>
#include <vector> 
#include <list>
#include <deque> 
#include <stack> 
#include <queue> 
#include <set>
#include <map>
#include <bitset>
#include <functional>
#include <utility>
#include <algorithm> 
#include <numeric> 
#include <typeinfo> 
#include <cstdio>
#include <cstdlib> 
#include <cstring>
#include <cmath>
#include <climits> 
#include <ctime>

using namespace std;

int main(void){
	int i;
	bool card[11];
	int have[3];
	while(~scanf("%d %d %d",&have[0],&have[1],&have[2])){
		int ans=20;
		int ans2=0;
		for(i=0;i<=10;i++)card[i]=false;
		ans-=have[0];
		ans-=have[1];
		for(i=0;i<=2;i++)card[have[i]]=true;
		for(i=1;i<=10;i++){
			if(card[i]==false){
				if(i<=ans)ans2++;
			}
		}
		if(ans2>=4)cout << "YES" << endl;
		else cout << "NO" << endl;
	}
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep2(i, s, n) for (ll i = s; i < (ll)(n); i++)
typedef long long ll;
typedef vector<vector<ll>> vvl;
typedef vector<ll> vl;
typedef vector<vector<char>> vvc;
typedef vector<char> vc;
typedef pair<ll,ll> pll;
ll max(ll x,ll y){
if(x>y)return x;
else return y;
}
ll min(ll x,ll y){
  return x+y-max(x,y);
}


int main() {
  int a,b;
  cin >> a >> b;
  cout << a*b/2 << endl;
}


Measured memory_bytes: 256