akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define si(X) scanf("%d", &(X))
#define sll(X) scanf("%lld",&(X))
const ll mod = 1e9+7;
#define INFL 0x3f3f3f3f3f3f3f3fLL
 
//-------------------------<MATH>-------------------------------------------------------//
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll expo(ll base,ll pow){ll ans = 1;
   while(pow!=0){if(pow&1==1){ans = ans*base;ans = ans%mod;}
   base *= base;base%=mod;pow/=2;}return ans;}
ll inv(ll x){return expo(x,mod-2);}
ll mult_mod(ll a , ll b){a = a%mod; b = b%mod;
ll c = (a * b)%mod;
//cout << a << " " << b << endl;
return c;}
ll add_mod(ll a , ll b){a = (a + mod)%mod;b = (b + mod)%mod;ll c = (a + b)%mod;return c;}
ll fac[(int)(5e5 + 5)] , inv_fac[(int)(5e5 + 5)];
void precomp_factorial(int M){fac[0] = 1;for(int i = 1 ; i <= M ; i++) fac[i] = mult_mod(i , fac[i - 1]);
    inv_fac[M] = inv(fac[M]);for(int i = M - 1 ; i >= 0 ; i--) inv_fac[i] = mult_mod(i + 1 , inv_fac[i + 1]);}
ll nCk(ll n , ll k){ll ans = fac[n];ans = mult_mod(ans , inv_fac[n - k]);ans = mult_mod(ans , inv_fac[k]);return ans;}
int lo[(int)(1e3 + 6)];
void sieve(int M){for(int i = 2 ; i < M ; i++){ if(lo[i]) continue; for(int j = i ; j < M ; j += i)lo[j] = i;}}
int max_expo_prime_n_fac(ll N , int prime){int ress = 0;while(N){ress += (N/prime);N /= prime;}return ress;}
//-------------------------</MATH>-------------------------------------------------------//
 
//-------------------------<STRING>-------------------------------------------------------//
string get_prefix(string x , int MAX){return x.substr(0 , min((int)x.size() , MAX));}
string get_suffix(string x,int MAX){int dn=1;for(int i=x.size()-1;i>=0;i--){if(dn==MAX)return x.substr(i);dn++;}return x;}
string convert_to_binary(int x,int len) {string ans=""; while(x){if(x&1){ans='1'+ans;}
    else{ans ='0'+ans;}x/=2;}int k = ans.size();while(k < len){ans = '0' + ans;k++;}return ans;}
//-------------------------</STRING>-------------------------------------------------------//
 
ull llrand() {ull r = 0;for(int i = 0; i < 5; ++i){r = (r << 15)|(rand() & 0x7FFF);}return r & 0xFFFFFFFFFFFFFFFFULL;}
int dx[8] = {1 , 0 , -1 , 0 , 1 , -1 , -1 , 1};    // last 4 diagonal
int dy[8] = {0 , 1 , 0 , -1 , 1 , 1 , -1 , -1};
 
const int SZ = 2345678;

 int main(){
     
     ll n, d;

     sll(n); sll(d);
     ll cnt = 0;
     for(int i = 0; i < n; i++){
         ll x, y;
         sll(x); sll(y);
         //cout << (x*x+y*y) << endl;
         if((x*x + y*y) <= d*d) cnt++;
     }
     cout << cnt << endl;
    
 }


Measured memory_bytes: 3696
c1 = list(map(int,input().split()))
c2 = list(map(int,input().split()))
c3 = list(map(int,input().split()))

if c3[0]-c3[1] == c2[0]-c2[1] and c2[0]-c2[1] == c1[0]-c1[1]:
    if c3[1]-c3[2] == c2[1]-c2[2]  and c2[1]-c2[2] == c1[1]-c1[2]:
        print("Yes")
    else:
        print("No")
else:
    print("No")

Measured memory_bytes: 3064
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayDeque;
import java.util.ArrayList;

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] inputs = br.readLine().split(" ");
		int n = Integer.parseInt(inputs[0]);

		ArrayList<Node> nodes = new ArrayList<>(n + 1);
		for ( int i = 0; i <= n; i++ ) {
			nodes.add(new Node());
		}

		for ( int i = 0; i < n - 1; i++ ) {
			inputs = br.readLine().split(" ");
			int u = Integer.parseInt(inputs[0]);
			int v = Integer.parseInt(inputs[1]);
			int w = Integer.parseInt(inputs[2]);
			nodes.get(u).nexts.add(new Edge(v, w));
			nodes.get(v).nexts.add(new Edge(u, w));
		}
		br.close();

		// nodes.forEach(nd -> System.out.println(nd));

		ArrayDeque<Integer> q = new ArrayDeque<>();
		q.add(1);
		int[] tree = new int[n + 1];
		tree[1] = 1;
		while ( !q.isEmpty() ) {
			int idx = q.poll();

			for ( Edge e : nodes.get(idx).nexts ) {
				if ( tree[e.to] == 0 ) {
					q.add(e.to);

					if ( e.dist % 2 == 0 ) {
						tree[e.to] = tree[idx];
					} else {
						tree[e.to] = tree[idx] * (-1);
					}
				}
			}
		}
		
		for ( int i = 1; i < tree.length; i++ ) {
			System.out.println( Math.max(tree[i], 0));
		}

	}

}

class Node {

	ArrayList<Edge> nexts = new ArrayList<>();

	@Override
	public String toString() {
		for ( Edge e : nexts ) {
			System.out.println("to:" + e.to + " dist:" + e.dist);
		}
		System.out.println();
		return " ";
	}
}

class Edge {

	int	to		= 0;
	int	dist	= 0;

	public Edge(int t, int d) {
		to = t;
		dist = d;
	}
}

Measured memory_bytes: 78104
#include <algorithm>
#include<string>
#include<iostream>
#include<queue>
using namespace std;
int main() {
    int N,M;
    cin >> N >> M;
    priority_queue<long long int> que;
    long long int s;
    for(int i=0;i<N;++i){
        cin >> s;
        que.push(s);
    }
    for(int j=0;j<M;++j){
        que.push(que.top()/2.0);
        que.pop();
    }
    long long int sum=0;
    for(int i=0;i<N;++i){
        s=que.top();
        que.pop();
        sum+=s;
    }
    cout << sum;
    return 0;
}


Measured memory_bytes: 1400
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
signed main() {
	ios::sync_with_stdio(false); cin.tie(0);
	//B
	int n, m;
	cin >> n >> m;
	vector<int> a(m);
	for (int i = 0; i < n; i++) {
		int k;
		cin >> k;
		for (int j = 0; j < k; j++) {
			int x;
			cin >> x;
			x--;
			a[x]++;
		}
	}
	int ans = 0;
	for (int i = 0; i < m; i++) {
		if (a[i] == n) ans++;
	}
	cout << ans <<endl;
	return 0;	
}

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

int main() {
  vector<char> S(6);
  for(int i=0;i<6;i++){
    cin>>S.at(i);
  }
  if(S.at(2)==S.at(3)&& S.at(4)==S.at(5)){
    cout<<"Yes";
  }
  else{
    cout<<"No";
  }
}


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

typedef long long ll;
int n,d;
string k;
ll p=1e9+7,dp[10000][100];
ll f(int x, int s, bool b){
    if(x==n){
        if(s%d==0)return 1;
        return 0;
    }
    int y=k[x]-'0',u=9,r=0;
    if(b)u=y;
    else if(dp[x][s]!=-1)return dp[x][s];
    for(int i=0;i<=u;i++){
        r=(r+f(x+1,(s+i)%d,b&&i==u))%p;
    }
    if(!b)dp[x][s]=r;
    return r;
}

int main() {
    cin>>k>>d;
    n=k.length();
    for(int i=0;i<n;i++){
        for(int j=0;j<100;j++){
            dp[i][j]=-1;
        }
    }
    ll ans=(f(0, 0, true)-1+p)%p;
    cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 8832
#include <bit>
#include <bitset>
#include <assert.h>
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <sstream>
#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <math.h>
#include <stdlib.h>
#include <queue>
#include <stack>


typedef long double ld;
typedef long long ll;

using namespace std;

ll MOD = ((ll)1e9 + 7);

struct mod {
	ll x;

	mod(ll tx = 0) {
		x = tx;
	}
	
	mod& operator=(const ll & tx) {
		x = tx;
		return *this;
	}
	
	mod& operator=(const mod & m2) {
		x = m2.x;
		return *this;
	}

	mod operator+(const mod& m2) const {
		return (x + m2.x) % MOD;
	}

	mod& operator+=(const mod& m2) {
		x += m2.x;
		x %= MOD;
		return *this;
	}

	mod operator-(const mod & m2) const {
		return (x - m2.x + MOD) % MOD;
	}

	mod& operator-=(const mod & m2) {
		x -= m2.x;
		x = (x + MOD) % MOD;
		return *this;
	}

	mod operator*(const mod & m2) const {
		return (x * m2.x) % MOD;
	}

	mod& operator*=(const mod & m2) {
		x *= m2.x;
		x %= MOD;
		return *this;
	}

	mod mypow(ll k) const {
		mod ret = 1;
		mod cur = x;
		while (k) {
			if (k & 1) {
				ret *= cur;
			}
			cur *= cur;
			k >>= 1;
		}
		return ret;
	}

	mod inv() const {
		return mypow(MOD - 2);
	}

	mod operator/(const mod & m2) const {
		return mod(((*this).x * (*this).inv().x) % MOD);
	}

	mod& operator/=(const mod & m2) {
		x *= m2.inv().x;
		x %= MOD;
		return *this;
	}

	bool operator<(const mod & m2) const {
		return x < m2.x;
	}
};

ostream &operator<<(ostream & os, const mod & m) {
	return os << m.x;
}

/* TEMPLATE ENDS HERE */

#define MAXN (1 << 20)

int p[MAXN];

bool prime(ll x) {
	if (x < MAXN) {
		return p[x];
	}
	for (ll i = 2; i * i <= x; i++) {
		if (x % i == 0) {
			return false;
		}
	}
	return true;
}

set<ll> ans;
ll a, b;

void check(ll x) {
	if (!x) {
		return;
	}
	if (!(a % x == 0) || !(b % x == 0)) {
		return;
	}
	if (!prime(x)) {
		return;
	}
	ans.insert(x);
}

int main() {
	cin >> a >> b;
	for (int i = 1; i < MAXN; i++) {
		p[i] = 1;
	}
	if (a > b) {
		swap(a, b);
	}
	for (int i = 2; i < MAXN; i++) {
		if (p[i]) {
			for (int j = 2 * i; j < MAXN; j += i) {
				p[j] = 0;
			}
		}
	}
	for (int i = 1; i < MAXN; i++) {
		check(i);
		check(a / i);
		check(b / i);
	}
	cout << ans.size() << endl;
	return 0;
}


Measured memory_bytes: 7292
#include<algorithm>
#include<iostream>
#include<stdio.h>
#include<iostream>
#include<stdio.h>
#include<vector>
#include<set>
#include<string>
#include<iomanip>
#include<queue>
#include<functional>
#include<cmath>
#include<map>
#define rep(i,n) for(int i=0; i<(int)n; i++)//n回繰り返す
using namespace std;
using ll = long long;
using P = pair<int, int>;
using graph = vector<vector<int>>;


int main() {
    int N, M,W=0; cin >> N >> M;
    int A[11000];
    rep(i, M) {
        cin >> A[i];
        W += A[i];
    }
    if (N >= W)
    {
        cout << N - W << endl;
    }
    else {
        cout << -1 << endl;
    }
   
}

    


    








































































































































Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
const int R[6] = {1, 10, 9, 12, 3, 4};

int main() {
  string S; cin >> S;
  int N = S.length();
  int dp[N][13] = {};
  if (S[N-1] == '?') {
    for (int i=0; i<=9; i++) dp[0][i] = 1;
  } else {
    int tmp = S[N-1] - '0';
    dp[0][tmp] = 1;
  }
  int remain;
  for (int i=1; i<N; i++) {
    if (S[N-1-i] == '?') {
      for (int j=0; j<13; j++) {
        for (int k=0; k<=9; k++) {
          remain = (k * R[i%6]) % 13;
          dp[i][(j+remain)%13] += dp[i-1][j];
          dp[i][(j+remain)%13] %= MOD;
        }
      }
    } else {
      for (int j=0; j<13; j++) {
        int k = S[N-1-i] - '0';
        remain = (k * R[i%6]) % 13;
        dp[i][(j+remain)%13] += dp[i-1][j];
        dp[i][(j+remain)%13] %= MOD;
      }
    }
  }
  cout << dp[N-1][5] << endl;
}


Measured memory_bytes: 5504
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;
typedef pair<double,double> Pd;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define fi first
#define se second
#define PI (acos(-1))

template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}
template<class T>
inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}
template<typename T> ostream& operator<<(ostream& s,const complex<T>& d) {return s<<"("<<d.real()<<", "<<d.imag()<< ")";}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const pair<T1,T2>& d) {return s<<"("<<d.first<<", "<<d.second<<")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& d){
	int len=d.size();
	rep(i,len){
		s<<d[i];if(i<len-1) s<<" ";
	}
	return s;
}
template<typename T> ostream& operator<<(ostream& s,const vector<vector<T>>& d){
	int len=d.size();
	rep(i,len){
		s<<d[i]<<endl;
	}
	return s;
}
template<typename T> ostream& operator<<(ostream& s,const set<T>& v){
	s<<"{ ";
	for(auto itr=v.begin();itr!=v.end();++itr) {
		if (itr!=v.begin()) {s<< ", ";}
		s<<(*itr);
	}
	s<<" }";
	return s;
}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const map<T1,T2>& m){
	s<<"{"<<endl;
	for(auto itr=m.begin();itr!=m.end();++itr){
		s<<" "<<(*itr).first<<" : "<<(*itr).second<<endl;
	}
	s<<"}"<<endl;
	return s;
}

const ll mod=1e9+7;
const ll inf=1e18;
const int INF=1e9;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int a,b,c,d;
	cin>>a>>b>>c>>d;
	int ans=INF;
	chmin(ans,abs(a+b-c-d));
	chmin(ans,abs(a+c-b-d));
	chmin(ans,abs(a+d-b-c));
	cout<<ans<<endl;
}


Measured memory_bytes: 3216
#include "iostream"
#include "vector"
#include "string"
#include "algorithm"
#include "math.h"
#include "cstring"
#include "stack"
#include "queue"

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

int main()
{
  int a, b, k;
  cin >> a >> b >> k;
  vector<int> v;
  for (int i = 100; i > 0; i--)
  {
    if (a % i == 0 && b % i == 0)
    {
      v.push_back(i);
    }
  }
  cout << v[k - 1] << "\n";
}


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

int main()
{
    int n;cin>>n;
    int arr[n],brr[n];
    for(int i=0;i<n;i++) cin>>arr[i];
    for(int i=1;i<=n;i++)
    {
        brr[arr[i-1]-1]=i;
    }
    for(int i=0;i<n;i++) cout<<brr[i]<<" ";
    return 0;
}

Measured memory_bytes: 1536
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> pi;
#define debug(x) cerr << #x << ": " << x << endl;
#define debug2(x, y) debug(x) debug(y);
#define repn(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(i, a) for(int i = 0; i < (int)(a); i++)
#define all(v) v.begin(), v.end() 
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define sq(x) ((x) * (x))

template<class T> T gcd(T a, T b){ return ((b == 0) ? a : gcd(b, a % b)); }

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	//freopen("input.in", "r", stdin);
	//freopen("output.out", "w", stdout);
	int x, a, b;
	cin >> x >> a >> b;
	if(abs(x - a) < abs(x - b)) cout << "A" << endl;
	else cout << "B" << endl;
	return 0;
}
/*
Things to look out for:
	- Integer overflows
	- Array bounds
	- Special cases
Be careful!
*/


Measured memory_bytes: 256
// link:
// [prajwal1721]
// g++ -Wall -Wextra -Wshadow filename.cpp
// ./a.out >input <output
/*comments:
*/



#include<bits/stdc++.h>
using namespace std; 
#define mod 1000000007
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a*(b/gcd(a,b))
#define bits(x) __builtin_popcountll(x)
#define vi              vector<int>
#define vl              vector<ll>
#define all(v)          v.begin(),v.end()
#define UNIQUE(X)       (X).erase(unique(all(X)),(X).end())



typedef long long int ll;
vector<ll> topological;
vector<ll> adj[100006];
ll Visit[100005]={0};
void dfs(int n)
{
    Visit[n]=1;
    for(auto i: adj[n])
    {
        if(Visit[i]==0)dfs(i);
    }
    if(Visit[n]==1)
        {
            topological.push_back(n);
            Visit[n]=2;
        }
}
void solve()
{
    ll n,t,m,u,v;cin>>n>>m;
    for(int i=0;i<m;i++)
    {
        cin>>u>>v;
        adj[u].push_back(v);
    }
    for(int i=1;i<=n;i++)
        Visit[i]=0;
    for(int i=1;i<=n;i++)
       if(!Visit[i])
        dfs(i);
    reverse(topological.begin(),topological.end());
    // for(auto i:topological)cout<<i<<" ";cout<<"\n";
    ll dist[n+1]={0},mx=0;
    for(auto i:topological)
    {
        for(auto j:adj[i])
            dist[j]=max(dist[j],dist[i]+1);
    }
    for(int i=1;i<=n;i++)mx=max(mx,dist[i]);
    cout<<mx<<"\n";
}


int main()
{ 
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    // ll t;cin>>t;
    // cout<<t<<"Hi test complete\n";
    // while(t--)
        {
            solve();
        }


    return 0;
}

Measured memory_bytes: 13352
N,K = map(int,input().split())
list1 = list(map(int,input().split()))
visited_town = [[] for i in range(N+1)] #どの町にいつ訪れたか,配列の0あける。
visited_time = [None for i in range(2*N)] #訪れた町の時系列。こっちは0あけない。

visited_town[1].append(0) 
visited_time[0] = 1

cycle_start = -1
cycle_end = -1

for i in range(1,2*N):
  next_town = list1[visited_time[i-1]-1]
  visited_town[next_town].append(i)
  visited_time[i] = next_town
  if len(visited_town[next_town]) == 2:
    cycle_start = visited_town[next_town][0]
    cycle_end   = visited_town[next_town][1]
    break

if K < cycle_start:
  ans = visited_time[K]
  print(ans)
else :   
  syuuki = cycle_end-cycle_start
  cycle = visited_time[cycle_start:cycle_end]
  ans = cycle[(K-cycle_start) % syuuki]
  print(ans)

Measured memory_bytes: 48372
# -*- coding: utf-8 -*-
import sys
import math
from bisect import bisect_left
from bisect import bisect_right
import collections
import copy
input = sys.stdin.readline
 
# bisect_left(lists, 3)
# bisect_right(lists, 3)
 
def main():
	N, K = map(int, input().split(" "))
	#S = input()
	#S = S[:-1]
	#S = list(S)

	sel = []
	for i in range(1, N+1):
		tmp = i
		counts = 0
		while True:
			if tmp >= K:
				break
			tmp *= 2
			counts += 1
		sel.append(counts)

	ans = 0
	for i, val in enumerate(sel):
		ans = ans + ((1/N) * ((1/2)**val))

	print(ans)

if __name__ == "__main__":
	main()

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

using namespace std;

int main()
{
    //freopen("code.in", "r", stdin);
   // freopen("code.out", "w", stdout);

    ios_base::sync_with_stdio(0);
    cin.tie(0);

    int n;
    long long a,b=0,c=0;
    cin>>n;
    while(n--)
    {
        cin>>a;
        if(a==0){b=0;}
        else{
        a+=b;
        c+=a/2;
        b=a%2;
        }
    }
    cout<<c<<"\n";

    return 0;
}


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

namespace AOJ
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.ReadLine();
            string line;
            while ((line = Console.ReadLine()) != null)
            {
                var ints = line.Select(x => x - '0').ToArray();
                var min = ints.OrderBy(x => x).Aggregate((a, b) => a * 10 + b);
                var max = ints.OrderByDescending(x => x).Aggregate((a, b) => a * 10 + b);
                Console.WriteLine(max - min);
            }
        }
    }
}

Measured memory_bytes: 6380
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<ll>;
using vii = vector<vi>;
using Pll = pair<ll, ll>;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(v) v.begin(), v.end()
#define sz(x) ((int) x.size())
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define F first
#define S second
const int MOD = 1000000007;
template<class T> void print(const T& t){ cout << t << endl; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
  ll n;
  cin >> n;
  bool ans = true;
  vector<string> w(n);
  rep(i,n){
    cin >> w[i];
  }
  for (ll i = 1; i < n;i++){
    if(w[i][0]!=w[i-1][sz(w[i-1])-1]){
      ans = false;
    }
  }
  sort(all(w));
  for (ll i = 1; i < n;i++){
    if(w[i]==w[i-1]){
      ans = false;
    }
  }
  if(ans){
    print("Yes");
  }
  else{
    print("No");
  }
}

Measured memory_bytes: 256
from collections import Counter

N = int(raw_input())
A = Counter(map(int, raw_input().split()))
cnt = 1
for k, v in A.items():
    if k == 0:
        continue
    if k % 2 == N % 2:
        print 0
        exit()
    if v != 2:
        print 0
        exit()
    cnt *= 2
    cnt %= 10 ** 9 + 7
print cnt


Measured memory_bytes: 13744
#include <bits/stdc++.h>
using namespace std;
int main(){
	int N, D;
	cin >> N >> D;
	int a, b, c = 0;
	for(int i = 1; i<=N; ++i){
		cin >> a >> b;
		if(sqrt(pow(a, 2) + pow(b, 2)) <= D){
			c++;
		}
	}
	cout << c;
}


Measured memory_bytes: 3588
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <cmath>
#include <set>
#include <stack>
#include <bitset>
#include <map>
#include <ctime>
#include <numeric>


#ifndef M_PI
#define M_PI 3.141592653589
#endif
#define int long long
#define double long double

#ifdef TIME
#define start cin.tie(NULL); cout.tie(NULL); cout.setf(ios::fixed); cout.precision(10); ios_base::sync_with_stdio(false);int32_t START = clock()
#define finish cout << "\ntime: " << (clock() - START) / (CLOCKS_PER_SEC * 1.0); return 0
#endif

#ifndef TIME
#define start cin.tie(NULL); cout.tie(NULL); cout.setf(ios::fixed); cout.precision(10); ios_base::sync_with_stdio(false)
#define finish return 0
#endif

using namespace std;


//vector input
template<typename T>
istream &operator>>(istream &is, vector<T> &vec) {
    for (auto &i : vec) {
        cin >> i;
    }
    return is;
}

//pair output
template<typename E>
ostream &operator<<(ostream &os, pair<E, E> &t) {
    os << t.first << ' ' << t.second;
    return os;
}

//"map" pair output
template<typename E>
ostream &operator<<(ostream &os, pair<const E, E> &t) {
    os << t.first << ' ' << t.second;
    return os;
}

//vector output
template<typename T>
ostream &operator<<(ostream &os, vector<T> &vec) {
    for (T i : vec) {
        os << i << ' ';
    }
    return os;
}

//2 dimensional vector output
template<typename T>
ostream &operator<<(ostream &os, vector<vector<T> > &vec) {
    for (vector<T> i : vec) {
        os << i << '\n';
    }
    return os;
}


int32_t main() {
    start;

    int K;
    cin >> K;
    int now = 7;
    for (int i = 1; i < 1e7; ++i) {
        if (now % K == 0) {
            cout << i << '\n';;
            finish;
        }
        now *= 10;
        now += 7;
        now %= K;
    }
    cout << -1 << '\n';

    finish;
}

Measured memory_bytes: 3616
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<vector>
#define mp make_pair
#define pb push_back
using namespace std;
typedef long long li;

const int Mod = 1e9 + 7;

inline int Add(int x, int y) {
  x += y;
  if (x >= Mod) x -= Mod;
  else if (x < 0) x += Mod;
  return x;
}
inline int Mul(int x, int y) {
  return 1LL * x * y % Mod;
}
int Pow(int a, int b) {
  int res = (a == 0) ? 0 : 1;
  while (b) {
    if (b & 1) res = Mul(res, a);
    a = Mul(a, a);
    b >>= 1;
  }
  return res;
}

const int N = 110;
int n, h[N];
int f[N][N][2][2][2], g[2][2][2];

int Getmin(int l, int r) {
  int res = Mod;
  for (int i = l; i <= r; ++i)
    res = min(res, h[i]);
  return res;
}
void Calc(int l, int r, int delta_h) {
  memset(g, 0, sizeof g);
  for (int i = 0; i < 2; ++i)
    for (int j = 0; j < 2; ++j) {
      if (delta_h) {
	g[i][j][0] = Add(g[i][j][0], Mul(f[l][r][i][j][0], Pow(2, delta_h - 1)));
	g[j][i][0] = Add(g[j][i][0], Mul(f[l][r][i][j][0], Pow(2, delta_h - 1)));
      } else {
	g[i][j][0] = Add(g[i][j][0], f[l][r][i][j][0]);
      }
      if (delta_h & 1) {
	g[i ^ 1][j ^ 1][1] = Add(g[i ^ 1][j ^ 1][1], f[l][r][i][j][1]);
      } else {
	g[i][j][1] = Add(g[i][j][1], f[l][r][i][j][1]);
      }
    }
  memcpy(f[l][r], g, sizeof g);
}
void Merge(int l, int r, int nowl, int nowr) {
  memset(g, 0, sizeof g);
  for (int i = 0; i < 2; ++i)
    for (int j = 0; j < 2; ++j)
      for (int k = 0; k < 2; ++k)
	for (int xi = 0; xi < 2; ++xi)
	  for (int xj = 0; xj < 2; ++xj)
	    for (int xk = 0; xk < 2; ++xk) {
	      int p = i, q = xj;
	      int s = k || xk || (j == xi);
	      int now = Mul(f[l][r][i][j][k], f[nowl][nowr][xi][xj][xk]);
	      g[p][q][s] = Add(g[p][q][s], now);
	    }
  memcpy(f[l][r], g, sizeof g);
}
void Solve(int l, int r) {
  if (l == r) {
    f[l][r][0][0][0] = f[l][r][1][1][0] = 1;
    return;
  }
  vector<pair<int, int> >now;
  int hmin = Getmin(l, r);
  int pre = l;
  for (int i = l; i <= r; ++i)
    if (h[i] == hmin) {
      if (pre < i) now.pb(mp(pre, i - 1));
      now.pb(mp(i, i));
      pre = i + 1;
    }
  if (pre <= r) now.pb(mp(pre, r));
  for (int i = 0; i < (int)now.size(); ++i) {
    int nowl = now[i].first, nowr = now[i].second;
    Solve(nowl, nowr);
    Calc(nowl, nowr, Getmin(nowl, nowr) - hmin);
    if (i) Merge(l, r, nowl, nowr);
    else memcpy(f[l][r], f[nowl][nowr], sizeof g);
  }
}

int main(void) {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i)
    scanf("%d", &h[i]);
  Solve(1, n);
  Calc(1, n, Getmin(1, n) - 1);
  int ans = 0;
  for (int i = 0; i < 2; ++i)
    for (int j = 0; j < 2; ++j)
      for (int k = 0; k < 2; ++k)
	ans = Add(ans, f[1][n][i][j][k]);
  printf("%d\n", ans);

  return 0;
}


Measured memory_bytes: 640
/*
If you want to aim high, aim high
Don't let that studying and grades consume you
Just live life young
******************************
*/
import java.util.*;
import java.io.*;

   public class Main
   {
      public static void main(String args[]) throws Exception
      {
         BufferedReader infile = new BufferedReader(new InputStreamReader(System.in));  
         StringTokenizer st = new StringTokenizer(infile.readLine());
         int N = Integer.parseInt(st.nextToken());
         double[] arr = new double[N];
         st = new StringTokenizer(infile.readLine());
         for(int i=0; i < N; i++)
            arr[i] = Double.parseDouble(st.nextToken());
         int headcount = N/2+1;
         double[][] dp = new double[N][N+1];
         dp[0][0] = 1.0-arr[0];
         dp[0][1] = arr[0];
         for(int a=1; a < N; a++)
            for(int b=0; b < N; b++)
            {
               dp[a][b] += dp[a-1][b]*(1-arr[a]);
               dp[a][b+1] += dp[a-1][b]*(arr[a]);
            }
         double res = 0.0;
         for(int x=headcount; x <= N; x++)
            res += dp[N-1][x];
         System.out.println(res);
      }
   }

Measured memory_bytes: 129744
#include <iostream>
#define rep(i, a, n) for(int i = a; i < n; i++)
using namespace std;

int main(){
    int a[4], b[4];
    while(1){
        rep(i, 0, 4) cin >> a[i];
        rep(i, 0, 4) cin >> b[i];
        if(cin.eof()) break;        
        bool f[4];
        rep(i, 0, 4) f[i] = false;
        int hit = 0, blow = 0;
        rep(i, 0, 4){
            if(a[i] == b[i]){
                hit++; f[i] = true;
            }
        }
        rep(i, 0, 4){
            if(f[i]) continue;
            rep(j, 0, 4){
                if(a[i] == b[j]) blow++;
            }
        }
        cout << hit << " " << blow << endl;
    }
}

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

int main(){
    int N, T, A;
    cin >> N >> T >> A;
    int H[N];
    for(int i =0; i < N; i++){
        cin >> H[i];
    }
    double dif[N];
    for(int i = 0; i < N; i++){
        dif[i] = abs(T - 0.006*H[i] - A);
    }
    int index = 0;
    double tempmin = dif[0];
    for(int i =1; i < N; i++){
        if(dif[i]<tempmin){
            index = i;
            tempmin = dif[i];
        }
    }
    cout << index + 1 <<endl;
}

Measured memory_bytes: 256
# cross point
def cross(c1, c2):
    return c1.real * c2.imag - c1.imag * c2.real

def cross_point(p1, p2, p3, p4):
    # p1 and p2 are  points on a segment.
    # p3 and p4 are points on the other segment.
    base = p4 - p3
    hypo1 = p1 - p3
    hypo2 = p2 - p3
    d1 = cross(base, hypo1) / abs(base)
    d2 = cross(base, hypo2) / abs(base)
    cp = p1 + d1 / (d1 - d2) * (p2 - p1)
    return cp

# area of a triangle
def _area_of_triangle(c1, c2, c3):
    v1 = c2 - c1
    v2 = c3 - c1
    return abs(v1.real * v2.imag - v1.imag * v2.real) / 2

# convex cut
def convex_cut(points, c1, c2):
    points.append(points[0])
    ref_vec = c2 - c1
    cross_point1 = None
    flag = 0
    # Detection of one intersection point
    for i, segment in enumerate(zip(points, points[1:])):
        p1, p2 = segment
        cross1 = cross(ref_vec, p1 - c1)
        cross2 = cross(ref_vec, p2 - c1)
        flag += cross1
        if cross1 <= 0 and cross2 > 0:
            cross_point1 = cross_point(c1, c2, p1, p2)
            points = points[i+1:]
            break
        elif cross1 > 0 and cross2 <= 0:
            cross_point1 = cross_point(c1, c2, p1, p2)
            points = points[i::-1] + points[:i:-1]
            break
    # Processing when there is no intersection point
    if cross_point1 == None:
        if flag > 0:
            cross_point1 = points[0]
            points = points[1:]
        else:
            return 0
    # find area
    cut_area = 0
    for p1, p2 in zip(points, points[1:]):
        if cross(ref_vec, p1 - c1) * cross(ref_vec, p2 - c1) <= 0:
            cross_point2 = cross_point(c1, c2, p1, p2)
            cut_area += _area_of_triangle(cross_point1, cross_point2, p1)
            break
        else:
            cut_area += _area_of_triangle(cross_point1, p1, p2)
    return cut_area

# acceptance of input
import sys

file_input = sys.stdin

n = int(file_input.readline())

def string_to_complex(s):
    x, y = map(float, s.split())
    return x + y * 1j

G = [string_to_complex(file_input.readline()) for i in range(n)]

# output
q = int(file_input.readline())

for line in file_input:
    p1x, p1y, p2x, p2y = map(int, line.split())
    p1 = p1x + p1y * 1j
    p2 = p2x + p2y * 1j
    ans = convex_cut(G.copy(), p1, p2)
    print("{:f}".format(ans))

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

int main() {
  int64_t N, D;
  cin >> N >> D;
  vector<vector<int>>XY(N, vector<int>(2));
  for(int i=0; i<N; i++)cin >> XY.at(i).at(0) >> XY.at(i).at(1);
  
  int count=0;
  
  for(int i=0; i<N; i++){
    int64_t X = XY.at(i).at(0);
    int64_t Y = XY.at(i).at(1);
    int64_t kyori = X*X + Y*Y;
    
    if(kyori<=D*D)count ++;
  }
  
  cout << count << endl;
}


Measured memory_bytes: 14340
import java.util.*;
import java.math.*;

class Main{       
   public static void main(String[] args){

      Scanner sc = new Scanner(System.in);
    
      int X = sc.nextInt();
      int t = sc.nextInt();
      
      if(t >= X){
          System.out.println(0);
          return;
      }else{
          System.out.println(X-t);
          return;
      }
      
   }
}
        

Measured memory_bytes: 21332
#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define ll long long int
#define vi vector<int>
#define vl vector<ll>
#define ppi pair<int,int>
#define ppl pair<ll,ll>
#define all(x) x.begin(),x.end()
#define ii int,int 
#define ff first    
#define ss second
#define forn(i,a,b) for(int i=a;i<b;i++)
#define forr(i,a,b) for(int i=a;i>=b;i--)
#define forv(i,m) for(auto i : m)
#define imx INT_MAX
#define imn INT_MIN
#define inf LONG_MAX
#define minf LONG_MIN
#define endl "\n"
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
#define sze size()
#define rvs reverse 
#define itr iterator 
#define pre cout<<fixed<<setprecision(10);
#define umap unordered_map
#define uset unordered_set

/*
#define MODM(a,b,md) ((a%md)*(b%md))%md
#define MODA(a,b,md) ((a%md)+(b%md))%md
#define ull unsigned long long int
#define si short int
*/

/*
bool compare(int a,int b) {return a > b;}
bool compare1(ppi a,ppi b) {return a.ff > b.ff;}
bool compare2(ppi a,ppi b) {return a.ss < b.ss;}
ll Npower(ll a,ll b) {ll product = 1; while(b){if(b&1){product = product*a;}a = a*a;b = b>>1;} return product;}
ll power(ll a,ll b,ll md) {ll product = 1; while(b){if(b&1){product = MODM(product,a,md);}a = MODM(a,a,md);b = b>>1;} return product%md;}
ll GCD(ll a,ll b) {return b==0 ? a:GCD(b,a%b);}
ll LCM(ll a,ll b) {return (a/GCD(a,b))*b; }
*/


int main()
{
    fast

    ll n;
    cin>>n;

    map<ll,ll> m;
    map<ll,ll> m1;

    int idx = 1;
    m[n] = idx;
    m1[idx] = n;

    while(true)
    {
        idx++;
        if(m1[idx-1]%2 == 0)
        {
            m1[idx] = m1[idx-1]/2;
            if(m[m1[idx-1]/2] != 0) break; 
            m[m1[idx-1]/2] = idx;
        }
        else
        {
            m1[idx] = 3*m1[idx-1]+1;
            if(m[3*m1[idx-1]+1] != 0) break;
            m[3*m1[idx-1]+1] = idx;
        }
    }

    cout<<idx;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{

    int cnt;
    cin>>cnt;
    int *ptr1=new int[cnt];
    int *ptr2=new int[cnt];
    for(int i=0;i<cnt;i++)
        cin>>ptr1[i];
    for(int i=0;i<cnt;i++)
        cin>>ptr2[i];
    for(int i=1;i<cnt;i++)
    {
        ptr1[i]+=ptr1[i-1];
        ptr2[cnt-i-1]+=ptr2[cnt-i];
    }
    int max=0;
    for(int i=0;i<cnt;i++)
        if(max<ptr1[i]+ptr2[i])max=ptr1[i]+ptr2[i];
    cout<<max;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#define int long long
using namespace std;
const int N=20;
const int inf=1e18+2;
int ar[N];
int dp(int l,int r,int x1,int x2){
	if(r-l==1){
		return 0;
	}
	int i,now=inf;
	for(i=l+1;i<r;i++){
		now=min(now,dp(l,i,x1,x1+x2)+dp(i,r,x1+x2,x2)+(x1+x2)*ar[i]);
	}
	return now;
}
signed main(){
	int n,i,j,k,l;
	cin>>n;
	for(i=1;i<=n;i++){
		cin>>ar[i];
	}
	cout<<dp(1,n,1,1)+ar[1]+ar[n];
}

Measured memory_bytes: 256
h,w,m=map(int, input().split())
hh=[]
ww=[]
b=set()
for _ in range(m):
    hi,wi=map(int, input().split())
    hh.append(hi)
    ww.append(wi)
    b.add((hi,wi))
from collections import Counter

hc=Counter(hh)
wc=Counter(ww)

hmx=0;hnow=-1
wmx=0;wnow=-1
hs=[];ws=[]
for hi in hc:
    if hc[hi]>hmx:
        hmx=hc[hi]
        hnow=hi
        hs=[hi]
    elif hc[hi]==hmx:
        hs.append(hi)
for wi in wc:
    if wc[wi]>wmx:
        wmx=wc[wi]
        wnow=wi
        ws=[wi]
    elif wc[wi]==wmx:
        ws.append(wi)

ans=hmx+wmx
flag=False
for hi in hs:
    for wi in ws:
        if (hi,wi) not in b:
            flag=True
            break
    if flag:break
if not flag:
    ans-=1

ans2=0

for hi,wi in b:
    ans2=max(ans2,hc[hi]+wc[wi]-1)
print(max(ans,ans2))
    
    

Measured memory_bytes: 222940
// clang-format off
#include <bits/stdc++.h>

#define mp make_pair
#define fst first
#define snd second
#define forn(i,n) for (int i = 0; i < int(n); i++)
#define forn1(i,n) for (int i = 1; i <= int(n); i++)
#define popcnt __builtin_popcount
#define ffs __builtin_ffs
#define ctz __builtin_ctz
#define clz __builtin_clz
#define all(a) (a).begin(), (a).end()
 
using namespace std;

using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pli = pair<ll,int>;
using pil = pair<int,ll>;
using pll = pair<ll,ll>;
template <typename T> using vec = vector<T>;
using vi = vec<int>;
using vl = vec<ll>;
template <typename T> using que = queue<T>;
template <typename T> using deq = deque<T>;

template <typename T> T id(T b) {return b;};
template <typename T> void chmax(T &x, T y) {if (x < y) x = y;}
template <typename T> void chmin(T &x, T y) {if (x > y) x = y;}
template <typename S, typename K> bool contains(S &s, K k) { return s.find(k) != s.end(); }
void fastio() { ios_base::sync_with_stdio(false); cin.tie(nullptr); }
constexpr ll TEN(int n) { if (n == 0) return 1LL; else return 10LL*TEN(n-1); }
// clang-format on

int main() {
    fastio();

    string s;
    cin >> s;

    int c = count(all(s), 'R');
    int ans = 0;
    if (c == 3)
        ans = 3;
    else if (c == 2 and s[1] == 'R')
        ans = 2;
    else if (c != 0)
        ans = 1;

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3608
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
int main() {
  int X;
  cin >> X;
  int ans = 0;
  for(int i = 0; i < 200; i++) {
    for(int j = 0; j < 200; j++) { 
      if(4 * i + 7 * j == X) {
        ans++;
        cout << "Yes" << endl;
        break;
      }
    }
    if(ans == 1) {
      break;
    }
  }
  if (ans == 0) {
    cout << "No" << endl;
  }
}

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

int main() {
  int A, B, C, D;
  cin >> A >> B >> C >> D;
  
  if (A + B > C + D)
    cout << "Left" << endl;
  else if (A + B < C + D)
    cout << "Right" << endl;
  else
    cout << "Balanced" << endl;
}

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

const ll big=1000000007;
int exp(int x,int y){
    if(y==0)return 1;//0^0=1
    if(x==1||x==0)return x;
    if(y%2==1)return (exp(x,y-1)*x);
    int t=exp(x,y/2);
    return (t*t);
}
void chmin(ll a,ll b){
    if(a>b)a=b;
    return;
}


void bfs(int n,vector<vector<int>> &road,vector<int> &ans,vector<ll> &dis){
  queue<int> que;
  que.push(0);
   while(!que.empty()){
     int s=que.front();
     que.pop();
     for(int v:road[s]){
       if(dis[v]<=dis[s]+1)continue;
       dis[v]=dis[s]+1;
       ans[v]=s;
       que.push(v);
     }
   }
}

int main(){
    int n,m;cin >> n >> m;
    vector<vector<int>> road(n);
    rep(i,m){
        int a,b;cin >>a >> b;a--;b--;
        road[a].push_back(b);
        road[b].push_back(a);
    }
    vector<int> ans(n,-1);
    vector<ll> dis(n,1000000000000000);
    dis[0]=0;
    bfs(n,road,ans,dis);
    cout << "Yes" << endl;
    rep2(i,1,n)cout << ans[i]+1 << endl;
}

Measured memory_bytes: 11120
N,K=map(int,input().split())
p=list(map(int,input().split()))
pE=list(map(lambda i :(1+i)/2,p))
pA=[sum(pE[0:K])]
inter=sum(pE[0:K])
for i in range(0,N-K):
    inter=inter+pE[K+i]-pE[i]
    pA.append(inter)

ans=max(pA)
print(ans)



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


int main()
{
    int N, W;
    cin >> N >> W;
    vector<long> w(N), v(N);
    for( int i = 0; i < N; ++i ) cin >> w[i] >> v[i];
    
    // dp[i][j]: i 番目以降の品物から重さの和が j 以下になるように
    //           選んだときの価値の最大値
    long dp[101][100001] = {};
    for( int i = 0; i <= W; ++i ) dp[N][i] = 0;
    for( int i = N-1; i >= 0; --i ){
        for( int j = 0; j <= W; ++j ){
            if( j >= w[i] ) dp[i][j] = max( dp[i+1][j], dp[i+1][j-w[i]] + v[i] );
            else            dp[i][j] = dp[i+1][j];
        }
    }
    cout << dp[0][W] << endl;

    return 0;
}

Measured memory_bytes: 79104
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x)  cerr << #x << " = " << (x) << endl;
//const int INF = 1e8;
using namespace std;

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


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

long long N;

int main() {
  scanf("%lld", &N);
  deque<int> digit;
  while(N > 0) { digit.push_front(N % 10); N /= 10; }
  int l = digit.size();
  int acc = 0, res = 0;
  for(int i = 0; i < l; ++i) {
    acc += digit[i];
    if(digit[i] == 0) continue;
    res = max(res, acc - 1 + 9 * (l - 1 - i));
  }
  res = max(res, acc);
  printf("%d\n", res);
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
#define loop(i,x,n) for(int i=(x);i<(n);i++)
#define all(v) (v).begin(),(v).end()
#define int long long
using namespace std;
const int MOD=1e9+7;
const int INF=1e15;

signed main(){
  int n;
  while(cin>>n,n){
    vector<pair<int,int>> rw(n);
    rep(i,n)cin>>rw[i].first>>rw[i].second;
    sort(all(rw));
    int readsum=0,writesum=0;
    rep(i,n){
      if(i<n-1)readsum+=rw[i].first;
      writesum+=rw[i].second;
    }
    if(readsum>=rw[n-1].first){
      cout<<readsum+rw[n-1].first+writesum<<endl;
    }else{
      int dp[1003][1003]={};
      dp[0][0]=1;
      int uplim=rw[n-1].first-readsum;
      int mw=0;
      rep(i,n){
        for(int j=0;j<=uplim;j++){
          if(dp[i][j]==1){
            dp[i+1][j]=1;
            if(j+rw[i].second<=uplim)dp[i+1][j+rw[i].second]=1;
          }
        }
      }
      rep(i,uplim+1){
        if(dp[n-1][i])mw=i;
      }
      //cout<<"uplim="<<uplim<<' '<<"mw="<<mw<<endl;
      cout<<2*rw[n-1].first+writesum-mw<<endl;
    }


  }
 return 0;
}



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

int main(){
  char a,b,c,d;cin>>a>>b>>c>>d;
  if(a==b&&a!=c&&c==d)cout<<"Yes"<<endl;
  else if(a==c&&a!=b&&b==d)cout<<"Yes"<<endl;
  else if(a==d&&a!=b&&b==c)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
  return 0;
}

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

using namespace std;
typedef long long ll;
#define rep(i,j,n) for (ll i = j; i < (n); i++)
#define CLR(mat,f) memset(mat, f, sizeof(mat))
#define IN(a, b, x) (a<=x&&x<b)
#define out(ans) cout << ans << endl
typedef pair<ll,ll>P;
const ll mod=1e9+7;
const int INF = 1000000;
const double PI=3.14159265359;

int h,w;
vector<int>v;

int ans[100][100];

void setAns(int count){
  int th=0;
  while(count!=h*w){
    for(int i=0;i<w;i++){
      if(count==h*w)return;
      ans[th][i]=v[count];
      count++;
    }
    th++;
    for(int i=w-1;i>=0;i--){
      if(count==h*w)return;
      ans[th][i]=v[count];
      count++;
    }
    th++;
  }
}

int main(){

  cin>>h>>w;
  int n;cin>>n;
  int a[n+10];
  rep(i,0,n)cin>>a[i];

  int count=0;
  CLR(ans,-1);

  rep(i,0,n){
    rep(j,0,a[i]){
      v.push_back(i+1);
    }
  }
  setAns(0);

  rep(i,0,h){
    rep(j,0,w){
      cout<<ans[i][j]<<" ";
    }
    cout<<endl;
  }

  return 0;
}


Measured memory_bytes: 512
import java.util.Scanner

object Main {
  def main(args:Array[String]) = {
      
  val sc = new java.util.Scanner(System.in)
  val n:Long = sc.nextLong
  val m:Long = sc.nextLong
  val days = List.fill(m.toInt)(sc.nextLong)
  
  val allHomeworkDays: Long = days.sum
  val calcRemnantDayes: Long = n - allHomeworkDays
  
  println( if(calcRemnantDayes < 0) "-1" else calcRemnantDayes.toString )
  }
  

    
}

Measured memory_bytes: 58256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <math.h>
#include <iomanip>
using namespace std;


int main() {
  int r, D, x[20];
  cin >> r >> D >> x[0];


  for (int i = 1; i <= 10; i++) {
    x[i] = r * x[i-1] - D;
    cout << x[i] << endl;
  }
}


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

namespace ABC114A
{
    class Program
    {
        static void Main(string[] args)
        {

            int a = int.Parse(Console.ReadLine());

            if (a == 3 || a == 5 || a == 7)

                Console.WriteLine("YES");

            else Console.WriteLine("NO");

            Console.ReadKey();









        }
    }
}

Measured memory_bytes: 11092
#include <bits/stdc++.h>
#include <math.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rrep(i, n) for(int i = 0; i <= (n); i++)
using namespace std;
typedef long long ll;
 
const ll INF = 1LL<<62;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using Graph = vector<vector<int>>;

typedef pair<int, int> P;
typedef priority_queue<int, vector<int>, greater<int>> PQ;
const int MOD = 1000000007;

const int max_a = 20005;

int main(){
    ll N; cin >> N;
    if (N%2==1){
        cout << 0 << endl;
        return 0;
    }

    ll ans = 0;
    N /= 2;
    while (N > 0){
        ans += N / 5;
        N /= 5;
    }

    cout << ans << endl;

}


Measured memory_bytes: 3624
#include<iostream>
using namespace std;
char c[100];
int main()
{
	cin>>c[1]>>c[2]>>c[3]>>c[4];
	if(c[1]==c[2]&&c[1]==c[3]||c[4]==c[2]&&c[4]==c[3]||c[1]==c[2]&&c[1]==c[3]&&c[3]==c[4])
	  cout<<"Yes"<<endl;
	else  cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 256
program takoyaki_festival_2019
    implicit none
    integer(4):: n
    integer(4), allocatable:: d(:)
    integer(4):: ans=0
    
    read*, n
    allocate(d(n))
    read*, d(:)
    block; integer(4):: i,j
        do i=1, n-1
            ans = ans + sum(d(i)*d(i+1:n))
        end do
    end block

    print*, ans
end program takoyaki_festival_2019

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		String s = sc.next();
		char[] c = s.toCharArray();
		int count = 0;
		for(int i = 0; i < n; i++) {
			if(c[i]=='R') {
				count++;
			}
		}
		int ans = count;
		for(int i = 0; i < count; i++) {
			if(c[i]=='R') {
				ans--;
			}
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 41008
parseInt(x) = parse(Int, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)
function permutation(a,n)
	ans = Array{Int,1}[copy(a)]
	c = ones(Int,n)
	i = 1
	while i<=n
		if c[i]<i
			if i%2==1
				tmp = a[1]
				a[1] = a[i]
				a[i] = tmp
			else
				tmp = a[c[i]]
				a[c[i]] = a[i]
				a[i] = tmp
			end
			c[i] += 1
			i = 1
			push!(ans,copy(a))
		else
			c[i] = 1
			i += 1
		end
	end
	ans
end

function main()
    n,m,rn = readline() |> split |> parseMap
    r = readline() |> split |> parseMap
    d = 10^18*ones(Int,n,n)
    for i in 1:n
        d[i,i] = 0
    end
    for i in 1:m
        a,b,c = readline() |> split |> parseMap
        d[a,b] = c
        d[b,a] = c
    end
    for i in 1:n
        for j in 1:n
            for k in 1:n
                d[i,j] = min(d[i,j],d[i,k]+d[k,j])
            end
        end
    end
    for i in 1:n
        for j in 1:n
            for k in 1:n
                d[i,j] = min(d[i,j],d[i,k]+d[k,j])
            end
        end
    end
    for i in 1:n
        for j in 1:n
            for k in 1:n
                d[i,j] = min(d[i,j],d[i,k]+d[k,j])
            end
        end
    end
    prm = permutation(r,rn)
    minim = 10^18
    for i in 1:length(prm)
        x = 0
        for j in 2:rn
            x += d[prm[i][j-1],prm[i][j]]
        end
        minim = min(minim,x)
    end
    println(minim)
end
main()

Measured memory_bytes: 190440
N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
INF = N**3
max_ab = max(max(A),max(B))+1
dp = [[INF] * max_ab for _ in range(2**N)]
dp[0][0]=0
for i in range(2**N):
  done = 0
  for j in range(N):
    if (i>>j)&1:
      done += 1
  
  for right_end in range(max_ab):
    if dp[i][right_end]==INF:
      continue
    for add_last in range(N):
      if (i>>add_last)&1:
        continue
      if abs(add_last-done)%2==0:
        add_last_surface = A[add_last]
      else:
        add_last_surface = B[add_last]
        
      if right_end>add_last_surface:
        continue
        
      num = 0
      for k in range(add_last):
        if (i>>k)&1==0:
          num+=1
          
      dp[i|1<<add_last][add_last_surface]=min(dp[i|1<<add_last][add_last_surface],
                                              dp[i][right_end]+num)
      
ans = min(dp[-1])
if ans==INF:
  print(-1)
else:
  print(ans)

Measured memory_bytes: 165660
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) FOR(i, 0, (n))
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define LAR(a, b) ((a)=max((a),(b)))
#define SML(a, b) ((a)=min((a),(b)))
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vl = vector<ll>;
using pii = pair<int, int>;
using vpii = vector<pair<int, int>>;
template<typename T>
using pque = priority_queue<T, vector<T>, greater<T>>;
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define ALL(a) (a).begin(), (a).end()
#ifdef LOCAL_DEBUG
#define DEBUG(...) printf(__VA_ARGS__)
#else
#define DEBUG(...)
#endif

#define N 212345
int n;
vi g[N];
set<int> a[2];
int ans[N];

void dfs(int i, int p, int d){
	a[d%2].emplace(i);
	for(int &j : g[i]){
		if(j == p) continue;
		dfs(j, i, d+1);
	}
}
int f(int x){
	REP(i, 2) if((int)a[i].size() >= x) return i;
	assert(false);
}
void h(int p, int i){
	auto it = a[p].begin();
	ans[*it] = i;
	a[p].erase(it);
}
void gg(int k){
	int cnt, p;
	cnt = 0;
	for(int i = k; i <= n; i += 3) cnt++;
	p = f(cnt);
	for(int i = k; i <= n; i += 3) {
		h(p, i);
	}
}

int main(){
	scanf("%d", &n);
	REP(i, n-1){
		int a, b; scanf("%d%d", &a, &b);
		g[a].EB(b);
		g[b].EB(a);
	}
	dfs(1, 0, 0);

	gg(1);
	gg(2);

	for(int i = 3; i <= n; i += 3){
		h(f(1), i);
	}

	for(int i = 1; i <= n; i++) printf("%d ", ans[i]);
}





Measured memory_bytes: 28288
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define REP(i, start, end) for (int i = start, i##Len = (end); i < i##Len; ++i)
#define REPR(i, start, end) for (int i = start, i##Len = (end); i > i##Len; --i)
using ll = long long;
using namespace std;

int main()
{
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);

    ll k;
    cin >> k;
    ll n = 0;
    REP(i, 1, k + 2)
    {
        n = (n * 10 + 7) % k;
        if (n == 0)
        {
            cout << i << endl;
            return 0;
        }
    }
    cout << -1 << endl;
}

Measured memory_bytes: 3636