akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimize "03"
#pragma GCC target("sse4")

#define ll long long int
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define FRE freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
#define f(i,n) for(ll i=0;i<n;i++)
#define fa(i,a,n) for(ll i=a;a<n?i<n:i>=n;a<n?i+=1:i-=1)
#define loop(i,a, n) for(ll i = a; i <= n; i++)
#define loopb(i,a, n) for(ll i = a; i >= n; i--)
#define pb push_back
#define pf push_front
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define setmem(x, k) memset(x, k, sizeof(x))
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define PI 3.1415926535897932384626
#define MOD 1000000007
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int>	vi;
typedef vector<ll> vl;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef long double ld;
// const ll N = 1e6+5;	
// ll a[N], b[N], dp[N], in[N], out[N], level[N], vis[N];
// vl g[N];
ll n, m;

ll dp[100005];

ll fun(vector<ll>& a, ll pos){
	if(pos == n - 1){
		return 0;
	}
	if(pos >= n){
		return INT_MAX;
	}
	if (dp[pos] != -1) return dp[pos];
	return dp[pos] = min(abs(a[pos] - a[pos+1]) + fun(a, pos + 1), abs(a[pos] - a[pos+2]) + fun(a, pos + 2));
}

void solve() {
	// ll k, x, y, p, q, r;
	cin>>n;
	vector<ll> a(n);
	f(i,n) cin >> a[i];
	setmem(dp, -1);
	cout << fun(a, 0);
}

int32_t main() {
	IOS
	ll T;
	// cin >> T;
	// while(T--)
		solve();
	cerr<<"Time elapsed : "<<clock()*1000.0/CLOCKS_PER_SEC<<"ms"<<'\n'; 
	return 0;
}

Measured memory_bytes: 4224
import sys
input = sys.stdin.readline
N,M = map(int, input().rstrip().split())
AB = [list(map(int, input().rstrip().split())) for _ in range(N)]
AB.sort(key=lambda x: x[0])
count = 0
price = 0
for i in range(N):
    count += AB[i][1]
    price += AB[i][0]*AB[i][1]
    if count >= M:
        break
mod = count - M
if mod != 0:
    price -= AB[i][0]*mod
print(price)

Measured memory_bytes: 29028
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
#define fr(i,n) for(int i=0;i<(n);++i)
#define Fr(i,n) for(int i=1;i<=(n);++i)
#define ifr(i,n) for(int i=(n)-1;i>=0;--i)
#define iFr(i,n) for(int i=(n);i>0;--i)
template<class T> void chmin(T&x,T y){if(x>y)x=y;}
template<class T> void chmax(T&x,T y){if(x<y)x=y;}

inline void PUTS(int a){
    static stack<char> C;
    while(a) C.emplace('0'+a%10),a/=10;
    if(C.empty()) putchar_unlocked('0');
    for(;!C.empty();C.pop()) putchar_unlocked(C.top());
    putchar_unlocked('\n');
}

int c,dp[1<<26],d[200001],n{};
int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    istream& in(cin);
    ostream& out(cout);
    d[0]=0;
    while((c=getchar_unlocked()-'a')>=0) d[n+1]=d[n]^(1<<c),++n;
    fill(dp,dp+(1<<26),500000);
    dp[d[n]]=0;
    ifr(i,n) fr(j,26) chmin(dp[d[i]],dp[d[i]^(1<<j)]+1);
    PUTS(max(dp[0],1));
}

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

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


Measured memory_bytes: 3096
//#include<bits/stdc++.h>
#include<iostream>
#include<cmath>
#include<cstdio>
#include<vector>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<utility>
#include<algorithm>
#include<cstring>
#include<sstream>
#include <iomanip>

using namespace std;

typedef long long ll ;
typedef double db;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef vector< pair<int,int> > vii;
const double pi = 2*acos(0) ;

#define pf		  	printf
#define sf			  scanf
#define pb(a)         push_back(a)
#define mp			make_pair
#define fi			 first
#define se			 second
#define for0(i,n)        for(int i=0;i<n;i++)
#define for1(i,n)        for(int i=1;i<=n;i++)
#define forab(i,a,b)       for(int i=a;i<=b;i++)
#define lcm(a, b)     ((a)*((b)/gcd(a,b)))
#define sq(a)		   (a)*(a)
#define nw				"\n"
#define abs(x)		fabs(x)
#define pcase(z,x)    cout<<"Case "<<z<<": "<<x<<"\n"
int main()
{
	int n,p,s=0;
	cin>>n;
	map<int,int>m;
	for0(i,n){
		cin>>p;
		m[p]++;
		}
	for(auto x:m){
		if(x.se>x.fi) s += x.se-x.fi;
		else if(x.se<x.fi) s += x.se;
		}
	cout<<s<<nw;
	return 0;
}

Measured memory_bytes: 4736
#include <stdio.h>

int main (void)
{
    /* variables for main process */
    unsigned char A, B, C;

    /* support variables for main process */
    int retval_scanf;

    // STEP.01
    // read out the given integers
    retval_scanf = scanf("%hhu %hhu %hhu", &A, &B, &C);

    // STEP.02
    // determine if there exists an equilateral triangle whose sides have lengths A, B and C.
    if (A == B && B == C) { printf("%s\n", "Yes"); }
    else                  { printf("%s\n", "No" ); }
    
    // STEP.TRUE_END
    return 0;
}

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

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

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

  rep(i,3) cout << s.at(i);

  
}

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

int main(){
    int a,b,c,k;
    cin >>a>>b>>c>>k;
    int sum=0;
    if(a>=k){
        sum=k;
    } else if(a+b>=k){
        sum = a;
    } else{
        sum = a-(k-a-b);
    }

    cout <<sum<<endl;

    return 0;
}

Measured memory_bytes: 3672
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <set>
#include <map>
#include <functional>
#include <cmath>
#include <cassert>
#include <string>
#include <iostream>

using namespace std;
typedef long long ll;
int vcount[1000010];
ll powMod(ll x, ll k, ll m) {
  if (k == 0)     return 1;
  if (k % 2 == 0) return powMod(x*x % m, k/2, m);
  else           return x*powMod(x, k-1, m) % m;
}

vector< ll > divisor(ll n) {
  vector< ll > ret;
  for(ll i = 1; i * i <= n; i++) {
    if(n % i == 0) {
      ret.push_back(i);
      if(i * i != n) ret.push_back(n / i);
    }
  }
  sort(begin(ret), end(ret));
  return (ret);
}

int main(){
    ll N;
    cin >> N;
    ll ans=0;
    vector<ll> d = divisor((ll)N);

    for(ll i:d){
        i--;
        if(i == 0)continue;
        if(floor(N/i) == (N % i))ans += i;

    }
    cout << ans << endl;
    
}


Measured memory_bytes: 384
#include <iostream>

using namespace std;

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

Measured memory_bytes: 256
use std::io;

fn main() {
    let (input1, input2, input3) = input_3_number();
    let mut numbers = [input1, input2, input3];
    numbers.sort();

    println!("{} {} {}", numbers[0], numbers[1], numbers[2]);
}

#[allow(dead_code)]
fn input_3_number() -> (i32, i32, i32) {
    let mut input = String::new();

    io::stdin().read_line(&mut input)
        .expect("Failed to read line");

    let vec: Vec<&str> = input.split_whitespace().collect();

    let input1: i32 = vec[0].parse().unwrap_or(0);
    let input2: i32 = vec[1].parse().unwrap_or(0);
    let input3: i32 = vec[2].parse().unwrap_or(0);

    (input1, input2, input3)
}

#[allow(dead_code)]
fn input() -> i32 {
    let mut input = String::new();

    io::stdin().read_line(&mut input)
        .expect("Failed to read line");
    let input: i32 = input.trim().parse()
        .expect("Failed to parse");

    input
}



Measured memory_bytes: 5032
public class Main{
  public void run(java.io.InputStream in, java.io.PrintStream out){
    java.util.Scanner sc = new java.util.Scanner(in);
/*answer*/
    int n;
    int count, i;

    for(;;){
      n = sc.nextInt();
      if(n == 0)break;
      count = 0;

      for(i = 2;(i * (i + 1) / 2) < 1000;i++){
        if(i % 2 == 0){
          if(n >= (i * (i + 1) / 2) && n % i == (i / 2))count++;
        }else{
          if(n >= (i * (i + 1) / 2) && n % i == 0)count++;
        }
      }
      out.println(count);
    }

    sc.close();
  }
  public static void main(String[] args){
    (new Main()).run(System.in, System.out);
  }
}

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

static const int INF=1e9;
static const int MOD=1000000007;
typedef long long ll;
typedef pair<int,int> P;

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

}


Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;

#define MOD 1000000007

ll rec(ll n) {
  if (n == 1) return 1;
  return rec(n / 2) * 2 + 1;
}

int main() {
  ll h;
  cin >> h;
  cout << rec(h) << endl;
  return 0;
}

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

class Main
{
    public static void main (String[] args) throws Exception
    {
        BufferedReader bu=new BufferedReader(new InputStreamReader(System.in));
        StringBuilder sb=new StringBuilder();
        int n=Integer.parseInt(bu.readLine());
        int i,a[]=new int[n];
        String s[]=bu.readLine().split(" ");
        for(i=0;i<n;i++)
        a[i]=Integer.parseInt(s[i]);
        ArrayList<Pair> al=new ArrayList<>();
        i=0;
        while(i<n-1)
        {
            while((i<n-1) && (a[i+1]<=a[i])) i++;
            if(i==n-1) break;
            Pair e=new Pair(0,0);
            e.l=i++;
            while((i<n) && (a[i]>=a[i-1])) i++;

            e.r=i-1;
            al.add(e);
        }

        long amt=1000;
        for(i=0;i<al.size();i++)
        {
            long st=amt/a[al.get(i).l];
            amt%=a[al.get(i).l];
            amt+=st*a[al.get(i).r];
        }
        System.out.print(amt);
    }

    static class Pair
    {
        int l,r;
        Pair(int a,int b)
        {
            l=a; r=b;
        }
    }
}

Measured memory_bytes: 32576
x, n = map(int, input().split())
lp = list(map(int, input().split()))

lp.sort()

distance = 0
try:
    idx = lp.index(x)
    while True:
        distance += 1
        dmin = x-distance
        dmax = x+distance
        if (idx-distance) < 0 or dmin != lp[idx-distance]:
            print(dmin)
            exit()
        if (idx+distance) >= len(lp) or  dmax != lp[idx+distance]:
            print(dmax)
            exit()
except ValueError:
    print(x)
    exit()

Measured memory_bytes: 9108
// WIP

#include <bits/stdc++.h>
using namespace std;

// Utility
#define ALL(X) (X).begin(), (X).end()
#define FOR(I, X, Y) for (int I = (X); I < (Y); I++)
using ll = int64_t;
using ull = uint64_t;
template<typename T> struct is_container {
template<typename C> static char test(typename C::const_iterator*); template<typename> static int test(...);
static bool const value = sizeof(test<T>(nullptr)) == sizeof(char) && !std::is_same<std::string, T>::value;
};
namespace std {
template<class ...Ts>        istream& operator>>(istream& i, tuple<Ts...>& x) { apply([&](auto&&... ys){ ((i >> ys), ...); }, x); return i; }
template<class T1, class T2> istream& operator>>(istream& i, pair<T1, T2>& x) { i >> x.first >> x.second; return i; }
template<class T, enable_if_t<is_container<T>::value, int> = 0>
istream& operator>>(istream& i, T& x) { for (auto& y : x) { i >> y; } return i; }
}

// Debugging
#ifndef DEBUG
#define DEBUG 0
#endif
#define dbg(X) do { if (DEBUG) { cout << #X ": " << (X) << endl << flush; } } while (0)
#define dbg2(X) do { if (DEBUG) { cout << #X ":" << endl; for (auto& __x : (X)) { cout << __x << endl << flush; } } } while (0)
#define dbgv(...) do { if (DEBUG) { cout << "(" #__VA_ARGS__ "): " << make_tuple(__VA_ARGS__) << endl << flush; } } while (0)
namespace std {
template<class ...Ts>        ostream& operator<<(ostream& o, const tuple<Ts...>& x) { o << "("; apply([&](auto&& y, auto&&... ys){ o << y; ((o << ", " << ys), ...); }, x); o << ")"; return o; }
template<class T1, class T2> ostream& operator<<(ostream& o, const pair<T1, T2>& x) { o << tie(x.first, x.second); return o; }
template<class T, enable_if_t<is_container<T>::value, int> = 0>
ostream& operator<<(ostream& o, const T& x) { o << "{"; for (auto it = x.begin(); it != x.end(); it++) { if (it != x.begin()) { o << ", "; } o << *it; } o << "}"; return o; }
}

// Main
void mainCase() {
  int n, m;
  cin >> n >> m;

  n = min(n, 2 * m + 1);
  vector<array<int, 2>> res;
  FOR(i, 0, (m / 2) + 1) {
    if (i < m - i) {
      res.push_back({i, m - i});
    }
    if (m + 1 + i < m + 1 + m - i - 1) {
      res.push_back({m + 1 + i, m + 1 + m - i - 1});
    }
  }
  dbg(res);
  assert(res.size() == m);

  for (auto [x, y] : res) {
    x++; y++;
    cout << x << " " << y << endl;
  }
}

int main() {
  ios_base::sync_with_stdio(0); cin.tie(0);
  mainCase();
  return 0;
}

/*
python misc/run.py atcoder/abc165/e/main.cpp --check

%%%% begin
7 3
%%%%
1 4
5 7
2 3
%%%% end

%%%% begin
9 4
%%%%
1 5
6 9
2 4
7 8
%%%% end
*/


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


int main()
{
  int mod = 1000000007;
  int n, m;
  cin >> n >> m;
  vector<ll> dp(n + 1, 0);
  rep(i, m)
  {
    int a;
    cin >> a;
    dp[a] = -1;
  }
  dp[0] = 1;
  if (dp[1] == -1)
    dp[1] = 0;
  else
    dp[1] = 1;
  for (int i=2; i<=n; i++)
    if (dp[i] == -1)
      dp[i] = 0;
    else
      dp[i] = (dp[i-1] + dp[i-2]) % mod;
  cout << dp[n] << endl;
  return 0;
}

Measured memory_bytes: 1024
// Problem : D - Redistribution
// Contest : AtCoder - AtCoder Beginner Contest 178
// URL : https://atcoder.jp/contests/abc178/tasks/abc178_d
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)


/*ヽ｀、ヽ｀｀、ヽ｀ヽ｀、、ヽ ｀ヽ 、ヽ｀🌙｀ヽヽ｀ヽ、ヽ｀
ヽ｀、ヽ｀｀、ヽ 、｀｀、 ｀、ヽ｀ 、｀ ヽ｀ヽ、ヽ ｀、ヽ｀｀、
ヽ、｀｀、｀、ヽ｀｀、 、ヽヽ｀、｀、、ヽヽ、｀｀、 、 ヽ｀、 
ヽ｀｀、 ヽ｀ヽ｀、、ヽ ｀ヽ 、 🚶ヽ｀｀｀｀ヽヽヽ｀、、ヽ｀、、ヽ*/

// #pragma GCC optimize ("O3")
// #pragma GCC target ("sse4")

#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;
 
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;
 
typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;
 
#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,b,a) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
#define trav(a,x) for (auto& a : x)
 
#define bug(x) cout<<#x<<"="<<x<<endl; 
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define ins insert
 
template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
const ld pii=3.14159265359; 
const int MOD = 1000000007;
const char nl = '\n';
const int MX = 200001; //check the limits, dummy
 ll mod_pow(ll x,ll n) {
	if (n == 0) return 1;
	ll res = mod_pow(x*x % MOD, n / 2);
	if (n & 1) res = res * x % MOD;
	return res;
}

ll comb(ll n, ll x) {
	ll ret = 1,k=1;
	F0R(i,x)ret = (ret * (n - i))%MOD;
	F0R(i,x)k = (k * (x-i))%MOD;
	k = mod_pow(k, MOD - 2);
	ret = (ret*k + MOD) % MOD;
	return ret;
}
int main() 
{
	ios_base::sync_with_stdio(0); cin.tie(0);    
	ll N;
	cin>>N;
	ll cpy=N,ans=0;
	FOR(x,1,MOD)
	{
		if(N<3*x)
			break;
		ans+=comb(N-3*x+x-1,N-3*x);
		ans%=MOD;
	}
	cout<<ans<<nl;
	return 0;
}
 
// read the question correctly (ll vs int)
// template by bqi343

Measured memory_bytes: 3532
N,K = list(map(int,input().split()))
AB = [list(map(int,input().split())) for i in range(N)]
bitK = bin(K)[2:]
bitK = bitK[::-1]
ans = 0
for i in range(N):
    if AB[i][0]|K==K:
        ans += AB[i][1]

for i in range(len(bitK)):
    score = 0
    if bitK[i]=="1":
        check = (K >> i)-1
        for j in range(N):
            if AB[j][0]>>i|check == check:
                score+=AB[j][1]
    ans = max(score,ans)

print(ans)

Measured memory_bytes: 61272
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define rep(i, n) for(int i=0;i<n;++i)
#define rrep(i, n) for(int i=n;i>=0;--i)
const int inf=1e9+7;
const ll mod=1e9+7;
const ll mod1=998244353;
const ll big=1e18;
const double PI=2*asin(1);

int main() {
  int N, M;
  cin>>N>>M;
  string S;
  cin>>S;
  vector<vector<int> > edge(N);
  int a, b;
  for(int i=0;i<M;++i) {
    cin>>a>>b;
    a--;
    b--;
    edge[a].push_back(b);
    edge[b].push_back(a);
  }
  map<int, pair<int, int> > amap;
  int anum, bnum;
  queue<tuple<int, int, int> > que;
  for(int i=0;i<N;++i) {
    anum = 0;
    bnum = 0;
    for(int j=0;j<edge[i].size();++j) {
      if(S[edge[i][j]]=='A') {
        anum++;
      }
      else {
        bnum++;
      }
    }
    if(anum==0 || bnum==0) que.push(make_tuple(i, anum, bnum));
    amap[i] = mp(anum, bnum);
  }
  map<int, int> bmap;
  tuple<int, int, int> state;
  int node;
  while(!que.empty()) {
    state = que.front();que.pop();
    node = get<0>(state);
    if(bmap[node]>0) continue;
    bmap[node] = 1;
    for(int i=0;i<edge[node].size();++i) {
      anum = amap[edge[node][i]].fi;
      bnum = amap[edge[node][i]].se;
      if(S[node]=='A') anum--;
      else bnum--;
      if(anum==0 || bnum==0) {
        if(bmap[edge[node][i]]==0) que.push(make_tuple(edge[node][i], anum, bnum));
      }
      amap[edge[node][i]] = mp(anum, bnum);
    }
  }
  bool can = false;
  for(int i=0;i<N;++i) {
    if(bmap[i]==0) can = true;
  }
  if(can) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}



Measured memory_bytes: 34096
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <numeric>

#define REP(i, a, b) for (int i = int(a); i < int(b); i++)
#ifdef _DEBUG_
#define dump(val) cerr << __LINE__ << ":\t" << #val << " = " << (val) << endl
#else
#define dump(val)
#endif

using namespace std;

typedef long long int ll;

template<typename T>
vector<T> make_v(size_t a, T b) {
    return vector<T>(a, b);
}
template<typename... Ts>
auto make_v(size_t a, Ts... ts) {
    return vector<decltype(make_v(ts...))>(a, make_v(ts...));
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<int> p(n);
    REP(i, 0, n) {
        cin >> p[i];
    }
    int cnt = 0;
    REP (i, 1, n - 1) {
        int mx = -1, mn = 1000;
        REP (j, i - 1, i + 2) {
            mx = max(mx, p[j]);
            mn = min(mn, p[j]);
        }
        cnt += (p[i] != mx && p[i] != mn);
    }
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstring>
#include <fstream>
#include <cmath>
#include <iomanip>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <map>
#include <deque>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <list>
#include <unordered_map>
#include <bitset>
#include <sstream>

typedef  long long ll;
#define mop 1000000007
using namespace std;

int main() {
    

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

}

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

#define _USE_MATH_DEFINES
#include<cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <algorithm>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iterator>
#include<iomanip>
#include<unordered_set>
#include<bitset>
#include<complex>

using namespace std;

#define rep(i,a,b) for(int i=(a), i##_len=(b);i<i##_len;i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)

#define int ll
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair

//typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<double, double> pdd;
typedef vector< vector<int> > mat;

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

const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;

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

	string S;
	cin >> S;

	string T = S;
	reverse(all(S));

	if (T == S)
	{
		cout << "Yes" << endl;
	}
	else
	{
		cout << "No" << endl;
	}

	return 0;
}

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

using namespace std;

using ll = long long;
using vi = vector<int>;

const ll linf = 1LL << 62;
const int inf = 999999;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};

#define Endl endl
#define pr(x) cout << x << endl
#define chmax(x,y) x = max(x,y)
#define chmin(x,y) x = min(x,y)
#define all(x) x.begin(),x.end()
#define atcoder(int)1e9+7
#define rep(i,n) for(int i = 0;i<n;i++)


ll gcd(ll a, ll b) {//最大公約数
	if (a%b == 0)return b;
	else gcd(b, a%b);
}

ll lcm(ll a, ll b) {//最小公倍数
	return (a / gcd(a, b))*b;
}

int  main() {

	int a, b;
	string s;

	cin >> a >> b;
	cin >> s;

	bool jud = true;

	if (s.length() != a + b + 1)jud = false;
	else if (s[a] != '-')jud = false;
	else{
		for (int i = 0; i < s.length(); i++) {
			if (i == a)continue;
			if (s[i] == '-')jud = false;
		}
	}

	if (jud)pr("Yes");
	else pr("No");

	return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
using namespace std;
struct point {
	int x, y;
	bool operator<(const point &p)const {
		return x != p.x ? x < p.x : y < p.y;
	}
}w[3010];
long long D[3010][2], F[201000], InvF[201000];
int n, H, W, Mod = 1000000007;
long long Pow(long long a, long long b) {
	long long r = 1;
	while (b) {
		if (b & 1)r = r*a%Mod;
		a = a*a%Mod; b >>= 1;
	}
	return r;
}
long long Comb(int a, int b) {
	return F[a] * InvF[b] % Mod*InvF[a - b] % Mod;
}
int main() {
	int i, j;
	F[0] = 1;
	for (i = 1; i <=200000; i++) {
		F[i] = F[i - 1] * i%Mod;
	}
	InvF[200000] = Pow(F[200000], Mod - 2);
	for (i = 200000; i >= 1; i--)InvF[i - 1] = InvF[i] * i%Mod;
	scanf("%d%d%d",&H,&W, &n);
	for (i = 1; i <= n; i++) {
		scanf("%d%d", &w[i].x, &w[i].y);
	}
	w[++n] = { 1,1 };
	w[++n] = { H,W };
	sort(w + 1, w + n + 1);
	D[1][1] = 1;
	for (i = 2; i <= n; i++) {
		for (j = 1; j < i; j++) {
			int dx = w[i].x - w[j].x, dy = w[i].y - w[j].y;
			if (dx >= 0 && dy >= 0) {
				long long t = Comb(dx + dy,dx);
				D[i][0] = (D[i][0] + t * D[j][1]) % Mod;
				D[i][1] = (D[i][1] + t * D[j][0]) % Mod;
			}
		}
	}
	printf("%lld\n", (D[n][0] - D[n][1] + Mod) % Mod);
}

Measured memory_bytes: 3328
#include<iostream>
using namespace std;
int main(){
	int A;
	int P;
	int x;
	int y;
	int z;
	cin >> A;
	cin >> P;
	x = A * 3;
	y = x + P;
	z = y / 2;
	cout << z << endl;
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <map>
#include <numeric>
#include <cmath>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <complex>
#include <string.h>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <iomanip>
#include <sys/time.h>
#include <tuple>
#include <random>
using namespace std;

#define endl '\n'
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define UNIQ(v) (v).erase(unique((v).begin(), (v).end()), (v).end())

typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
typedef tuple<int, ll, ll> T;
typedef complex<double> comp;
typedef vector< vector<ld> > matrix;
struct pairhash {
public:
    template<typename T, typename U>
    size_t operator()(const pair<T, U> &x) const {
	size_t seed = hash<T>()(x.first);
	return hash<U>()(x.second) + 0x9e3779b9 + (seed<<6) + (seed>>2);
    }
};
const ll inf = 1e18 + 9;
const ll mod = 1e9 + 7;
const double eps = 1e-8;
const double pi = acos(-1);

int n;
int k[200100];
ll l[200100], r[200100];

ll solve() {
    vector<T> vec0, vec1;
    ll sum0 = 0, sum1 = 0, sum_l = 0;
    for (int i = 0; i < n; i++) {
        if (k[i] == n) {
            sum_l += l[i];
        } else if (l[i] >= r[i]) {
            vec0.push_back(make_tuple(k[i], l[i], r[i]));
            sum0 += l[i];
        } else {
            vec1.push_back(make_tuple(-k[i], l[i], r[i]));
            sum1 += r[i];
        }
    }
    const int sz0 = (int)vec0.size();
    const int sz1 = (int)vec1.size();
    
    sort(ALL(vec0));
    priority_queue<ll> que;
    int idx = 0;
    for (int i = 1; i <= sz0; i++) {
        while (idx < sz0 && get<0>(vec0[idx]) <= i) {
            const ll g = get<2>(vec0[idx]) - get<1>(vec0[idx]);
            if ((int)que.size() < i) {
                que.push(g);
            } else {
                const ll d = que.top();
                if (g < d) {
                    que.pop();
                    que.push(g);
                    sum0 += d;
                } else {
                    sum0 += g;
                }
            }
            idx++;
        }
    }

    sort(ALL(vec1));
    que = priority_queue<ll>();
    idx = 0;
    for (int i = n; i > n-sz1; i--) {
        while (idx < sz1 && -get<0>(vec1[idx]) >= i-1) {
            const ll g = get<1>(vec1[idx]) - get<2>(vec1[idx]);
            if ((int)que.size() < n-i+1) {
                que.push(g);
            } else {
                const ll d = que.top();
                if (g < d) {
                    que.pop();
                    que.push(g);
                    sum1 += d;
                } else {
                    sum1 += g;
                }
            }
            idx++;
        }
    }
    return sum0 + sum1 + sum_l;
}

void input() {
    cin >> n;
    for (int i = 0; i < n; i++) cin >> k[i] >> l[i] >> r[i];
}

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

    int t;
    cin >> t;
    for (int i = 0; i < t; i++) {
        input();
        cout << solve() << endl;
    }
}


Measured memory_bytes: 12956
import java.util.Scanner;
class Main{
   public static void main(String[] args){
      Scanner stdIn = new Scanner(System.in);

      int a;
      int b;
      String op;


         while(true){

        	 a = stdIn.nextInt();
             op = stdIn.next();
             b = stdIn.nextInt();

             if (op.equals("?"))
        		 break;

             else if(op.equals("+"))
        		 System.out.println(a + b);

        	 else if(op.equals("-"))
        		 System.out.println(a - b);

        	 else if(op.equals("*"))
        		 System.out.println(a * b);

        	 else if(op.equals("/"))
        		 System.out.println(a / b);
         }
   }
}

Measured memory_bytes: 26188
#include<iostream>
#include<vector>
#include<math.h>
using namespace std;

int main(){
    int N,D,count=0;
    double d=0;
    cin>>N>>D;
    vector<vector<int>> X(N,vector<int>(D));
    for(int i=0;i<N;i++){
        for(int j=0;j<D;j++){
            cin>>X.at(i).at(j);
        }
    }

    for(int i=0;i<N;i++){
        for(int j=i+1;j<N;j++){
            int norm=0;
            for(int k=0;k<D;k++){
                int diff=abs(X.at(i).at(k)-X.at(j).at(k));
                norm+=diff*diff;
            }
            for(int k=0;k<=norm;k++){
                if(k*k==norm){
                    count++;
                }
            }
        }
    }
    cout<<count<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
// int N, M, X;
// vector<int> C(N);
// vector<vector<int>> A(N, vector<int>(M));


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

    ll ans = 1000000000;
    vector<bool> can(1<<N, true);
    bool flg = false;
    for (int bit = 0; bit < (1<<N); bit++)
    {   
        ll sum = 0;
        vector<int> B(M);
        for (int i = 0; i < N; i++)
        {
            if (bit & (1<<i))
            {
                sum += C[i];
                for (int j = 0; j < M; j++)
                {
                    B[j] += A[i][j];
                }
                

            }
            
        }
        for (int i = 0; i < M; i++)
        {
            if (B[i] < X)
            {
                can[bit] = false;
                break;
            }
            
        }
        if (can[bit] == true)
        {
            ans = min(ans, sum);
            flg = true;
        }
        
        
    }
    
    if (flg)
    {
        cout << ans << endl;
    } else
    {
        cout << -1 << endl;
    }
    
    return 0;
    
    

    
}

Measured memory_bytes: 3624
n = int(input())
ab = []
for _ in range(n):
    a, b = map(int, input().split())
    ab.append((a, b))
di = {}
z = 0
def gcd(a, b):
    while b!=0:
        a, b = b, a%b
    return a
for a, b in ab:
    if a*b!=0:
        g = gcd(abs(a), abs(b))
        a, b = a//g, b//g
    if a*b>0:
        ind = (abs(a), abs(b))
    elif a*b<0:
        ind = (abs(b), abs(a))
    else:
        ind = 0
    if ind in di:
        x, y = di[ind]
    else:
        x = y = 0
    if a*b==0:
        if b!=0:
            di[ind] = (x+1, y)
        elif a!=0:
            di[ind] = (x, y+1)
        else:
            z += 1
    else:
        if a*b>0:
            di[ind] = (x+1, y)
        else:
            di[ind] = (x, y+1)
mod = 10**9+7
ans = 1
for i, j in di.values():
    ans *= (pow(2, i, mod)+pow(2, j, mod)-1)
    ans %= mod
print((ans+z-1)%mod)

Measured memory_bytes: 84596
#include <iostream>
#include <list>
#include <numeric>
#include <string>

#define SIZE_OF_ARRAY(array) (sizeof(array)/sizeof(array[0]))

using namespace std;
 
int main(){
    int n;
    cin >> n;
    int l[n];
    for(int i=0;i<n;i++){
    cin >> l[i];
    }

    int max;
    
    for(int i = 0; i < SIZE_OF_ARRAY(l) ; ++i) {
        if( l[i] > max )
            max = l[i];
    }

    if (max < accumulate(l, l + SIZE_OF_ARRAY(l), 0) - max){
        cout << "Yes"<<endl; 
    }else
    {
        cout << "No"<<endl; 
    }
    
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <complex>
#include <string>
#include <algorithm>
#include <numeric>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#ifndef LOCAL
#define debug(x) ;
#else
#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;

template <typename T1, typename T2>
ostream &operator<<(ostream &out, const pair<T1, T2> &p) {
  out << "{" << p.first << ", " << p.second << "}";
  return out;
}

template <typename T>
ostream &operator<<(ostream &out, const vector<T> &v) {
  out << '{';
  for (const T &item : v) out << item << ", ";
  out << "\b\b}";
  return out;
}
#endif

#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 200010

ll dp[101][50000][2];
int counter[50000];

int main() {
  int N, K;

  cin >> N >> K;

  if (N == 1) {
    cout << 1 << endl;
    return 0;
  }

  int T = 0;

  for (int i=1; i*i<N; i++) T = i;

  int prev = T;
  for (int i=N/T-1; i>=1; i--) {
    counter[i] = N / i - prev;
    prev = N / i;
  }

  for (int i=1; i*i<=N; i++)
    debug(counter[i]);

  for (int i=1; i*i<=N; i++) {
    if (i * i < N) dp[1][i][0] = 1;
    dp[1][i][1] = counter[i];
  }

  for (int i=1; i<K; i++) {
    ll sum = 0;
    for (int j=1; j*j<=N; j++) {
      if (j * j < N) sum = (sum + dp[i][j][0]) % mod;
      if (j * j == N) sum = (sum + dp[i][j][1]) % mod;

      dp[i+1][j][1] = sum * counter[j] % mod;
    }
    for (int j=T; j>=1; j--) {
      sum = (sum + dp[i][j][1]) % mod;
      dp[i+1][j][0] = sum;
    }
  }

  ll ans = 0;

  debug(dp[K-1][1][0]);
  debug(dp[K-1][2][1]);
  debug(dp[K-1][1][1]);

  debug(dp[K][1][0]);
  debug(dp[K][2][1]);
  debug(dp[K][1][1]);

  for (int i=0; i<=T+1; i++) {
    ans += dp[K][i][0] + dp[K][i][1];
  }

  cout << ans % mod << endl;


  return 0;
}

// 4 1, 3 1, 2 1, 2 2, 1 4, 1 3, 1 2, 1 1,


// 1: 1, 2: 1, 3: 2
// 1: 4, 2: 2, 3: 2


Measured memory_bytes: 77696
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int MAX=200005;
const int mod=1e9+7;
//ll a[MAX],x[MAX],b[MAX];
int main()
{
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    double l;
    cin>>l;
    l/=3;
    l=l*l*l;
    cout<<fixed<<setprecision(12)<<l;
}


Measured memory_bytes: 256
n=int(input())

if n%10==1:
    n=n-1+9
elif n%10==9:
    n=n-9+1
    

if int((n%100)/10)==1:
    n=n-10+90
elif int((n%100)/10)==9:
    n=n-90+10


if int(n/100)==1:
    n=n-100+900
elif int(n/100)==9:
    n=n-900+100

print(n)


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

#define For(i, j, k) for(int i = j; i <= k; i++)
#define Forr(i, j, k) for(int i = j; i >= k; i--)

using namespace std;

const int N = 500010;

char S[N];
int n;

set<int> pos;

int main(){
	scanf("%s", S + 1);
	n = strlen(S + 1);
	int ans = 1;
	For(i, 1, n - 1) if(S[i] > S[i + 1]) pos.insert(i);
	For(i, 1, n - 1)
		if(S[i] >= S[i + 1] && pos.size() && S[*pos.begin()] == S[i]){
			if(S[i] > S[i + 1]) pos.erase(i);
			++ans;
			S[n]++;
			int l = i, bound = l;
			S[l] = '0';
			Forr(j, n, l + 1){
				if(S[j] > '9'){
					S[j] = '0';
					S[j - 1]++;
				}
				else{
					bound = j - 1;
					break;
				}
			}
			For(j, bound, n - 1){
				if(S[j] <= S[j + 1] && pos.count(j)) pos.erase(j);
				else if(S[j] > S[j + 1] && !pos.count(j)) pos.insert(j);
			}
		//	printf("%s\n", S + 1);
			i = l - (S[l] > '0');
		}
		else S[i] = '0';
	printf("%d\n", ans);
	return 0;
}

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

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))

template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}

using namespace std;

int n,w,d;
int s[1010],g[1010];

inline int convert(int x,int y){
	if(x==0) return y;
	if(y==d) return d+x;
	if(x==w) return d+w+(d-y);
	if(y==0) return d+w+d+(w-x);
	return 0;
}

int greedy(int n,int start,int all){
	using state=tuple<int,int>;
	vector<state> ary;
	
	rep(i,n){
		bool add=true;

		if(s[i]<=g[i]){
			if(s[i]<=start && start <= g[i]) add=false;
		}else{
			if(start<=g[i]||s[i]<=start) add=false;
		}

		if(add){
			int cs=(s[i]-start+2*all)%all,cg=(g[i]-start+2*all)%all;
			ary.push_back(make_tuple(cg,cs));
		}
	}

	
	sort(_all(ary));	
	int res=1,cur=0;
	
	for(auto &it:ary){
		if(cur<get<1>(it)) 
			cur=get<0>(it),res++;
	}

	return res;
}

int main(void){
	cin >> n >> w >> d;
	rep(i,n){
		int x,y;
		char type;
		cin >> x >> y >> type;

		const int u=d-y,b=y,l=x,r=w-x;

		switch(type){
			case 'N':
				s[i]=(l<=u?convert(0,y+l):convert(x-u,d));
				g[i]=(r<=u?convert(w,y+r):convert(x+u,d));
				break;

			case 'W':
				s[i]=(b<=l?convert(x-b,0):convert(0,y-l));
				g[i]=(u<=l?convert(x-u,d):convert(0,y+l));
				break;

			case 'E':
				s[i]=(u<=r?convert(x+u,d):convert(w,y+r));
				g[i]=(b<=r?convert(x+b,0):convert(w,y-r));
				break;

			case 'S':
				s[i]=(r<=b?convert(w,y-r):convert(x+b,0));
				g[i]=(l<=b?convert(0,y-l):convert(x-b,0));
				break;
		}
	}

	const int all=2*(w+d);

	int ans=n;

	rep(i,n){
		chmin(ans,greedy(n,s[i],all));
		chmin(ans,greedy(n,g[i],all));
	}

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

Measured memory_bytes: 3140
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

ll solve(){
    int n;
    ll k;
    cin >>n >>k;
    vector<ll> a(n);
    rep(i,n) cin >>a[i];

    if(k==1) return 0;

    vector<ll> s(a);
    for(int i=1; i<n; ++i) (s[i] += s[i-1]) %= k;

    map<ll,int> ct;
    rep(i,n) s[i] = (s[i] - (i+1)%k + k)%k;
    rep(i,min(n,(int)k-1)) ++ct[s[i]];

    ll ans = 0;
    ll x = 0;
    rep(i,n){
        if(ct.count(x)) ans += ct[x];

        if(i+k-1<n) ++ct[s[i+k-1]];
        --ct[s[i]];

        (x += a[i]-1) %= k;
    }
    return ans;
}

int main(){
    cout << solve() << "\n";
    return 0;
}


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

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

using namespace std;
using lint=long long;

int main(){
	int n; scanf("%d",&n);
	vector<int> a(n);
	rep(i,n) scanf("%d",&a[i]), a[i]--;

	vector<lint> hist(n);
	rep(i,n) hist[a[i]]++;

	lint res=0;
	rep(i,n) res+=hist[i]*(hist[i]-1)/2;
	rep(i,n) printf("%lld\n",res-hist[a[i]]*(hist[a[i]]-1)/2+(hist[a[i]]-1)*(hist[a[i]]-2)/2);

	return 0;
}


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

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

   int cnt = 0;

   if (s[0] == 'R')
   {
      cnt++;

      if (s[1] == 'R')
      {
         cnt++;

         if (s[2] == 'R')
         {
            cnt++;
         }
      }
   }
   else
   {
      if (s[1] == 'R')
      {
         cnt++;
      }

      if (s[2] == 'R')
      {
         cnt++;
      }
   }

   cout << cnt;

   return 0;
}

Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define N 10010
const ll mod=1e9+7;
vector<int>e[N];
int d[N],c[N];
int in[N];
int vis[N];
int k=2,ans=0;
bool cmp(int a,int b)
{
    return a>b;
}
void dfs(int x)
{
    int n=e[x].size();
    for(int i=0;i<n;i++)
    {
        int to=e[x][i];
       if(vis[to])continue;
       vis[to]=1;

       ans+=c[k++];

       d[to]=c[k-1];

       dfs(to);
    }
}
int main()
{
   int n,u,v;
   scanf("%d",&n);
   int ma=0,pos;
    for(int i=1;i<n;i++)
    {
        scanf("%d%d",&u,&v);
        in[u]++,in[v]++;
        e[u].push_back(v);
        e[v].push_back(u);

        if(ma<in[u])
            pos=u,ma=in[u];
        if(ma<in[v])
            pos=v,ma=in[v];
    }
    for(int i=1;i<=n;i++)
        scanf("%d",&c[i]);
    sort(c+1,c+1+n,cmp);
    vis[pos]=1;
    d[pos]=c[1];
    dfs(pos);
    printf("%d\n",ans);
    for(int i=1;i<=n;i++)
        printf("%d ",d[i]);
    return 0;
}


Measured memory_bytes: 1152
#include<iostream>
#include<vector>
using namespace std;
typedef long long ll;

int main(){
    int n; cin>>n;
    vector<ll> a(n);
    ll sum=0;
    for(int i=0;i<n;i++){
        cin>>a[i];
        sum+=a[i];
    } 
    
    ll ans=sum,t=0;
    for(int i=0;i<n;i++){
        t+=a[i];
        ans=min(ans,abs(t-(sum-t)));
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 1920
n = gets.to_i
hs = gets.strip.split.map(&:to_i)

# 右から見ていって、自分より右側にあるものの最小値を覚えておく
# 自分を1下げた時、自分より右側に自分より小さいものがあればダメ

arr = []
min = 10 ** 10

hs.each_with_index.reverse_each do |v, i|
    min = v if min > v
    arr << min
end

arr.reverse!

puts hs.each_with_index.map {|v, i| v - 1 <= arr[i]}.all? ? "Yes" : "No"

Measured memory_bytes: 16384
#!/usr/bin/ruby

def measurePoints(r, t)
  (r / 100) + (t / 30) * 5
end

def nearTR(tr,tr_flag)
  a = Array.new
  if tr_flag == 't'
    devide = 30
  elsif tr_flag == 'r'
    devide = 100
  else
    raise "unexpected flag"
  end

  if (tr % devide) == 0
    a << tr
  else
    sh = tr / devide * devide
    a << sh
    a << sh + devide
  end
  a
end

n = STDIN.gets.chomp.to_i

n.times do
  r, t = STDIN.gets.chomp.split(/\s+/).map(&:to_i)

  rP = nearTR(r,'r')
  tP = nearTR(t,'t')

  ans = Array.new
  rP.each do |rp|
    tP.each do |tp|
      ans << measurePoints(rp,tp)
    end
  end

  puts ans.sort.join(" ")
end

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

#define rep(i,n) for(long long i=0; i<(long long)(n);i++)
#define rep2(i,s,n) for(long long i=(s); i<(long long)(n);i++)

#define mod 1e9+7;
#define inf 1e18+7;

typedef long long ll;


int main() {
    int n;cin>>n;
    int ans=pow(n,2);
    cout<<ans<<endl;

}



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

//-----------------------------------------------
int mod=2019;
//------------------------------------------------
int main(){
  int l,r,ans,a;
  cin>>l>>r;
  ans=2018;
  rep(i,l,r){
    if(r/673-l/673>0){
      ans=0;
      break;
    }
    rep(k,i+1,r+1){
      a=(i%mod) * (k%mod);
      ans=min(ans,a%mod);
      if(ans==0) break;
    }
  }
cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <vector>
#include <sstream>
#include <iomanip>
using namespace std;

int main(void){
    long long int n, a, b;
    long long int ans;
    cin >> n >> a >> b;
    if((b-a)%2 == 0)
        ans = (b-a)/2;
    else{
        long long int check = min(a-1, n-b);
        ans = check + 1 + ((b-a)-1)/2;
    }
        
    cout << ans << endl;
        
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int r = sc.nextInt();
		sc.close();
		
		if(r < 1200) {
			System.out.println("ABC");
		} else if(r < 2800) {
			System.out.println("ARC");
		} else {
			System.out.println("AGC");
		}
	}

}

Measured memory_bytes: 23636
def _main(n):
    codes = "abcdefghijklmnopqrstuvwxyz"
    b = len(codes)
    values = ""
    while True:
        n -= 1
        values += codes[int(n % b)]
        n, mod = divmod(n, b)
        if n == 0:
            print(values[::-1])
            break


def _entry():
    n = int(input())
    _main(n)


if __name__ == "__main__":
    _entry()


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

#define ff first
#define ss second
#define mp make_pair

using namespace std;

typedef long long ll;

vector<int> G[1005];
int vis[1005], pass, vis2[1005];
int p[1005], pcerto[1005];
pair<bool,int> dp[1005];

pair<bool, int> dfs(int v, bool fst) {
	if(v == pass && !fst) return {true, 1};
	if(vis[v] == pass) return dp[v];
	vis[v] = pass;
	vis2[v] = 1;

	int ans = 1e9;
	for(int x : G[v]) {
		if(vis2[x] == 1 && x != pass) continue;
		auto res = dfs(x,0);
		if(res.ff) {
			if(res.ss+1 < ans)
				p[v] = x;
			ans = min(res.ss+1, ans);
		}
	}

	vis2[v] = 2;
	return dp[v] = {ans != 1e9, ans};
}

vector<int> vec;

int main() {
    int n,m,a,b;

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

    for(int i = 0; i < m; i++) {
    	scanf("%d%d", &a, &b);
    	G[a].push_back(b);
    }

    int ans = 1e9, me;
    for(int i = 1; i <= n; i++) {
    	pass = i;
    	memset(vis2, 0, sizeof vis2);
    	auto res = dfs(i, 1);
    	if(res.ff) {
			if(res.ss < ans) {
				me = i;
				for(int i = 1; i <= n; i++)
					pcerto[i] = p[i];
			}
			ans = min(res.ss, ans);
		}
    }

    if(ans != 1e9) {
		int tmp = me;
		vec.push_back(tmp);
		tmp = pcerto[tmp];
		while(tmp != me) {
			vec.push_back(tmp);
			tmp = pcerto[tmp];
		}
		printf("%d\n", (int)vec.size());
		for(int a : vec)
			printf("%d\n", a);
	}
	else printf("-1\n");

    return 0;
}


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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define ALL(a)     (a).begin(),(a).end()
#define VI         vector<int>
#define MOD 1000000007

typedef long long int ll;

const ll INF=(ll)1e19;
//const int INF=(1<<30);


int main(){
  int d,g;
  cin >> d >> g;

  VI p(d),c(d);

  REP(i,d){
    cin >> p[i] >> c[i];
  }

  int ans = 10000000;

  REP(i,(1<<d)){
    int ii=i;

    int score=0;
    int cnt=0;
    int ma = -1;
    REP(j,d){
      if( (ii>>j) &1){
        score += 100*(j+1)*p[j]+c[j];
        cnt += p[j];
      }else{
        ma = j;
      }
    }

    if(score<g){
      if(((g-score)+(100*(ma+1))-1)/(100*(ma+1)) < p[ma]){
        cnt += ((g-score)+(100*(ma+1))-1)/(100*(ma+1));
        ans = min(ans,cnt);
      }
    }else{
      ans = min(ans,cnt);
    }
  }
  cout << ans << endl;
}




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

const int MAXN = 2e5+10;
int n, a[MAXN], b[MAXN];
vector<pair<int,int>> as;
int ans[MAXN];

int main(){
  cin.tie(0); ios_base::sync_with_stdio(0);
  cin >> n;
  for(int i=0;i<n;i++) cin >> a[i];
  for(int i=0;i<n;i++) cin >> b[i];
  for(int i=0;i<n;i++) {
    as.push_back({a[i], i});
  }
  sort(as.begin(), as.end());
  sort(b, b+n);
  reverse(b, b+n);
  int same = -1;
  int scnt = 0;
  bool pos = true;
  for(int i=0;i<n;i++) {
    if (as[i].first==b[i]) {
      same = b[i];
      scnt++;
    }
  }
  for(int i=0;i<n;i++) {
    ans[as[i].second] = b[i];
  }
  if (same != -1) {
    vector<int> other;
    for(int i=0;i<n;i++) {
      if (as[i].first!=same && b[i]!=same) {
        other.push_back(i);
      }
    }
    if (other.size()<same) pos = false;
    else {
      for(int i=0;i<n;i++) {
        if (as[i].first==b[i]) { // swap this pairing with other.back()
          swap(ans[as[i].second], ans[other.back()]);
          other.pop_back();
        }
      }
    }
  }
  if (pos) {
    cout << "Yes" <<endl;
    for(int i=0;i<n;i++) cout << ans[i] << " "; 
    cout <<endl;
  }
  else {
    cout << "No" <<endl;
  }
}


Measured memory_bytes: 8916
package main

import "fmt"

func main() {
	var n int
	fmt.Scan(&n)

	a := make([]int, n)
	var slim []int
	for i := 0; i < n; i++ {
		fmt.Scan(&a[i])
		if i > 0 {
			if a[i] != a[i-1] {
				slim = append(slim, a[i])
			}
			continue
		}
		slim = append(slim, a[i])
	}
	slim = append(slim, 0)

	kabu := 0
	cash := 1000

	for i := 0; i < len(slim)-1; i++ {
		// if i == len(slim) - 1 {
		// 	if slim[i] > slim[i-1] {
		// 		cash += slim[i] * kabu
		// 		continue
		// 	}
		// 	cash += slim[i-1] * kabu
		// 	continue
		// }
		if slim[i] > slim[i+1] {
			if kabu > 0 {
				// 売る
				cash += slim[i] * kabu
				kabu = 0
			}
		} else {
			if kabu == 0 {
				// 買う
				kabu = cash / slim[i]
				cash = cash % slim[i]
			}
		}
	}
	fmt.Println(cash)

}


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

int H, W;

int main() {
  cin >> H >> W;
  int x = 0;
  for(int i = 0; i < H * W; ++i) {
    char A; cin >> A; x += A == '#';
  }
  cout << (x == H + W - 1 ? "Possible" : "Impossible") << endl;
  return 0;
}


Measured memory_bytes: 256