akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <queue>
#include <math.h>
#include <assert.h>
#include <set>
#include <map>
#include <bitset>
#include <ctime>
#include <time.h>
#include <algorithm>
#include <cstdio>
#include <fstream>
#include <stack>
#include <ctype.h>
#include <numeric>
#include <sstream>
#include <unistd.h>
#include <unordered_map>
#include <unordered_set>
#include <limits>
#include <random>
#include <chrono>
#include <iomanip>
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
using ll = long long;
#define endl '\n'
#define debug(name) DEBUG(#name, (name))
template<typename T>
void DEBUG(string label, T value) {
    cerr << "[" << label << " = " << value << "]\n";
}

void solve(){
    int n;
    cin >> n;
    vector<int> arr(n);
    for(int i = 0; i < n; ++i){
        cin >> arr[i];
    }
    sort(arr.begin(),arr.end());
    arr.resize(unique(arr.begin(), arr.end()) - arr.begin());
    cout << ((int)arr.size() == n ? "YES" : "NO") << endl;
}

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

    int t = 1;
    while(t--){
        solve();
    }
}


Measured memory_bytes: 3900
import sys

def bubble_sort(C, N):
	for i in range(N):
		for j in range(N - 1, i, -1):
			if C[j][1] < C[j - 1][1]:
				C[j], C[j - 1] = C[j - 1], C[j]
				
	return C

def	selection_sort(C, N):
	for i in range(N):
		minj = i
		for j in range(i, N):
			if C[j][1] < C[minj][1]:
				minj = j

		C[i], C[minj] = C[minj], C[i]
	
	return C

#fin = open("test.txt", "r")
fin = sys.stdin

N = int(fin.readline())
A = fin.readline().split()
B = A[:]

A = bubble_sort(A, N)
B = selection_sort(B, N)

print(" ".join(A))
print("Stable")

print(" ".join(B))
if A == B:
	print("Stable")
else:
	print("Not stable")

Measured memory_bytes: 7716
#include <bits/stdc++.h>
#define pb push_back
#define fst first
#define snd second
#define fore(i,a,b) for(int i=a,ggdem=b;i<ggdem;++i)
#define SZ(x) ((int)x.size())
#define ALL(x) x.begin(),x.end()
#define mset(a,v) memset((a),(v),sizeof(a))
#define FIN ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
using namespace std;
typedef long long ll;

const ll MOD=1000000007;
string s;

ll dp[3030][3030];
ll sump[3030][3030];

ll f(ll x, ll y){
	ll &r=dp[x][y];
	if(r>=0)return r;
	if(x==1&&y==0){
		r=1; return r;
	}
	if(s[x-2]=='<'){
		r=sump[x-1][y]; return r;
	}
	r=(sump[x-1][x-1]-sump[x-1][y]+MOD)%MOD; return r;
}

int main(){FIN;
	ll n; cin>>n;
	cin>>s;
	mset(dp,-1);
	fore(i,1,n+1){
		fore(j,0,i+1){
			sump[i][j+1]=sump[i][j]+f(i,j);
			if(sump[i][j+1]>MOD)sump[i][j+1]-=MOD;
		}
	}
	ll res=0;
	fore(i,0,n){
		res+=f(n,i);
		if(res>MOD)res-=MOD;
	}
	/*fore(i,1,n+1){
		fore(j,0,i){
			cout<<f(i,j)<<" ";
		}
		cout<<"\n";
	}
	fore(i,1,n+1){
		fore(j,0,i+2){
			cout<<sump[i][j]<<" ";
		}
		cout<<"\n";
	}*/
	cout<<res;
	return 0;
}

Measured memory_bytes: 142080
import fractions
N, K = map(int, input().split())
A = list(map(int, input().split()))
G = A[0]
for i in range(1,N):
  G = fractions.gcd(G,A[i])
if (K < max(A) and K % G == 0) or K == max(A):
  print('POSSIBLE')
else:
  print('IMPOSSIBLE')


Measured memory_bytes: 16240
#include <bits/stdc++.h>
#define repp(i,l,r)for(long long i=(l);i<(r);i++)
#define rep(i,n) for (long long i = 0; i < (n); ++i)
#define per(i,n) for (long long i = (n); i >= 0; --i)
#define all(v) v.begin(), v.end()
const int INF = 1<<30;
const long long LINF = 1LL << 60;
const long long int MOD = 1000000007;
using namespace std;
using ll = long long;
using P = pair<int,int>;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
//ミョ(-ω- ?)
int main() {
    cin.tie(nullptr) ;
    ios::sync_with_stdio(false) ;
    
    int a;
    cin >> a;
    if (a) cout << "0\n";
    else cout << "1\n";

    return 0;
}

Measured memory_bytes: 3648
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]
dy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1]


def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


def ceil(a, b):
    return (a + b - 1) // b


def main():
    N, K = map(int, input().split())

    m = defaultdict(int)
    for i in range(1, N + 1):
        m[i % K] += 1

    ans = 0
    for a in range(1, N + 1):
        if (a + a) % K == 0:
            ans += m[a % K] ** 2

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 15844
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

//INSERT ABOVE HERE
signed main(){
  Int n;
  cin>>n;
  cout<<(n/2)-(n%2==0)<<endl;
  return 0;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline

n = int(input())
ll = []
for i in range(n):
  x, l = map(int, input().split())
  ll.append([x-l, x+l])
ll.sort(key=lambda x:x[1])

ans = 0
tmp = -10**9

for s, t in ll:
  if s >= tmp:
    ans += 1
    tmp = t

print(ans)

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

int main() {
  int H, W;
  cin >> H >> W;
  char tmp;
  int S[H][W];
  for(int i=0;i<H;i++) {
    for(int j=0;j<W;j++) {
      cin >> tmp;
      if(tmp=='#') S[i][j]=1;
      else S[i][j]=0;
    }
  }

  int NG = 0;
  for(int i=0;i<H;i++) {
    for(int j=0;j<W;j++) {
      if(S[i][j]==1) {
        if((j+1) < W) { // 右
          S[i][j] += S[i][j+1];
        }
        if((i+1) < H) { // 下
          S[i][j] += S[i+1][j];
        }
        if((j-1) >= 0) { // 左
          S[i][j] += S[i][j-1];
        }
        if((i-1) >= 0) { // 上
          S[i][j] += S[i-1][j];
        }
      }
    }
  }
  for(int i=0;i<H;i++) {
    for(int j=0;j<W;j++) {
      if(S[i][j]==1) { 
        NG=1;
        break;
      }
    }
  }
  if(NG==0) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define Rep(i,n) for(int i=0;i<(int)(n);i++)
#define For(i,n1,n2) for(int i=(int)(n1);i<(int)(n2);i++)
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define RREP(i,n) for(ll i=((ll)(n)-1);i>=0;i--)
#define FOR(i,n1,n2) for(ll i=(ll)(n1);i<(ll)(n2);i++)
#define RFOR(i,n1,n2) for(ll i=((ll)(n1)-1);i>=(ll)(n2);i--)
#define all(a)  (a).begin(),(a).end()
#define SORT(a) sort((a).begin(),(a).end())
#define oorret 0
#define oor(x) [&](){try{x;} catch(const out_of_range& oor){return oorret;} return x;}()
#define IOS cin.tie(0),ios::sync_with_stdio(false)
typedef long long ll;
typedef unsigned long long ull;
typedef std::pair<ll, ll> P;
template<typename T1, typename T2> inline bool chmin(T1& a, T2 b) { if (a > b) { a = b; return 1; }return 0; }
template<typename T1, typename T2> inline bool chmax(T1& a, T2 b) { if (a < b) { a = b; return 1; }return 0; }
template<class Type>struct is_vector : std::false_type {};
template<class ValueType, class Alloc>struct is_vector<std::vector<ValueType, Alloc>> : std::true_type {};
template <typename T> inline std::ostream& operator << (std::ostream& out, const std::vector<T>& v) {
    if (v.empty())return out;
    constexpr bool is_vector_v = is_vector<T>::value;
    if (is_vector_v)for (auto itr = v.begin(); itr != v.end();)out << (*itr), out << ((++itr != v.end()) ? "\n" : "");
    else for (auto itr = v.begin(); itr != v.end();)out << (*itr), out << ((++itr != v.end()) ? " " : "");
    return out;
}
inline void put() {}
template<class T> inline void put(const T& first) { std::cout << first << "\n"; }
template<class T, class... N> inline void put(const T& first, const N& ... rest) { std::cout << first << " "; put(rest...); }
inline void putn() {}
template<class T, class... N> inline void putn(const T& first, const N& ... rest) { std::cout << first << "\n"; putn(rest...); }

int main(){
    IOS;
    string s;
    cin >> s;
    int n=s.size();
    if(n==26){
        RREP(i,n-1){
            int a = s[i]-'a';
            int b = s[i+1] - 'a';
            if(a<b){
                string t = s.substr(0,i);
                for(int j=25;j>=i;--j){
                    if(s[i]<s[j]){
                        put(t+s[j]);
                        return 0;
                    }
                }
            }
        }
        put(-1);
    }else{
        vector<int> c(26,0);
        REP(i,n){
            c[s[i]-'a']++;
        }
        REP(i,26){
            if(c[i]==0){
                char c = (char)i+'a';
                put(s+c);
                return 0;
            }
        }
        
    }
    return 0;
}


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

#define f first
#define s second
#define pb push_back
#define all(x) x.begin(), x.end()

using LL   =  long long;
using pii  =  pair <int, int>;
using vii  =  vector <pii>;

const int INF = INT_MAX;
const int MOD = 1e9 + 7;
const int N = 1e5 + 5;

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

    int n;
    cin>>n;

    priority_queue <int> Q;
    for(int i = 0; i < n; i++) {
        int x;
        cin>>x;
        Q.push(x);
    }

    int A = 0, B = 0, i = 0;
    while(!Q.empty()) {
        int x = Q.top();
        Q.pop();

        if(i % 2 == 0) {
            A += x;
        }
        else {
            B += x;
        }
        i++;
    }

    cout<<abs(A-B)<<"\n";
    return 0;
}

Measured memory_bytes: 256
num = list("1234567890")
a,b = map(int, input().split())
s = input()
if s[a] != "-":
    print("No")
    quit()
s_a,s_b = list(s[:a]),list(s[a+1:])
for i in s_a:
    if i not in num:
        print("No")
        quit()
for i in s_b:
    if i not in num:
        print("No")
        quit()
print("Yes")

Measured memory_bytes: 38384
#include <iostream>
#include <fstream>
#include <cstdio>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <stack>
#include <queue>
#include <algorithm>
#include <string.h>
#include <string>
#include <math.h>
#include <iomanip>
using namespace std;

#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define pb push_back

typedef pair<int, int> pii;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;

const int mod = 1e9 + 7;
const int mod2 = 998244353;

void fact_init(int n);
ll exp(ll taban, ll us, ll md);
ll ebob(ll a, ll b);
ll ekok(ll a, ll b);
ll komb(ll a, ll b);

vector<ll> fact;
vector<ll> inv_fact;
void fact_init(int n){
    fact.resize(n+5);
    inv_fact.resize(n+5);
    fact[0] = inv_fact[0] = 1;
    for(int i = 1; i <= n; i++){
        fact[i] = (fact[i-1] * i) % mod;
        inv_fact[i] = exp(fact[i], mod-2, mod);
    }
}
ll exp(ll taban, ll us, ll md) {
    ll carpan = taban % md;
    if(carpan == 0) return 0;
    ll temp = us;
    ll res = 1;
    while(temp){
        if(temp % 2) res = (res*carpan) % md;
        temp /= 2;
        carpan = (carpan*carpan) % md;
    }
    return res;
}
 
ll ebob(ll a, ll b){
    if(!a)return b;
    return ebob(b%a, a);
}

ll ekok(ll a, ll b){
    return (a*b)/ebob(a, b);
}

ll komb(ll a, ll b){
    if(a < b) return 0;
    return fact[a] * (inv_fact[a-b] * inv_fact[b] % mod) % mod;
}

const int N = 2e5 + 5;

int main(){
    ios::sync_with_stdio(false); cin.tie(NULL);
	int n; cin>>n;
	int w = 0, r = 0;
	vector<int> vec(n);
	for(int i = 0; i < n; i++){
		char c; cin>>c;
		vec[i] = c == 'R';
		vec[i] ? r++ : c++;
	}
	int cnt = 0;
	for(int i = 0; i < r; i++){
		if(!vec[i]) cnt++;
	}
	int cnt2 = 0;
	for(int i = r; i < n; i++){
		if(vec[i]) cnt2++;
	}
	cout<<min(cnt, cnt2);
}

Measured memory_bytes: 3984
#include <bits/stdc++.h>
#include <vector>
#include <iostream>
#include<algorithm>
#include<string>
#include <map>
#include <queue>
#include <stack>
#include<set>
#include<tuple>

#define DIV 998244353
using namespace std;
using ll = long long;
using ldb = long double;

int main() {
	ll N, K; cin >> N >> K;
	vector<pair<ll, ll>> po(N);
	for (int i = 0; i < N; i++) {
		cin >> po[i].first >> po[i].second;
	}

	sort(po.begin(), po.end());
	vector<vector<ll>> Y(N);
	ll ans = 4e18;
	for (int i = 0; i < N; i++) {
		for (int j = i; j < N; j++) {
			Y[i].push_back(po[j].second);
			//printf("L[%d][%d]=%lld R[%d][%d]=%lld ", i, j, L[i][j], i, j, R[i][j]);
			if (j >= i + K - 1) {
				sort(Y[i].begin(), Y[i].end());
				for (int k = 0; k <= j - i - K + 1; k++) {
					ll temp = (po[j].first - po[i].first) * (Y[i][k + K - 1] - Y[i][k]);
					ans = min(ans, temp);
					//printf("i=%d j=%d k=%d temp=%lld\n", i, j, k, temp);
				}
			}
		}
		//cout << endl;
	}

	cout << ans << endl;
}


Measured memory_bytes: 3608
def cmb(n, r, p):
    if (r < 0) or (n < r):
        return 0
    r = min(r, n - r)
    return fact[n] * factinv[r] * factinv[n-r] % p
p = 10 ** 9 + 7
N = 10 ** 6 
fact = [1, 1]
factinv = [1, 1]
inv = [0, 1]
for i in range(2, N + 1):
    fact.append((fact[-1] * i) % p)
    inv.append((-inv[p % i] * (p // i)) % p)
    factinv.append((factinv[-1] * inv[-1]) % p)  

n,k = map(int,input().split())
a = [int(i) for i in input().split()]
a = sorted(a)
ans = 0
for i in range(n-k+1):
    ans += (a[-1-i] - a[i]) * cmb(n-1-i, k-1, p)
    ans %= p
print(ans)

Measured memory_bytes: 133008
#include <cstdio>
#include <string>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <iterator>
#include <cassert>
#include <numeric>
#pragma warning(disable:4996) 
 
typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF  9223300000000000000
#define LINF2 1223300000000000000
#define INF 2140000000
const long long MOD = 1000000007;
//const long long MOD = 998244353;

using namespace std;


void solve()
{
    int n;
    scanf("%d", &n);
    vector < vector<pair<int, int> > > v(n);
    int i,j;
    for (i = 0; i < n; i++) {
        int num;
        scanf("%d", &num);
        for (j = 0; j < num; j++) {
            int x, y;
            scanf("%d%d", &x, &y); x--;
            v[i].push_back(make_pair(x, y));
        }
    }
    int ans = 0;
    int k;
    for (k = 0; k < (1 << n); k++) {
        int bad = 0;
        int cnt = 0;
        for (i = 0; i < n; i++) {
            if (k & (1 << i)) {
                cnt++;
                int siz = (int)v[i].size();
                for (j = 0; j < siz; j++) {
                    int x = v[i][j].first;
                    int y = v[i][j].second;
                    if (k & (1 << x)) {
                        if (y == 0) bad = 1;
                    }
                    else {
                        if (y) bad = 1;
                    }
                }
            }
        }
        if(bad==0) ans = MAX(ans, cnt);
    }
    printf("%d\n", ans);

    return;
}

int main(int argc, char* argv[])
{
#if 1
    solve();
#else
    int T;
    scanf("%d", &T);
    int t;
    for(t=0; t<T; t++) {
        printf("Case #%d: ", t+1);
        solve();
    }
#endif
    return 0;
}



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

int main()
{
    string a, b, c;
    cin >> a >> b >> c;
    int sizea = a.size();
    int sizeb = b.size();
    int sizec = c.size();
    
    if (a.at(sizea-1) == b.at(0) && b.at(sizeb-1) == c.at(0))
    {
        cout << "YES" << endl;
    }
    else
    {
        cout << "NO" << endl;
    }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define sf1(n) scanf("%d",&n)
#define sf2(n,q) scanf("%d %d",&n,&q)
#define f first
#define ss second
#define pb push_back
#define lli long long
#define mem(ar,false) memset(ar,false,sizeof(ar))
#define mpr make_pair
#define endl "\n"
#define mod 1000000007
using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    lli a ,b,c,k;
    cin >> a >> b >> c >> k;
    lli sum=0;
    if(a<k)
    {
        sum+=a;
        k-=a;
        k-=b;
        k = max(k,0LL);
        sum-=k;
    }
    else
    {
        sum+=k;
    }
    cout << sum << endl;
    return 0;
}


Measured memory_bytes: 3656
eval'H,W='+gets.split*?,
s=$<.read.tr".#\n","10"
c=s.count ?1
W+=t=1
c,t=c-1,(t<<1|t>>1|t<<W|t>>W|r=t)&s.to_i(2)while t!=r&&t<1<<H*W-1
p r<t ?c:-1

Measured memory_bytes: 2044
#include <iostream>
using namespace std;
int main(void){
    string input;
    string r = "yuiophjklnm";
    while (cin >> input && input != "#") {
        int pre = 0, now = 0;
        int count = 0;
        int len = input.length();
        for (int i = 0; i < len; ++i) {
            char c = input[i];
            now = -1;
            for (int j = 0; j < 11; ++j) {
                if (c == r[j]) {
                    now = 1;
                    break;
                }
            }
            count += pre != 0 && pre != now;
            pre = now;
        }
        cout << count << endl;
    }
}

Measured memory_bytes: 1188
#include <math.h>
#include <assert.h>

#include <vector>
#include <numeric>
#include <iostream>
#include <algorithm>
#include <functional>

template <typename A, typename B>
std::ostream& operator<<(std::ostream& os, std::pair<A, B>& v) {
    return os << "(" << v.first << " " << v.second << ")";
}

template <typename T>
std::ostream& operator<<(std::ostream& os, std::vector<T>& v) {
    os << "[ "; for (auto &i: v) os << i << " "; return os << "]";
}

template <typename T>
void eout(const char *s, T H) {
    std::cerr << s << "=" << H << "\n";
}

template <typename T1, typename... T2>
void eout(const char *s, T1 H, T2... T) {
    while (*s != ',') std::cerr << *s++;
    std::cerr << "=" << H << " | "; eout(++s, T...);
}

#define nl                std::cout << "\n"
#define in(x)             std::cin  >> (x)
#define out(x)            std::cout << (x) << " "
#define err(args...)      std::cerr << "DBG:"; eout(#args, args)

#define inn(x)            int x; in(x)
#define rep(i, n)         for (int i =  0 ; i < (n); ++i)
#define per(i, n)         for (int i = (n) - 1; i > -1; --i)
#define repr(i, l, r)     for (int i = (l); i < (r); ++i)

#define sz(v)             ((int) v.size())
#define all(v)            (v).begin(), (v).end()

#define no                std::cout << "NO\n"
#define yes               std::cout << "YES\n"

#define INF    	          2147483647
#define LNF               9223372036854775807LL

using ll  = long long int;
using vi  = std::vector<int>;
using vb  = std::vector<bool>;
using ii  = std::pair<int, int>;
using iii = std::pair< ii, int>;
using vii = std::vector<ii>;

const int N = 1010101;
const int MD = 1e9 + 7;

int solve();
int main() {
    std::ios_base::sync_with_stdio(0); std::cin.tie(0); std::cout.tie(0);

    //inn(t); repr(tc, 1, t + 1)
    (void) solve();

    return 0;
}

int solve() {
    inn(n); inn(a); inn(b);
    out(std::min(n*a , b));
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

#define NUM 10000

void input(int *p1, int *p2, int t);
void output(int *p1, int *p2);
void comp(int *p1, int *p2, char *p_c, int t);
void score(int *p1, int *p2, int t);

int a[NUM] = {0}, b[NUM] = {0}, score_a[NUM] = {0}, score_b[NUM] = {0};
char tmp[NUM];
int cnt = 0;

int main()
{
	int n;
	while(1) {
		scanf("%d", &n);
		if(n == 0) {
			break;
		}
		input(a, b, n);
		comp(a, b, tmp, n);
		score(score_a, score_b, n);
		cnt++;
	}
	output(score_a, score_b);
	return 0;
}

void input(int *p1, int *p2, int t)
{
	int i = 0;
	while(1) {
		if (i == t) {
			break;
		}
		scanf("%d %d", &*(p1 + i), &*(p2 + i));
		i++;
	}
}

void output(int *p1, int *p2)
{
	int i = 0;
	for (i = 0; i < cnt; i++) {
		printf("%d %d\n", *(p1 + i), *(p2 + i));
	}
}

void comp(int *p1, int *p2, char *p_c, int t)
{
	int i = 0;
	while(1) {
		if (i == t) {
			break;
		}
		if (*(p1 + i) > *(p2 + i)) {
			*(p_c + i) = 'a';
		}
		if (*(p1 + i) < *(p2 + i)) {
			*(p_c + i) = 'b';
			}
		if (*(p1 + i) == *(p2 + i)) {
			*(p_c + i) = 'e';
		}
		i++;
	}
}

void score(int *p1, int*p2, int t)
{
	int sum_a = 0, sum_b  = 0, i = 0;
	
	while(1) {
		if (i == t) {
			break;
		}
		if(tmp[i] == 'a') {
			sum_a = sum_a + a[i] + b[i];
		}
		if(tmp[i] == 'b') {
			sum_b = sum_b + a[i] + b[i];
		}
		if(tmp[i] == 'e') {
			sum_a = sum_a + a[i];
			sum_b = sum_b + b[i];
		}
		i++;
	}
	
	*(p1+cnt) = sum_a;
	*(p2+cnt) = sum_b;
	
	sum_a = 0;
	sum_b = 0;
}

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

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

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

int main(){

    int n;

    cin >> n;

    vector<ll> t(n);

    ll c;
    cin >> c;

    for(int i=1;i<n;i++){
        cin >> t[i];
        c=lcm(c,t[i]);
    }

    cout << c << endl;

    return 0;
}

Measured memory_bytes: 256
#include <cstdio>

#define FOR(i, a, b) for(i=a; i<b; ++i)

#define MAXN

int soler(int &x1, int &y1, int &x2, int &y2) {
	printf("%d %d %d %d\n", x2-y2+y1, y2+x2-x1, x1-y2+y1, x2-x1+y1);
}

int main() {
	int x1,y1,x2,y2;

	scanf("%d %d %d %d", &x1, &y1, &x2, &y2);

	soler(x1, y1, x2, y2);

	return 0;
}



Measured memory_bytes: 128
/* ex3_3 KitamoriFumiya */
#include <stdio.h>

int main(void){
	
	int number, notation, digit; // number(整数), notation(表記法), digit(桁数)をint型の変数として宣言
	scanf("%d %d", &number, &notation); // number, notationを入力
	
	digit = 0; // 桁数を初めは0としておく
	// 整数numberをnotation進数で表すと何桁になるかをnumberが何回notationで割れるかで計算する
	while (number > 0){
		number = number / notation;
		digit++; // numberをnotationで1回割ったら桁数digitを1増やす
	}
	
	printf("%d", digit); // 桁数digitを出力
	
	return 0;
}

Measured memory_bytes: 128
#include <stdio.h>

/* prototype declaration */
int getCombi(int n);

/* main */
int main(int argc, const char *argv[])
{
	int n;

	while(scanf("%d", &n) != EOF)
		printf("%d\n", getCombi(n));
	return 0;
}

int getCombi(int n)
{
	int a, b, c, d, cnt = 0;
	
	for(a=0; a<10; a++){
		for(b=0; b<10; b++){
			for(c=0; c<10; c++){
				for(d=0; d<10; d++){
					if(a+b+c+d == n) cnt++;
				}
			}
		}
	}
	
	return cnt;
}

Measured memory_bytes: 0
#include <iostream>
#include <sstream>
#include <vector>
#include <cmath>
#include <ctime>
#include <cassert>
#include <iomanip>
#include <vector>
#include <cstdio>
#include <float.h>
#include <queue>
#include <set>
#include <map>
#include <fstream>
#include <cstdlib>
#include <string>
#include <cstring>
#include <algorithm>
#include <numeric>
#include <stack>
#include <functional>
 
using namespace std;
 
#define endl '\n'
#define MOD 1000000007
#define INF 1ll<<30
#define MAX 100010
#define eps 1e-11
#define bit_max 1ll<<32
#define _USE_MATH_DEFINES

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
  //  freopen("input.txt","r",stdin);
  // freopen("output.txt","w",stdout);
    double a,b,t;
    cin>>a>>b>>t;
    t+=0.5;
    cout<<(int)(t/a)*b;
    

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cctype>
#include <queue>
#include <map>
#include <set> 
#include <bitset>
#include <cmath>
using namespace std;
typedef long long ll;
#define REP(i,n) for(int i=0;i<n;i++)

int main () {
    
    int n; cin >> n;
    int mx = -1;
    int mn = 1000000000;

    for (int i = 0; i < n; i++) {
        int a; cin >> a;
        mx = max(mx, a);
        mn = min(mn, a);
    }

    cout << mx - mn << endl;

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
using namespace std;
int main() {
  int a,b;
  cin >> a >> b;
  int ans = b-a;
  int next = (ans*(ans+1))/2;
  int ans1 = next-b;
  cout << ans1 << endl;
}

Measured memory_bytes: 384
#include <bits/stdc++.h> //C++の標準ライブラリを一行で一括でインクルードする
#include <math.h> //数学関数と数学定数を利用する
#define rep(i,n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
template<class T> void chmax(T &a,T b) { if (a<b) a=b;}
template<class T> void chmin(T &a,T b) { if (a>b) a=b;}

vector<int> prime(int n){
  vector<int> ret;
  for(int i = 1; i <= n; i++){
    int cnt = 0;
    for(int j = 1; j <= i;j++){
      if(i%j==0) cnt++;
    }
    if(cnt == 2){
      ret.push_back(i);
    }
  }
  
  return ret;
}

int main(){
  int n;
  cin >> n;
  map<int,int> mp;
  
  vector<int> a = prime(n);
  
  for(int i = 1;i <= n; i++){
    for(auto b:a){
      int tmp = i;
      while(true){
        if(tmp%b == 0){
          tmp /= b;
          mp[b]++;
        }else break;
      }
    }
  }
  
  ll ans = 1LL;
  for(auto m:mp){
    //printf("%d -> %d\n",m.first,m.second);
    ans *= m.second + 1;
    ans %= 1000000007;
  }
  
  cout << ans;
  
  
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define N 64000
#define LL long long
#define Mod 1000000007
#define db(x) cout<<#x<<"="<<x<<endl;
using namespace std;
int n,k,t,cnt[N];
int l[N],r[N],tot;
LL dp[105][N];
int main() {
	scanf("%d%d",&n,&k);
	int x=1;
	while(x<=n) {
		int a=n/x;
		int b=n/a;
		l[++tot]=x,r[tot]=b;
		x=b+1;
	}
	for(int i=1; i<=tot; i++)dp[1][i]=cnt[i]=r[i]-l[i]+1,dp[1][i]+=dp[1][i-1];
	for(int i=2; i<=k; i++)
		for(int j=1; j<=tot; j++) {
			dp[i][j]+=dp[i-1][tot-j+1]*cnt[j]%Mod;
			dp[i][j]+=dp[i][j-1];
			dp[i][j]%=Mod;
		}
	printf("%lld\n",dp[k][tot]);
	return 0;
}


Measured memory_bytes: 52992
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        @SuppressWarnings("resource")
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        for (int i = 0 ; i < s.length() ; i++) {
            System.out.print("x");
        }
        System.out.print("\n");
    }

}

Measured memory_bytes: 23124
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
    int ans = 0;
    for(int i = a; i <= b; i++) {
      String s = String.valueOf(i);
      int p = 0;
      for(int j = 0; j < s.length(); j++) {
        if(s.charAt(j) != s.charAt(s.length() - 1 - j)) p++;
      }
      if(p == 0) ans++;
    }
    System.out.println(ans);
  }
}

Measured memory_bytes: 28624
s = input()
n1 = int(s[:2])
n2 = int(s[2:])


def is_month(n):
    return n > 0 and n <= 12


if is_month(n1) and is_month(n2):
    print("AMBIGUOUS")
elif is_month(n1):
    print("MMYY")
elif is_month(n2):
    print("YYMM")
else:
    print("NA")


Measured memory_bytes: 2940
using System;
using System.Collections.Generic;
using System.Linq;
using System.Collections;
using System.Linq.Expressions;

static class Program
{
    static void Main()
    {
        new Magatro().Solve();
    }
}

struct P
{
    public string Name;
    public int Time;
    public P(string s, int time)
    {
        Name = s;
        Time = time;
    }
}

class Magatro
{
    private int N;
    private void Scan()
    {
        N = int.Parse(Console.ReadLine());
    }

    public void Solve()
    {
        Scan();
        LinkedList<int> List = new LinkedList<int>();
        for (int i = 0; i < N; i++)
        {
            var command = Console.ReadLine().Split(' ');
            switch (command[0])
            {
                case "insert":
                    List.AddFirst(int.Parse(command[1]));
                    break;
                case "delete":
                    List.Remove(int.Parse(command[1]));
                    break;
                case "deleteFirst":
                    List.RemoveFirst();
                    break;
                case "deleteLast":
                    List.RemoveLast();
                    break;
                default:
                    throw new Exception();
            }
        }
        Console.WriteLine(string.Join(" ", List.Select(i => i.ToString()).ToArray()));
    }

}

Measured memory_bytes: 83044
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
map<pair<ll, ll>, P> mp;
const ll mod = 1000000007;
struct mint
{
    ll x; // typedef 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, const mint &a) { return is >> a.x; }
ostream &operator<<(ostream &os, const mint &a) { return os << a.x; }

ll gcd(ll x, ll y)
{
    if (y == 0)
    {
        return x;
    }
    return gcd(y, x % y);
}

int main()
{
    int N;
    cin >> N;
    ll zero = 0;
    for (int i = 0; i < N; i++)
    {
        ll x, y;
        cin >> x >> y;

        if (x == 0 && y == 0)
        {
            zero++;
            continue;
        }
        // (1) 単位ベクトルに回転
        ll g = gcd(x, y);
        x /= g;
        y /= g;

        // (3) y < 0の時、180度回転
        if (y < 0)
        {
            x = -x;
            y = -y;
        }

        // (2) x = 0 or y = 0なら同様に正規化
        if (y == 0 && x < 0)
        {
            x = -x;
            y = -y;
        }

        // (4) x <= 0のとき、90度回転
        bool rot90 = false;
        if (x <= 0)
        {
            rot90 = true;
            ll tmp = y;
            y = -x;
            x = tmp;
        }

        // 同じグループに格納
        if (rot90)
        {
            mp[{x, y}].first++;
        }
        else
        {
            mp[{x, y}].second++;
        }
    }

    mint ans = 1;
    for (auto p : mp)
    {
        int s = p.second.first;
        int t = p.second.second;

        mint now = 1;
        now += mint(2).pow(s) - 1;
        now += mint(2).pow(t) - 1;

        ans *= now;
    }

    ans -= 1;    // 何も選ばない
    ans += zero; // x =0, y=0を選ぶ

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 16072
#include<bits/stdc++.h>
#define mins(a,b) a=min(a,b)
#define maxs(a,b) a=max(a,b)
 template < typename T > std::string to_string( const T& n )
  {
    std::ostringstream stm ;
    stm << n ;
    return stm.str() ;
  }
using namespace std;

const long long INF=9000000000000000;
int main(){
  char n;
  int ans=0;
  string s;
  cin>>s;
  n=s[0];
  for(int i=1;i<s.size();i++){
    if(n!=s[i]){
      ans++;
      n=s[i];
    }
  }
  cout<<ans<<endl;
}

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

int main() {
    int N; cin >> N;
    int m = 0;
    vector<int> L(N);
    for (int i = 0; i < N; i++) {
        cin >> L[i];
        m = max(L[i], m);
    }
    int sum = -1 * m;
    for (int i = 0; i < N; i++) {
        sum += L[i];
    }
    if (m < sum) cout << "Yes" << endl;
    else cout << "No" << endl;
}


Measured memory_bytes: 256
"use strict";
var input=require("fs").readFileSync("/dev/stdin","utf8");
var cin=input.split(/ |\n/),cid=0;
function next(){return +cin[cid++];}
function nextstr(){return cin[cid++];}
function nextbig(){return BigInt(cin[cid++]);}
function nexts(n,a){return a?cin.slice(cid,cid+=n):cin.slice(cid,cid+=n).map(a=>+a);}
function nextm(h,w,a){var r=[],i=0;if(a)for(;i<h;i++)r.push(cin.slice(cid,cid+=w));else for(;i<h;i++)r.push(cin.slice(cid,cid+=w).map(a=>+a));return r;}
function xArray(v){var a=arguments,l=a.length,r="Array(a["+--l+"]).fill().map(x=>{return "+v+";})";while(--l)r="Array(a["+l+"]).fill().map(x=>"+r+")";return eval(r);}

var myOut = main();
if(myOut !== undefined)console.log(String(myOut));

function main(){
  var x = next(), y = next();
  if(y%2 === 1 || y < x*2 || y > x*4)return "No";
  return "Yes";
}

Measured memory_bytes: 29632
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

typedef pair<int, int> P;

struct D {
	P pos;
	int w;

	D(P pos, int w) : pos(pos), w(w) { }
};

bool cp(D a, D b) {
	return a.pos.first < b.pos.first;
}

int main() {
	int n;
	while (cin >> n, n) {
		vector<D> data;
		for (int i = 0; i < n; ++i) {
			int m, a, b; cin >> m >> a >> b;
			data.push_back( D( P(a, b), m ) );
		}

		sort( data.begin(), data.end(), cp );

		bool ans = true;
		vector<int> now; int w = 0;
		for (int i = 0; i < data.size(); ++i) {
			for (int j = 0; j < now.size(); ++j)
				if (data[now[j]].pos.second <= data[i].pos.first) {
					w -= data[now[j]].w;
					now.erase( now.begin() + j-- );
				}

			now.push_back(i);
			w += data[i].w;

			if (w > 150) ans = false;
		}

		if (ans) cout << "OK" << endl;
		else cout << "NG" << endl;
	}
}

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

bool vis[55][55];

string s[55];
int n , m;
int dr[] = {0 ,  - 1,  0 ,  1 };
int dc[] = { 1 ,  0 ,-1 ,  0 }; 
int cnt  = 0;
void dfs(int x , int y)
{
	cnt ++;
	//cout<<x<<" "<<y<<endl;
	vis[x][y] =true;
	for(int i = 0; i < 4; i++)
	{
		int tx = x + dr[i];
		int ty = y + dc[i];
		if(tx < 0 || ty < 0 || tx >= n || ty >= m) continue;
		if(s[tx][ty] =='.' || vis[tx][ty] ) continue;
		dfs(tx , ty);
	}
}

int main()
{
	cin>>n>>m;
	for(int i= 0; i < n; i++)
	{
		cin>>s[i];
	}
	
	
	for(int i  = 0; i < n; i++)
	{
		for(int j = 0; j < m; j++)
		{
			if(s[i][j] =='#')
			{
				cnt = 0;
				memset(vis , false , sizeof vis);
				dfs(i , j);
				if(cnt <= 1)
				{
					cout<<"No"<<endl;
					return 0;
				}
			}
		}
	}
	cout<<"Yes"<<endl;
	return 0;
}


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

namespace ConsoleApp5
{
    class Program
    {
        static void Main(string[] args)
        {
            string read = Console.ReadLine();
            string[] splitted = read.Split(' ');

            int x = int.Parse(splitted[0]);
            int time = int.Parse(splitted[1]);

            int answer;

            if (x > time)
            {
                answer = x - time;
            }
            else
            {
                answer = 0;
            }

            Console.WriteLine(answer.ToString());
          
        }
    }
}


Measured memory_bytes: 11092
fun main(args : Array<String>) {
    val (R, G, B, N) = readLine()!!.split(" ").map { it.toInt() }

    var count = 0

    (0..N).forEach { r ->
        (0..N).forEach { g ->
            val remain = N - (R * r + G * g)
            if (remain >= 0 && remain.mod(B) == 0) {
                count++
            }
        }
    }

    println(count)
}

Measured memory_bytes: 40280
from itertools import permutations

n=int(input())
l=[list(map(int,input().split())) for i in range(n)]

ans=0
cnt=0
for i in permutations(l):
  cnt+=1
  for j in range(len(i)-1):
    ans+=((i[j][0]-i[j+1][0])**2+(i[j][1]-i[j+1][1])**2)**0.5
print(ans/cnt)

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

using ll = long long;

struct Line {
	mutable ll k, m, p;
	bool operator<(const Line& o) const { return k < o.k; }
	bool operator<(ll x) const { return p < x; }
};

struct LineContainer : multiset<Line, less<>> {
	// (for doubles, use inf = 1/.0, div(a,b) = a/b)
	const ll inf = LLONG_MAX;
	ll div(ll a, ll b) { // floored division
		return a / b - ((a ^ b) < 0 && a % b); }
	bool isect(iterator x, iterator y) {
		if (y == end()) { x->p = inf; return false; }
		if (x->k == y->k) x->p = x->m > y->m ? inf : -inf;
		else x->p = div(y->m - x->m, x->k - y->k);
		return x->p >= y->p;
	}
	void add(ll k, ll m) {
		auto z = insert({k, m, 0}), y = z++, x = y;
		while (isect(y, z)) z = erase(z);
		if (x != begin() && isect(--x, y)) isect(x, y = erase(y));
		while ((y = x) != begin() && (--x)->p >= y->p)
			isect(x, erase(y));
	}
	ll query(ll x) {
		assert(!empty());
		auto l = *lower_bound(x);
		return l.k * x + l.m;
	}
};

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

	LineContainer lc;
	int N; ll C; cin >> N >> C;
	for (int i = 0; i < N; i++) {
		ll h; cin >> h;
		Line l;
		l.k = 2*h;
		if (i == 0) {
			l.m = -h*h;
		} else {
			ll best = -lc.query(h) + h*h + C;
			if (i == N-1) {
				cout << best << '\n';
				exit(0);
			}
			l.m = -(best + h*h);
		}
		lc.add(l.k, l.m);
	}

	assert(false);
}


Measured memory_bytes: 12800
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <complex>
using namespace std;

typedef long long ll;
typedef uint64_t ull;
typedef pair<int, int> P;
constexpr double PI = 3.1415926535897932;   // acos(-1)
constexpr double EPS = 1e-9;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)

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

    int n, x;
    cin >> n >> x;
    if(x == 1 || x == 2 * n - 1){
        cout << "No\n";
        return 0;
    }

    vector<int> ans(2 * n - 1);
    int pos = (2 * n - 1) / 2;
    ans[pos] = x;
    --pos;
    if(x == 1)  x = 2 * n - 1;
    else    --x;

    while(pos >= 0){
        ans[pos] = x;
        if(x == 1)  x = 2 * n - 1;
        else    --x;
        --pos;
    }

    pos = 2 * n - 2;
    while(pos > (2 * n - 1) / 2){
        ans[pos] = x;
        if(x == 1)  x = 2 * n - 1;
        else    --x;
        --pos;
    }
    
    cout << "Yes\n";
    for(int output : ans)   cout << output << '\n';
}

Measured memory_bytes: 2304
#include <bits/stdc++.h>
#include <stdlib.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll,ll> llP;

ll mod(ll a, ll b){
  ll ret=a%b;
  if(ret<0) ret+=b;
  return ret;
}

ll modpow(ll a,ll b,ll c){
  ll res=1;
  while(b>0){
    if(b&1) res=mod(res*a,c);
    a=mod(a*a,c);
    b>>=1;
  }
  return res;
}

int main() {
  int k,n;
  cin>>n>>k;
  ll ans=0;
  for(int i=k+1;i<=n;i++){
    if(n%i>=k) ans+=((n/i)*(i-k)+(n%i)-k+1);
    else ans+=((n/i)*(i-k));
  }
  if(k==0){
    ans-=n;
  }
  cout<<ans<<endl;
  return 0;
}



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

const int inf = 1e9;
const ll linf = 1e18;

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

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

    int h, w; cin >> h >> w;
    vector<string> s(h);
    for (int i = 0; i < h; i++) cin >> s[i];
    
    int ans = 0;
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            if (s[i][j] == '#') continue;
            vector<vector<int>> d(h, vector<int>(w, -1));
            d[i][j] = 0;
            queue<pair<int, int>> que;
            que.push({i, j});
            while (!que.empty()) {
                auto p = que.front(); que.pop();
                for (int k = 0; k < 4; k++) {
                    int ny = p.first + dy[k], nx = p.second + dx[k];
                    if (0 <= ny && ny < h && 0 <= nx && nx < w && s[ny][nx] != '#' && d[ny][nx] == -1) {
                        d[ny][nx] = d[p.first][p.second] + 1;
                        que.push({ny, nx});
                    }
                }
            }

            int tmp = 0;
            for (int k = 0; k < h; k++) tmp = max(tmp, *max_element(d[k].begin(), d[k].end()));
            ans = max(ans, tmp);
        }
    }
    cout << ans << endl;
    return 0;
}

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

#include <boost/range/adaptors.hpp>
#include <boost/range/irange.hpp>

using namespace std;
using namespace boost;
using namespace boost::adaptors;

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

    vector p(n, 0L), c(n, 0L);
    for (auto&& pp : p) {
        cin >> pp;
        --pp;
    }

    for (auto&& cc : c) {
        cin >> cc;
    }

    int64_t ans = numeric_limits<int64_t>::min();
    for (auto i : irange(0L, n)) {
        int64_t t = 0;
        int64_t pos = i;
        int64_t score = 0;

        vector<int64_t> mx(1L, numeric_limits<int64_t>::min());
        while (true) {
            pos = p[pos];
            score += c[pos];
            mx.emplace_back(max(mx.back(), score));
            ++t;

            if (t == k) {
                break;
            }

            if (pos == i) {
                break;
            }
        }

        ans = max(ans, mx.back());

        if (k - t > 0 && score > 0) {
            ans = max(ans, (k - t) / t * score + mx.back());
            ans = max(ans, k / t * score + max(0L, mx[k % t]));
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 3804
# -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0140

"""
import sys
from sys import stdin
input = stdin.readline



def solve(start, goal):
    path = []                   #  ?????????n???????????????????????????????????????
    # ????????????????????¨????????´?????¨????????????????????¨????????´????????°??????
    path.append([[0, 1, 2, 3, 4, 5, 6, 7, 8, 9], []])
    path.append([[1, 2, 3, 4, 5, 6, 7, 8, 9, 5, 4, 3, 2], [1, 0]])
    path.append([[2, 3, 4, 5, 6, 7, 8, 9, 5, 4, 3, 2], [2, 1, 0]])
    path.append([[3, 4, 5, 6, 7, 8, 9, 5, 4, 3, 2], [3, 2, 1, 0]])
    path.append([[4, 5, 6, 7, 8, 9, 5, 4, 3, 2], [4, 3, 2, 1, 0]])
    path.append([[5, 6, 7, 8, 9, 5, 4, 3, 2], [5, 4, 3, 2, 1, 0]])
    path.append([[6, 7, 8, 9, 5, 4, 3, 2, 1, 0, 1, 2, 3, 4, 5], []])
    path.append([[7, 8, 9, 5, 4, 3, 2, 1, 0, 1, 2, 3, 4, 5, 6], []])
    path.append([[8, 9, 5, 4, 3, 2, 1, 0, 1, 2, 3, 4, 5, 6, 7], []])
    path.append([[9, 5, 4, 3, 2, 1, 0, 1, 2, 3, 4, 5, 6, 7, 8], []])

    path_a = [0]*100            #  ???????????????????????????
    path_b = [0]*100
    try:
        path_a = path[start][0][:path[start][0].index(goal)+1]
    except ValueError:
        pass
    try:
        path_b = path[start][1][:path[start][1].index(goal)+1]
    except ValueError:
        pass

    if len(path_a) < len(path_b):
        return ' '.join(map(str, path_a))
    else:
        return ' '.join(map(str, path_b))


def main(args):
    n = int(input())
    for _ in range(n):
        start, goal = map(int, input().split())
        result = solve(start, goal)
        print(result)






if __name__ == '__main__':
    main(sys.argv[1:])

Measured memory_bytes: 7908
import java.util.*;
import java.util.Map.Entry;

import javax.swing.text.Segment;
import javax.xml.ws.WebEndpoint;

import java.io.*;
import java.lang.reflect.Array;
import java.math.BigInteger;

import static java.lang.Math.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;
 
public class Main //implements Runnable
{
//    static int dx[]={-1,0,1,0};
//    static int dy[]={0,-1,0,1};

    public static void main(String[] args)   throws Exception, IOException{        
        long mod=1000000007;
        Reader sc = new Reader(System.in);
        PrintWriter out=new PrintWriter(System.out);
        PriorityQueue<Integer> q=new PriorityQueue<>();
        
//        int n=sc.nextInt();
        double a=sc.nextDouble();
        double b=sc.nextDouble();
        double x=sc.nextDouble();
        
        double tan=b-(2*x-a*a*b)/(a*a);
//        db(b,tan);
        if(x<a*a*b/2) {
        	tan=2*x/(a*b);
        	tan/=b;
//            db(tan);
        	
            a = 90-toDegrees(atan(tan));
        }
        else {
            tan/=a;        	
            a = Math.atan(tan);
            a = toDegrees(a);
        }

        out.println(a);
     	out.flush();
    }
    
    static void ret(String ans) {
    	System.out.println(ans);
    	System.exit(0);
    }
    
    static boolean validpos(int x,int y,int r, int c){
        return x<r && 0<=x && y<c && 0<=y;
    }

    static void db(Object... os){
        System.err.println(Arrays.deepToString(os));
    }
}


class P {
	int x, y, d;
	P(int  x, int y, int d) {
	  this.x=x;
	  this.y=y;
	  this.d=d;
	}
}

//class P implements Comparable<P>{
//    int a,b;
//    P(int a, int b) {
//    	this.b=b;
//    	this.a=a;
//    }
//
//    public int compareTo(P p){
//        return p.a-a;//des
//    }
//}

class Reader
{ 
    private BufferedReader x;
    private StringTokenizer st;
    
    public Reader(InputStream in)
    {
        x = new BufferedReader(new InputStreamReader(in));
        st = null;
    }
    public String nextString() throws IOException
    {
        while( st==null || !st.hasMoreTokens() )
            st = new StringTokenizer(x.readLine());
        return st.nextToken();
    }
    public int nextInt() throws IOException
    {
        return Integer.parseInt(nextString());
    }
    public int[] nextIntArray(int size) throws IOException{
        int r[] = new int[size];
        for (int i = 0; i < size; i++) {
            r[i] = this.nextInt(); 
        }
        return r;
    }
    public long[] nextLongArray(int size) throws IOException{
        long r[] = new long[size];
        for (int i = 0; i < size; i++) {
            r[i] = this.nextLong(); 
        }
        return r;
    }
    public char[] getCharSet() throws IOException{
        return this.nextString().toCharArray();
    }    
    public long nextLong() throws IOException
    {
        return Long.parseLong(nextString());
    }
    public double nextDouble() throws IOException
    {
        return Double.parseDouble(nextString());
    }
}


Measured memory_bytes: 21332
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
#define REP(i, a, n) for(int i=a; i<n; i++)
#define RREP(i, a, n) for(int i=n-1; i>=a; i--)

int main() {
	int N;
	while (cin >> N, N) {
		int M[101], K, l[101];
		int num[101][101];
		REP(i, 0, N) {
			cin >> M[i];
			REP(j, 0, M[i]) {
				cin >> num[i][j];
			}
		}
		cin >> K;
		REP(i, 0, K) cin >> l[i];

		int identify = -1;
		int person = 0;
		REP(i, 0, N) {
			if (M[i] < K) continue;

			int cnt = 0;
			REP(j, 0, K) {
				REP(k, 0, M[i]) {
					if (l[j] == num[i][k]) {
						cnt++;
						break;
					}
				}
			}

			if (cnt == K) {
				identify = i + 1;
				person++;
			}
		}

		if (person <= 1) cout << identify << endl;
		else cout << -1 << endl;
	}
	return 0;
}

Measured memory_bytes: 3128
import sys
num = input()

for bit in range(2**(len(num)-1)):
    lis = [num[0]]
    for i in range(len(num)-1):
        
        if ((bit>>i) & 1):
            lis.append("+")
        else:
            lis.append("-")
        
        lis.append(num[i+1])
    
    ans = "".join(lis)
    if eval(ans) == 7:
        print(ans+"=7")
        sys.exit()

Measured memory_bytes: 3060