akhauriyash/Code-Regression huggingface dataset:
#define rep(i, n) for(int i = 0; i < n; i++)
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
	string s;
	cin >> s;
	int ans = 0;
	if (s == "RRR") ans = 3;
	else if (s == "RRS" || s == "SRR") ans = 2;
	else if (s == "RSS" || s == "SRS" || s == "SSR" || s == "RSR") ans = 1; 
	else ans = 0;

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 3620
#include<bits/stdc++.h>
#include<iterator>
#define FIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define M 7
using namespace std;
typedef unsigned long long int ll;
ll bigmod(ll n, ll k)
{
    if(k == 0) return 1;
    ll re = bigmod(n,k/2);
    re = (re * re) ;
    if(k % 2) re  = (re * n);
    //cout<<re<<endl;
    return re;
}
int main()
{

  string s;
  cin >> s;
 if(s == "SAT") cout << 1 << '\n';
  if(s == "SUN") cout << 7 << '\n';
   if(s == "MON") cout << 6 << '\n';
    if(s == "TUE") cout << 5 << '\n';
     if(s == "WED") cout << 4 << '\n';
      if(s == "THU") cout << 3 << '\n';
       if(s == "FRI") cout << 2 << '\n';





}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
int main(){
	int H,W,n;
	while(cin >> W >> H , H){
		cin >> n;
		int dp[17][17] = {0};
		bool bad[17][17] = {0};
		rep(i,n){
			int a,b;
			cin >> a >> b;
			bad[b][a] = 1;
		}
		for(int i=1;i<=H;i++){
			for(int j=1;j<=W;j++){
				if(i == 1 && j == 1){
					dp[1][1] = 1;
				}else{
					dp[i][j] = dp[i-1][j] + dp[i][j-1];
				}
				if(bad[i][j])dp[i][j] = 0;
			}
		}
		cout << dp[H][W] << endl;
		
	}
}

Measured memory_bytes: 0
x = int(input())
dp = [False]*101000
dp[0] = True
l = [100, 101, 102, 103, 104, 105]
for i in range(100001):
  for j in l:
    if dp[i]:
      dp[i+j] = True
if dp[x]:
  print(1)
else:
  print(0)

Measured memory_bytes: 9604
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <unordered_map>
#include <vector>
#include <map>
#include <list>
#include <queue>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <cmath>
#include <stack>
#include <set>
#pragma GCC optimize(3 , "Ofast" , "inline")
using namespace std ;
#define ios ios::sync_with_stdio(false) , cin.tie(0) , cout.tie(0)
#define x first
#define y second
typedef long long ll ;
const double esp = 1e-6 , pi = acos(-1) ;
typedef pair<int , int> PII ;
const int N = 1e6 + 10 , INF = 0x3f3f3f3f , mod = 1e9 + 7;
ll in()
{
  ll x = 0 , f = 1 ;
  char ch = getchar() ;
  while(!isdigit(ch)) {if(ch == '-') f = -1 ; ch = getchar() ;}
  while(isdigit(ch)) x = x * 10 + ch - 48 , ch = getchar() ;
  return x * f ;
}
int ans[N] , f[2][N] ;
int main()
{
  int n ;
  cin >> n ;
  // if(n == 1) {
  //   string s ;
  //   cin >> s ;
  //
  //   if(s[0] == '1') cout << 0 << endl ;
  //   else cout << 1 << endl ;
  //
  //   return 0 ;
  // }
  for(int i = 0 ; i <= n ;i ++ ) {
    int res = 0 , p = i ;
    while(p) {
         int t = p ;
         res ++ ;
         int cnt = 0 ;
         while(t) cnt += t % 2 , t /= 2 ;

         p %= cnt ;
    }
    ans[i] = res ;
  }
  string s ;
  cin >> s ;
  int y = 0 ;
  for(int i = 0 ;i < n ;i ++ ) y += s[i] == '1' ;
  int t1 = 0 , t2 = 0 ;
  if(y == 1) {
    for(int i = 0 ;i < n ;i ++ ) {
      if(s[i] == '1') cout << 0 << endl ;
      else {
        s[i] = '1' ;
        if(s[n - 1] != '1') cout << 1 << endl ;
        else cout << 2 << endl ;
        s[i] = '0' ;
      }
    }
    return 0 ;
  }
  for(int i = 0 ;i < n ;i ++ )
   {
     t1 = t1 * 2 ;
     t2 = t2 * 2 ;
     if(s[i] == '1')
      t1 ++ , t2 ++ ;
     t1 %= (y - 1) , t2 %= (y + 1) ;
   }
  f[0][0] = f[1][0] = 1;

  for(int i = 1; i <= n ;i ++ ) f[1][i] = f[1][i - 1] * 2 % (y + 1) , f[0][i] = f[0][i - 1] * 2 % (y - 1) ;
  for(int i = 0 ;i < n ;i ++ )
   {
     int res = 0 ;
     if(s[i] == '1')
      {

        res = (t1 - f[0][n - i - 1]) % (y - 1) ;
        res = (res % (y - 1) + (y - 1)) % (y - 1) ;
      }
      else {

        res = (t2 + f[1][n - i - 1]) % (y + 1) ;
        res = (res % (y + 1) + (y + 1)) % (y + 1) ;
      }
      cout <<  ans[res] + 1 << endl ;
   }
  return 0 ;
}
/*
*/


Measured memory_bytes: 5596
a, b, x = gets.split.map!(&:to_i)

ans_rad = if x > a * a * b / 2.0
  Math.atan(2.0 * (a * a * b - x) / (a * a * a))
else
  Math.atan(a * b * b / (2.0 * x))
end

puts ans_rad * 180 / Math::PI


Measured memory_bytes: 1788
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main{

	public static void main(String[] args) throws IOException {
		// TODO Auto-generated method stub
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line;
		while ((line = br.readLine()) != null) {
			int d = Integer.parseInt(line);
			System.out.println(calc(d));
		}
	}

	public static int calc(int d) {
		int ret = 0;
		for (int i = d; i <= 600 - d; i += d) {
			ret += i * i * d;
		}
		return ret;
	}

}

Measured memory_bytes: 24196
sub p{my($a,$b)=@_;$b?p($a**2%$=,$b>>1)*($b%2?$a:1)%$=:1}@s=map$%=($%+p$_,($==1e9+7)-2)%$=,1..<>;$\+=$_*($s[$i++]+$s[-$i]-1)%$=for glob<>;$\=$\*++$j%$=for@s;print

Measured memory_bytes: 34892
const stdin = require('fs').readFileSync('/dev/stdin', 'utf8')

const _n = stdin.split('\n')[0]
const n = Number(_n)

const [t,a] = stdin.split('\n')[1].split(' ').map(Number)

const h = stdin.split('\n')[2].split(' ').map(Number)

let diffMin = Infinity

const temps = h.map(x=>{
  const tmp = t - x * 0.006
  return Math.abs(a-tmp)
})

const min = Math.min(...temps)

const ans = temps.indexOf(min) + 1

console.log(ans)


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

int main(){
	ios::sync_with_stdio(false);

	int N; cin>>N;
	vector<ll> A(N);
	rep(i,N) cin>>A[i];

	ll high=A[0];
	ll sum=0;

	for(int i=0; i<N; i++){
		if(high > A[i]){
			sum += high - A[i];
		}else{
			high = A[i];
		}
	}
	cout << sum << endl;
}


Measured memory_bytes: 4760
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define vi vector<ll>
#define vvi vector<vi>
#define mod 1000000007
 
#define p(x) cout<<x<<" ";
#define p2(x,y) cout<<x<<" "<<y<<" "
#define p3(x,y,z) cout<<x<<" "<<y<<" "<<z<<" "
#define F(i,a,b) for(ll i=a;i<=b;i++)
#define RF(i,a,b) for(ll i=a;i>=b;i--)
 
#define ff first
#define ss second
#define mp(x,y) make_pair(x,y)
#define pi pair<ll,ll>
#define ppi pair<ll,pi>
#define pb push_back
#define all(v) v.begin(), v.end() 




vector<int> v[100005];
list<int>topo;
bool visited[100005];
int indegree[100005]={0};
   int dist[100005];


void dfs(int s){
  visited[s]=true;
  for(auto i:v[s]){
    if(dist[i]<dist[s]+1)
      dist[i]=dist[s]+1;
    indegree[i]--;
    if(indegree[i]==0)
      dfs(i);
  }

}

int main()
{

ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cout<<fixed<<setprecision(6);

// #ifndef ONLINE_JUDGE
// freopen("input.txt","r",stdin);
// freopen("output.txt","w",stdout);
// #endif
  
    ll t=1;
    //cin>>t;
    
    while(t--)
    {
      int n,m;
      cin>>n>>m;
      F(i,0,m-1){
        int a,b;
        cin>>a>>b;
        v[a].pb(b);
        indegree[b]++;
      }
     memset(dist,0,sizeof(dist));
      F(i,1,n)
      if(!visited[i]&&indegree[i]==0)
      dfs(i);


    dist[topo.front()]=0;

    

    int ans=0;
    F(i,1,n){
      ans=max(ans,dist[i]);
    }
    cout<<ans<<"\n";
    }
        
}

Measured memory_bytes: 9728
import java.util.*;
import static java.lang.System.*;
import java.math.*;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt(); //人数	
		//証言リスト。n+1番目にはnの証言がTesimonyクラスとして格納されている
		ArrayList<Tesimony>[] tesList = new ArrayList[n + 1];
		for (int i = 0; i < n + 1; i++)
			tesList[i] = new ArrayList<>();
		for(int i = 0; i < n; i++) {
			int a = sc.nextInt();
			 for (int j = 0; j < a; j++) {
				 int to = sc.nextInt();
				 int isTrust = sc.nextInt();
				 Tesimony tes = new Tesimony(to, isTrust);
				 tesList[i + 1].add(tes);
			 }
		}
		int ans = 0;

		for (int bit=0; bit< Math.pow(2, n); bit++) {
			boolean flag = true;
			//全員に対して証言チェック。証言者が「不親切」ならスルー
			for(int i = 0; i < n; i++) {
				if ((1&bit>>i) == 0)  continue;
				//証言の矛盾がないかチェック。矛盾があればループを抜ける
				for(int j = 0; j < tesList[i+ 1].size(); j++) {
					Tesimony tes = tesList[i+1].get(j);
					//矛盾があった場合
					if ( (1&bit>>(tes.to - 1) )  != tes.isTrust) {
						flag = false;
						break;
					}			
				}
			}
			if (flag) {
				int cnt = 0;
				for(int k = 0; k < n; k++) {
					if ((1&bit>>k) == 1) cnt++;
				}
				if (ans < cnt) ans = cnt;
			}
		}
		out.println(ans);	
	}
	//証言。証言対象と真偽を持つ
	static class Tesimony {
		int to;
		int isTrust;
		
		Tesimony(int to, int isTrust){
			this.to = to;
			this.isTrust = isTrust;
		}
		
	}
}

Measured memory_bytes: 22100
T = input()
def gettotal(s):
    score = 0
    for i in range(len(s)):
        if s[i] == "D":
            score +=1        
        if i < len(s)-1:
            if s[i] + s[i+1] == "PD":
                score +=1
    return score

def pd(T):
    T = T.replace("?","D")
    print(T)
    #return gettotal(T)

pd(T)

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

int main(){
	int a1,a2,a3,b1,b2,b3;
	int x[4][4];
	
	for(int i=1; i<=3; i++){
		for(int j=1; j<=3; j++){
			cin>>x[i][j];
		}
	}
	
	a1=0;
	b1=x[1][1]-a1;
	b2=x[1][2]-a1;
	b3=x[1][3]-a1;
	
	a2=x[2][1]-b1;
	a3=x[3][1]-b1;
	
	if(a2+b2==x[2][2] && a2+b3==x[2][3] && a3+b2==x[3][2] && a3+b3==x[3][3]){
		 cout<<"Yes"<<endl;
		 return 0;
	}
	
	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<(n); i++)
#define FOR(i, m, n) for(int i=(m);i<(n);i++)
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define SORT(x) sort((x).begin(),(x).end())
#define REVE(x) reverse((x).begin(),(x).end())
#define mp make_pair
#define pb push_back
 
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<vector<int>> VVI;
typedef pair<int, int> PII;
typedef long long LL;
typedef vector<bool> VB;

int main() {
    int n;
    cin >> n;
    if(n%2 == 0) {
        cout << (double)(n/2)/n << endl;
    } else {
        cout << (double)(n/2 + 1)/n << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
  {int X, Y; cin >> X >> Y;
  puts((Y - 2 * X) % 2 == 0 and 0 <= (Y - 2 * X) / 2 and 0 <= X - (Y - 2 * X) / 2 ? "Yes" : "No");}

Measured memory_bytes: 3592
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <ctime>
#include <bitset>
#include <complex>
#include <chrono>
#include <random>
#include <functional>

using namespace std;

#define rep(i, n) for (int i = 0; i < (n); ++i)
typedef long long ll;

int main(){

  string S;
  cin >> S;

  int Q;
  cin >> Q;

  bool flop = false;

  deque<char> dq;
  rep(i, S.size()){
    dq.push_back(S[i]);
  }

  rep(i, Q){
    int t;
    cin >> t;

    if(t==1){
      flop = !flop;
    }else if(t==2){
      int f;
      cin >> f;

      char c;
      cin >> c;

      if(f == 1){
        if(!flop){
          dq.push_front(c);
        }else{
          dq.push_back(c);
        }
      }else if(f==2){
        if(!flop){
          dq.push_back(c);
        }else{
          dq.push_front(c);
        }
      }
    }
  }

  //
  
  rep(i, dq.size()){
    if(!flop){
      cout << dq[i];
    }else{
      cout << dq[dq.size()-1-i];
    }
  }

  cout << endl;

  return 0;
}

Measured memory_bytes: 896
#include <stdio.h>
#include <algorithm>
using namespace std;
using ll = long long;

void solve();
int main() {
	solve();
#ifdef DBG
	while (true);
#endif
}

bool isPrime(int n) {
	for (int i = 2; (i * i) <= n; i++)
		if (n % i == 0)
			return false;
	return true;
}
void solve() {
	int n;
	scanf("%d", &n);

	int last_prime = 1;
	for (int i = 0; i < n; i++) {
		last_prime += 10;
		while (!isPrime(last_prime))
			last_prime += 10;
		printf("%d\n", last_prime);
	}
}

Measured memory_bytes: 128
fun main(args: Array<String>) {
    val (A, B) = listOfLong()
    val G = gcd(A, B)
    val C = factorize(G)
    println(C.count() + 1)
}
fun next() = readLine()!!
fun listOfString() = next().split(" ")
fun listOfLong(delta: Long = 0L) = listOfString().map { java.lang.Long.parseLong(it) + delta }
tailrec fun gcd(a: Long, b: Long): Long = if (a % b == 0L) b else gcd(b, a % b)
fun factorize(N: Long): MutableList<Long> {
    val res = mutableListOf<Long>()
    var n = N
    var i = 2L
    while (i * i <= n) {
        if (n % i == 0L) {
            var m = 0
            while (n % i == 0L) {
                n /= i
                m += 1
            }
            if (m > 0) res.add(i)
        }
        i += 1L
    }
    if (n != 1L) res.add(n)
    return res
}

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

using namespace std;
int n, a[200001];
long long ans, pref[200001], xr[200001];
int main(){
    cin >> n;
    for(int i = 1; i <= n; i++){
        cin >> a[i];
        pref[i] = a[i] + pref[i - 1];
        xr[i] = (a[i]^xr[i - 1]);
    }
    for(int i = 1; i <= n; i++){
        int l = i,
        r = n;
        while(r - l > 1){
            int mid = (r + l) / 2;
            if(pref[mid] - pref[i - 1] == (xr[mid]^xr[i - 1])){
                l = mid;
            }
            else{
                r = mid;
            }
        }
        if(pref[r]- pref[i - 1] == (xr[r]^xr[i - 1])){
            ans += (r - i + 1);
        }
        else{
            ans += (l - i + 1);
        }
    }
    cout << ans;
}


Measured memory_bytes: 4096
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <unordered_map>
#include <vector>

#define MOD 1000000007
#define int long long
//#define PI 3.14159265358979

#define rep(i, n) for (int i = 0; i < (int)(n); i++)

using namespace std;

template < typename T >
ostream &operator<<(ostream &os, const vector< T > &A) {
	for (int i = 0; i < A.size(); i++)
		os << A[i] << " ";
	os << endl;
	return os;
}
template <>
ostream &operator<<(ostream &os, const vector< vector< int > > &A) {
	int N = A.size();
	int M;
	if (N > 0)
		M = A[0].size();
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < M; j++)
			os << A[i][j] << " ";
		os << endl;
	}
	return os;
}

typedef pair< int, int > pii;
typedef long long ll;

struct edge {
	int from, to, d, c;
	edge(int _from = 0, int _to = 0, int _d = 0, int _c = 0) {
		from = _from;
		to = _to;
		d = _d;
		c = _c;
	}
	bool operator<(const edge &rhs) const {
		return (d == rhs.d) ? (c < rhs.c) : (d < rhs.d);
	}
};

typedef vector< edge > edges;
typedef vector< edges > graph;
struct flow {
	int to, cap, rev, cost;
	flow(int to = 0, int cap = 0, int rev = 0, int cost = 0) : to(to), cap(cap), rev(rev), cost(cost) {}
};
typedef vector< vector< flow > > flows;

const int di[4] = {0, -1, 0, 1};
const int dj[4] = {-1, 0, 1, 0};
const int ci[5] = {0, 0, -1, 0, 1};
const int cj[5] = {0, -1, 0, 1, 0};
const ll LINF = LLONG_MAX / 2;
const int INF = INT_MAX / 2;
const double PI = acos(-1);

template < typename T, typename U >
bool chmin(T &x, const U &y) {
	if (x > y) {
		x = y;
		return true;
	}
	return false;
}
template < typename T, typename U >
bool chmax(T &x, const U &y) {
	if (x < y) {
		x = y;
		return true;
	}
	return false;
}

struct initializer {
	initializer() {
		cout << fixed << setprecision(11);
	}
};
initializer _____;

int compress(vector< int > &x1, int W) {
	vector< int > xs;
	int N = x1.size();
	for (int i = 0; i < N; i++) {

		int tx1 = x1[i];

		xs.push_back(tx1);
	}

	sort(xs.begin(), xs.end());
	xs.erase(unique(xs.begin(), xs.end()), xs.end());
	for (int i = 0; i < N; i++) {
		x1[i] = lower_bound(xs.begin(), xs.end(), x1[i]) - xs.begin() + 1;
	}
	return (int)xs.size();
}

int N, M, K, T, Q;
signed main() {
	int N, A, B;
	cin >> N >> A >> B;
	if (A * B < N || N + 1 < A + B) {
		cout << -1 << endl;
		return 0;
	}
	vector< int > ans(N);
	ans.resize(0);
	//rep(i, A * B) ans[(B - 1 - i % B) * A + i / B] = i + 1;
	int k = A * B - N;
	rep(i, A * B) {
		if (k && i % A > 0 && i / A > 0)
			if (k >= A - 1) {
				k -= A - 1;
				i += A - 2;
			} else
				k--;
		else
			ans.push_back((i % A) * B + (B - i / A));
	}

	//ans.erase(unique(ans.begin(), ans.end()), ans.end());
	compress(ans, N);
	cout << ans;
	return 0;
}

Measured memory_bytes: 8560
#include <iostream>
#include <stdio.h>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>
#include <cmath>
#include <limits.h>
#include <assert.h>
#include <bitset>
#include <deque>
#include <list>
#include <map>
#include <math.h>
#include <stack>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string.h>

using namespace std;

#define mp make_pair
#define pb push_back
#define ll long long int
#define db double
#define ldb long double
#define MOD 1000000007
#define Fi first
#define Se second
#define INF INT_MAX
#define NINF INT_MIN
#define L_INF LLONG_MAX
#define L_NINF LLONG_MIN
#define gc getchar
#define sz(x) (int)(x).size()
#define pii pair<int,int>
#define pll pair<ll,ll>

void fsscan(){ios_base::sync_with_stdio(false);cin.tie(NULL);}

void scani(int &x)
{
    register int c = gc();x = 0;int neg = 0;
    for(;((c<48 || c>57) && c != '-');c = gc());
    if(c=='-') {neg=1;c=gc();}
    for(;c>47 && c<58;c = gc()) {x = (x<<1) + (x<<3) + c - 48;}
    if(neg) x=-x;
}

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

int main()
{
    fsscan();
    ll r,d,x;
    cin>>r>>d>>x;
    ll a[11];
    a[0]=x;
    for(int i=1;i<=10;i++)
    {
        a[i]=r*a[i-1]-d;
    }
    for(int i=1;i<=10;i++)
    {
        cout<<a[i]<<endl;
    }
    return 0;
}


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

rtn = "Yes"
f = 1
for i in range(n-1):
    hi = h[i]
    hii = h[i+1]
    
    if (hi == hii + f):
        f = 0
    elif (hi > hii + f):
        rtn = "No"
        break
    else:
        f = 1

print(rtn)


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

#define ll long long
#define fornum(A,B,C) for(A=B;A<C;A++)
#define mp make_pair
#define pii pair<int,int>
#define pll pair<ll,ll>

using namespace std;

/////////////////////////////////////////////////////
#define MOD (ll)998244353
#define Amx (ll)(1e6+9)

ll moddiv(ll a,ll b){
    a %= MOD;
    b %= MOD;
    for(ll m=MOD-2;m>0;m/=2){
        if(m&1){
            a=a*b%MOD;
        }
        b=b*b%MOD;
    }
    return a;
}


ll N,A[202020];
vector<ll> d[1010101];
ll mk[1010101];
ll g[1010101];
ll i, j, k, ans;
int main(){
    scanf("%lld", &N);
    
    fornum(i,0,N){
        scanf("%lld", &A[i]);
    }

    fornum(i,1,Amx){
        for (j = i; j < Amx; j += i)
        {
            d[j].push_back(i);
        }
    }
    fornum(i,1,Amx){
        ll a = moddiv(1, i);
        fornum(j,0,d[i].size()){
            a = (a + MOD - g[d[i][j]]) % MOD;
        }
        g[i] = a;
    }

    fornum(i,0,N){
        ll a = 0,ai=A[i];
        fornum(j,0,d[ai].size()){
            a = (a + g[d[ai][j]]*mk[d[ai][j]]) % MOD;
            mk[d[ai][j]] = (mk[d[ai][j]] + ai) % MOD;
        }
        ans = (ans + a * ai) % MOD;
    }
    printf("%lld", ans);

    return 0;
}

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

int main() {
  int N;
  cin >> N;
  vector<int64_t> A(N), B(N);
  for(int i = 0; i < N; i++) {
    int64_t x, y;
    cin >> x >> y;
    A.at(i) = x + y;
    B.at(i) = x - y;
  }
  sort(A.begin(), A.end());
  sort(B.begin(), B.end());
  cout << max(A.at(N - 1) - A.at(0), B.at(N - 1) - B.at(0)) << endl;
}

Measured memory_bytes: 6368
// #pragma GCC optimize("O3", "unroll-loops")
// #pragma GCC target("avx2")
 
#include <bits/stdc++.h>
using namespace std;
 
// #include <ext/pb_ds/assoc_container.hpp> 
// #include <ext/pb_ds/tree_policy.hpp> 
// using namespace __gnu_pbds;
// #define ost tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
 
#define    int                      long long int
#define    ld                       long double
#define    f(i,j,n)                 for(int i = j; i <= n; i++)
#define    r(i,n,j)                 for(int i = n; i >= j; i--)
#define    mod                      1000000007
#define    speed                    ios_base::sync_with_stdio(false);
#define    upp                      cin.tie(NULL),cout.tie(NULL);
#define    pb                       push_back
#define    mp                       make_pair
#define    T                        int ttt; cin >> ttt; while(ttt--)
#define    ff                       first
#define    ss                       second
#define    all(container)            container.begin() , container.end()
#define    sz(container)            (int)container.size()
#define    pii                      pair <int , int>
#define    sp(x)                    setprecision(x)
#define    bp(x)                    __builtin_popcount(x)
#define    endl                     "\n"
int power(int x, int y, int p)  
{  
    int res = 1;    
    x = x % p; 
    if (x == 0) return 0; 
    while (y > 0)  
    {     
        if (y & 1)  
            res = (res*x) % p;  
        y = y>>1; 
        x = (x*x) % p;  
    }  
    return res; 
}

int32_t main()
{
    speed upp
    int a,b,n;
    cin>>n>>a>>b;
    if(a%n==0 || b%n==0)
        cout<<"OK";
    else if(a/n == b/n)
        cout<<"NG";
    else    
        cout<<"OK";
        }

Measured memory_bytes: 3648
// Depth First Search
// 所要時間 x分
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<(n); ++i)
#define REP(i, d, n) for(int i=(d); i<(n); ++i)
#define all(v) v.begin(), v.end()

int t = 0;
vector<vector<int> > graph;
vector<pair<int, int> > ans;
vector<bool> visit;

void dfs(int node, int pre = -1){
    if(visit[node]){
        return;
    }
    visit[node] = true;
    t++;
    ans[node].first = t;
    for(int i=0; i<graph[node].size(); ++i){
        dfs(graph[node][i], node);
    }
    t++;
    ans[node].second = t;
}

int main() {

    int n;
    cin >> n;
    graph.resize(n);
    ans.resize(n);
    visit.resize(n);
    rep(i, n){
        int u, k;
        cin >> u >> k;
        --u;
        rep(j, k){
            int v;
            cin >> v;
            --v;
            graph[u].push_back(v);  
        }
    }

    rep(i, n){
        dfs(i);
    }

    rep(i, n){
        cout << i+1 << " " << ans[i].first << " " << ans[i].second << endl;
    }

    return 0;
}


Measured memory_bytes: 3148
import math, string, itertools, fractions, heapq, collections, re,  array, bisect, sys, random, time, copy, functools
sys.setrecursionlimit(10**7)
inf = 10 ** 20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def _I(): return int(sys.stdin.readline())
def _F(): return float(sys.stdin.readline())
def pf(s): return print(s, flush=True)

N=_I()
A=LI()
l = [0,0,0,0,0,0,0,0]
x=0
for a in A:
	if a <= 399:
		l[0]+=1
	elif a<= 799:
		l[1] += 1
	elif a <= 1199:
		l[2] += 1
	elif a <= 1599:
		l[3] += 1
	elif a <= 1999:
		l[4] += 1
	elif a<= 2399:
		l[5]+=1
	elif a<= 2799:
		l[6]+=1
	elif a<=3199:
		l[7]+=1
	else:
		x+=1
	
ans =sum(1 if i>0 else 0 for i in l)
if ans==0:
	print(1, end=" ")
else:
	print(ans,end=" ")

print(ans+x)
	
		
	


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

int main(){
    long long N,A,B,count[51][51];
    cin >> N >> A >> B;
    vector<long long> v(N);
    for(int i=0;i<N;i++) cin >> v[i];
    long long dp[51][51];
    for(int i=0;i<N+1;i++){ 
        dp[0][i]=0;
        count[0][i]=1;
    }
    for(int i=0;i<N;i++){
        for(int j=0;j<N+1;j++){
            dp[i+1][j]=dp[i][j];
            count[i+1][j]=count[i][j];
            if(j<=i+1&&j>0){
                long long left=dp[i][j];
                long long right=dp[i][j-1]+v[i];
                if(left==right) count[i+1][j]=count[i][j]+count[i][j-1];
                else if(left<right) count[i+1][j]=count[i][j-1];
                dp[i+1][j]=max(left,right);
            } 
        }
    }
    long long ans_a = 0, ans_b = 1, all = 0;
    for(int i = A; i <=B; i++){
      long long a = dp[N][i];
      if(a * ans_b > ans_a * i){
        ans_a = a;
        ans_b = i;
        all = count[N][i];
      }else if(a * ans_b == ans_a * i){
        all += count[N][i];
      }
    }
    double ans = (double)ans_a / (double) ans_b;
    printf("%.16f\n%lld",ans,all);
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
typedef unsigned int uint;
using namespace std;

const ll mod = 998244353LL;
ll red[4005], blue[4005], dp[4005][4005];

int main() {
    string s;
    cin >> s;
    int len = s.size();
    for (int i = 0; i < len; i++) {
        red[i+1] = red[i] + 2 - (s[i] - '0');
        blue[i+1] = blue[i] + (s[i] - '0');
    }

    dp[0][0] = 1;
    for (int i = 1; i <= 2 * len; i++) {
        dp[i][0] = dp[i-1][0] * (blue[min(len, i)] >= i);
        for (int j = 1; j <= i; j++) {
            // 合計i個並べたときに、赤をj個を使っている場合の数
            dp[i][j] = (dp[i-1][j] * (blue[min(len, i)] >= i-j) + dp[i-1][j-1] * (red[min(len, i)] >= j)) % mod;
        }
    }

    ll ans = 0LL;
    for (int i = 0; i <= 2 * len; i++) {
        ans = (ans + dp[2 * len][i]) % mod;
    }

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

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

int main() {
  int n,max_a=0;
  cin>>n;
  map<int,int> mx;
  vector<int> A(n);
  rep(i,n){
    int a;
    cin>>a;
    A[i]=a;
    max_a=max(max_a,a);
    mx[a]++;
  }
  rep(i,n){
    if(A[i]==max_a){
      if(mx[max_a]==1){
        for(int j=max_a-1;j>=0;j--){
          if(mx[j]>=1){
            cout<<j<<endl;
            break;
          }
        }
      }else{
        cout<<max_a<<endl;
      }
      continue;
    }
    cout<<max_a<<endl;
  }
}

Measured memory_bytes: 10112
#include <bits/stdc++.h>
using namespace std;
#define rep(i, m, n) for (int i = m; i < n; ++i)
#define rem(i, m, n) for (int i = m; i >= n; --i)

int main() {
  int N; cin >> N;
  vector<int> L(2 * N);
  rep(i, 0, 2 * N) cin >> L[i];
  sort(L.begin(), L.end());
  int ans = 0;
  rep(i, 0, N) ans += L[i*2];
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
N = int(input())
otoshidama = []
for _ in range(N):
    [a, b] = input().split()                                                                                   
    otoshidama.append([float(a), b])

ans = 0 
for i in range(N):
    if otoshidama[i][1] == 'JPY':
        ans += otoshidama[i][0]
    else:
        ans += otoshidama[i][0] * 380000

print(ans)

Measured memory_bytes: 3060
#include <iostream>
#include <set>

using namespace std;

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

  set<string> S;
  for(int i = 0; i < static_cast<int>(s.size()); ++i){
    auto m {min(K,static_cast<int>(s.size()-i))};
    for(int j = 1; j <= m; ++j){
      S.emplace(s.substr(i,j));
    }
  }

  auto ans {begin(S)};
  advance(ans,K-1);

  cout << *ans << endl;
}

Measured memory_bytes: 1664
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif




#define int long long
#define rng(i,l,r) for(size_t i=(l);i<(r);++i)
#define rep(i,n) rng(i,0,n)
#define gnr(i,l,r) for(size_t i=(r)-1;i>=(l);i--)
#define per(i,b) gnr(i,0,b)
#define ALL(obj) (obj).begin(), (obj).end()   //1,2,3,...
#define rALL(obj) (obj).rbegin(), (obj).rend()//...,3,2,1

using namespace std;


//constant
const int MOD = 1e9+7;
const int INF = 1e18;
const int dx4[4] = {1, 0, -1, 0};
const int dy4[4] = {0, 1, 0, -1};
const int dx8[8] = {1,1,0,-1,-1,-1,0,1};
const int dy8[8] = {0,1,1,1,0,-1,-1,-1};
const double pi = acos(-1);


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 gcd(int a,int b){return b?gcd(b,a%b):a;}
//*max_element(ALL(vector))
//count(ALL(vector),num) -> n
//memset(obj,value,sizeof(obj));




void solve(){
    
    // remove the bottom 3 lines when you submit this code.
    std::ifstream in("sample.txt");
    std::cin.rdbuf(in.rdbuf());

    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int n; cin >> n;
    int A[n]; rep(i,n) cin >> A[i];
    
    int x[n]; memset(x,0,sizeof(x));
    
    rep(i,n) x[0] += (i%2)?-A[i]:A[i]; x[0] /= 2;
    
    for (int i = 1; i < n; i++) x[i] = A[i-1] - x[i-1];
    
    rep(i,n) cout << 2*x[i] << " "; cout << endl;
    
    
    
    
}





signed main() {
    solve();
    return 0;
}




Measured memory_bytes: 2944
using System;
using System.Collections.Generic;
class Program
{
    //static List<string> str = new List<string>();
	static void Main(string[] args)
	{
		// 入力フェーズ
		int N = Int32.Parse(Console.ReadLine()); // 夏休みの日数
		//string[] stone = Console.ReadLine().Split(' '); // 足場の高さ
		int[] an = new int[N];
		int[] bn = new int[N];
		int[] cn = new int[N]; // a,b,cの幸福度
		for(int i=0; i<N; i++){
			string[] happy = Console.ReadLine().Split(' '); // 幸福度
			an[i] = Int32.Parse(happy[0]);
			bn[i] = Int32.Parse(happy[1]);
			cn[i] = Int32.Parse(happy[2]);
		}
//Console.WriteLine(height.Count + "");
		long[,] dp = new long[N+1,3]; //i日目に活動？をした時の幸福度の総和の最大値テーブル

// 初期値設定
		dp[0,0] = 0;
		dp[0,1] = 0;
		dp[0,2] = 0;
		for(int i=1; i<=N; i++)
		{
			// i日目に活動Aをした場合の幸福度の総和の最大値
			dp[i,0] = Math.Max(
										dp[i-1,1] + an[i-1] // 前日にBをした時の最大値＋今日Aをした時の幸福度
										, dp[i-1,2] + an[i-1] // 前日にCをした時の・・・
										);

			// i日目に活動Bをした時の幸福度の総和の最大値
			dp[i,1] = Math.Max(
										dp[i-1,0] + bn[i-1] // 前日にAをした時の最大値＋今日Bをした時の幸福度
										, dp[i-1,2] + bn[i-1] // 前日にCをした時の・・・
										);
			// i日目に活動Cをした時の幸福度の総和の最大値
			dp[i,2] = Math.Max(
										dp[i-1,1] + cn[i-1] // 前日にBをした時の最大値＋今日Cをした時の幸福度
										, dp[i-1,0] + cn[i-1] // 前日にAをした時の・・・
										);

			//Console.WriteLine(i + "日目; " + dp[i,0] + " " + dp[i, 1] + " " + dp[i,2]);
		}

		// dp[N][0,1,2]のうちの最大のものを出力する
		long maxHappy = Math.Max(dp[N,0], Math.Max(dp[N,1], dp[N,2]));
		Console.WriteLine(maxHappy + "");


    }

}


Measured memory_bytes: 18496
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int man=100005;
const int MAXM= 15000005;
int n,x;
int a[man];
ll gcd(ll a,ll b)
{
	if(a<b) swap(a,b);
	return b?gcd(b,a%b):a;
}
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin>>n>>x;
  for(int i=0;i<n;i++)
    cin>>a[i];
  a[n]=x;
  sort(a,a+n+1);
  ll ans=0;
  for(int i=1;i<n+1;i++)
  {
  	 ans=gcd(a[i]-a[i-1],ans);
  }
  cout<<ans<<endl;
}


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

#ifdef LOCAL
    #define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
        #define eprintf(...) 42
#endif

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define all(x) (x).begin(),(x).end()
#define foreach(u,v) for(auto (u) : (v))
#define pb push_back
#define mp make_pair
#define mt make_tuple

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

const int inf = 1e9;
const ll linf = 1LL<<60;
const ll mod = 1e9 + 7;
const double eps = 1e-9;

/*
*/

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

  ll k;
  bool exist = false;
  for(k = 1; k <= n; k++){
    if(k*(k+1)/2 == n){
      exist = true;
      break;
    }
  }

  if(!exist) cout << "No" << endl;
  else{
    cout << "Yes" << endl;
    cout << k+1 << endl;

    vector<vl> res(k+1, vl());
    ll sum = 1;
    for(int i = k; i >= 1; i--){
      rep(j, i){
        res[k-i].pb(sum+j);
        res[k-i+j+1].pb(sum+j);
      }
      sum += i;
    }

    rep(i, k+1){
      cout << res[i].size();
      for(ll j : res[i]) cout << " " << j;
      cout << endl;
    }
  }

  return 0;
}


Measured memory_bytes: 3200
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <stdlib.h>
#include <string.h>
using namespace std;

int main(){
    char s[30];
    cin >> s;
    if(strcmp(s,"2019/04/30") <= 0){
        cout << "Heisei" << endl;
    }
    else {
        cout << "TBD" << endl;
    }
}

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

int main()
{
    string s;
    int q = 0;
    char c;
    int t = 0,f = 0;
    cin >> s >> q;
    string s2;
    for( int i = 0; i < q; ++i )
    {
        cin >> t;
        if( t == 1 )
        {
            swap(s,s2);
        }
        else if( t == 2 )
        {
            cin >> f >> c;
            if( f == 1 )
            {
                s2 = s2 + c;
            }
            else if( f == 2 )
            {
                s = s + c;
            }
        }
    }
    
    reverse(s2.begin(),s2.end());
    cout << s2 + s << endl;
    return 0;
}



Measured memory_bytes: 1708
import io.{StdIn => in}

object Main extends App {
  val arr = Array.ofDim[Int](8)
  in.readLine.split(" ").map(_.toInt).foreach(i => arr(i) += 1)
  val ans = if(arr(5) == 2 & arr(7) == 1) "YES" else "NO"

  println(ans)
}


Measured memory_bytes: 25408
import sys
INF = 10**10
MOD = 10**9 + 7
sys.setrecursionlimit(100000000)
from functools import lru_cache
from itertools import permutations
from math import factorial


def main():
    s = input()
    n = len(s)
    flag = False
    ans = (-1,-1)
    for i in range(n - 1):
        if s[i] == s[i + 1]:
            flag = True
            ans = (i + 1,i + 2)
            break
    
    if flag:
        print(*ans)
        exit()
    
    else:
        for i in range(n - 2):
            if s[i] == s[i + 2]:
                flag = True
                ans = (i + 1,i + 3)
                break

    print(*ans)

if __name__=='__main__':
    main() 

Measured memory_bytes: 3812
n, k, q = list(map(int, input().split(" ")))
# a = []
m = [0] * len(range(n))
for i in range(q):
    m[int(input())-1] += 1


for i in m:
    ans = k-q+i
    if ans > 0:
        print('Yes')
    else:
        print('No')


Measured memory_bytes: 4680
#include <iostream>
using namespace std;
int main(){
	int N,K,x[10000]={},iyada=0;
	cin>>N>>K;
	for(int i=0;i<N;i++){
		cin>>x[i];
	}
	for(int i=0;i<N;i++){
		if(x[i]>K){
			iyada=iyada+(x[i]-K)*2;
		}
		else{
			if(x[i]<=K-x[i]){
				iyada=iyada+x[i]*2;
			}
			if(x[i]>K-x[i]){
				iyada=iyada+(K-x[i])*2;
			}
		}
	}
	cout<<iyada<<endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(int argc, const char * argv[]) {
    // insert code here...
    int n, i;
    double min, max,a[10001], sum=0;
    scanf("%d", &n);
    for (i=0; i<n; i++) {
        scanf("%lf", &a[i]);
    }
    min=a[0];
    max=a[0];
    for (i=0; i<n; i++) {
        sum+=a[i];
        if (min>a[i]) {
            min=a[i];
        }else if(max<a[i]){
            max=a[i];
        }
    }
    printf("%0.f %0.f %0.f\n", min, max, sum);
    return 0;
}



Measured memory_bytes: 2140
using System;
using System.Linq;

class Program
{
    static void Main(string[] args)
    {
        string[] nk = Console.ReadLine().Split(' ');
        long n = long.Parse(nk[0]);
        long k = long.Parse(nk[1]);
        if (n % k == 0)
        {
            Console.WriteLine(0);
            return;
        }
        Console.WriteLine(Remainder(n % k, k));
    }

    static long Remainder(long x, long k)
    {
        if (x < Math.Abs(x - k)) return x;
        return Remainder(Math.Abs(x - k), k);
    }
}


Measured memory_bytes: 27536
input1 = int(input())
input2 = input().split()


N = input1
cost = list(map(int,input2))

dp=[0]*(N)


dp[1] = dp[0] + abs(cost[1] - cost[0])

for i in range(2,N):
    dp[i] = dp[i - 1] + abs(cost[i] - cost[i - 1])
    dp[i] = min(dp[i],dp[i - 2] + abs(cost[i] - cost[i - 2]))

print(dp[-1])


Measured memory_bytes: 17948
using System;
using System.Collections.Generic;
using System.Text;

class TEST{
	static void Main(){
		while(true){
			var d=Array.ConvertAll(Console.ReadLine().Split(new char[2]{' ','\t'}),elem=>int.Parse(elem));
			if(d[0]==0 && d[1]==0)break;
			Sol mySol=new Sol(d[0],d[1]);
			Console.WriteLine(mySol.Ans);
		}
	}
}



class Sol{
	int ans;
	public int Ans{
		get{return ans;}
	}
	
	int s,d;
	int[,] D_Spring;
	int[,] D_District;
	public Sol(int sin,int din){
		s=sin;d=din;
		D_Spring=new int[s,d];
		for(int i=0;i<s;i++){
			var ss=Console.ReadLine().Split(new char[2]{' ','\t'});
			for(int j=0;j<d;j++)D_Spring[i,j]=int.Parse(ss[j]);
		}
		D_District=new int[d,d];
		for(int i=0;i<d;i++)D_District[i,i]=0;
		for(int i=0;i<d-1;i++){
			var ss=Console.ReadLine().Split(new char[2]{' ','\t'});
			for(int j=i+1;j<d;j++){
				D_District[i,j]=D_District[j,i]=int.Parse(ss[j-(i+1)]);
			}
		}
		
		Dijkstra();
	}
	
	void Dijkstra(){
		bool[] isFixed=new bool[d];
		for(int i=0;i<d;i++)isFixed[i]=false;

		int[] score=new int[d];
		
		//init
		for(int i=0;i<d;i++){
			int min=999;
			for(int j=0;j<s;j++){
				if(D_Spring[j,i]>0 && D_Spring[j,i]<min)min=D_Spring[j,i];
			}
			score[i]=min;
		}
		
		//dijkstra
		for(int i=0;i<d;i++){
//Console.WriteLine("score  :"+String.Join("\t",Array.ConvertAll(score,elem=>elem.ToString())));
//Console.WriteLine("isFixed:"+String.Join("\t",Array.ConvertAll(isFixed,elem=>elem.ToString())));
			int min;
			int jmin=0;
			min=999;
			for(int j=0;j<d;j++){
				if(isFixed[j]==false && score[j]<=min){
					jmin=j;
					min=score[j];
				}
			}
			for(int j=0;j<d;j++){
				if(isFixed[j]==true){
					for(int k=0;k<d;k++){
						if(isFixed[k]==false && D_District[j,k]>0 && D_District[j,k]<=min){
							jmin=k;
							min=D_District[j,jmin];
						}
					}
				}
			}
			isFixed[jmin]=true;
			score[jmin]=min;
		}
		
		int sum=0;
		for(int i=0;i<d;i++)sum+=score[i];
		ans=sum;
	}
}

Measured memory_bytes: 5800
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <unordered_map>
#include <cstdio>

using namespace std;

const int N_MAX = 100000;

int main() {
    int n;
    unordered_map<string, long long> mp;

    cin >> n;

    for (int i = 0; i < n; i++) {
        string s;
        cin >> s;
        sort(s.begin(), s.end());

        if (mp.find(s) == mp.end()) {
            mp[s] = 1;
        } else {
            mp[s] += 1;
        }
    }

    long long sum = 0;
    for (auto x : mp) {
        sum += (x.second * (x.second - 1))/2;
    }

    cout << sum << endl;

}


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

using namespace std;
int main(){
long long int N,K;
 cin >> N >> K;
long long int count = 0;
 vector<long long int> H(N);
 for(int i = 0; i < N; i++) cin >> H[i];
  sort(H.begin(),H.end(),greater<int>());
  if(N <= K){
    cout << 0;
    return 0;
  }
    
  for(int i = K; i < N; i++){
    count += H[i];
  }

  cout << count << endl;

 


 return 0;
}

Measured memory_bytes: 1792
#include <stdio.h>
    
    int main(void){
        int a,b,d,r;
        double f;

        scanf("%d %d",&a,&b);
        d = a / b;
        r = a % b;
        f = (double)a / (double)b;

        printf("%d %d %lf\n",d,r,f);
    }


Measured memory_bytes: 2096
#pragma GCC optimize(2)
#include<bits/stdc++.h>
#define ll long long
#define maxn 2000005
#define inf 1e9
#define pb push_back
#define rep(i,a,b) for(int i=a;i<=b;i++)
using namespace std;

inline int read()
{
	int x=0,w=1; char c=getchar();
	while(c<'0'||c>'9') {if(c=='-') w=-1; c=getchar();}
	while(c<='9'&&c>='0') {x=(x<<1)+(x<<3)+c-'0'; c=getchar();}
	return w==1?x:-x;
}

multiset <int,greater<int> > s2;
multiset <int> s1;
multiset <int>::iterator it,it2;
int x,n,a[maxn];

int main()
{
	x=read(); n=(1<<x);
	for(int i=1;i<=n;i++) a[i]=read(),s1.insert(a[i]);
	it=s1.end(); it--; s1.erase(it); s2.insert(*it);
	while(s2.size()!=n)
	{
		vector <int> vec; vec.clear();
		for(multiset <int,greater<int> >::iterator it1=s2.begin();it1!=s2.end();it1++)
		{
			it2=s1.lower_bound(*it1);
			if(it2==s1.begin()) {puts("No"); return 0;}
			it2--; vec.pb(*it2); s1.erase(it2); 
		}
		for(int i=0;i<vec.size();i++) s2.insert(vec[i]);
	}
	puts("Yes");
	return 0;
}

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

int main(){
  int n, m, a, sum=0;
  cin >> n >> m;
  for(int i=0;i<m;i++){
    cin >> a ;
    sum = sum + a;
  }
  if(sum<=n)
    cout << n-sum << endl;
  else
    cout << -1 << endl;
}

Measured memory_bytes: 3636
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")

#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define sc second
#define st first
#define pii pair<int, int>
#define arr array
#define task "A"
#define task_check "A"

const int maxn = 5e5 + 5;
const int maxN = 1e5 + 5;
const int mod = 1e9 + 7;

using namespace std;

/// Count : 1

int n, m;
ll a[maxn];

int main()
{
    /*if(fopen(task".inp", "r")){
        freopen(task".inp", "r", stdin);
        //freopen(task".out", "w", stdout);
    }*/
    cin >> n;
    ll ans = 0;
    for(int i=1; i<=n; i++){
        cin >> a[i];
    }
    for(int i=2; i<=n; i++){
        ans += max(a[i - 1] - a[i], 0LL);
        a[i] = max(a[i], a[i-1]);
    }
    cout << ans;
}


Measured memory_bytes: 5196
#include<bits/stdc++.h>
using namespace std;
#define int long
using pi=pair<int,int>;

signed main(){
    int k;
    cin >> k;
    queue<int> que;
    for (int i = 1; i <= 9; ++i) que.push(i);
    for(int i=0;i<k;++i){
        int x = que.front();
        que.pop();
        if (i == k - 1) return cout << x, 0;
        if (x % 10 > 0) que.push(10 * x + x % 10 - 1);
        que.push(10 * x + x % 10);
        if (x % 10 < 9) que.push(10 * x + x % 10 + 1);
    }
}

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

def remove_dpl(x):
  it=iter(x)
  before=next(it)
  res=[before]
  for e in it:
    if e!=before:
      res.append(e)
      before=e
  return res

c=0
h=remove_dpl(h)
while len(h)!=1:
  if h[0]>h[1]:
    c+=h[0]-h[1]
    h[0]=h[1]
  if h[len(h)-2]<h[len(h)-1]:
    c+=(h[len(h)-1]-h[len(h)-2])
    h[len(h)-1]=h[len(h)-2]
  for i in range(1,len(h)-1):
    if h[i]>h[i-1] and h[i]>h[i+1]:
      c+=h[i]-max(h[i-1],h[i+1])
      h[i]=max(h[i-1],h[i+1])
  h=remove_dpl(h)
print(c+h[0])

Measured memory_bytes: 3064
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"sort"
	"strconv"
	"strings"
)

var sc = bufio.NewScanner(os.Stdin)

func oneInt() int {
	var a int
	fmt.Scan(&a)
	return a
}

func oneInt64() int64 {
	var a int64
	fmt.Scan(&a)
	return a
}

func oneStr() string {
	var a string
	fmt.Scan(&a)
	return a
}

func nextLine() string {
	sc.Scan()
	return sc.Text()
}

func scanNums() (nums []int) {
	s := nextLine()
	numStr := strings.Split(s, " ")

	for _, n := range numStr {
		i, _ := strconv.Atoi(n)
		nums = append(nums, i)
	}
	return nums
}

func scanStrings() (strs []string) {
	s := nextLine()
	list := strings.Split(s, " ")
	strs = append(strs, list...)
	return strs
}

func abs(a int) int {
	return int(math.Abs(float64(a)))
}

func pow(p, q int) int {
	return int(math.Pow(float64(p), float64(q)))
}

func min(nums ...int) int {
	if len(nums) == 0 {
		panic("funciton min() requires at least one argument.")
	}
	res := nums[0]
	for i := 0; i < len(nums); i++ {
		res = int(math.Min(float64(res), float64(nums[i])))
	}
	return res
}

func max(nums ...int) int {
	if len(nums) == 0 {
		panic("funciton max() requires at least one argument.")
	}
	res := nums[0]
	for i := 0; i < len(nums); i++ {
		res = int(math.Max(float64(res), float64(nums[i])))
	}
	return res
}

func strSearch(a []string, b string) bool {
	for i := 0; i < len(a); i++ {
		if a[i] == b {
			return true
		}
	}
	return false
}

func sortAsc(a []int) []int {
	sort.Ints(a)
	return a
}

func sortDesc(a []int) []int {
	sort.Sort(sort.Reverse(sort.IntSlice(a)))
	return a
}

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

func lcm(a, b int) int {
	if a == 0 && b == 0 {
		return 0
	}
	return a * b / gcd(a, b)
}

func permutation(n int, k int) int {
	v := 1
	if 0 < k && k <= n {
		for i := 0; i < k; i++ {
			v *= (n - i)
		}
	} else if k > n {
		v = 0
	}
	return v
}

func factorial(n int) int {
	return permutation(n, n-1)
}

func combination(n int, k int) int {
	return permutation(n, k) / factorial(k)
}

func homogeneous(n int, k int) int {
	return combination(n+k-1, k)
}

func main() {
	N := oneInt()

	var hights []int
	var table []int
	for index := 0; index < N; index++ {
		hights = append(hights, oneInt())
		table = append(table, math.MaxInt64)
	}
  
	table[0] = 0
	table[1] = abs(hights[0] - hights[1])

	for index := 2; index < N; index++ {
		score1 := abs(hights[index] - hights[index-1])
		score2 := abs(hights[index] - hights[index-2])
		table[index] = min(table[index-1]+score1, table[index-2]+score2)
	}

	fmt.Print(table[N-1])
}


Measured memory_bytes: 6528
#include <bits/stdc++.h>
#define rep(i,n) for (int (i) = 0; (i) < (n); i++)
#define ll long long
using namespace std;
int main() {
  string S; cin >> S;
  ll a = 0;
  rep(i,S.size()){
    ll x = S[i] - 48;
    a += x;
  }
  if(a % 9 == 0){
    cout << "Yes";
  }
  else{
    cout << "No";
  }
}

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

#define REP(i, n) for(int i = 0; i < (int)(n); ++i)

const int MOD = 1e+9 + 7;


int main()
{
    int N, M;
    cin >> N >> M;
    vector<int> A(N), B(M);
    for( int i = 0; i < N; ++i ) cin >> A[i];
    for( int i = 0; i < M; ++i ) cin >> B[i];

    vector<bool> in_A(N*M+1, false), in_B(N*M+1, false);
    REP(i, N) in_A[A[i]] = true;
    REP(i, M) in_B[B[i]] = true;

    // 大きいものから順に決めていく
    long long ans = 1;
    int rc = 0, rr = 0; // row, col でそれぞれ今まで現れた値の数
    for(int i = N*M; i > 0; --i){
        if(in_A[i] and in_B[i]) ++rc, ++rr;
        else if(in_A[i]){
            ans *= rr % MOD;
            ++rc;
        }else if(in_B[i]){
            ans *= rc % MOD;
            ++rr;
        }else{
            // A にも B にも現れないとき、i より大きい場所でまだ空いているに場所にのみ置ける
            // -> i より大きい場所: rc*rr, まだ空いているに場所: - (N*M-i)
            ans *= (rc * rr - (N*M-i)) % MOD;
        }
        ans %= MOD;
    }
    cout << ans << endl; 

    return 0;
}

Measured memory_bytes: 512
a=ord('a')
alpha=['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z']

s=input()
K=int(input())
a=ord('a')
N=len(s)
L=[0]*N
t=K
for i in range(N):
    L[i]=ord(s[i])-a
i=0
while i<N:
    #print(L)
    if L[i]==0:
        i+=1
        continue
    if t>=26-L[i]:
        t=t-(26-L[i])
        L[i]=0
    i+=1
L[-1]=(L[-1]+t)%26
x=''
for i in range(N):
    x+=alpha[L[i]]
print(x)

Measured memory_bytes: 4340