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

using namespace std;
typedef long long ll;
#define REP(i,n) for(int i=0; i<int(n); i++)
#define FOR(i,m,n) for(int i=int(m); i<int(n); i++)
#define ALL(obj) (obj).begin(),(obj).end()
#define VI vector<int>
#define VLL vector<long long>
#define VVI vector<vector<int>>
#define VVLL vector<vector<long long>>
#define VC vector<char>
#define VS vector<string>
#define VVC vector<vector<char>>
#define fore(i,a) for(auto &i:a)

typedef pair <int, int> P;
template<class T> bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }
const int  INF = 2147483647;
const ll INFL = 9223372036854775807;
const ll mod = 1000000007;





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

	int n = s.size() - 7;
	bool b = false;
	if (s == "keyence")b = true;
	REP(i, 7) {
		string t = s;
		t.erase(i, n);
		//cout << t << endl;
		if (t == "keyence")b = true;
	}

	if (b)cout << "YES" << endl;
	else cout << "NO" << endl;
	

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define endl "\n"
#define int long long 
const int N=2e3+5;
int n;
map <string, int> mp;

int32_t main(){
	IOS;
	cin>>n;
	int maxx=0;
	for(int i=0;i<n;i++){
	    string str;
	    cin>>str;
	    mp[str]++;
	    maxx= max(maxx, mp[str]);
	}
	for(auto it: mp){
	   if(it.second ==maxx){
	        cout<<it.first<<endl;
	    }
	}
	//code
	return 0;
}

Measured memory_bytes: 23808
#include<bits/stdc++.h>
using namespace std;
int main()
{

       long long int a[200000],n,i,s1=0;
        cin>>n;
        for(i=0;i<n;i++)
            cin>>a[i];
        sort(a,a+n);
            for(i=0;i<(n-1);i++){
            if(a[i]==a[i+1]){
                s1=1;
               break;} }
                if(s1==1)
                     cout<<"NO"<<endl;
            else
                cout<<"YES"<<endl;

return 0;
}










Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std; 
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define int long long int
#define rep(i,a,b) for(int i=a;i<b;i++)
#define reprev(i,a,b) for(int i=b-1;i>=a;i--)
#define all(c) c.begin(),c.end()
#define ff first
#define ss second
#define pii pair<int,int>
#define vi vector<int>
#define vii vector<pii>
#define vin(a,n) vi a(n); rep(i,0,n) cin>>a[i];
#define vout(a) rep(i,0,a.size()) cout<<a[i]<<" "; cout<<endl;
#define mapp map<int,int>
#define pb push_back
#define mp  make_pair
#define mod 1000000007
#define mod2 998244353
#define inf LLONG_MAX
#define pi 3.1415926535897932384626
#define tr(container, it) \
for(auto it = container.begin(); it != container.end(); it++)

bool comps(const pair<int,int> &a, const pair<int,int> &b) {return (a.second<b.second);} 

int power(int x, unsigned int y, int p)  
{  
    int res = 1;     // Initialize result  
  
    x = x % p; // Update x if it is more than or  
                // equal to p 
   
    if (x == 0) return 0; // In case x is divisible by p; 
  
    while (y > 0)  
    {  
        // If y is odd, multiply x with result  
        if (y & 1)  
            res = (res*x) % p;  
  
        // y must be even now  
        y = y>>1; // y = y/2  
        x = (x*x) % p;  
    }  
    return res;  
}

signed main()
{
    IOS
    int n,s;
    cin>>n>>s;
    vin(a,n);
    vector<vi> dp(n+1, vi(s+1));
    dp[0][0]=power(2,n,mod2);
    rep(i,0,n)
    {
        rep(j,0,s+1)
        {
            dp[i+1][j]+=dp[i][j];
            dp[i+1][j]%=mod2;
            if(j+a[i]<=s)
            {
                dp[i+1][j+a[i]] += (dp[i][j])*(power(2,mod2-2,mod2));
                dp[i+1][j+a[i]]%=mod2;
            }
        }
    }
    cout<<dp[n][s];
    return 0;
}


Measured memory_bytes: 73672
import numpy as np

C = list(map(int,input()))
op1 = np.array([1,-1,1,1])
op2 = np.array([1,1,-1,1])
op3 = np.array([1,1,1,-1])
C = np.array(C)

if(sum(C) == 7):
    print("{}+{}+{}+{}=7".format(C[0],C[1],C[2],C[3]))
elif(sum(C*op1) == 7):
    print("{}-{}+{}+{}=7".format(C[0],C[1],C[2],C[3]))
elif(sum(C*op2) == 7):
    print("{}+{}-{}+{}=7".format(C[0],C[1],C[2],C[3]))
elif(sum(C*op3) == 7):
    print("{}+{}+{}-{}=7".format(C[0],C[1],C[2],C[3]))
elif(sum(C*op1*op2) == 7):
    print("{}-{}-{}+{}=7".format(C[0],C[1],C[2],C[3]))
elif(sum(C*op1*op3) == 7):
    print("{}-{}+{}-{}=7".format(C[0],C[1],C[2],C[3]))
elif(sum(C*op1*op2*op3) == 7):
    print("{}-{}-{}-{}=7".format(C[0],C[1],C[2],C[3]))
elif(sum(C*op2*op3) == 7):
    print("{}+{}-{}-{}=7".format(C[0],C[1],C[2],C[3]))

Measured memory_bytes: 12416
#include<iostream>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<set>
#include<string>
#include<map>
#include<string.h>
#include<complex>
#include<math.h>
#include<queue>
#include<time.h>
using namespace std;
typedef long long int llint;
typedef pair<int, int> pint;
typedef pair<llint, llint> pllint;
typedef vector<int> vint;
typedef vector<llint> vllint;
typedef vector<pint> vpint;
typedef vector<pair<llint, llint>> vpllint;
typedef vector<vector<int>> vvint;
typedef vector<vector<llint>> vvllint;
typedef vector<vector<pint>> vvpint;
typedef vector<bool> vbool;
#define rep(i,n) for(int i=0;i<n;i++)
#define drep(i,n) for(int i=n-1;0<=i;i--)
#define yes(ans) if(ans)cout<<"yes"<<endl;else cout<<"no"<<endl;
#define Yes(ans) if(ans)cout<<"Yes"<<endl;else cout<<"No"<<endl;
#define YES(ans) if(ans)cout<<"YES"<<endl;else cout<<"NO"<<endl;
#define POSSIBLE(ans) if(ans)cout<<"POSSIBLE"<<endl;else cout<<"IMPOSSIBLE"<<endl;
#define Pi 3.1415926535897932384626
#define mod llint(1e9+7)

class UnionFind {
public:
	//親の番号を格納する。親だった場合は-(その集合のサイズ)
	vector<int> Parent;

	//作るときはParentの値を全て-1にする
	//こうすると全てバラバラになる
	UnionFind(int N) {
		Parent = vector<int>(N, -1);
	}

	//Aがどのグループに属しているか調べる
	int root(int A) {
		if (Parent[A] < 0) return A;
		return Parent[A] = root(Parent[A]);
	}

	//自分のいるグループの頂点数を調べる
	int size(int A) {
		return -Parent[root(A)];//親をとってきたい
	}

	//AとBをくっ付ける
	bool connect(int A, int B) {
		//AとBを直接つなぐのではなく、root(A)にroot(B)をくっつける
		A = root(A);
		B = root(B);
		if (A == B) {
			//すでにくっついてるからくっ付けない
			return false;
		}

		//大きい方(A)に小さいほう(B)をくっ付けたい
		//大小が逆だったらひっくり返しちゃう。
		if (size(A) < size(B)) swap(A, B);

		//Aのサイズを更新する
		Parent[A] += Parent[B];
		//Bの親をAに変更する
		Parent[B] = A;

		return true;
	}
};

//aとbの最大公約数を求めるよ
long long GCD(long long a, long long b) {
	if (b == 0) return a;
	else return GCD(b, a % b);
}

// 返り値: a と b の最大公約数
// ax + by = gcd(a, b) を満たす (x, y) が格納される
long long extGCD(long long a, long long b, long long& x, long long& y) {
	if (b == 0) {
		x = 1;
		y = 0;
		return a;
	}
	long long d = extGCD(b, a % b, y, x);
	y -= a / b * x;
	return d;
}

bool check(llint a, llint b) {
	return a > b;
}

// mod. m での a の逆元 a^{-1} を計算する
long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}

//aCbを1000000007で割った余りを求める
llint convination(llint a, llint b) {
	llint ans = 1;
	for (llint i = 0; i < b; i++) {
		ans *= a - i;
		ans %= 1000000007;
	}
	for (llint i = 1; i <= b; i++) {
		ans *= modinv(i, 1000000007);
		ans %= 1000000007;
	}
	return ans;
}

//aのb乗をmodで割った余りを求める
llint power(llint a, llint b) {
	if (b == 1)return a;
	if (b == 0)return 1;
	llint tmp = power(a, b / 2);
	tmp *= tmp;
	tmp %= mod;
	if (b % 2 == 1) {
		tmp *= a;
		tmp %= mod;
	}
	return tmp;
}

int main() {
	int n;
	cin >> n;
	vint a(n);
	rep(i, n)cin >> a[i];
	int ans = 0;
	int now = -1;
	rep(i, n) {
		if (now == -1) {
			now = 0;
		}
		else {
			if (a[i - 1] >= a[i])now++;
			else now = 0;
		}
		ans = max(now, ans);
	}
	cout << ans << endl;
	return 0;
}

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

int main() {
  int n;
  cin>>n;
  int a[n];
  for(int i=0;i<n;i++){
    int k;
    cin>>k;
    a[i]=k;
  }
  int ans=0;
  for(int i=0;i<n;i++){
    int l;
    cin>>l;
    ans+=l;
  }
  int b[n-1];
  for(int i=0;i<n-1;i++){
    int k;
    cin>>k;
    b[i]=k;
  }
  for(int i=0;i<n-1;i++){
    if(a[i]==a[i+1]-1)ans+=b[a[i]-1];
  }
  cout<<ans<<endl;
  
}


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

vector<bool> honest(16);
int res = 0;

void go(int x, int n, vector<vector<int>> tt){
    if (x > n){
        bool ok = true;
        int cnt = 0;
        for (int i = 1; i <= n && ok; i++)
            if (honest[i]){
                for (int j = 1; j <= n && ok; j++)
                if (honest[j] && tt[i][j] == 0 || !honest[j] && tt[i][j] == 1)
                    ok = false;
                cnt++;
            }

        if (ok)
            res = max(res, cnt);

    }
    else {
        honest[x] = false;
        go(x + 1, n, tt);
        honest[x] = true;
        go(x + 1, n, tt);
    }
}

int main(){;
    int n;
    cin >> n;
    vector<vector<int>> tt(n + 1, vector<int> (n + 1, -1));
    for (int i = 1; i <= n; i++){
        int a;
        cin >> a;
        while (a--){
            int x, y;
            cin >> x >> y;
            tt[i][x] = y;
        }
    }

    go(1, n, tt);

    cout << res << "\n";

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cmath>

using namespace std;

double surfaceArea(double x, double h)
{
  return x*x + x*sqrt(4*h*h+x*x);
}

int main()
{
  int x, h;

  while(cin>>x>>h && x != 0 && h != 0){
    printf("%.6lf\n", surfaceArea((double)x, (double)h));
  }

  return 0;
}

Measured memory_bytes: 1192
#include<stdio.h>
#include<iostream>
#include<vector>
#include<math.h>
#include<queue>
#include<map>
#include<algorithm>
#include<string.h>
#include<functional>
#include<limits.h>
#include<stdlib.h>
#include<string>
#include<unordered_map>
using namespace std;

#define intmax INT_MAX
#define lmax LONG_MAX
#define uintmax UINT_MAX
#define ulmax ULONG_MAX
#define llmax LLONG_MAX
#define ll long long
#define rep(i,a,N) for((i)=(a);(i)<(N);(i)++)
#define rrp(i,N,a) for((i)=(N)-1;(i)>=(a);(i)--)
#define llfor ll i,j,k
#define sc(a) cin>>a
#define pr(a) cout<<a<<endl
#define pY puts("YES")
#define pN puts("NO")
#define py puts("Yes")
#define pn puts("No")
#define pnn printf("\n")
#define sort(a) sort(a.begin(),a.end())
#define push(a,b) (a).push_back(b)
#define llvec vector<vector<ll>>
#define charvec vector<vector<char>>
#define sizeoof(a,b) (a,vector<ll>(b))
#define llpvec vector<pair<ll,ll>>
/*繰り上げ除算*/ll cei(ll x,ll y){ll ans=x/y;if(x%y!=0)ans++;return ans;}
/*最大公約数*/ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}
/*最小公倍数*/ll lcm(ll x,ll y){return x/gcd(x,y)*y;}
/*n乗*/ll llpow(ll x,ll n){ll i,ans=1;rep(i,0,n)ans*=x;return ans;}
/*階乗*/ll fact(ll x){ll i,ans=1;rep(i,0,x)ans*=(x-i);return ans;}
/*nCr*/ll ncr(ll n,ll r){return fact(n)/fact(r)/fact(n-r);}
/*nPr*/ll npr(ll n,ll r){return fact(n)/fact(n-r);}
/*primejudge*/bool prime(ll a){if(a<=1)return false;ll i;for(i=2;i*i<=a;i++){if(a%i==0)return false;}return true;}
double ans=0;llfor;///////////////////////////////////////////////////////////
int main(){
 ll a,b;
 sc(a);sc(b);
 rep(i,12,1260){
  //cout<<0.08*i<<" "<<0.1*i<<endl;
  if(int(0.08*i)==a&&int(0.1*i)==b){
   pr(i);return 0;
  }
 }
 puts("-1"); 
return 0;}

Measured memory_bytes: 3616
import math

def main():
    N = int(input())
    count = 0
    for m in range(1, N+1):
        if m % 2 == 1 and factors(m):
            count += 1
    return count

def factors(m):
    fs = set()
    for i in range(1, int(math.sqrt(m))+1):
        if m % i == 0:
            fs.add(i)
            fs.add(m // i)
    if len(fs) == 8:
        return True
    else:
        return False


if __name__ == '__main__':
    print(main())

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

fn input<T: std::str::FromStr>() -> T {
    let stdin = std::io::stdin();
    let token: String = stdin
        .lock()
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}

#[allow(dead_code)]
fn with_stdout_lock<F: FnOnce(std::io::BufWriter<std::io::StdoutLock>)>(f: F) {
    let out = std::io::stdout();
    let w = std::io::BufWriter::new(out.lock());
    f(w);
}

#[allow(unused_macros)]
macro_rules! debug {
    ($var:expr) => {
        match &$var { v => eprintln!(concat!(stringify!($var), "={:?}"), v) }
    };
    ($var:expr, $($vars:expr),*) => {
        match &$var { v => eprint!(concat!(stringify!($var), "={:?} "), v) }
        debug!($($vars),*);
    };
}

fn main() {
    let n: i32 = input();
    let m: i32 = input();

    let mut v = vec![];
    for i in 1..m {
        if i * i > m {
            break;
        }
        if m % i == 0 {
            v.push(i);
            if i * i != m {
                v.push(m / i);
            }
        }
    }
    v.sort_by_key(|&v| -v);

    let mut ans = 1;
    for v in v {
        if m / v >= n {
            ans = v;
            break;
        }
    }

    println!("{}", ans);
}


Measured memory_bytes: 4352
#include <iostream>
#include <cmath>
#include <cstdio>

using namespace std;

int main()
{
	int n;
	double x[3], y[3], a1, b1, c1, a2, b2, c2, px, py, r;

	cin >> n;

	for(int i=0; i<n; i++)
	{
		cin >> x[0] >> y[0] >> x[1] >> y[1] >> x[2] >> y[2];

		a1 = 2 * (x[1]-x[0]);
		b1 = 2 * (y[1]-y[0]);
		c1 = (x[0]*x[0]) - (x[1]*x[1]) + (y[0]*y[0]) - (y[1]*y[1]);
		a2 = 2 * (x[2]-x[0]);
		b2 = 2 * (y[2]-y[0]);
		c2 = (x[0]*x[0]) - (x[2]*x[2]) + (y[0]*y[0]) - (y[2]*y[2]);
		px = (b1*c2 - b2*c1)/(a1*b2 - a2*b1);
		py = (c1*a2 - c2*a1)/(a1*b2 - a2*b1);
		r  = sqrt((px-x[0])*(px-x[0]) + (py-y[0])*(py-y[0]));

		printf("%.3f %.3f %.3f\n", px, py, r);
	}

	return 0;
}

Measured memory_bytes: 1244
#include<iostream>
#include<vector>
int main()
{
    long long int a,b,c,d;
    std::vector<long long int> vc;
    std::cin>>a>>b>>c>>d;
    vc.push_back(a*d);vc.push_back(a*c);vc.push_back(b*d);vc.push_back(b*c);
   long long int max=vc[0];int i=0;
   for(i=0;i<4;i++)
   {
       if(max<vc[i]) max=vc[i];
   }

    std::cout <<std::fixed<< max <<std::endl;

}


Measured memory_bytes: 3604
#include <bits/stdc++.h>
#define f(i,j,k) for(int i=j;i<k;i++)
#define f2(i,j,k) for(int i=j;i>k;i--)
using namespace std;
int main(){
    long long n,t,ans=0;
    cin>>n>>t;
    long long a[n];
    f(i,0,n){
        cin>>a[i];
    }
    f(i,1,n){
        ans+=min(a[i]-a[i-1],t);
    }
    cout<<ans+t<<endl;
    return 0;
}


Measured memory_bytes: 5100
#!usr/bin/env python3
from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations, accumulate
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.buffer.readline().split()]
def I(): return int(sys.stdin.buffer.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    n = I()
    a = LI()
    s = [2 if i&1 else 1 for i in a]
    ans = 0
    for b in range(1,1<<n):
        res = 1
        c = 0
        for i in range(n):
            if b&(1<<i):
                res *= s[i]
                c ^= 1
            else:
                res *= 3
        ans += (2*c-1)*res
    print(ans)
    return

#Solve
if __name__ == "__main__":
    solve()


Measured memory_bytes: 39920
a, b, c, d = list(map(int, input().split()))
if c >= a:
    if c - a <= d or b - a <= d and c - b <= d:
        print("Yes")
    else:
        print("No")
if c < a:
    if a - c < d or b - c <= d and a - b <= d:
        print("Yes")
    else:
        print("No")


Measured memory_bytes: 38384
import java.util.Scanner;
class Main{
  public static void main(String args[]){
    Scanner scan=new Scanner(System.in);
    long a=scan.nextLong();
    long b=scan.nextLong();
    System.out.println(func(b)^func(a-1));
  }
  public static long func(long n){
    if(n<0){
      return 0L;
    }else{
      if(n%4==0){
        return n;
      }else if(n%4==1){
        return 1L;
      }else if(n%4==2){
        return n^1;
      }else{
        return 0L;
      }
    }
  }
}


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

int main() {
	int n;
	while(cin>>n,n){
		vector<long long>wait(n);
		long long sum=0;
		for(int i=0;i<n;i++)cin>>wait[i];
		sort(wait.begin(),wait.end());
		for(int i=0;i<n-1;i++)sum+=wait[i],wait[i+1]+=wait[i];;
		cout<<sum<<endl;
	}
	return 0;
}

Measured memory_bytes: 1296
#include<stdio.h>
 
int main(void){
    char str[20];
    int i=0;

    scanf("%s",str);

    while(str[i]){
        i++;
    }

    for(i -=1;i>=0;i--){
        printf("%c",str[i]);
    }
        printf("\n");

    return 0;
}

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

namespace C
{
    class Program
    {
        static void Main(string[] args)
        {
            var source = new int[] { 0, 1, 2, 3, 4 };
            var comb = Comb(source, 3);
            var result = comb.Select(x => x.ToList()).ToList();
            var startWith = new char[] { 'M', 'A', 'R', 'C', 'H' };
            int N = int.Parse(Console.ReadLine());
            var nameList = new List<string>();
            for(int i = 0; i < N; i++)
            {
                nameList.Add(Console.ReadLine());
            }
            List<long> numOfStart = new List<long>() { 0, 0, 0, 0, 0 };
            foreach(var name in nameList)
            {
                for(int i = 0; i < 5; i++)
                {
                    if(name[0] == startWith[i])
                    {
                        numOfStart[i]++;
                    }
                }
            }
            long sum = 0;
            for(int i = 0; i < result.Count; i++)
            {
                long a = numOfStart[result[i][0]];
                long b = numOfStart[result[i][1]];
                long c = numOfStart[result[i][2]];
                sum += a * b * c;
            }
            Console.WriteLine(sum);
        }

        public static IEnumerable<IEnumerable<T>> Comb<T>(IEnumerable<T> items, int r)
        {
            if (r == 0)
            {
                yield return Enumerable.Empty<T>();
            }
            else
            {
                var i = 1;
                foreach (var x in items)
                {
                    var xs = items.Skip(i);
                    foreach (var c in Comb(xs, r - 1))
                        yield return Before(c, x);

                    i++;
                }
            }

        }

        public static IEnumerable<T> Before<T>(IEnumerable<T> items, T first)
        {
            yield return first;

            foreach (var i in items)
                yield return i;
        }
    }
}

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

int n, m, a, b, c;
int can[50][50][110];
vector<int> G[50];

void bfs(int s) {
	can[s][s][0] = 1;
	for (int t = 0; t < 100; t++) {
		for (int v = 0; v < n; v++) {
			if (can[s][v][t] == 0)
				continue;
			for (int u : G[v]) {
				can[s][u][t + 1] = 1;
			}
		}
	}
}

const int MAX_T = 5010;
const int INF = 1 << 25;
int dp[MAX_T][50];

int f(int t, int v) {
	if (v == n - 1)
		return 0;
	if (t == MAX_T)
		return INF;

	int& d = dp[t][v];
	if (d != -1)
		return d;

	int m[3] = { a, b, c };
	d = 0;
	for (int i = 0; i < 3; i++) { // opp
		int mindist = INF;
		for (int u = 0; u < n; u++) { // my
			if (can[v][u][m[i]]) {
				mindist = min(mindist, f(t + 1, u) + 1);
			}
		}
		d = max(d, mindist);
	}
	return d;
}

int main() {
	cin >> n >> m >> a >> b >> c;

	for (int i = 0; i < m; ++i) {
		int u, v;
		cin >> u >> v;
		u--, v--;
		G[u].push_back(v);
	}

	for (int i = 0; i < n; ++i) {
		bfs(i);
	}

	memset(dp, -1, sizeof dp);
	int res = f(0, 0);
	if (res == INF)
		cout << "IMPOSSIBLE" << endl;
	else
		cout << res << endl;
}

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

#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for (int i = x; i < n; i++)
#define OP(m) cout << m << endl
typedef long long ll;
typedef unsigned long long ull;

int main()
{
    double a, b;
    cin >> a >> b;
    if (a > b)
        OP("GREATER");
    else if (a < b)
        OP("LESS");
    else
        OP("EQUAL");

    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		sc.close();

		System.out.println((a + b >= 10) ? "error" : a + b);

	}

}




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

int main() {
  string s;
  cin >> s;
  if(s.at(1) == 'B') cout << "ARC" << endl;
  else if(s.at(1) == 'R') cout << "ABC" << endl;
  return 0;
}

Measured memory_bytes: 3588
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <cmath>
#include <numeric>
#include <iomanip>
#include <stack>
#include <complex>
#include <functional>
#include <tuple>

using namespace std;

#define Rep(i,a,b) for(ll i = a; i < b; ++i)
#define rep(i,b) Rep(i,0,b)
#define allof(a) (a).begin(), (a).end()

#define Yes(q) ((q) ? "Yes" : "No")
#define YES(q) ((q) ? "YES" : "NO")
#define Possible(q) ((q) ? "Possible" : "Impossible")
#define POSSIBLE(q) ((q) ? "POSSIBLE" : "IMPOSSIBLE")

using ll = long long;

constexpr int inf = 1e9 + 7;
constexpr ll infll = 1ll << 60ll;
constexpr ll mod = 998244353;
// 0~3までは右左下上 4~7までは斜め
constexpr int dx[] = { 1, 0, -1, 0, 1, 1, -1, -1 };
constexpr int dy[] = { 0, -1, 0, 1, 1, -1, -1, 1 };

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

    void Cout(long long x, const char* end = "\n") { std::cout << x << end; }
    template <typename T> void Cout(const T& x, const char* end = "\n") { std::cout << x << end; }
    template <typename T> void Cout(const std::vector<T>& x, const char* sep = " ", const char* end = "\n") { for (std::size_t i = 0, sz = x.size(); i < sz; ++i) { std::cout << x[i] << (i == sz - 1 ? end : sep); } }

    // 標準入出力
    struct inp {
        std::size_t szi, szj;
        inp(std::size_t _szi = 1, std::size_t _szj = 1) : szi(_szi), szj(_szj) {}
        template <typename T> operator T () const { T a; std::cin >> a; return a; }
        template <typename T> operator std::vector<T>() const { std::vector<T> a(szi); for (std::size_t i = 0; i < szi; ++i) std::cin >> a[i]; return a; }
        template <typename T> operator std::vector<std::vector<T>>() const {
            std::vector<std::vector<T>> a(szi, std::vector<T>(szj));
            for (std::size_t i = 0; i < szi; ++i) for (std::size_t j = 0; j < szj; ++j) cin >> a[i][j]; return a;
        }
    };
    inp inp1;
}

int main() {

    ll n, k;
    cin >> n >> k;
    vector<int> a = inp(n);
    rep(i, n) --a[i];

    int cur = 0;
    rep(j, 62) {
        if (k & (1LL << j)) cur = a[cur];
        vector<int> na(n);
        rep(i, n) {
            na[i] = a[a[i]];
        }
        a = move(na);
    }

    Cout(cur + 1);

    return 0;
}


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

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pii;

#define fi first
#define se second
#define mp make_pair
#define fastIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);

const ll N = (ll)1e5 + 9;
ll a[N];
map<ll,ll> cnt;

int main(){
  fastIO;
  ll n;
  cin >> n;
  for(ll i = 1; i <= n; i ++ ) cin >> a[i];
  ll l = 1;
  ll r = (ll)1e9 + 9;
  ll md;
  ll cur;
  ll ss = 1;
  ll sum;
  ll kk;
  while(l + 1 < r){
    md = (l + r) / 2ll;
    cnt.clear(); // unnesecary log but who cares?
    cnt[0] = 1;
    cur = 0;
    ss = 1;
    sum = 0;
    for(ll i = 1; i <= n; i ++ ){
      if(a[i] >= md) {
        cur ++ ;
        cnt[cur]++;
        ss += cnt[cur];
      }
      else{
        ss -= cnt[cur];
        cur--;
        cnt[cur]++;
        ss++;
      }
      sum += ss;
    }
    sum -= n;
    kk = n*(n+1)/2ll;
    if(sum >= (kk+1)/2){
      l = md;
    }
    else
      r = md;
  }
  cout << l;
  return 0;
}

Measured memory_bytes: 7296
#include <bits/stdc++.h>
using namespace std;
const int N = 100010;
int prime[N],sum[N];
int q,l,r;

void init()
{
	for(int i=2;i<N;i++)
		prime[i]=1;
}
void find()
{
	init();
	for(int i=2;i<=sqrt(N);i++)
		if(prime[i])
		{
			for(int j=i*2;j<N;j+=i)
				prime[j]=0;
		}
	for(int i=1;i<N;i++)
		if(prime[i]&&prime[(i+1)/2]) sum[i]=sum[i-1]+1;
			else sum[i]=sum[i-1];
}
int main()
{
	cin>>q;
	find();
	for(int i=1;i<=q;i++)
	{
		cin>>l>>r;
		cout<<sum[r]-sum[l-1]<<"\n";
	}
}

Measured memory_bytes: 1408
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <utility>
#include <cmath>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <deque>
#include <numeric>


using namespace std;

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


using namespace std;



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

	vector<vector<int> > vs;


	for (int i = 1; i <= n / 2; i++) {
		vector<int> v;
		v.push_back(i);
		v.push_back((n / 2) * 2 - i + 1);
		vs.push_back(v);
	}

	if (n % 2 == 1) {
		vector<int> v;

		v.push_back(n);
		vs.push_back(v);
	}
	/*
	rep(i, vs.size()) {
		rep(j ,vs[i].size()) {
			cout << vs[i][j] << " ";
		}
		cout << endl;
	}
	cout << "----" << endl;
	*/
	int size = vs.size();
	vector<pair<int, int > > ps;

	if (n == 3) {
		ps.push_back(mkp(1, 3));
		ps.push_back(mkp(2, 3));
	} else {
		for (int i = 0; i < size; i++) {
			for (int j = 0; j < vs[i].size(); j++) {
				if (n == 4 && i == 0) continue;
				int prev = (i - 1 + size) % size;

				for (int k = 0; k < vs[prev].size(); k++) {
					ps.push_back(mkp(vs[i][j],vs[prev][k]));
				}
			}	
		}
	}
	cout << ps.size() << endl;
	for (auto p : ps) {
		cout << p.first << " " << p.second << endl;
	}

	return 0;

}

Measured memory_bytes: 888
n = int(input())
A = [int(i) for i in input().split()]
tmp,tmp2,two = 0,0,0
for a in A:
    if a%4 == 0: tmp += 1
    elif a%2 == 0: two = 1
    else: tmp2 += 1
#print(tmp,tmp2,two)
if tmp2+two-tmp >= 2: print('No')
else: print('Yes')


Measured memory_bytes: 14252
#include <iostream>
#include <map>
#include <vector>
#include <algorithm>

using namespace std;

typedef long long ll;


int main(int argc, char const *argv[])
{
    ll x[3], y[3], s;
    cin >> s;
    x[0] = 0;
    y[0] = 0;
    x[1] = 1e9;
    y[1] = 1;

    y[2] = (s + (x[1] - 1)) / x[1];
    x[2] = x[1]*y[2] - s;

    for (int i = 0; i < 3; ++i) {
        cout << x[i] << ' ' << y[i] << ' ';
    }
    cout << endl;

    return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("O3")

#define _GLIBCXX_DEBUG
#include <iostream>
#include <vector>
#include <string>
#include <string_view>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <cassert>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
using namespace std;

/*----------macros----------*/

//output================
#define endl '\n'
#define fcout(a) cout << fixed << setprecision((int)(a))

//typedef===============
typedef long long       ll;
typedef long double     ld;
typedef pair<int, int>  Pii;
typedef pair<ll, ll>    Pll;

//const number==========
constexpr ll INF9   = (ll)1e9 + 1;
constexpr ll INF18  = (ll)1e18 + 1;
constexpr ll MOD    = 1000000007;
constexpr ll MOD2   = 998244353;
constexpr ld PI     = 3.141592653589793L;

//member================
#define pb push_back
#define eb emplace_back
#define pf push_front
#define mp make_pair
#define fi first
#define se second

//others================
#define all(x)          (x).begin(), (x).end()
#define rall(x)         (x).rbegin(), (x).rend()
#define rep(i, n)       for(int i = 0; (i) < (n); ++(i))
#define reps(i, n)      for(int i = 1; (i) <= (n); ++(i))
#define rrep(i, n)      for(int i = n - 1; (i) >= 0 ; --(i))
#define repbit(bit, n)  for(int bit = 0; (bit) < (1 << (n)); ++(bit))
#define ifbit(bit, i)   if((bit) & (1 << (i)))
#define CtoI(c)         int((c)) - int('0')
#define ItoC(c)         char((c) + '0')

//functions=============
template<typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }

template<typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

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

/*--------additional--------*/



/*----------main------------*/

int main() {
/*----------fastio----------*/
    std::cin.tie(nullptr);
    std::cout.tie(nullptr);
    std::ios::sync_with_stdio(false);
/*----------solve-----------*/

    int n; cin >> n;
    cout << n * n * n << endl;

return 0;
}

Measured memory_bytes: 3516
#include <iostream>
#include <vector>
#include <stdio.h>
#include <string.h>
using namespace std;

int main(){

    string s = "";

    cin >> s;

    int r1=0,r2=0;

    
    for(int i=0;i<s.length();i++){
        if( (s[i]=='0') && (i % 2 != 0) ){
           r1++;
        } 
        if( (s[i]=='1') && (i % 2 == 0) ){
           r1++;
        }  
    }

    for(int i=0;i<s.length();i++){
        if( (s[i]=='1') && (i % 2 != 0) ){
           r2++;
        } 
        if( (s[i]=='0') && (i % 2 == 0) ){
           r2++;
        } 
    } 
    

    if(r1 > r2){
        cout << r2 << endl;
    } else {
        cout << r1 << endl;
    }

}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using ld=long double;
using st=string;
using ch=char;
typedef pair<ll,ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<P> vP;
typedef vector<ch> vc;
typedef vector<vc> vvc;
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) FOR(i,0,n)
#define ROF(i,a,b) for(ll i=a;i>=b;i--)
#define per(i,a) ROF(i,a,0)
const ll MOD=1000000007;
const ll MOD2=998244353;
const ld PI=acos(-1);
const ll INF=1e18;
st abc="abcdefghijklmnopqrstuvwxyz";
st ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
struct edge{ll to,cost;};

int main() {
  ll n,k;
  st s;
  cin >> n >> s >> k;
  k--;
  rep(i,n){
    if(s[i]!=s[k]){
      s[i]='*';
    }
  }
  cout << s << endl;
}


Measured memory_bytes: 256
def main():
    N = int(input())
    A = list(map(int, input().split(" ")))
    negative = 0
    result = 0
    abs_minimum = 10**9
    for a in A:
        abs_minimum = min(abs_minimum, abs(a))
        if a < 0:
            negative += 1
    if negative % 2 == 0:
        for a in A:
            result += abs(a)
    else:
        for a in A:
            if abs(a) == abs_minimum:
                result += min(a, -a)
            else:
                result += abs(a)
    print(result)


if __name__ == '__main__':
    main()

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



int main() {
    ll n, k;
    cin>>n>>k;

    ll ans;

    n = n % k;
    ans = n;

    while( abs(n-k) < ans ){
        ans = abs(n-k); 
        n -= k;
    }

    cout << ans << endl;

    return 0;
}

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

namespace Problem
{
    class Solver{
        public void Solve(){
            int [] a = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            Array.Sort(a);
            Console.WriteLine(a[2]-a[0]);
        }

    }

    class M{
        public static void Main(string[] args)
        {
            new Solver().Solve();
        }
    }
    
};


Measured memory_bytes: 13396
#k = int(input())
#s = input()
#a, b = map(int, input().split())
#s, t = map(str, input().split())
#l = list(map(int, input().split()))
#l = [list(map(int,input().split())) for i in range(n)]
#a = [input() for _ in range(n)]

n = int(input())


def func(n):
    if n%2==0:
        return n//2
    else:
        return 3*n+1

a = [n]
for i in range(2, 1000001):
    n = func(n)
    if n in a:
        print(i)
        exit()
    else:
        a.append(n)








Measured memory_bytes: 9176
A = [tuple(map(int, input().split())) for _ in range(3)]
C = [[False]*3 for _ in range(3)]
n = int(input())

for _ in range(n):
    b = int(input())
    for i in range(3):
        for j in range(3):
            if A[i][j] == b:
                C[i][j] = True

ans = 'No'
for i in range(3):
    if all(C[i]):
        ans = 'Yes'
        break
for j in range(3):
    if C[0][j] + C[1][j] + C[2][j] == 3:
        ans = 'Yes'
        break

if (C[0][0] + C[1][1] + C[2][2] == 3 or
    C[0][2] + C[1][1] + C[2][0] == 3):
    ans = 'Yes'

print(ans)


Measured memory_bytes: 9248
using System;
class Program
{
    static void Main(string[] args)
    {
        int[] p = new int[int.Parse(Console.ReadLine())];
        for (int i = 0; i < p.Length; i++)
        {
            p[i] = int.Parse(Console.ReadLine());
        }
        int maxValue = 0;
        int valueSum = 0;
        for(int i = 0; i < p.Length; i++)
        {
            valueSum += p[i];
            if (p[i] > maxValue)
                maxValue = p[i];
        }
        Console.WriteLine(valueSum - maxValue / 2);
    }
}

Measured memory_bytes: 11092
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <string>
using namespace std;

int main() {
  int x, y, z;
  cin >> x >> y >> z;
  swap(x, y);
  swap(x, z);
  cout << x << " " << y << " " << z << endl;

  return 0;
}


Measured memory_bytes: 256
import java.util.*;

import java.lang.*;

import java.math.*;



public class Main {

	Scanner sc = new Scanner(System.in);

	

	void run(){

		int[] weight = new int[10];

		weight[0] = 1;

		for(int i=0; i<9;i++){

			int[] prev = weight.clone();

			for(int j = 1 ; j < 10;j++){

				weight[j] = prev[j]+prev[j-1];

			}

		}

//		System.out.println(Arrays.toString(weight));

		for(;sc.hasNextLine();){

			String buffer = sc.nextLine();

			int ans = 0;

			for(int i=0; i< 10;i++){

				ans+=weight[i]*(buffer.charAt(i)-'0');

			}

			System.out.println(ans%10);

		}

	}

	public static void main(String[] args){

		Main m = new Main();

		m.run();

		

	}

}

Measured memory_bytes: 12000
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> lpair;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define rREP(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define printa(x,n) for(ll i = 0; i < n; i++){ cout << (x[i]) << " ";} cout<<endl;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int n;
    cin >> n;
    int ary[2][n];
    rep(i,2)rep(j,n) cin >> ary[i][j];

    int rsw[2][n];
    rsw[0][0] = ary[0][0];
    REP(i,1,n)
    {
        rsw[0][i] = rsw[0][i-1] + ary[0][i]; 
    }
    rsw[1][0] = ary[0][0] + ary[1][0];
    REP(i,1,n)
    {
        rsw[1][i] = max(rsw[0][i], rsw[1][i-1]) + ary[1][i];
    }
    cout << rsw[1][n-1] << endl;
}



Measured memory_bytes: 256
n, m = map(int, input().split())
a = sorted([int(i) for i in input().split()])
bc = sorted([tuple(map(int, input().split())) for i in range(m)], key=lambda x: x[1], reverse=True)
i = 0
for b, c in bc:
    while b:
        if i < n and a[i] < c:
            a[i] = c
            b -= 1
        else:
            break
        i += 1
print(sum(a))

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

int main() {
  int A,B,C,K;
  cin>>A>>B>>C>>K;
  int kai=0;
  while(A>=B){
    B=B*2;
    kai++;
  }
  while(B>=C){
    C=C*2;
    kai++;
  }
  if(kai<=K) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}

Measured memory_bytes: 3632
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
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<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

int main() {
    int n, m;
    cin >> n >> m;
    VI a(n), b(n), c(m), d(m);
    REP(i,n) cin >> a[i] >> b[i];
    REP(i,m) cin >> c[i] >> d[i];
    REP(i,n){
        int mi = 1e9, ans;
        REP(j,m){
            int p = abs(a[i]-c[j]) + abs(b[i]-d[j]);
            if (p < mi){
                ans = j+1;
                mi = p;
            }
        }
        cout << ans << endl;
    }

    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    static long inv[];
    static int mod = 1_000_000_007;

    static long pow(long a, int n) {
        long res = 1;
        while (n > 0) {
            if ((n - n / 2 * 2) == 1) {
                res = res * a % mod;
            }
            a = a * a % mod;
            n >>= 1;
        }
        return res;
    }

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);

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

        inv = new long[b + 1];
        inv[1] = 1;
        for (int i = 2; i <= b; i++) {
            inv[i] = inv[mod % i] * (mod - mod / i) % mod;
        }

        long comb[] = new long[b + 1];
        comb[0] = 1;

        for (int i = 1; i <= b; i++) {
            comb[i] = comb[i - 1] * ((n - i + 1) % mod);
            comb[i] %= mod;
            comb[i] *= inv[i];
            comb[i] %= mod;
        }

        long ans = pow(2, n);
        ans -= 1;
        ans %= mod;
        ans -= comb[a];
        if(ans < 0) {
            ans += mod;
        }
        ans %= mod;
        ans -= comb[b];
        if(ans < 0) {
            ans += mod;
        }
        ans %= mod;

        System.out.println(ans);

    }
}


Measured memory_bytes: 25812
import java.io.*;
import java.util.*;

public class Main{
    public static void main(String[] args)throws Exception{
        Scanner sc = new Scanner(System.in);
        Map<String,Boolean> map = new HashMap<>();
        int n=sc.nextInt();
        int count=0;
        for(int i=0;i<n;i++){
            String s=sc.next();
            if(!map.containsKey(s)){
                count++;
                map.put(s,true);
            }
        }
        System.out.println(count);
    }
}

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

const int N = (5e2) + 5;
vector<ll> divs;
int n, k;
pair<ll, ll> rem[N];
ll a[N];

void divisors(ll n) {
  divs.clear();
  for (ll i = 1; i * i <= n; ++i) {
    if (n % i == 0) {
      divs.emplace_back(i);
      if (i != n / i) divs.emplace_back(n / i);
    }
  }
  sort(divs.begin(), divs.end());
}

// claudio van
int main() {
  scanf("%d %d", &n, &k);
  for (int i = 0; i < n; ++i) {
    scanf("%lld", &a[i]);
  }
  ll sum = accumulate(a, a + n, 0);
  divisors(sum);
  for (int i = (int) divs.size() - 1; i >= 0; --i) {
    int d = divs[i];
    ll tot_neg = 0;
    for (int j = 0; j < n; ++j) {
      rem[j] = make_pair(d - (a[j] % d), -(a[j] % d));
      if (rem[j].first == d) {
        rem[j].first = 0;
      }
      tot_neg += -(a[j] % d);
    }
    sort(rem, rem + n);
    ll s1 = 0, s2 = 0;
    for (int j = 0; j < n; ++j) {
      s1 += rem[j].first;
      s2 += rem[j].second;
      if (s1 == abs(tot_neg - s2)) {
        if (s1 <= k) {
          printf("%d\n", d);
          return 0;
        }
        break;
      }
    }
  }
  return 0;
}

Measured memory_bytes: 256
//#include <tourist>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <string>
#include <iomanip>
#include <limits>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <list>
#include <queue>
#include <tuple>
#include <deque>
#include <algorithm>
#include <numeric>
#include <iomanip>
#include <utility>
#include <complex>
#include <functional>
using namespace std;
const int MOD = 1000000007;
typedef long long ll;
typedef pair<ll, ll> p;
const int INF = (1 << 28);
const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1}, Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
//setprecision(15)有効数字15桁
//-std=c++14
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b)
{
    return a * b / gcd(a, b);
}
int h, w;
struct edge{ll to, cost;};
typedef pair<ll,ll> P;
struct graph{
  ll V;
  vector<vector<edge> > G;
  vector<ll> d;
//vector<vector<int> > prev((int)G.size()); // prev[v] := v から復元できる辺たち
  graph(ll n){
    init(n);
  }

  void init(ll n){
    V = n;
    G.resize(V);
    d.resize(V);
    REP(i,V){
      d[i] = INF;
    }
  }

  void add_edge(ll s, ll t, ll cost){
    edge e;
    e.to = t, e.cost = cost;
    G[s].push_back(e);
  }

  void dijkstra(ll s){
    REP(i,V){
      d[i] = INF;
    }
    d[s] = 0;
    priority_queue<P,vector<P>, greater<P> > que;
    que.push(P(0,s));
    while(!que.empty()){
      P p = que.top(); que.pop();
      ll v = p.second;
      if(d[v]<p.first) continue;
      for(auto e : G[v]){
        if(d[e.to]>d[v]+e.cost){
          d[e.to] = d[v]+e.cost;
          que.push(P(d[e.to],e.to));
          // 復元のための
          //prev[e.first].clear();
          //prev[e.first].push_back(v);
        }
      }
    }
  }
};
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> h>>w;
    vector<string> s;
    graph g(h*w);
    for (int i = 0; i < h; i++)
    {
        string temp;
        cin >> temp;
        s.push_back(temp);
    }
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            if(s[i][j]=='#')continue;
            for(int k=0;k<4;k++){
                if(i+dx[k]<0||j+dy[k]<0||i+dx[k]>=h||j+dy[k]>=w)continue;
                if(s[i+dx[k]][j+dy[k]]=='.'){
                g.add_edge(i*w+j,(i+dx[k])*w+j+dy[k],1);
                g.add_edge((i+dx[k])*w+j+dy[k],i*w+j,1);
                }
            }
        }
    }
    g.dijkstra(0);
    int count=0;
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            if(s[i][j]=='#'){
                count++;
            }
        }
    }
    if(g.d[h*w-1]==INF){
        return cout<<-1<<"\n",0;
    }
    cout << h*w-g.d[h*w-1]-1-count << "\n";
}



Measured memory_bytes: 640
#include <stdio.h>
int main()
{
	int a, b, c;
	
	while(scanf("%d %d %d", &a, &b, &c) != EOF)
	{
		if(a == -1 && b == -1 && c == -1)
		{
			break;
		}
		if((a == -1 || b == -1) && c == -1)
		{
			printf("F\n");
		}
		else 
		{
			int sum = 0, k = 0;
			if(a >= 0)
			{
				sum += a;
			}
			if(b >= 0)
			{
				sum += b;
			}
			if(sum >= 80)
			{
				printf("A\n");
			}
			else if(sum >= 65 && sum < 80)
			{
				printf("B\n");
			}
			else if((sum >= 50 && sum < 65) || c >= 50)
			{
				printf("C\n");
			}
			else if(sum >= 30 && sum < 50)
			{
				printf("D\n");
			}
			else 
			{
				printf("F\n");
			}
		}
	}
	return 0;
}


Measured memory_bytes: 2596
import sys
import math
from collections import deque

sys.setrecursionlimit(1000000)
MOD = 10 ** 9 + 7
input = lambda: sys.stdin.readline().strip()
NI = lambda: int(input())
NMI = lambda: map(int, input().split())
NLI = lambda: list(NMI())
SI = lambda: input()


def make_grid(h, w, num): return [[int(num)] * w for _ in range(h)]


def main():
    N, X = NMI()
    A = [1]
    P = [1]
    for i in range(N):
        A.append(A[-1]*2+3)
        P.append(P[-1]*2+1)

    def rec(n, x):
        if n == 0:
            return 1

        if x == 1:
            return 0
        elif x <= A[n-1]+1:
            return rec(n-1, x-1)
        elif x == A[n-1]+2:
            return P[n-1]+1
        elif x <= A[n]-1:
            return P[n-1]+1+rec(n-1, x-A[n-1]-2)
        else:
            return P[n]

    print(rec(N, X))


if __name__ == "__main__":
    main()

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

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl





using ll = long long;

const ll mod = 1e9+7;
const int maxn = 1e6 + 5;





int main() {
    ios_base::sync_with_stdio(false); cin.tie(0);  cout.tie(0);
    ll k;
    cin>>k;
    ll cur=0;
    for (int i=1; i<maxn; i++) {
	cur=cur*10;
	cur+=7;
	cur %= k;
	if (cur==0) out(i);
    }

    out(-1);    
    return 0;
}


Measured memory_bytes: 3616
#![allow(unused_imports, unused_macros, dead_code)]

macro_rules! min {
    ($x:expr) => ($x);
    ($x:expr, $($ys:expr),*) => {{
        let t = min!($($ys),*);
        if $x < t { $x } else { t }
    }}
}
macro_rules! max {
    ($x:expr) => ($x);
    ($x:expr, $($ys:expr),*) => {{
        let t = max!($($ys),*);
        if $x > t { $x } else { t }
    }}
}

macro_rules! ewriteln {
    ($($args:expr),*) => { let _ = writeln!(&mut std::io::stderr(), $($args),*); };
}
macro_rules! trace {
    ($x:expr) => { ewriteln!(">>> {} = {:?}", stringify!($x), $x) };
    ($($xs:expr),*) => { trace!(($($xs),*)) }
}
macro_rules! put {
    ($x:expr) => { println!("{}", $x) };
    ($x:expr, $($xs:expr),*) => { print!("{} ", $x); put!($($xs),*) }
}

const M: i64 = 1_000_000_007;

fn main() {
    let mut sc = Scanner::new();
    let m: usize = sc.cin();
    const N: usize = 100002;
    let mut xy = vec![vec![]; N];
    let mut yx = vec![vec![]; N];
    for _ in 0..m {
        let x: usize = sc.cin();
        let y: usize = sc.cin();
        xy[x].push(y);
        yx[y].push(x);
    }
    let mut used = vec![false; N];
    let mut used_y = vec![false; N];
    let mut ans: usize = 0;
    for i in 0..N {
        if used[i] { continue }
        if xy[i].len() == 0 { continue }
        let mut x_count = 0;
        let mut y_count = 0;
        let mut e_count = 0;
        let mut stack = vec![(true, i)];
        while let Some((b, u)) = stack.pop() {
            // trace!(b, u);
            if b {
                if used[u] { continue }
                used[u] = true;
                x_count += 1;
                for &v in xy[u].iter() {
                    e_count += 1;
                    if used_y[v] { continue }
                    stack.push((false, v));
                }
            } else {
                if used_y[u] { continue }
                used_y[u] = true;
                y_count += 1;
                for &v in yx[u].iter() {
                    if used[v] { continue }
                    stack.push((true, v));
                }
            }
        }
        // trace!(x_count, y_count, e_count);
        ans += x_count * y_count - e_count;
    }
    put!(ans);
}

use std::io::{self, Write};
use std::str::FromStr;
use std::collections::VecDeque;

struct Scanner { stdin: io::Stdin, buffer: VecDeque<String>, }
impl Scanner {
    fn new() -> Self { Scanner { stdin: io::stdin(), buffer: VecDeque::new() } }
    fn cin<T: FromStr>(&mut self) -> T {
        while self.buffer.len() == 0 {
            let mut line = String::new();
            let _ = self.stdin.read_line(&mut line);
            for w in line.split_whitespace() {
                self.buffer.push_back(String::from(w));
            }
        }
        self.buffer.pop_front().unwrap().parse::<T>().ok().unwrap()
    }
}


Measured memory_bytes: 16636
#include <stdio.h>

int main() {
	int x, n,count=0;
	while(1){
                count = 0;
		scanf("%d %d", &n, &x);
		if (x == 0 && n == 0) {
			break;
		}
		for (int r = 1; r <= n; r++) {
			for (int p = r+1; p <= n; p++) {
				for (int q = p+1; q <= n; q++) {
					if (r + p + q == x) {
						count += 1;
					}
				}
			}
		}
		printf("%d\n", count);
	}

}


Measured memory_bytes: 2688