akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int k = in.nextInt();
		int x = in.nextInt();
		int y = in.nextInt();

		if (n < k) {
			System.out.println(n * x);
		} else {
			System.out.println(x * k + ((n - k) * y));
		}

	}
}

Measured memory_bytes: 21844
//agrawal117
//chahatagrawal117
#include<bits/stdc++.h>
#define endl '\n'
#define mod 1000000007
typedef long long int ll;
using namespace std;
#define MAX 100005
ll ans=1;
void an(ll n)
{
    for(ll i=2;i<=sqrt(n);i++){
        if(n%i==0)
        {
            ans++;
            if(i!=n/i) ans++;
        }
    }
     if(n!=1) ans++;
}
bool check(ll n, ll i)
{
    while(n%i==0)
    {
        n=n/i;
    }
    if(n%i==1) return true;
    return false;
}
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    ll n; cin>>n;
    an(n-1);
    // cout<<ans<<endl;
    for(ll i=2;i<=sqrt(n);i++){
        if(n%i==0)
        {
            if(check(n,i)) ans++;
            if(i!=n/i && check(n,n/i)) ans++;
        }
    }
    cout<<ans<<endl;
    
    
}



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

#define MAX_N 1000001

bool table[MAX_N];

void init() {
    memset(table, 1, sizeof(table));
    table[0] = table[1] = false;
    for (int i = 2; i < MAX_N; i++) {
        if (table[i]) {
            for (int j = i + i; j < MAX_N; j += i) {
                table[j] = false;
            }
        }
    }
}

int main() {
    init();
    int n;
    while (cin >> n) {
        if (n == 0) break;
        int count = 0;
        for (int i = 2; i <= n/2; i++) {
            if (table[i] && table[n - i]) {
//                cout << i << ' ' << n - i << endl;
                count++;
            }
        }
        cout << count << endl;
    }
    return 0;
}

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

using namespace std;

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

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define CHMIN(a,b) a=min((a),(b))
#define CHMAX(a,b) a=max((a),(b))

// mod
const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

// floating
typedef double Real;
const Real EPS = 1e-11;
#define EQ0(x) (abs(x)<EPS)
#define EQ(a,b) (abs(a-b)<EPS)
typedef complex<Real> P;

int n,c;
int a[125],b[125],k[125];

int dp[125][12525];

int main(){
  scanf("%d%d",&n,&c);
  REP(i,n)scanf("%d%d%d",a+i,b+i,k+i);
  REP(i,125)REP(j,12525)dp[i][j] = -8302521;
  dp[0][0] = 0;

  REP(i,n){
    int aa = a[i];
    int bb = b[i];
    int cc = k[i];
    FORR(j,0,c)REP(x,12525){
      if(j+cc <= c){
        if(x+aa < 12525){
          CHMAX(dp[j+cc][x+aa], dp[j][x]+bb);
        }
        if(x+bb < 12525){
          CHMAX(dp[j+cc][x+bb], dp[j][x]+aa);
        }
      }
    }
  }
  int ans = 0;
  REP(i,c+1)REP(x,12525)CHMAX(ans,min(x,dp[i][x]));
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 9324
#include <stdio.h>  
#include <algorithm>  
#include <assert.h>
#include <bitset>
#include <cmath>  
#include <complex>  
#include <deque>  
#include <functional>  
#include <iostream>  
#include <limits.h>  
#include <map>  
#include <math.h>  
#include <queue>  
#include <set>  
#include <stdlib.h>  
#include <string.h>  
#include <string>  
#include <time.h>  
#include <unordered_map>  
#include <unordered_set>  
#include <vector>  

#pragma warning(disable:4996)  
#pragma comment(linker, "/STACK:336777216")  
using namespace std;

#define mp make_pair  
#define Fi first  
#define Se second  
#define pb(x) push_back(x)  
#define szz(x) ((int)(x).size())  
#define rep(i, n) for(int i=0;i<n;i++)  
#define all(x) (x).begin(), (x).end()  
#define ldb ldouble  

typedef tuple<int, int, int> t3;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <ll, int> pli;
typedef pair <db, db> pdd;

int IT_MAX = 1 << 19;
const ll MOD = 1000000007;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const db PI = acos(-1);
const db ERR = 1e-10;

ll in[200050];
ll sum[200050];
int main() {
	int N, i;
	scanf("%d", &N);
	for (i = 1; i <= N; i++) scanf("%lld", &in[i]);
	for (i = 1; i <= N; i++) sum[i] = sum[i - 1] + in[i];

	ll ans = LL_INF;
	for (i = 2; i <= N - 2; i++) {
		int st, en, mi, rv;
		vector <pll> Vl1;
		vector <pll> Vl2;
		
		st = 1, en = i - 1, rv = 0;
		while (st <= en) {
			mi = (st + en) / 2;
			if (sum[mi] <= sum[i] - sum[mi]) {
				rv = mi;
				st = mi + 1;
			}
			else en = mi - 1;
		}
		if (rv != 0) Vl1.emplace_back(sum[rv], sum[i] - sum[rv]);
		if (rv != i - 1) Vl1.emplace_back(sum[rv + 1], sum[i] - sum[rv + 1]);
		for (auto &it : Vl1) if (it.first > it.second) swap(it.first, it.second);

		st = i + 1, en = N - 1, rv = i;
		while (st <= en) {
			mi = (st + en) / 2;
			if (sum[mi] - sum[i] <= sum[N] - sum[mi]) {
				rv = mi;
				st = mi + 1;
			}
			else en = mi - 1;
		}
		if (rv != i) Vl2.emplace_back(sum[rv] - sum[i], sum[N] - sum[rv]);
		if (rv != N - 1) Vl2.emplace_back(sum[rv + 1] - sum[i], sum[N] - sum[rv + 1]);
		for (auto &it : Vl2) if (it.first > it.second) swap(it.first, it.second);

		for (auto it1 : Vl1) for (auto it2 : Vl2) ans = min(ans, max(it1.second, it2.second) - min(it1.first, it2.first));
	}
	return !printf("%lld\n", ans);
}

Measured memory_bytes: 3328
#include<stdio.h>
int main()
{
    int i,n,m;
    long long int s=1;
    scanf("%d",&n);
    m = 1000000007;
    for(i=n;i>1;i--)
    {
        s=(s*i)%m;
    }
     printf("%lld",s);
    return 0;
}

Measured memory_bytes: 128
n = int(input())
h = list(map(int, input().split()))

times = []
count = 0
pos = 0

for i in range(n-1):
  if h[pos] >= h[pos+1]:
    count += 1
    pos += 1
  else:
    times.append(count)
    count = 0
    pos += 1

  times.append(count)
  
if n == 1:
  print(0)
else:
  print(max(times))

Measured memory_bytes: 67736
n=int(input())
s=list(map(int, input().split()))
s=sorted(s)
q=int(input())
t=list(map(int, input().split()))
frt=0
end=n
def src(x:list, y:int):
  frt=0
  end=len(x)-1
  while end>=frt:
    cent=(frt+end)//2
    if x[cent]==y:
      return 1
    elif x[cent]<y:
      frt=cent+1
    else:
      end=cent-1
  return 0
ans=0
for i in t:
  ans+=src(s, i)
print(ans)
  
  
       


Measured memory_bytes: 16712
def yymm():
    num = input()
    former = num[:2]
    latter = num[2:]

    former = int(former)
    latter = int(latter)
    # print(former)
    # print(latter)

    if 1 <= former <= 12 and 1<= latter <= 12:
        print('AMBIGUOUS')
    elif 1 <= former <= 12:
        print('MMYY')
    elif 1 <= latter <= 12:
        print('YYMM')
    else:
        print('NA')

if __name__ == '__main__':
    yymm()

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

int main(){
	int n;
	string s;
	cin >> n >> s;
	
	int ans, l = 0, r = 0;
	
	for(int i = 1;i < n;++i){
		if(s[i] == 'E'){
			++r;
		}
	}
	
	ans = r;
	
	for(int i = 1;i < n;++i){
		if(s[i - 1] == 'W'){
			++l;
		}
		if(s[i] == 'E'){
			--r;
		}
		
		if(ans > l + r){
			ans = l + r;
		}
	}
	
	cout << ans << endl;
	
	
	return 0;
}

Measured memory_bytes: 900
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
  int n,a,ans=-1e9,amin=1e9;
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>a;
    if(i>0)ans=max(a-amin,ans);
    amin=min(amin,a);
  }  
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 3124
program main
implicit none
integer :: n, x
integer , allocatable :: l(:)
integer :: i, nc, j

read(*,*) n, x
allocate( l(n))
read(*,*) l(:)
j = 0
nc = 1
do i = 1, n
   j = j+l(i)
   if( j .le. x ) then
      nc = nc + 1
   end if
end do
write(*,'(i0)') nc



end program main


Measured memory_bytes: 768
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
String s=sc.next();
int mode;
char c[]=s.toCharArray();
if(c[0]=='W'){mode=1;}else{mode=2;}

int che=0;
for(int i=1;i<=s.length()-1;i++){
if(mode==1&&c[i]=='B'){
	che++;
	mode=2;
}

if(mode==2&&c[i]=='W'){
	che++;
	mode=1;
}
}
System.out.println(che);
	}}

Measured memory_bytes: 26448
#include <iostream>
#include <iomanip>
#include <cmath>
#include <vector>
#include <queue>
#include <limits>
#include <algorithm>
#include <string>
#include <set>
#include <map>
using namespace std;

int main()
{
	int32_t X, A, B;
	cin >> X >> A >> B;

	if (B <= A)
		cout << "delicious" << endl;
	else if (B <= A + X)
		cout << "safe" << endl;
	else
		cout << "dangerous" << endl;

	return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <ctime>
#include <cstring>
#include <iostream>
#include <algorithm>
#define debug(x) cout<<#x<<" = "<<x<<endl;
#define lowbit(x) x&(-x)
#define PA pair<int, int>
#define MK make_pair
using namespace std;
typedef long long LL;
inline int read()
{
	int l = 0, f = 1;
	char a = getchar();
	for (; a < '0' || a > '9'; a = getchar())
		if (a == '-') f = -1;
	for (; a >= '0' && a <= '9'; a = getchar())
		l = l*10+a-48;
	return l*f;
}
const int N = 105;
int n, mp[5][N], f[5][N];
int main(int argc, char const *argv[])
{
	n = read();
	for (int i = 1; i <= 2; ++i)
		for (int j = 1; j <= n; ++j)
			f[i][j] = read();
	for (int i = 1; i <= 2; ++i)
		for (int j = 1; j <= n; ++j)
			mp[i][j] = max(mp[i-1][j], mp[i][j-1])+f[i][j];
	printf("%d\n", mp[2][n]);
	return 0;
}

Measured memory_bytes: 256
function Main(input) {
  input = input.trim().split("\n").map(function(x) { return x.split(" ")});
  var L1 = input[0].map(e => parseInt(e, 10));
  var N = L1[0];
  var M = L1[1];
  var K = L1[2];
  var vec_A = input[1].map(e => parseInt(e, 10));
  var vec_B = input[2].map(e => parseInt(e, 10));
  var vec_SumA = [];
  var vec_SumB = [];
  var tmp = 0;
  for (var i = 0; i < N; i++) {
    tmp += vec_A[i];
    if (tmp > K) break;
    vec_SumA.push(tmp);
  }
  tmp = 0;
  for (var i = 0; i < M; i++) {
    tmp += vec_B[i];
    if (tmp > K) break;
    vec_SumB.push(tmp);
  }
  var ans = vec_SumB.length;
  var tmpDepthB = vec_SumB.length - 1;
  for (var i = 0; i < vec_SumA.length; i++){
    while ((tmpDepthB !== -1) && (vec_SumB[tmpDepthB] + vec_SumA[i] > K)){
      tmpDepthB --;
      
    }
    ans = Math.max(ans, i + tmpDepthB + 2);
  }
  console.log(ans);
}
 
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


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

using namespace std;

int main() {

	double a, b, h, m;
	cin >> a >> b >> h >> m;

	double hh, mm;
	hh = h * 30 + 30 * m / 60;
	mm = m * 6;

	double degg;
	degg = min(abs(hh - mm),360-abs(hh-mm));

	cout << setprecision(15) << pow(a * a + b * b - 2 * a*b*cos(degg / 180 * 3.14159265354),0.5) << endl;

	return 0;
}

Measured memory_bytes: 4356
def main():
    N,L = map(int,input().split())
    taste = []

    for i in range(N):
        taste.append(L+i)
    
    pie = sum(taste)
    ans = 1e10
    ans = [0]*N

    for i in range(N):
        tmp = taste[i]
        taste[i] = 0
        ans[i] = abs(pie-sum(taste))
        taste[i] = tmp
    
    print(pie-taste[ans.index(min(ans))])




if __name__=="__main__":
    main()

Measured memory_bytes: 3064
#include <stdio.h>

int main(void)
{
int i, j, n, m;
int A[100][100];
int b[100], c[100];

scanf("%d %d", &n, &m);

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

for(i = 0; i < m; i++)
scanf("%d", &b[i]);

for(i = 0; i < n; i++)
{
 for(j = 0; j < m; j++)
{
 c[i] += A[i][j] * b[j];
}
}
for(i = 0; i < n; i++)
printf("%d\n", c[i]);

return 0;

}




Measured memory_bytes: 2052
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0; i<n; i++)
#define eb(t) emplace_back(t)
typedef long long ll;
typedef long long unsigned int llu;
ll MOD = 1000000007;
ll INF = 1000000009;



ll gcd( ll a, ll b )
{
    ll temp;

    if( a < b ) { temp = a; a = b; b = temp; }
    if( b < 1 ) return -1;

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

ll a[100010];

void solve(){

    ll n,m;
    cin >> n >> m;
    ll x;
    bool b=true;
    rep(i,n){
        cin >> a[i];
        if(i==0) x=a[i];
        else{
            x=x*a[i]/gcd(x,a[i]);
        }
        if(x>2*m){
            b=false;
            break;
        }
        //cout << x << endl;
    }
    
    ll l=x;
    if(!b){
        cout << 0 << endl;
        return;
    }

    //cout << l << endl;

    ll tmp = l/2;
    rep(i,n){
        if(tmp%a[i]!=(a[i]/2)){
            cout << 0 << endl;
            return;
        }
    }
    ll i=0;
    ll ans = 0;
    ans = (m/tmp+1)/2;

    cout << ans << endl;

}

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


Measured memory_bytes: 1024
#include<iostream>
#include <stdio.h>
#include<string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <cstdint>
#include <queue> 
#include <map>
#include <set>
#define MOD 1000000007
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n)  FOR(i,0,n)
#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
typedef long long ll;
using namespace std;

int main(){

  string s,t;
  cin >> s >> t;
  
  sort(s.begin(),s.end());
  sort(t.begin(),t.end());
  reverse(t.begin(),t.end());
  
  if(s < t) cout << "Yes" << endl;
  else		cout << "No"  << endl;
  

 return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
	string s, k = "keyence";
	cin >> s;
	int head_tail = 0, tail_head = 0;
	for(int i = 0; i < k.size(); i++){
		if(s[i] != k[i] ){
			head_tail = i;
			break;
		}
	}
	reverse(s.begin(), s.end());
	reverse(k.begin(), k.end());
//	cout << s << endl;
//	cout << k << endl;
	for(int i = 0; i <= k.size() - head_tail; i++){
		if(s[i] != k[i] || i == k.size() - head_tail){
			tail_head = i;
			break;
		}
	}
	string ans = "NO";
	if(head_tail + tail_head == k.size() || s == k)ans = "YES";
	cout << ans << endl;
//	cout << head_tail << " " << tail_head << endl;
}


Measured memory_bytes: 256
n=int(input())
l=list(map(int,input().split()))

for i in range(n):
    if l[i]/2==l[i]//2:
        if l[i]/3!=l[i]//3 and l[i]/5!=l[i]//5:
            print("DENIED")
            break

    if i==n-1:
        print("APPROVED")


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

#define REP(i, n, N) for(ll i=(n); i<(N); i++)
#define RREP(i, n, N) for(ll i=(N-1); i>=n; i--)
#define CK(n, a, b) ((a)<=(n)&&(n)<(b))
#define ALL(v) (v).begin(),(v).end()
#define MCP(a, b) memcpy(b,a,sizeof(b))
#define p(s) cout<<(s)<<endl
#define p2(a, b) cout<<(a)<<" "<<(b)<<endl
#define v2(T) vector<vector<T>>
typedef long long ll;
using namespace std;
const ll mod = 1e9 + 7;
const ll inf = 1e18;

int main() {
    string s;
    int n;
    cin>>s>>n;
    for(int i=0;i<s.size();i+=n){
        cout<<s[i];
    }
    cout<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define CLEAR(a) memset(a,0,sizeof a)
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define fr freopen("input.txt", "r", stdin);
#define fw freopen("output.txt", "w", stdout);
typedef long long LL;
typedef pair<int,int> pii;
const int MOD = 1e9 + 7;
const int MAX = 1e3 + 5;
char grid[MAX][MAX];
int vis[MAX][MAX], r, c;

bool valid(int i, int j){
    if(i >=0 &&i < r && j >=0 && j < c) return 1;
    return 0;
}

int main() {
    cin >> r >> c;
    REP(i, r) REP(j, c) cin >> grid[i][j];

    queue<pii> q;
    q.push(mp(0,0));
    vis[0][0] = 1;
    while(!q.empty()){
        pii p = q.front();
        q.pop();
        int x = p.F, y = p.S;

        if(valid(x+1, y)){
            if(grid[x+1][y] == '#' && vis[x+1][y] == 0){
                vis[x+1][y] = 1;
                q.push(mp(x+1, y));
                continue;
            }
        }
       if(valid(x, y+1)){
            if(grid[x][y+1] == '#' && vis[x][y+1] == 0){
                vis[x][y+1] = 1;
                q.push(mp(x, y+1));
            }
        }
    }

    REP(i, r){
        REP(j, c){

            if(grid[i][j] == '#' && vis[i][j] == 0){
                cout << "Impossible";
                return 0;
            }
        }
    }
    cout << "Possible";
    return 0;
}

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

int N, M;
const int MOD = 1.0e9 + 7;

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

    ll ans = 0;
    if (N - M == 1 || M - N == 1) {
        ans = 1;
        for (int i = 1; i <= N; i++) {
            ans = (ans*i) % MOD; 
        }
        for (int i = 1; i <= M; i++) {
            ans = (ans*i) % MOD;
        }
    }
    else if (N - M == 0 || M - N == 0){
        ans = 1;
        for (int i = 1; i <= N; i++) {
            ans = (ans*i) % MOD; 
        }
        for (int i = 1; i <= M; i++) {
            ans = (ans*i) % MOD;
        }
        ans = (ans*2) % MOD;
    } 

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
use proconio::input;
use std::cmp;

fn dfs(g: &Vec<Vec<usize>>, c: &Vec<usize>, res: &mut Vec<usize>, cnt: &mut Vec<i64>,
       v: usize, p: i64) -> i64 {
  let mut sz: i64 = 1;
  let tmp = cnt[c[v]];

  for &u in &g[v] {
    cnt[c[v]] = 0;
    if u as i64 != p {
      sz += dfs(g, c, res, cnt, u, v as i64);
    }
  }

  cnt[c[v]] = -sz + tmp;

  if p == -1 {
    for (i, &x) in cnt.iter().enumerate() {
      let x = (x + sz) as usize;
      if x != 0 {
        res[i] -= x * (x - 1) / 2 + x;
      }
    }
  } else {
    let x = (cnt[c[p as usize]] + sz) as usize;
    if x != 0 {
      res[c[p as usize]] -= x * (x-1) / 2 + x;
      // println!("{} {}: {} {}", v, c[p as usize], x, res[c[p as usize]]);
    }
  }

  // for (i, &x) in cnt.iter().enumerate() {
    // print!("({}: {}) ", i, x);
  // }
  // println!();

  sz
}

fn main() {
  input! {
    n: usize,
    mut c: [usize; n],
    e: [(usize, usize); n-1],
  }
  let mut g = vec![Vec::<usize>::new(); n];
  for x in &mut c {
    *x -= 1;
  }
  for (a, b) in e {
    g[a-1].push(b-1);
    g[b-1].push(a-1);
  }

  let mut res = vec![n*(n-1)/2 + n; n];
  let mut cnt = vec![0i64; n];

  dfs(&g, &c, &mut res, &mut cnt, 0, -1);

  for x in res {
    println!("{}", x);
  }
}


Measured memory_bytes: 43276
import java.util.*;
import java.awt.geom.*;

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

		while(true){
			int n = sc.nextInt();
			if(n == 0) break;
			Point2D[] p = new Point2D[n];

			for(int i=0;i<n;i++){
				String[] s = sc.next().split(",");
				p[i] = new Point2D.Double(Double.parseDouble(s[0]), Double.parseDouble(s[1]));
			}

			System.out.println(p.length - convexHull(p).length);
		}
	}

	public static Point2D[] convexHull(Point2D[] ps) {        
		Arrays.sort(ps , new Comparator< Point2D >() {
				public int compare(Point2D o1, Point2D o2) {
					if(o1.getX() < o2.getX()) return -1;
					else if(o1.getX() > o2.getX()) return 1;
					else if(o1.getY() < o2.getY()) return -1;
					else if(o1.getY() > o2.getY()) return 1;
					else return 0;        
				}
			});
		int n = ps.length, k = 0;
		Point2D[] ch = new Point2D[2 * n];

		for (int i = 0; i < n; ch[k++] = ps[i++])
			while (k >= 2
						 && Line2D.relativeCCW(ch[k - 2].getX(), ch[k - 2].getY(),
																	 ch[k - 1].getX(), ch[k - 1].getY(), ps[i].getX(),
																	 ps[i].getY()) <= 0)
				k--;

		for (int i = n - 2, t = k + 1; i >= 0; ch[k++] = ps[i--])
			while (k >= t
						 && Line2D.relativeCCW(ch[k - 2].getX(), ch[k - 2].getY(),
																	 ch[k - 1].getX(), ch[k - 1].getY(), ps[i].getX(),
																	 ps[i].getY()) <= 0)
				k--;
		return Arrays.copyOf(ch, k - 1);
	}
}

Measured memory_bytes: 12000
#include <bits/stdc++.h>
using namespace std;
int main() 
{
    //ifstream cin("input.in");
    //ofstream cout("output.out");
    ios::sync_with_stdio(0);cin.tie(0);
    string s;
    cin>>s;
    for(long i=0;i<s.size();i+=2)
        cout<<s[i];
    return 0;
}   

Measured memory_bytes: 592
#include <bits/stdc++.h>
#define f first
#define s second
#define pb push_back
#define endl '\n';
typedef long long ll;
typedef long double ld;
using namespace std;

int a[22];

int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  int cnt = 0;
  for (int i = 2; i + 1 <= n; i++) {
    if ((a[i - 1] < a[i] && a[i] < a[i + 1]) || (a[i - 1] > a[i] && a[i] > a[i + 1])) {
      cnt++;
    }
  }
  cout << cnt << endl;
  return 0;
}

Measured memory_bytes: 256
x, y = map(int, input().split())
out = 0
if x == 1:
  out += 300000
elif x == 2:
  out += 200000
elif x == 3:
  out += 100000

if y == 1:
  out += 300000
elif y == 2:
  out += 200000
elif y == 3:
  out += 100000
if x ==1 and y == 1:
  out += 400000  
print(out)  

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i) 
#define rrep(i, a, b) for (int i = (a); i < (b); ++i)
#define PI acos(-1)
#define pcnt __builtin_popcountll
#define rng(a) a.begin(), a.end()
#define rrng(a) a.rbegin(), a.rend()
#define sz(x) (int)(x).size()
#define v(T) vector<T>
#define vv(T) v(v(T))
#define fi first
#define se second

using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using LP = pair<ll, ll>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using tl = tuple<ll, ll, ll>;

template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) {if (a > b) { a = b; return true; } return false; }

const int mod = 1000000007;
struct mint {
    ll x; // using long long ll;
    mint(ll x=0):x((x%mod+mod)%mod){}
    mint operator-() const { return mint(-x);}
    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod-a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
    mint operator+(const mint a) const { return mint(*this) += a;}
    mint operator-(const mint a) const { return mint(*this) -= a;}
    mint operator*(const mint a) const { return mint(*this) *= a;}
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }
    
    // for prime mod
    mint inv() const { return pow(mod-2);}
    mint& operator/=(const mint a) { return *this *= a.inv();}
    mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

struct combination {
    vector<mint> fact, ifact;
    combination(int n):fact(n+1),ifact(n+1) {
        assert(n < mod);
        fact[0] = 1;
        for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
        ifact[n] = fact[n].inv();
        for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
    }
    mint operator()(int n, int k) {
        if (k < 0 || k > n) return 0;
        return fact[n]*ifact[k]*ifact[n-k];
    }
    mint p(int n, int k) {
        return fact[n]*ifact[n-k];
    }
};

ll INF = 1001001001;
ll LINF = 1001001001001001001ll;

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

    ll x, y; cin>>x>>y;
    if ((x + y) % 3) {
        cout<<0<<endl;
        return 0;
    }

    ll c = (x + y) / 3;
    combination comb(1001001);
    ll b = x - c;
    cout<<comb(c, b)<<endl;
}


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

const int MAX = 30;
const int MAX2 = 500;
const int INF = 1073741823; // 10^30-1、使わない辺とかに用いる

int main() {
	int N, C, D[MAX][MAX], c[MAX2][MAX2];
	cin >> N >> C;
	for (int i = 0;i < C;i ++) for (int j = 0;j < C;j ++) cin >> D[i][j];
	for (int i = 0;i < N;i ++) for (int j = 0;j < N;j ++) cin >> c[i][j];
	
	int comfort[3][MAX]; // 色を決め打った時の違和感の大きさ
	for (int i = 0;i < 3;i ++) {
		for (int j = 0;j < C;j ++) {
			comfort[i][j] = 0;
			for (int x = 0, y = (x + i) % 3;x < N;y += 3) {
				if (y >= N) {
					x ++;
					y = (y + 2) % 3;
					if (x >= N) break;
				}
				comfort[i][j] += D[c[x][y] - 1][j];
			}
		}
	}
	
	int ans = INF;
	for (int i = 0;i < C;i ++) {
		for (int j = 0;j < C;j ++) {
			for (int k = 0;k < C;k ++) {
				if (i == j || i == k || j == k) continue;
				ans = min(ans, comfort[0][i] + comfort[1][j] + comfort[2][k]);
			}
		}
	}
	cout << ans;
	return 0;
}
/*
31536000のコメント解説欄
ここテンプレで用意してるから、A問題とかだとこの先空欄の危険あり

まず、(1, 1)について色を決め打った時の違和感の大きさをそれぞれの色について計算するとO(CN^2)です
これを3個行っておきます
次に、これらの中から最小の組み合わせを探すのはO(C^3)です
よって全体でO(CN^2+C^3)で解くことができます
*/

Measured memory_bytes: 1280
#include <iostream>
#include <vector>
#include <climits>
using namespace std;
int main(void){
    int N, T, min;
    bool flag = false;
    int *c;
    int *t;
    cin >> N >> T;
    
    c = new int[N];
    t = new int[N];
    
    for(int i = 0; i < N; i++){
        cin >> c[i] >> t[i];
    }
    
    min = INT_MAX;
    for(int i = 0; i < N; i++){
        if(t[i] <= T && c[i] <= min){
            flag = true;
            min = c[i];
        }
    }
    
    if(flag == false){
        cout << "TLE" << endl;
        exit(0);
    }
    else{
        cout << min << endl;
        exit(0);
    }
    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define int long long
#define double long double
#define endl "\n"
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb(x) push_back(x)
#define mp(a,b) make_pair(a,b)
#define ms(v,x) memset(v,x,sizeof(v))
#define pii pair<int,int>
#define ff first
#define ss second
#define frr(i,n) for(int i=0;i<n;i++)
#define td(v) v.begin(),v.end()
#define inf 1000000000 // 1e9
#define M   1000000007 // 1e9 + 7
using namespace std;
inline int mod(int n, int m){ int ret = n%m; if(ret < 0) ret += m; return ret; }
int gcd(int a, int b){return (b == 0 ? a : gcd(b, a%b));}
int lcm(int a,int b){return (a*b)/gcd(a,b);}
int exp(int a,int b,int m){
    if(b==0) return 1;
    if(b==1) return mod(a,m);
    int k = mod(exp(a,b/2,m),m);
    if(b&1){
        return mod(a*mod(k*k,m),m);
    }
    else return mod(k*k,m);
}
vector<int> adj[100100];
pii dfs(int u,int p){
    pii ret = {1,1};
    for(int v : adj[u]){
        if(v==p) continue;
        pii w = dfs(v,u);
        ret = {mod(ret.ff * (w.ff + w.ss),M),mod(ret.ss * w.ff,M)};
    }
    return ret;
}
int32_t main(){
    fastio;
    int n;
    cin >> n;
    for(int i=1;i<n;i++){
        int a,b;
        cin >> a >> b;
        adj[a].pb(b);
        adj[b].pb(a);
    }
    pii ans = dfs(1,0);
    cout << mod(ans.ff + ans.ss,M) << endl;
}

Measured memory_bytes: 12672
/* Murad Eynizade */

#include <bits/stdc++.h>
#define intt long long
#define FAST_READ ios_base::sync_with_stdio(0);cin.tie(0);
#define SIZE 300001
#define INF INT_MAX
#define F first
#define S second
#define in(a) scanf("%d",&a);
#define outn(a) printf("%d\n",&a);
#define outs(a) printf("%d ",&a);


using namespace std;

int n , a[SIZE] , b[SIZE] , c[SIZE] , dp[SIZE][3];

int main()
{
    FAST_READ;
    cin>>n;
    for (int i = 1;i<=n;i++) cin>>a[i]>>b[i]>>c[i];
    for (int i = 1;i<=n;i++) {
        dp[i][0] = max(dp[i - 1][1] , dp[i - 1][2]) + a[i];
        dp[i][1] = max(dp[i - 1][0] , dp[i - 1][2]) + b[i];
        dp[i][2] = max(dp[i - 1][1] , dp[i - 1][0]) + c[i];
    }
    cout<<max(dp[n][0] , max(dp[n][1] , dp[n][2]))<<endl;
    return 0;
}


Measured memory_bytes: 5632
from collections import deque
n=int(input())
graph=[[False for j in range(n)] for i in range(n)]
for i in range(n):
    s=input()
    for j in range(n):
        if s[j]=="1":
            graph[i][j]=True
L=0
def bfs(i):
    longest=0
    global dist
    dist=[-1]*n
    dist[i]=0
    D=deque([i])
    while D:
        v=D.popleft()
        for j in range(n):
            if graph[v][j]==False:continue
            if dist[j]!=-1:
                if abs(dist[v]-dist[j])==1:continue
                else:return -1
            else:
                D.append(j)
                dist[j]=dist[v]+1
                if dist[j]>longest:longest=dist[j]
    return longest
for i in range(n):
    A=bfs(i)
    
    if A==-1:print(-1);exit()
    if A>L:L=A
print(L+1)


Measured memory_bytes: 3820
#include "bits/stdc++.h"
#define in std::cin
#define out std::cout
#define rep(i,N) for(LL i=0;i<N;++i)
typedef long long int LL;

int main()
{
	LL N, D;
	in >> N >> D;
	out << (N / (D * 2 + 1) + (N % (D * 2 + 1) == 0 ? 0 : 1)) << std::endl;
}


Measured memory_bytes: 256
import sys
from collections import Counter,defaultdict
imput = sys.stdin.readline

N = int(input())
A = list(map(int,input().split()))
Q = int(input())
ans = sum(A)
A = Counter(A)
for i in range(Q):
    b,c = map(int,input().split())
    tmp = A.pop(b,None)
    if tmp:
        ans += (c-b)*tmp
        print(ans)
        if c in A:
            A[c] += tmp
        else:
            A[c] = tmp

    else:
        print(ans)

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

using ll = long long;
using ld = long double;
using pii = pair<int, int>;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))

int dx4[4] = {1,0,-1,0}, dy4[4] = {0,1,0,-1};


int main()
{
    int h,w;
    cin>>h>>w;
    
    for(int i = 0; i < h; i++)
    {
        string s;
        cin >>s;
        
        for(int j = 0; j < 2; j++)
        {
            cout << s << endl;
        }        
    }

    return 0;
}

Measured memory_bytes: 256
import math

mozir=input()
hyo=mozir.split(' ')

dogs=int(hyo[0])
monks=int(hyo[1])


hou=10**9+7

if dogs == monks:
    # d_0 m_0 d_1 m_1 ...
    tmp_1=1
    for idx in range(1,dogs+1,1):
        tmp_1=(tmp_1*idx) % hou
    for idx in range(1,monks+1,1):
        tmp_1=(tmp_1*idx) % hou

    # m_0 d_0 m_1 d_1 ...
    tmp_2=1
    for idx in range(1,monks+1,1):
        tmp_2=(tmp_2*idx) % hou
    for idx in range(1,dogs+1,1):
        tmp_2=(tmp_2*idx) % hou
    ans=(tmp_1+tmp_2)%hou
    
elif dogs + 1 == monks:
    # d_0 m_0 d_1 ... m_(n-1) d_n
    ans=1
    for idx in range(1,dogs+1,1):
        ans=(ans*idx) % hou
    for idx in range(1,monks+1,1):
        ans=(ans*idx) % hou
    
elif monks + 1 == dogs:
    # m_0 d_0 m_1 ... d_(n-1) m_n
    ans=1
    for idx in range(1,monks+1,1):
        ans=(ans*idx) % hou
    for idx in range(1,dogs+1,1):
        ans=(ans*idx) % hou

else:
    ans=0

print(ans)


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

int main(){
  int sunuke[101];
  int d,n,k;
  int a;
  cin >> n >> k;
  for(int i=1; i<=n; i++){
    sunuke[i] = 0;
  }
  for(int i=1; i<=k; i++){
    cin >> d;
    for(int j=1; j<=d; j++){
      cin >> a;
      sunuke[a] += 1;
    }
  }
  int ans = 0;
  for(int i=1; i<=n; i++){
    if(sunuke[i] == 0){
      ans += 1;
    }
  }
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
 
#define endl '\n'
#define die(x) return cout << x << endl, 0
#define all(v) v.begin(), v.end()
#define sz(x) (int)(x.size())
const int N = 1e5 + 5;

int A[N], B[N], P[N];

int GetPar(int v) { return P[v] == v ? v : P[v] = GetPar(P[v]); }
void Merge(int v, int u) {
	v = GetPar(v), u = GetPar(u);
	if (u == v) return;
	P[v] = u;
}

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

	int n, x = 0, ans = 0; cin >> n;
	vector<int> a, b;
	for (int i = 0; i < n; i++) cin >> A[i], x ^= A[i];
	A[n] = x,  x = 0;
	for (int i = 0; i < n; i++) cin >> B[i], x ^= B[i];
	B[n] = x, x = 0;
	for (int i = 0; i < n; i++) if (A[i] != B[i]) a.push_back(A[i]), b.push_back(B[i]), ans++;
	a.push_back(A[n]), b.push_back(B[n]);
	sort(all(a)), sort(all(b));
	if (a != b) die(-1);
	a.resize(unique(all(a)) - a.begin()), b.resize(unique(all(b)) - b.begin());
	for (int i = 0; i < sz(a); i++) P[i] = i;
	for (int i = 0; i <= n; i++) if (A[i] != B[i]) {
		int v = lower_bound(all(a), A[i]) - a.begin();
		int u = lower_bound(all(b), B[i]) - b.begin();
		Merge(v, u);
	}
	for (int i = 0; i < sz(a); i++) ans += (GetPar(i) == i);
	cout << ans - 1 << endl;

	return 0;
}


Measured memory_bytes: 8400
#include <bits/stdc++.h>
#define MOD 100000007
#define PI 3.141592653589793238
#define pb push_back
#define ALL(V) (V).begin(), (V).end()
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long long int lint;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef vector<int> VI;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
ll gcd(ll a, ll b) { return (a % b == 0 ? b : gcd(b, a % b)); }
ll lcm(ll a, ll b) { return a * b / gcd(a, b); }
ll char_to_ll(char c) { return (int)(c - '0'); }
ll string_to_ll(string s) { return char_to_ll(atoi(s.c_str())); }
bool is_prime(ll x){ if(x <= 1) return false; for(ll i = 2; sqrt(i) <= x; i++) if(x % i == 0) return false; return true; }

int main(){
    string S, T, U;
    ll A, B;
    cin >> S >> T >> A >> B >> U;

    if(U == S) cout << A-1 << " " << B << endl;
    else if(U == T) cout << A << " " << B-1 << endl;

    return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;
#define rep(i, begin, n) for (int i = begin; i < n; i++)
#define repe(i, begin, n) for (int i = begin; i <= n; i++)
#define repr(i, begin, n) for (int i = begin; i > begin - n; i--)
#define repre(i, begin, end) for (int i = begin; i >= end; i--)

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

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

const int inf = INT_MAX;
const int MOD = 1000000007;
const long long INF = LLONG_MAX;
const long long MINF = LLONG_MIN;

// -------------------------------------------------------

map<int, int> all;
int dupcnt, nodupcnt, dupvar;

int N;

int main() {
  cin >> N;
  rep(i, 0, N) {
    int a;
    cin >> a;
    ++all[a];
  }

  for (auto e : all) {
    if (e.second == 1) {
      ++nodupcnt;
    } else {
      dupcnt += e.second - 1;
      ++dupvar;
    }
  }

  if (dupcnt % 2 == 0) {
    cout << nodupcnt + dupvar;
  } else {
    cout << nodupcnt + dupvar - 1;
  }
}


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

using namespace std;

typedef long long ll;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
  int n;
  cin >> n;
  vector<int> h(n);
  for (int i = 0; i < n; i++) {
    cin >> h[i];
  }
  const int inf = 1e9 + 7;
  vector<int> dp(n, inf);
  dp[0] = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 1; j <= 2; j++) {
      if (i - j >= 0) {
        int pos = i - j;
        int cost = abs(h[i] - h[pos]);
        dp[i] = min(dp[i], dp[pos] + cost);
      }
    }
  }
  cout << dp[n - 1] << '\n';
	return 0;
}



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

typedef long long ll;
typedef unsigned long long ull;

ull p2[61];

ull f(int x) {
  return p2[x+2]-3;
}

ull p(int x) {
  return p2[x+1]-1;
}

ull solve (int level, ull x) {
  if (level == 0) 
    return (x == 1 or x == 2 ? 1 : 0);
  if (x < f(level-1)+2) {
    return solve(level-1,x-1);
  } else if (x == f(level-1)+2) {
    return p(level-1)+1;
  } else if (x <= f(level)-1) {
    return solve(level-1,x-f(level-1)-2)+p(level-1)+1;
  }
  return p(level);
}

int main () {
  p2[0] = 1;
  for (ull i = 1; i < 61; i++)
    p2[i] = p2[i-1]*2;
  ull n, x; cin >> n >> x;
  cout << solve(n,x) << endl;
  return 0;
}

Measured memory_bytes: 256
l1 = list(map(int, input().split()))
l2 = list(map(int, input().split()))
l3 = list(map(int, input().split()))

total = [1]
now = 1
l = [l1,l2,l3]

for i in range(3):
    for ll in l:
        if now in ll:
            ll.pop(ll.index(now))
            now = max(ll)
            total.append(now)
            l.pop(l.index(ll))

if 1 in total and 2 in total and 3 in total and 4 in total:
    print("YES")
else:
    print("NO")

Measured memory_bytes: 3064
package main

import "fmt"

type dice struct {
	a [7]int
}

func (d *dice) init(a [6]int) {
	for i := range a {
		d.a[i+1] = a[i]
	}
}

func (d *dice) top() int {
	return d.a[1]
}

func (d *dice) north() {
	d.a[1], d.a[2], d.a[5], d.a[6] = d.a[2], d.a[6], d.a[1], d.a[5]
}

func (d *dice) south() {
	d.a[1], d.a[2], d.a[6], d.a[5] = d.a[5], d.a[1], d.a[2], d.a[6]
}

func (d *dice) west() {
	d.a[1], d.a[4], d.a[6], d.a[3] = d.a[3], d.a[1], d.a[4], d.a[6]
}

func (d *dice) east() {
	d.a[1], d.a[4], d.a[6], d.a[3] = d.a[4], d.a[6], d.a[3], d.a[1]
}

func main() {
	var a [6]int
	for i := range a {
		fmt.Scan(&a[i])
	}
	var d dice
	d.init(a)
	var s string
	fmt.Scan(&s)
	for _, c := range s {
		switch c {
		case 'N':
			d.north()
		case 'S':
			d.south()
		case 'W':
			d.west()
		case 'E':
			d.east()
		}
	}
	fmt.Println(d.top())
}



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

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

Measured memory_bytes: 256
// C++ 14
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define loop(__x, __start, __end) for(int __x = __start; __x < __end; __x++)
#define chmax(x,y) (x = max(x, y))

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

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

int main() {
  int x; cin >> x;
  cout << lcm(x, 360) / x << endl;
  return 0;
}


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


using namespace std;
int grad[100005];
vector <int> lista[100005];
int v[100005];
int dp[100005];
int main()
{
    int n, m, i, j, x, y;
    cin >> n >> m;
    for (i = 1; i <= m; i++)
    {
        cin >> x >> y;
        lista[x].push_back(y);
        grad[y]++;
    }
    for (i = 1; i <= n; i++)
        if (grad[i] == 0)
            v[++v[0]] = i;
    for (i = 1; i <= n; i++)
    {
        for (j = 0; j < lista[v[i]].size(); j++)
        {
            grad[lista[v[i]][j]]--;
            if (!grad[lista[v[i]][j]])
                v[++v[0]] = lista[v[i]][j];
        }
    }
    for (i = 1; i <= n; i++)
    {
        for (j = 0; j < lista[v[i]].size(); j++)
            dp[lista[v[i]][j]] = max(dp[lista[v[i]][j]], dp[v[i]]+ 1);
    }
    int maxi = 0;
    for (i = 1; i <= n; i++)
        maxi = max(dp[i], maxi);
    cout << maxi;
    return 0;
}


Measured memory_bytes: 6912
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cctype>
#include <locale>
#include <cmath>
#include <iomanip>
#include <numeric>

using namespace std;

int main(){
    long H,W;
    cin >> H >> W;
    long loop = H / 2;
    long ans = W * loop;
    if(W == 1) {
        cout << 1 << endl;
    } else if(H == 1) {
        cout << 1 << endl;
    }
    else if(H % 2 == 1){
        long last = W /2;
        if(W % 2 == 1)last += 1;
        cout << ans + last  << endl;
    } else {
        cout << ans << endl;
    }
    return 0;
}

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

using namespace std;

#define REP(i,a,b) for(int i=a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
#define all(c) (c).begin(), (c).end()
#define zero(a) memset(a, 0, sizeof a)
#define minus(a) memset(a, -1, sizeof a)
#define watch(a) { cout << #a << " = " << a << endl; }
template<class T1, class T2> inline bool minimize(T1 &a, T2 b) { return b < a && (a = b, 1); }
template<class T1, class T2> inline bool maximize(T1 &a, T2 b) { return a < b && (a = b, 1); }

typedef long long ll;
int const inf = 1<<29;

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

template<class T> inline bool in_range(T y, T x, T H, T W) { return 0<=y&&y<H&&0<=x&&x<W; }

auto ng() {
  cout << "Impossible\n"; exit(0);
}

int main() {

  int H, W; cin >> H >> W;
  vector<string> A(H);
  rep(i, H) {
    cin >> A[i];
  }

  int y {0}, x {0};
  vector<vector<bool>> vis(H, vector<bool>(W));
  if(A[0][0] == '.') ng();
  vis[0][0] = 1;
  while(y != H-1 || x != W-1) {
    int dir = -1;
    rep(k, 4) {
      const int ny {y + dy[k]}, nx {x + dx[k]};
      if(!in_range(ny, nx, H, W)) continue;
      if(vis[ny][nx]) continue;
      if(A[ny][nx] == '.') continue;
      if(k == 0 || k == 1) ng();
      if(dir < 0) dir = k;
      else ng();
    }
    if(dir < 0) ng();
    y += dy[dir], x += dx[dir];
    vis[y][x] = 1;
  }

  if(A[H-2][W-1] == '#' && A[H-1][W-2] == '#') ng();

  cout << "Possible\n";
  
  return 0;
}

Measured memory_bytes: 256
### constant

MAX_N = 200

D_NS = 0
D_EW = 1

### main

loop do
  n = gets.to_i
  break if n == 0

  nm2id = {}
  nid = 0
  cpairs = []

  n.times do
    st0, st1 = gets.strip.split('-')

    if nm2id[st0].nil?
      nm2id[st0] = nid
      nid += 1
    end
    if nm2id[st1].nil?
      nm2id[st1] = nid
      nid += 1
    end
    cpairs << [nm2id[st0], nm2id[st1]]
  end
  #p nm2id
  #p cpairs

  cmat = nid.times.map{nid.times.map{nil}}
  nbrs = nid.times.map{[]}

  cpairs.each do |st0, st1|
    cmat[st0][st1] = 1
    cmat[st1][st0] = -1
    nbrs[st0] << st1
    nbrs[st1] << st0
  end

  cgrps = []
  ncgrp = 0
  drcs = []

  for id in (0...nid)
    next if drcs[id]

    cgrps[id] = ncgrp
    drcs[id] = D_NS
    q = [id]

    while ! q.empty?
      u = q.shift
      ud = drcs[u]

      for v in nbrs[u]
        if ! drcs[v]
          cgrps[v] = ncgrp
          drcs[v] = 1 - ud
          q << v
        end
      end
    end
    #p drcs

    ncgrp += 1
  end

  dsts = ncgrp.times.map{2.times.map{[]}}
  (0...nid).each{|id| dsts[cgrps[id]][drcs[id]] << id}
  #p dsts

  for i in (0...nid)
    cgrp = cgrps[i]
    d = drcs[i]

    for j in dsts[cgrp][d]
      next if i >= j

      cnd1 = false
      cnd23 = true

      for k in dsts[cgrp][1 - d]
        cik = cmat[i][k]
        cjk = cmat[j][k]
        if cik && cjk
          cnd1 = true
          if cik != cjk
            cnd23 = false
            break
          end
        end
      end

      if cnd1 && cnd23
        cmat[i][j] = cmat[j][i] = 0
        nbrs[i] << j
        nbrs[j] << i
      end
    end
  end
  #p cmat
  #p nbrs

  puts nid

  m = gets.to_i

  m.times do
    q0, q1 = gets.strip.split('-').map{|st| nm2id[st]}

    yorn = false
    if q0 && q1 && drcs[q0] && drcs[q1] && drcs[q0] != drcs[q1]
      visited = nid.times.map{false}
      visited[q0] = true
      q = [q0]

      while ! q.empty?
        u = q.shift
        if u == q1
          yorn = true
          break
        end

        for v in nbrs[u]
          next if visited[v]
          cuv = cmat[u][v]
          if cuv && cuv >= 0
            visited[v] = true
            q << v
          end
        end
      end
    end

    puts (yorn ? "YES" : "NO")
  end
end

Measured memory_bytes: 7004
import java.util.Scanner;
import java.io.*;

public class Main{
	public static String solve(double[] p){
		double a = p[4]-p[0]; //  c-a
		double b = p[6]-p[2]; //  g-e
		double c = p[5]-p[1]; //  d-b
		double d = p[7]-p[3]; //  h-f
		double e = p[3]*p[6]-p[2]*p[7]; //  fg-eh
		double f = p[0]*p[5]-p[1]*p[4]; //  ad-bc
		
		if( a == 0 ){
			double key = (d/b)*(p[0]-p[2])+p[3];
			if( (key-p[1])*(key-p[5]) < 0 && (p[0]-p[2])*(p[0]-p[6]) < 0 ){
				return "YES";
			} else {
				return "NO";
			}
		} else if( b == 0 ){
			double key = (c/a)*(p[2]-p[0])+p[1];
			if( (key-p[3])*(key-p[7]) < 0 && (p[2]-p[0])*(p[2]-p[4]) < 0 ){
				return "YES";
			} else {
				return "NO";
			}
		} else {
			double key = (a*e+b*f)/(-a*d+c*b);
			if( (key-p[0])*(key-p[4]) <= 0 && (key-p[2])*(key-p[6]) <= 0 ){
				return "YES";
			} else {
				return "NO";
			}
		}
	}
			
	public static void main(String[] args) throws IOException{
		Scanner stdIn = null;
		String[] result = new String[10000];
		int index = 0;
		
		try{
			stdIn = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
			while( stdIn.hasNext() ){
				String str = stdIn.next();
				String[] s = str.split(",");
				double[] p = new double[s.length];
				for(int i = 0; i < s.length; i++){
					p[i] = Double.parseDouble(s[i]);
				}
				result[index] = solve(p);
				index++;
			}
			for(int i = 0; i < index; i++){
				System.out.println(result[i]);
			}
		} finally {
			if( stdIn != null ){
				stdIn.close();
			}
		}
	}
}

Measured memory_bytes: 11000
#include <stdio.h>

int main() {
    char str[4];

    scanf("%s", str);
    if ( (str[0] == str[1] && str[2] == str[3] && str[0] != str[2]) ||
         (str[0] == str[2] && str[1] == str[3] && str[0] != str[1]) ||
         (str[0] == str[3] && str[1] == str[2] && str[0] != str[1]) ) {
        printf("Yes\n");
    }
    else {
        printf("No\n");
    }

    return 0;
}

Measured memory_bytes: 128
// This amazing code is by Eric Sunli Chen.
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>
using namespace std;
template<typename T> void get_int(T &x)
{
	char t=getchar();
	bool neg=false;
	x=0;
	for(; (t>'9'||t<'0')&&t!='-'; t=getchar());
	if(t=='-')neg=true,t=getchar();
	for(; t<='9'&&t>='0'; t=getchar())x=x*10+t-'0';
	if(neg)x=-x;
}
template<typename T> void print_int(T x)
{
	if(x<0)putchar('-'),x=-x;
	short a[20]= {},sz=0;
	while(x>0)a[sz++]=x%10,x/=10;
	if(sz==0)putchar('0');
	for(int i=sz-1; i>=0; i--)putchar('0'+a[i]);
}
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define get1(a) get_int(a)
#define get2(a,b) get1(a),get1(b)
#define get3(a,b,c) get1(a),get2(b,c)
#define printendl(a) print_int(a),puts("")
typedef long long LL;
typedef unsigned long long uLL;
typedef pair<int,int> pii;
const int inf=0x3f3f3f3f;
const LL Linf=1ll<<61;
const double pi=acos(-1.0);

const int mod=1e9+7;
int dp[44][1<<17][2],n,x[3];
int main()
{
	get1(n);get3(x[0],x[1],x[2]);int sz=x[0]+x[1]+x[2];
	dp[1][1][0]=1;
	for(int i=1;i<=n;i++)for(int j=0;j<1<<sz;j++)for(int k=0;k<2;k++)
	{
		for(int nxt=1,nj,nk;nxt<=10;nxt++)
		{
			nj=(j<<nxt)|(1<<nxt);nk=k;if(((nj>>x[2])&1)&&((nj>>x[2]+x[1])&1)&&((nj>>x[2]+x[1]+x[0])&1))nk|=1;
			dp[i+1][nj&(1<<sz)-1][nk]+=dp[i][j][k];
			if(dp[i+1][nj&(1<<sz)-1][nk]>=mod)dp[i+1][nj&(1<<sz)-1][nk]-=mod;
		}
	}
	int ans=0;
	for(int j=0;j<1<<sz;j++)
	{
		ans+=dp[n+1][j][1];
		if(ans>=mod)ans-=mod;
	}
	printendl(ans);
	return 0;
}

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

int N, M, Q;
int acc[510][510];

void makeacc(){
	for (int i = 1; i <= N; i++){
		for (int j = 1; j <= N; j++){
			acc[i][j] += acc[i][j - 1];
		}
	}
}

int main(){
	cin >> N >> M >> Q;
	for (int i = 0; i < M; i++){
		int L, R;
		cin >> L >> R;
		acc[L][R]++;
	}

	makeacc();

	for (int i = 0; i < Q; i++){
		int ans = 0;
		int p, q;
		cin >> p >> q;
		for (int i = p; i <= q; i++){
			ans += (acc[i][q] - acc[i][p - 1]);
		}
		cout << ans << endl;
	}

	return 0;
}

Measured memory_bytes: 1920