akhauriyash/Code-Regression huggingface dataset:
def main23():
    strbuf = input("");
    flag = [];
    for i in range(4):
        flag.append(False);
    for i in range(len(strbuf)):
        if strbuf[i] == 'N':
            flag[0] = True;
        if strbuf[i] == 'W':
            flag[1] = True;
        if strbuf[i] == 'S':
            flag[2] = True;
        if strbuf[i] == 'E':
            flag[3] = True;
    if (flag[0] and not(flag[2])) or (flag[2] and not(flag[0])):
        print("No");
    elif (flag[1] and not(flag[3])) or (flag[3] and not(flag[1])):
        print("No");
    else:
        print("Yes");

if __name__ == '__main__':
    main23()

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define ll long long int
#define yorn(f) cout << ((f) ? "Yes" : "No") << endl;
#define YORN(f) cout << ((f) ? "YES" : "NO") << endl;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define println(x) cout << x << endl;
using namespace std;
int main()
{
    int n;
    cin >> n;
    vector<string> s(n);
    rep(i, n) cin >> s[i];
    
    auto c = vector<int>({0, 0, 0, 0});
    rep(i, n)
    {
        if ("AC" == s[i])
        {
            c[0]++;
        }
        if ("WA" == s[i])
        {
            c[1]++;
        }
        if ("TLE" == s[i])
        {
            c[2]++;
        }
        if ("RE" == s[i])
        {
            c[3]++;
        }
    }

    cout << "AC x " << c[0] << endl;
    cout << "WA x " << c[1] << endl;
    cout << "TLE x " << c[2] << endl;
    cout << "RE x " << c[3] << endl;
    return 0;
}

Measured memory_bytes: 6408
#include <iostream>
#include <cstdint>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <unordered_set>
#pragma GCC optimize("Ofast")

using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int, int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define irep(it, stl) for (auto it = stl.begin(); it != stl.end(); it++)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define mes(a) cout << (a) << endl
#define dmes(a, b) cout << (a) << " " << (b) << endl

#define CHOOSE(a) CHOOSE2 a
#define CHOOSE2(a0,a1,a2,a3,a4,x,...) x
#define debug_1(x1) cout<<#x1<<": "<<x1<<endl
#define debug_2(x1,x2) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<endl
#define debug_3(x1,x2,x3) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<endl
#define debug_4(x1,x2,x3,x4) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<", "#x4<<": "<<x4<<endl
#define debug_5(x1,x2,x3,x4,x5) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<", "#x4<<": "<<x4<<", "#x5<<": "<<x5<<endl
#define debug(...) CHOOSE((__VA_ARGS__,debug_5,debug_4,debug_3,debug_2,debug_1,~))(__VA_ARGS__)

#define ynmes(a) (a) ? mes("Yes") : mes("No")
#define YNmes(a) (a) ? mes("YES") : mes("NO")
#define re0 return 0
#define mp(p, q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define rSort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define itn int;
int dx[8] = { 1, 0, -1, 0, 1, -1, -1, 1 };
int dy[8] = { 0, 1, 0, -1, 1, 1, -1, -1 };
template <class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template <class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
struct io { io() { ios::sync_with_stdio(false); cin.tie(0); } };
const int INF = INT_MAX;
const ll LLINF = 1LL << 60;
const ll MOD = 1000000007;
const double EPS = 1e-9;

signed main() {
    ll n, m;
    cin >> n >> m;
    
    vll a(n), b(n), c(m), d(m);
    rep(i, n) {
        cin >> a[i] >> b[i];
    }
    rep(i, m) {
        cin >> c[i] >> d[i];
    }
    
    ll r;
    
    rep(i, n) {
        ll tmp = 1e9;
        rep(j, m) {
            ll x = abs(a[i]-c[j])+ abs(b[i]-d[j]);
            if (x < tmp) {
                tmp = x;
                r = j+1;
            }
            
        }
        
        mes(r);
    }

    
    
    
}


Measured memory_bytes: 3628
#include <stdio.h>

int main(void)
{
    int a, b, c;
    int i, count=0;

    scanf("%d %d %d", &a, &b, &c);

    for(i=a;i<=b;i++){
        if((c % i) == 0){count++;}
    }
    printf("%d\n", count);
    return 0;
}

Measured memory_bytes: 596
class UnionFind:
    def __init__(self, n):
        self.N      = N
        self.depth  = [0] * N
        self.parent = list(range(N))

    def find(self, x):
        if x == self.parent[x]:
            return x
        self.parent[x] = self.find(self.parent[x])
        return self.parent[x]

    def unite(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        if self.depth[x] < self.depth[y]:
            self.parent[x] = y
        else:
            self.parent[y] = x
            if self.depth[x] == self.depth[y]:
                self.depth[x] += 1

    def are_same(self, x, y):
        return self.find(x) == self.find(y)

    def is_root(self, x):
        return x == self.find(x)

    def num_tree(self):
        return sum([self.is_root(i) for i in range(self.N)])


N, M = map(int, input().split())

T = UnionFind(N)

for m in range(M):
    X, Y, Z  = map(int, input().split())
    T.unite(X-1, Y-1)

print(T.num_tree())


Measured memory_bytes: 9972
#include<stdio.h>
#include<string.h>
int main()
{
    char a[11],b[11],c[11];
    scanf("%s",a);
    scanf("%s",b);
    scanf("%s",c);
    int l=strlen(a),m=strlen(b);
    if(a[l-1]==b[0]&&b[m-1]==c[0]) printf("YES\n");
    else printf("NO\n");
    return 0;
}


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

int main(){
    int n,m;
    cin>>n;
    vector<string>s(n);
    for(int i=0;i<n;i++){
        cin>>s.at(i);
        }

    cin>>m;
    vector<string>t(m);
    for(int i=0;i<m;i++){
        cin>>t.at(i);
        }
    int ans=0;
    for(int i=0;i<n;i++){
        int count;
        count=0;
        for(int j=0;j<n;j++){
            if(s.at(i)==s.at(j)){
                count++;
                }
            }
        for(int k=0;k<m;k++){
            if(s.at(i)==t.at(k)){
                count--;
                }
            }
        ans=max(count,ans);
        }
        cout<<ans<<endl;
    }


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

const int maxn = 1e5+5;
int n, m;
string ss;

int dp[maxn], nxt[maxn];

int main() {
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    cin >> n >> m;
    cin >> ss;
    set<pair<int,int>> s;
    s.insert({0,n});
    for (int i = n-1; i >= 0; i--) {
        if (ss[i] == '0' && !s.empty()) {
            auto p = *s.begin();
            dp[i] = p.first + 1;
            nxt[i] = p.second;
            s.insert({dp[i],i});
            /*
            cout << i << ": " << dp[i] << '\n';
            cout << "nxt = " << nxt[i] << '\n';
            */
        }
        if (i+m <= n && s.count({dp[i+m],i+m})) {
            s.erase({dp[i+m],i+m});
        }
    }
    if (nxt[0] != 0) {
        int cur = 0;
        while (true) {
            int next = nxt[cur];
            cout << next-cur << ' ';
            cur = next;
            if (cur == n) break;
        }
        cout << '\n';
    }
    else {
        cout << -1 << '\n';
    }
}



Measured memory_bytes: 3712
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define pi 3.1415926536
#define pb push_back
#define N 1000000007
#define M 998244353
int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    ll n,i,ans = 0,j,x,y,k;
    cin>>n;
    if(n < 10 || n%2 == 1) cout<<0;
    else{
    	ll count = 0;
		x = 5;
		n = n/2;
    	while(x <= n){
    		ans = ans + n/x;
    		x = x*5;
    		count++;
		}
		cout<<ans<<endl;
    	
	}
    
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
int main(){
    string s;
    cin >> s;
    int cnt1=0,cnt2=0;
   if(s[2]!=s[3] || s[4]!=s[5]){
    cout <<"No";
   } 
   else if(s[2]==s[3] && s[4]==s[5]){
     cout <<"Yes";
   }
   else cout <<"No";
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void) {

	int i;
	int k, n;
	char s[100000];

	scanf("%d", &n);

	scanf("%s", s);

	scanf("%d", &k);

	for (i = 0; s[i] != '\0'; i++) {
		if (s[i] != s[k - 1])s[i] = '*';
		printf("%c", s[i]);
	}

	printf("\n");

	return 0;
}

Measured memory_bytes: 128
// https://atcoder.jp/contests/abc129/tasks/abc129_e

#include <bits/stdc++.h>

using namespace std;

#define REP(i,n)   for(int i=0; i<(int)(n); i++)
#define FOR(i,b,e) for(int i=(b); i<=(int)(e); i++)
#define DUMP(a, n) REP(_i, n) printf("%d%c", a[_i], _i + 1 == n ? '\n' : ' ')
#define DUMP2D(a, n, m) REP(_i, n) REP(_j, m) printf("%d%c", a[_i][_j], _j + 1 == m ? '\n' : ' '); puts("")

const int L_MAX = 100'001;
const int MOD = 1e9+7;

char L[L_MAX + 1];

int N;
int dp[L_MAX + 1][2];

void solve() {
  N = strlen(L);
  dp[0][0] = 1;
  REP(i, N) {
    int d = L[i] - '0';
    REP(smaller, 2) REP(j, smaller || d ? 3 : 1) {
      int smaller2 = smaller || j < d;
      dp[i + 1][smaller2] = (dp[i + 1][smaller2] + dp[i][smaller]) % MOD;
    }
  }
  // DUMP2D(dp, N + 1, 2);
  int ans = (dp[N][0] + dp[N][1]) % MOD;
  printf("%d\n", ans);
}

void input() {
  scanf("%s", L);
}

int main() {
  input();
  solve();
  return 0;
}


Measured memory_bytes: 1152
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
const ll M = 1e18;
int si[] = {-1, 0, 1, 0};
int sj[] = {0, -1, 0, 1};


int main() {
  int h1, m1, h2, m2, k;
  cin >> h1 >> m1 >> h2 >> m2 >> k;

  cout << h2 * 60 + m2 - h1 * 60 - m1 - k << endl;
  return 0;
}


Measured memory_bytes: 3584
#![allow(unused_imports)]
#![allow(unused_macros)]
#![allow(non_snake_case)]
#![allow(dead_code)]
#![allow(unused_variables)]
#![allow(unused_mut)]
#![allow(unused_assignments)]
use proconio::input;
use proconio::marker::Usize1;
use std::collections::*;
use std::cmp::*;
use std::f64::consts::*;

const MOD: u64 = 1000000007;
const INF: usize = std::usize::MAX / 4;

fn main() {
    input! {
        N: usize,
        S: [String; N],
    }

    let mut cnt: HashMap<String, usize> = HashMap::new();
    for s in S {
        *cnt.entry(s).or_insert(0) += 1;
    }

    println!("{}", cnt.keys().len());
}


Measured memory_bytes: 28032
#include <bits/stdc++.h>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<P,int> PP;
typedef pair<int,P> IP;

int n;
string s[1005];
vector<PP> G[1005][16];
int dist[1005][16];

int main(void){
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		cin >> s[i];
	}
	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++){
			for(int k=0;k<s[i].size();k++){
				if(i==j && k==0)continue;
				bool sam=true;
				for(int l=0;l<min(s[i].size()-k,s[j].size());l++){
					if(s[i][l+k]!=s[j][l]){
						sam=false;
						break;
					}
				}
				if(sam){
					if((s[i].size()-k)==(s[j].size())){
						G[i][k].push_back(PP(P(n,0),min(s[i].size()-k,s[j].size())));
					}
					if((s[i].size()-k)<(s[j].size())){
						G[i][k].push_back(PP(P(j,s[i].size()-k),min(s[i].size()-k,s[j].size())));
					}
					if((s[i].size()-k)>(s[j].size())){
						G[i][k].push_back(PP(P(i,k+s[j].size()),min(s[i].size()-k,s[j].size())));
					}
				}
			}
		}
	}
	for(int i=0;i<=n;i++){
		for(int j=0;j<16;j++){
			dist[i][j]=1<<30;
		}
	}
	priority_queue<IP,vector<IP>,greater<IP> > que;
	for(int i=0;i<n;i++){
		que.push(IP(0,P(i,0)));
		dist[i][0]=0;
	}
	while(que.size()){
		IP p=que.top();
		que.pop();
		if(p.first>dist[p.second.first][p.second.second])continue;
		for(int i=0;i<G[p.second.first][p.second.second].size();i++){
			PP e=G[p.second.first][p.second.second][i];
			if(dist[e.first.first][e.first.second]>dist[p.second.first][p.second.second]+e.second){
				dist[e.first.first][e.first.second]=dist[p.second.first][p.second.second]+e.second;
				que.push(IP(dist[e.first.first][e.first.second],e.first));
			}
		}
	}
	if(dist[n][0]==(1<<30)){
		printf("0\n");
	}else{
		printf("%d\n",dist[n][0]);
	}
	return 0;
}



Measured memory_bytes: 20304
import math
K = int(input())
count = 0
for i in range(1, K+1):
  for j in range(1, K+1):
    x=math.gcd(i, j)
    for k in range(1, K+1):
      _gcd=math.gcd(x, k)
      count += _gcd
print(count)

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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ull mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

template < typename T >
void vprint(T &v){
	REP(i, v.size()){
		cout << v[i] << " ";
	}
	cout << endl;
}

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

    string S;
    cin >> S;
    ll res = 0;
    REP(i, S.size()){
    	REP(j, S.size()){
    		if(i>j) continue;
    		string T = S.substr(i, j-i+1);
    		bool flag = true;
    		REP(k, T.size()){
    			if(T[k] != 'A' && T[k] != 'C' && T[k] != 'G' && T[k] != 'T') flag = false;
    		}
    		if(flag) res = max(res, (ll)T.size());
    	}
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> T;

string S;
int x, y;
bool dpx[8001][16010] = {{0}};
bool dpy[8001][16010] = {{0}};

int main(void){
    
    cin >> S;
	scanf("%d %d", &x, &y);
	x += 8000, y += 8000;
	
	vector<int> vx, vy;
	int cnt = 0, sum = 0;
	for(int i = 0; i < S.size(); ++i){
	    if(S[i] == 'T'){
	        ++cnt;
	        if(sum == 0) continue;
	        (cnt % 2 == 1) ? vx.push_back(sum) : vy.push_back(sum);
	        sum = 0;
	    }
	    else ++sum;
	}
	(cnt % 2 == 0) ? vx.push_back(sum) : vy.push_back(sum);
	
	for(int i = 0; i < vx.size(); ++i){
	    if(i){
	        for(int j = 0; j < 16010; ++j){
	            if(dpx[i - 1][j]) dpx[i][j - vx[i]] = true;
	            if(dpx[i - 1][j]) dpx[i][j + vx[i]] = true;
	        } 
	    }
	    else dpx[0][8000 + vx[i]] = (S.front() == 'T') ? dpx[0][8000 - vx[i]] = true : true;
	}
	
	for(int i = 0; i < vy.size(); ++i){
	    if(i){
	        for(int j = 0; j < 16010; ++j){
	            if(dpy[i - 1][j]) dpy[i][j - vy[i]] = true;
	            if(dpy[i - 1][j]) dpy[i][j + vy[i]] = true;
	        } 
	    }
	    else dpy[0][8000 + vy[i]] = dpy[0][8000 - vy[i]] = true;
	}
	dpx[0][8000] = dpy[0][8000] = true;
	
	if(vx.size() == 0 && vy.size() != 0 && dpx[0][x] && dpy[vy.size() - 1][y]) printf("Yes\n");
	else if(vx.size() != 0 && vy.size() == 0 && dpx[vx.size() - 1][x] && dpy[0][y]) printf("Yes\n");
	else if(vx.size() == 0 && vy.size() == 0 && dpx[0][x] && dpy[0][y]) printf("Yes\n");
	else if(vx.size() != 0 && vy.size() != 0 && dpx[vx.size() - 1][x] && dpy[vy.size() - 1][y]) printf("Yes\n");
	else printf("No\n");
	
    return 0;
}


Measured memory_bytes: 64256
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<vector>

using namespace std;

const int maxn = 2e5;

int n, a[maxn + 5], b[maxn + 5];
int l[maxn + 5], r[maxn + 5];
int ans[maxn + 5];

int main()
{
	scanf("%d", &n);
	for (int i = 1; i <= n; ++i)scanf("%d", &a[i]);
	for (int i = 1; i <= n; ++i)scanf("%d", &b[i]);
	for (int i = 1; i <= n; ++i)r[a[i]] = i;
	for (int i = n; i > 0; --i)l[b[i]] = i;
	int res = 0;
	for (int i = 1; i <= n; ++i)if (l[i] && r[i])res = max(res, r[i] - l[i] + 1);
	for (int i = 1; i <= n; ++i) {
		int npos = i + res;
		if (npos > n)npos -= n;
		ans[npos] = b[i];
	}
	for (int i = 1; i <= n; ++i) {
		if (a[i] == ans[i]) {
			printf("No\n");
			return 0;
		}
	}
	printf("Yes\n");
	for (int i = 1; i <= n; ++i)printf("%d%c", ans[i], " \n"[i == n]);
	return 0;
}

Measured memory_bytes: 7660
import numpy as np
A,B,H,M= map(int,input().split())

md = (M % 60) * 6 # deg
hd = (H % 12) * 30 + M * 0.5 # deg

cos2 = np.cos((hd - md) * np.pi / 180)

C2 = A**2 + B**2 - 2*A*B*cos2
print(C2**0.5)






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

long long sum , n ;
int a[100000];

int main()
{
    cin >> n;
    for ( int i = 0 ; i < n * 2  ; i ++)
    {
        cin >> a[i];
    }
    sort(a , a+n*2);
    for ( int i = 0 ; i < n * 2;i+=2){
        sum += min ( a[i] , a[i+1]);
    }
    cout << sum << endl;
    return 0;
}


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

int main()
{
  string s;
  cin >> s;
  bool ok = true;
  bool clear = false;
  string check = "keyence";
  int i, j;
  j = 0;
  for(i = 0; i < 7; i++)
  {
    if(s.at(i) != check.at(i))ok = false;
  }
  if(ok)clear = true;
  ok = true;
  for(i = 0; i < 7; i++)
  {
    if(s.at(s.size()-7+i) != check.at(i))ok = false;
  }
  if(ok)clear = true;
  for(j = 0; j < 6; j++)
  {
    ok = true;
    for(i = 0; i < 7; i++)
    {
      if(i > j)
      {
        if(s.at(s.size()-7+i) != check.at(i))ok = false;
      }
      else
      {
        if(s.at(i) != check.at(i))ok = false;
      }
    }
    if(ok)clear = true;
  }
  if(clear)cout << "YES" << endl;
  else cout << "NO" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (ll i = 0; i < n; ++i)
#define sz(x) int(x.size())
#define ALL(c) (c).begin(), (c).end()
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end())
#define FORV(i, v) for (auto i = v.begin(); i != v.end(); i++)
using namespace std;

using ll = long long;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
const int INF = 1001001001;
const long long INFLL = LLONG_MAX / 3;
const double eps = (1e-9);

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

  ll n, m;
  cin >> n >> m;
  vector<vector<pair<ll, ll>>> a(n, vector<pair<ll, ll>>());
  rep(i, m) {
    ll l, r, d; cin >> l >> r >> d; l--, r--;
    a[l].emplace_back(r, d);
    a[r].emplace_back(l, -d);
  }

  set<ll> nodes;    // 座標が決まっていない人
  rep(i, n) nodes.insert(i);

  vector<ll> d(n, INFLL);   // 座標が決まってなければ INFLL

  while (!nodes.empty()) {
    ll i = *nodes.begin();
    nodes.erase(i);
    d[i] = 0;
    queue<ll> q;
    q.push(i);
    while (!q.empty()) {
      ll id = q.front(); q.pop();
      for (auto& p : a[id]) {   // first: id, second: d[id] からの距離
        if (d[p.first] == INFLL) {
          d[p.first] = d[id] + p.second;
          q.push(p.first);
          nodes.erase(p.first);
        } else if (d[p.first] != d[id] + p.second) {
          puts("No");
          return 0;
        }
      }
    }
  }

  puts("Yes");

  return 0;
}


Measured memory_bytes: 18176
N=int(input())
A=list(map(int, input().split()))
B=list(map(int, input().split()))
C=list(map(int, input().split()))

total=0
for i in range(N):
  total+=B[A[i]-1]
  if i>0 and A[i-1]+1==A[i]:
    total+=C[A[i-1]-1]
print(total)

Measured memory_bytes: 3064
#include <math.h>
#include <stdio.h>
#include <string.h>
int max(int x, int y) {
	return x > y ? x : y;
}
int main() {
	char s[100000];
	int a = 0, b = 0, c = 0;
	scanf("%s", s);
	int len = strlen(s);
	for (int i = 0; i < len; i++) {
		if (s[i] == 'a') {
			a++;
		} else if (s[i] == 'b') {
			b++;
		} else {
			c++;
		}
	}
	if (abs(a - b) <= 1 && abs(b - c) <= 1 && abs(c - a) <= 1) {
		printf("YES\n");
	} else {
		printf("NO\n");
	}
	return 0;
}

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

#ifdef LOCAL_PC
	#define debug(args...) { cout.flush(); fflush(stdout); fprintf(stderr, args); }
#else
	#define debug(args...) ; /*  */
#endif
#define pb push_back
#define eb emplace_back
#define mk make_pair
#define fi first
#define se second
using ll = long long;
using pii = pair<int, int>;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template<class Ty> Ty rnd(Ty a, Ty b) { return uniform_int_distribution<Ty>(a, b)(rng); }

template<class num> inline void rd(num &x) {
	char c; while(isspace(c = getchar()));
	bool neg = false;
	if(!isdigit(c)) neg = (c == '-'), x = 0;
	else x = c - '0';
	while(isdigit(c = getchar()))
		x = (x << 3) + (x << 1) + c - '0';
	if (neg) x = -x;
} template <class T, class... Args> inline void rd(T& x, Args&... args) { rd(x); rd(args...); }

const int MAXN = 2e5 + 5, INF = 0x3f3f3f3f;

int main() {
	//ios::sync_with_stdio(false); cin.tie(NULL);
	 ll n, k; rd(n, k);
	 vector<int> par(n+1);
	 for (int i = 1; i <= n; i++) rd(par[i]);

	 vector<int> vis(n+1);
	 vector<int> cycle;
	 vector<int> pos(n+1);
	
	 int last = 1;
	 for (int u = 1;; u = par[u]) {
		  if (vis[u]) {
				last = u;
				break;
		  }
		  cycle.eb(u);
		  pos[u] = cycle.size() - 1;
		  vis[u] = true;
	 }

	 if (k < (int) cycle.size()) printf("%d\n", cycle[k]);
	 else {
			k -= pos[last];
			k %= cycle.size() - (pos[last]);
			printf("%d\n", cycle[pos[last] + k]);
	 }
}


Measured memory_bytes: 6608
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    x = int(readline())

    if x == 1:
        print(0)
    else:
        print(1)


if __name__ == '__main__':
    main()


Measured memory_bytes: 61680
#include <iostream>
#include <algorithm>
#include <climits>
#include <numeric>
#include <iomanip>
#include <cmath>
#include <vector>
#include <set>
#include <unordered_set>
#include <string>
#include <queue>
#include <deque>
#include <stack>
#include <cstring>
#include <map>
#include <unordered_map>
#include <tuple>
 
using namespace std;
 
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
#define umap unordered_map
#define uset unordered_set
#define cina(s, n, a) for(int i = s; i < n; i++) cin >> a[i]
#define couta(s, n, a) for(int i = s; i < n; i++) cout << a[i] << ' '
#define copy(s, n, a, b) for(int i = s; i < n; i++) b[i] = a[i]
#define yesno(ok) cout << (ok ? "YES\n" : "NO\n")
#define mod(a, b) (b + (a % b)) % b
#define MOD (int)1e9 + 7
 
typedef long long ll;
typedef unsigned long long ull;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;

void add_self (int& a, int b){ a += b; if (a >= MOD) a -= MOD; }
//-------------------------------------------------------------------------------------------------------//

void solve(){
    int n;
    cin >> n;
    vll a(n);
    cina(0, n, a);
    ll ans = INT_MAX;
    for(int i = 1; i <= 100; i++){
        ll tmp = 0;
        for(int j = 0; j < n; j++){
            tmp += (a[j] - i) * (a[j] - i);
        }
        ans = min(ans, tmp);
    }
    cout << ans;
}

int main(){
    ios::sync_with_stdio(false);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    int q = 1;
    //cin >> q;
    for(int i = 1; i <= q; i++){
        solve();
    }
}


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

int main(void)
{
  int i, n;
  cin >> n;
  long long r[n], max = 0, min = 1000000000, diff = -1000000000;
  for (i = 0; i < n; i++) {
    cin >> r[i];
  }
  for (i = 0; i < n; i++) {
    if (i == 0) {
      max = r[i];
      min = r[i];
      continue;
    }
    if ((r[i] - min) > diff) diff = r[i] - min;
    if (r[i] < min) min = r[i];
  }
  cout << diff << endl;
  return 0;
}

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

int main() {
    long n;
    cin >> n;
    vector<long> h(5);
    for(long i=0; i<5; i++){
        cin >> h.at(i);
    }
    sort(h.begin(), h.end());
    if(h.at(0) >= n){
        cout << 5 << endl;
    }
    else{
        cout << (n + h.at(0) - 1) / h.at(0) + 4 << endl;
    }

}

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

long long gcd(long long a, long long b)
{
    while(a&&b)
    {
        if(a>b) a%= b;
        else b %= a;
    }
    return a+b;
}

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


int main(void)
{
    long long a, b, c, d;
    cin >> a >> b >> c >> d;

    long long lcm_cd = lcm(c, d);
    long long count_c = b/c - (a-1)/c;
    long long count_d = b/d - (a-1)/d;
    long long count_lcm = b / lcm_cd - (a-1)/lcm_cd;
    cout << b-a+1-(count_c+count_d-count_lcm) << endl;
}

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

#define ll long long
#define vecll vector<long long>
#define vec2ll vector<vector<long long>>
#define vecbool vector<bool>
#define vecpairll vector<pair<long long,long long>>
#define forll(s,a,b) for(long long s = a;s < b;s++)
#define forllde(s,a) for(long long s = a;s > 0;s--)


int main()
{
  ll n, m, c;
  cin >> n >> m;
  vecll x(m);
  vecll l(m-1);
  forll(i, 0, m)
	cin >> x[i];
  if (n >= m){
	cout << 0 << endl;
	return 0;
  }
  sort(x.begin(), x.end());
  c = x[x.size()-1] - x[0];
  forll(i, 0, m-1)
	l[i] = x[i + 1] - x[i];
  sort(l.begin(), l.end());
  forll(i, 0, n-1){
	c -= l[l.size() - 1];
	l.pop_back();
  }

  cout << c << endl;
}



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

int main(){
    int n; cin>>n;
    int p[100010];
    p[0]=p[n+1]=0;
    for(int i=1;i<=n;i++){
        cin>>p[i];
    }
    int d[100010],dsum=0;
    for(int i=0;i<=n;i++){
        d[i]=abs(p[i+1]-p[i]);
        dsum+=d[i];
    }
    for(int i=1;i<=n;i++){
        cout<<dsum-d[i]-d[i-1]+abs(p[i-1]-p[i+1])<<endl;
    }
}


Measured memory_bytes: 2048
i = input()
list1 = i.split()
tmpA = list1[0]
list1[0] = list1[1]
list1[1] = tmpA

tmpA = list1[0]
list1[0] = list1[2]
list1[2] = tmpA
print(list1[0] + " " + list1[1] + " " + list1[2])

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

int main(){
    ll N, K, R, S, P;
    cin >> N >> K >> R >> S >> P;
    string T;
    cin >> T;
    ll ans = 0;
    rep(i, 0, N){
        if(i + K < N && T[i + K] == T[i]){
            T[i + K] = 'd';
        }
        {
            if(T[i] == 's') ans += R;
            if(T[i] == 'r') ans += P;
            if(T[i] == 'p') ans += S;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#define inf          0x3f3f3f3f
#define go(a,b,c)    for(int a=b;a<=c;a++)
#define rgo(a,b,c)   for(int a=b;a>=c;a--)
#define sf(a)        scanf("%d",&a)
#define sff(a,b)     scanf("%d%d",&a,&b)
#define sfff(a,b,c)  scanf("%d%d%d",&a,&b,&c)
#define eps          1e-9
#define ft           first
#define sd           second
#define prt(a)       printf("%d\n",a)
#define prn(i,n,a)   printf("%d%c",a,i==n?'\n':' ')
#define pb           push_back
typedef long long LL;
typedef pair<int,int> pii;
typedef set<int> si;
typedef vector<int> vi;
typedef map<int,int> mii;
typedef double db;
int gcd(int a,int b){return b?gcd(b,a%b):a;}
const int maxn=1e5+10;
int read()
{
	int f=0,x=0;
	char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch<='9'&&ch>='0'){x=x*10+ch-'0';ch=getchar();}
	return f*x;
}
//=======================================================
int a[maxn],n;
void work()
{
	go(i,1,n)sf(a[i]);
	int tot=0,pos=1;
	while(1)
	{
		while(pos<n&&a[pos]==a[pos+1])pos++;
		if(pos>n)break;
		if(pos<n&&a[pos+1]<a[pos])
			while(pos<n&&a[pos+1]<=a[pos])pos++;
		else if(pos<n&&a[pos+1]>a[pos])
			while(pos<n&&a[pos+1]>=a[pos])pos++;
		pos++;
		tot++;
	}
	prt(tot);
}
int main()
{
	while(~sf(n))
	{
		work();	
	} 
	return 0;
}

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

using namespace std;

int main(void) {
  int n;
  cin >> n;
  int a[n];
  for(int i = 0; i < n; i++) {
    cin >> a[i];
  }

  deque<int> b;
  for(int i = 0; i < n; i++) {
    if((n % 2 == 0) == (i % 2 == 0)) {
      b.push_back(a[i]);
    }
    else {
      b.push_front(a[i]);
    }
  }

  string s;
  for(int i = 0; i < n; i++) {
    s += to_string(b[i]);
    s += " ";
  }
  s.pop_back();
  cout << s << endl;
}

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

int main(){
  int N, a, b, c,  d;
  cin >> N;
  a = N / 1000;
  b = N % 1000 / 100;
  c = N % 100 / 10;
  d = N % 10;
  if ((a == b && b == c) || (b == c && c == d)) {
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;


#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define PSET(x,y) fixed<<setprecision(y)<<x
#define pb push_back
#define pii pair<int,int>
#define pf push_front
#define mp make_pair
#define vi vector<int>
#define vip vector<pair<int,int> >
#define ff first
#define ss second
#define int long long
#define mod 1000000007
#define BIG 998244353
#define s(t) scanf("%lld",&t)
#define p(t) printf("%lld\n",t)
#define mii map<int,int>
#define MSET(table,i) memset(table, i, sizeof(table))
#define endl '\n'
#define tc int t;cin>>t;while(t--)
#define pi  3.1415926358
#define bits(x) __builtin_popcount(x)
#define minimum(a,n) min_element(a,a+n)-a
#define maximum(a,n) max_element(a,a+n)-a
#define pqbig priority_queue<int>
#define pqsmall priority_queue<pii,vector<pii>,greater<pii> >
#define all(v) v.begin(),v.end()
#define sitr set<int>:: iterator
#define spitr set<pii>:: iterator
#define mitr map<int,int>:: iterator

int toint(const string &s) {stringstream ss; ss << s; int x; ss >> x; return x;}
string tostring ( int number ) {stringstream ss; ss << number; return ss.str();}


typedef tree<int, null_type, less<int>, rb_tree_tag,
        tree_order_statistics_node_update>
        new_data_set;


#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl


int32_t main()
{
    fast;
    int n;cin>>n;
    int cur=100;
    int cnt=0;
    while(cur<n)
    {
        cur+=(cur/100);
        cnt++;
    }

    cout<<cnt;
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
#define rep1(i,N) for(int i=1;i<int(N);++i)
#define all(a) (a).begin(),(a).end()		 //sort(all(vi S)) sort(all(string S))
#define print(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<_<<", "; cerr<<"]"<<endl; }
#define printpair(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<"{"<<_.first<<","<<_.second<<"}"<<", "; cerr<<"]"<<endl; }

using P = pair<int, int>;		//P.first, P.second
typedef long long ll;
typedef vector<int> vi;
typedef set<int> seti;
typedef vector<string> vs;

const int MOD = 1e9+7;
const int INF = 1e9;
int main() {
    string S,T;
    cin>>S>>T;
    int ans = 0;
    rep(i,3){
        if(S[i] == T[i])ans++;
    }
    cout<<ans<<endl;

}

Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;

#define rep(i, n) for(ll i = 0; i < n; i++)
#define REP(i, n) for(ll i = 1; i < n + 1; i++)
#define PI 3.14159265359
#define EPS 0.0000000001
#define MOD 1000000007
//cout << std::fixed << std::setprecision(15) << y << endl;


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

    deque<ll> q;
    ll a;
    rep(i, n){
        cin >> a;
        if(i % 2 == 0){
            q.push_back(a);
        }else{
            q.push_front(a);
        }
    }

    if(n % 2 == 0){
        rep(i, n){
            if(i != 0){
                cout << " ";
            }
            cout << q.front();
            q.pop_front();
        }
    }else{
        rep(i, n){
            if(i != 0){
                cout << " ";
            }
            cout << q.back();
            q.pop_back();
        }
    }
    cout << endl;

    return 0;
}

Measured memory_bytes: 5216
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
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 All(v) (v).begin(), (v).end()
typedef long long ll;

int main() {
    int A, B;
    cin >> A >> B;
    cout << max(A + B, max(A - B, A * B));
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <numeric>
#include <utility>
#include <limits>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include<climits>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
using namespace std;
const double pi=acos(-1.0);
#define boost  ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define endl '\n'
#define sl(n) scanf("%lld",&n)
#define mp make_pair
#define pb push_back
#define ppb pop_back
#define fi first
#define se second
#define ll long long
#define ull unsigned long long
#define pii pair<ll, ll>
#define f(i,a,b) for(ll i = (ll)(a); i < (ll)(b); i++)
#define rf(i,a,b) for(ll i = (ll)(a); i > (ll)(b); i--)
#define ms(a,b) memset((a),(b),sizeof(a))
#define max(a,b) ((a>b)?(a):(b))
#define min(a,b) ((a<b)?(a):(b))
#define vec(g1) int temp;cin>>temp;g1,push_back(temp);
#define abs(x) ((x<0)?(-(x)):(x))
#define MAX 1000005
#define inf LLONG_MAX
#define MIN INT_MIN
//typedef
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<PII> VII;
typedef vector<VI> VVI;
typedef map<int,int> MPII;
typedef set<int> SETI;
typedef multiset<int> MSETI;
typedef long int int32;
typedef unsigned long int uint32;
typedef long long int int64;
typedef unsigned long long int  uint64;

int mod = 1e9 + 7 ;
ll gcd(ll a , ll b){return b==0?a:gcd(b,a%b);}
ll powmod(ll a,ll b) {ll res=1;if(a>=mod)a%=mod;for(;b;b>>=1){if(b&1)res=res*a;if(res>=mod)res%=mod;a=a*a;if(a>=mod)a%=mod;}return res;}
// ll fac[200005];
// ll inverse(ll n){return powmod(n, mod-2);}
// ll nCr(ll n, ll r){return (fac[n] * inverse(fac[r]) % mod * inverse(fac[n-r]) % mod) % mod;}

/**.................................................................................................................................*/
bool fun(pair<ll,ll> &a, pair<ll,ll> &b){return a.second<b.second;}
int main(){
	boost;
      int n;
      cin>>n;
      vector<pair<ll,ll> > g1;
      f(i,0,n){
      	ll a,b;
      	cin>>a>>b;
      	g1.pb(mp(a,b));
      }
      sort(g1.begin(),g1.end(),fun);
      int flag=1;
      ll sum=0;
      
     f(i,0,n){sum+= g1[i].fi;
                 if(g1[i].se < sum){flag=0 ;break; }
  }
  if(flag)cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;

}


Measured memory_bytes: 6524
#include <algorithm>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
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 All(v) (v).begin(), (v).end()
#define MP make_pair
#define pb push_back
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1 << 30;
const ll LINF = 1LL << 61;
const int MOD = 1e9 + 7;

int main() {
    int N;
    cin >> N;
    cout << "ABC" << N << endl;
    return 0;
}

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

#define ll long long int
#define mp make_pair 
#define pb push_back
#define fast  ios_base::sync_with_stdio(false);cin.tie(0);
#define ff first
#define ss second
#define ll_MAX 922337203685477999
#define endl "\n"
inline ll absdiff(ll a,ll b) {return (a>b)?a-b:b-a;}
const ll MOD = 1000000007;
ll fast_expo(ll x,ll p){if(p==0) return 1;
else if(p%2==0){ ll t=fast_expo(x,p/2)%MOD;return (t*t)%MOD;} else return (x*(fast_expo(x,p-1))%MOD)%MOD;}
ll gcd(ll a,ll b){if(a==0||b==0) return a+b;  else return gcd(b%a,a); }

int main()
{
    // freopen("input.txt","r",stdin);
    // freopen("output.txt", "w", stdout);

    ll t_c;t_c = 1;
    // cin >> t_c;
    for (ll ti = 0; ti < t_c; ++ti)
    {  
        ll dp[101][100005];
        for(ll i=0; i<101; ++i){
            for(ll j=0; j<100005; ++j)
                dp[i][j] = ll_MAX;
        }

        ll n,w; cin >> n >> w;
        pair<ll,ll> arr[n+1];
        for(ll i=1; i<=n; ++i)
            cin >> arr[i].ff >> arr[i].ss;

        dp[0][0] = 0;
        for(ll i=1; i<=n; ++i){
            for(ll j=0; j<100005; ++j)
                dp[i][j] = dp[i-1][j];
            for(ll j=0; j<100005-arr[i].ss; ++j)
                dp[i][j+arr[i].ss] = min(dp[i][j+arr[i].ss],dp[i-1][j]+arr[i].ff);
        }

        ll ans = -1;
        for(ll i=0; i<100005; ++i){
            if(dp[n][i]<=w)
                ans = i;
        }
        cout << ans;
    }
    return 0;       
}       

Measured memory_bytes: 79232
"""
漸化式的に解く
一般性を失わない範囲をちゃんと考える。
"置き換え可能"というのをどの部分で持たせられるかを考える
今回の場合は、リスト作りの際に作ったので十分
"""

from collections import defaultdict
N, K = map(int,input().split())
# dd = defaultdict(list)
pairs = [list(map(int,input().split())) for _ in range(N)]
# 美味しい順にソート
pairs = sorted(pairs,reverse=True, key=lambda x: x[1])
kinds = set()
change = [] #変更できるもの(2個以上あるもの)



cnt = 0
for t,d in pairs[:K]: #K個上から順番に取ってみる
    if t in kinds:
        change.append(d) 
    kinds.add(t)
    cnt += d

n = len(kinds)
cnt += len(kinds)**2
ans = cnt

"""
K+1以降
Kまでに大きい順に加えたもので、2個以上あるものから順に置き換えていく。
1個のものはそのままで良い。
また、K+1以降で、2回同じものを追加する可能性はない。
なぜなら新規の追加ではないので、その場合はchangeに入ってある美味しさdiよりも
K+1以降のものは必ず低い美味しさの値になっているからである。
"""
for t,d in pairs[K:]:
    # 交換できるものがなくなったら終わり
    if len(change) == 0:
        break
    # 同じものは交換しない
    if t in kinds:
        continue
    d_min = change.pop()
    cnt = cnt - (d_min + n**2)  + (d + (n+1)**2)
    kinds.add(t)
    n += 1
    ans = max(cnt,ans)
# 集計
print(ans)


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

int N;

bool isPrime[300030];

void init(){
  for(int i=1;i<=300000;i++) isPrime[i]=true;
  isPrime[1]=false;
  for(int i=2;i<=300000;i++){
    if(isPrime[i]&&(i%7==1||i%7==6)){
      for(int j=2;j*i<=300000;j++){
        isPrime[i*j]=false;
      }
    }
  }
}

void solve(){
  vector<int> ans;
  for(int i=2;i<=N;i++){
    if(i%7==1||i%7==6){
      if(N%i==0&&isPrime[i]) ans.push_back(i);
    }
  }
  cout<<N<<":";
  for(int i=0;i<ans.size();i++) cout<<" "<<ans[i];
  cout<<endl;
}

int main(){
  init();
  while(1){
    cin>>N;
    if(N==1) break;
    solve();
  }

  return 0;
}



Measured memory_bytes: 3456
import sys

def input():
    return sys.stdin.readline().rstrip()

if __name__ == "__main__":
    n = int(input())
    alist = list(map(int, input().split()))
    
    res = float("inf")
    for a in alist:
        b = format(a, "b")
        res = min(res, (len(b)-1) - b.rfind("1"))
    
    print(int(res))


Measured memory_bytes: 2940
import std.stdio;
import std.string;
import std.conv;
import std.algorithm;

void SelectionSort(ref int[] arr){

    int mini,count = 0;
    for(int i=0;i<arr.length;i++){
	mini = i;
	for(int j=i;j<arr.length;j++){
	    if(arr[mini] > arr[j]) mini = j;
	}
	swap(arr[mini],arr[i]);
	if(mini != i)
	count++;
    }

    writef("%d",arr[0]);
    for(int i=1;i<arr.length;i++){
	writef(" %d",arr[i]);
    }
    writeln();
    writeln(count);
}

void main(){
    int N;
    readf("%d\n",&N);
    string[] s;
    int[] arr;
    s = split(readln());
    for(int i=0;i<N;i++){
	arr ~= to!int(s[i]);
    }
    SelectionSort(arr);
    
}

Measured memory_bytes: 2536
#include <stdio.h>

int F[45];

int Fib(int n){
  if(F[n]!=0) return F[n];
  if(n == 0 || n == 1) return F[n] = 1;
  return F[n] = Fib(n-1) + Fib(n-2);
}

int main(){
  int n;
  scanf("%d",&n);
  printf("%d\n",Fib(n));
  return 0;
}



Measured memory_bytes: 2104
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ff first
#define ss second
#define pb push_back
#define clr(a) memset(a,0,sizeof(a))
#define reset(a) memset(a,-1,sizeof(a))
#define mod 1000000007
#define pi acos(-1)
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);

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


int main()
{
    // #ifndef ONLINE_JUDGE
    //     freopen("input.txt", "r", stdin);
    //     freopen("output.txt", "w", stdout);
    // #endif

    fastio
    
    string s;
    cin>>s;
    int n = s.length();
    n--;
    if(s[n] == 's')s+="es";
    else s += 's';

    cout << s << "\n";

    return 0;
}

Measured memory_bytes: 3664
times = gets.split(' ')
h1 = times[0].to_i * 60
m1 = times[1].to_i
h2 = times[2].to_i * 60
m2= times[3].to_i
between = times[4].to_i

start_time = h1 + m1
end_time = h2 + m2

# 指定した勉強時間が、起床時間より短ければ0を返す
value = 0
study_time = end_time - start_time
if study_time > between then
 value = study_time - between
end

  
puts value

Measured memory_bytes: 14316
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<tuple>
#include<map>
#include<queue>
#include<math.h>
#include<numeric>
#include<iomanip>
#define rep(i, n) rep2(i,0,n)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define PI acos(-1);
typedef long long ll;
using namespace std;
const int MOD = 1000000007;
//scanf("%d", &a); '\n'; cout << fixed << setprecision(10);

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int x;
	cin >> x;
	ll y = 0;
	y += (x / 500) * 1000;
	x -= (x / 500) * 500;
	cout << y + (x / 5) * 5;
}

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

public class Main {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        while(input.hasNext()){
            double a = input.nextInt();
            double b = input.nextInt();
            double c = input.nextInt();
            
            double d = input.nextInt();
            double e = input.nextInt();
            double f = input.nextInt();
            
            e -= b * (d / a);
            f -= c * (d / a);
            double y = f / e;
            
            b *= y;
            c -= b;
            double x = c / a;
            System.out.println(String.format("%.3f %.3f", x, y));
        }
    }
}

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

struct StNode
{
  StNode* m_poParnt;
  StNode* m_poLeft;
  StNode* m_poRigt;
  int m_nKey;

  StNode(int nNo) :
    m_poParnt(nullptr), m_poLeft(nullptr), m_poRigt(nullptr), m_nKey(nNo)
  { }
};

void fnInsert(StNode*& rpoRoot, StNode* poNewMe)
{
  StNode*  poParnt = nullptr;
  StNode** ppoNode = &rpoRoot;

  while (*ppoNode)
  {
    poParnt = *ppoNode;
    if (poNewMe->m_nKey < poParnt->m_nKey)
      ppoNode = &poParnt->m_poLeft;
    else
      ppoNode = &poParnt->m_poRigt;
  }
  poNewMe->m_poParnt = poParnt;
  *ppoNode = poNewMe;
}

StNode* fnFind(StNode* poRoot, int nNo)
{
  StNode* poNode = poRoot;
  while (poNode)
    if (nNo == poNode->m_nKey)
      return poNode;
    else if (nNo < poNode->m_nKey)
      poNode = poNode->m_poLeft;
    else
      poNode = poNode->m_poRigt;

  return nullptr;
}

void fnDelete(StNode*& rpoRoot, StNode* poDelMe)
{
  StNode** ppoPrToMe;
  if (poDelMe == rpoRoot)
    ppoPrToMe = &rpoRoot;
  else
    if (poDelMe->m_nKey < poDelMe->m_poParnt->m_nKey)
      ppoPrToMe = &poDelMe->m_poParnt->m_poLeft;
    else
      ppoPrToMe = &poDelMe->m_poParnt->m_poRigt;

  int nDegr = 0;
  StNode* poMeToCd;
  if (poDelMe->m_poLeft)
  {
    ++nDegr;
    poMeToCd = poDelMe->m_poLeft;
  }
  if (poDelMe->m_poRigt)
  {
    ++nDegr;
    poMeToCd = poDelMe->m_poRigt;
  }

  if (!nDegr)
  {
    *ppoPrToMe = nullptr;
    delete poDelMe;
  }
  else if (nDegr == 1)
  {
    *ppoPrToMe = poMeToCd;
    poMeToCd->m_poParnt = poDelMe->m_poParnt; 
    delete poDelMe;
  }
  else if (nDegr == 2)
  {
    StNode* poNext = poDelMe->m_poRigt;
    while (poNext->m_poLeft)
      poNext = poNext->m_poLeft;

    poDelMe->m_nKey = poNext->m_nKey;
    fnDelete(rpoRoot, poNext);
  }
}

void fnInOrder(StNode* poNode)
{
  if (!poNode)  return;

  fnInOrder(poNode->m_poLeft);
  cout << " " << poNode->m_nKey;
  fnInOrder(poNode->m_poRigt);
}

void fnPreOrder(StNode* poNode)
{
  if (!poNode)  return;

  cout << " " << poNode->m_nKey;
  fnPreOrder(poNode->m_poLeft);
  fnPreOrder(poNode->m_poRigt);
}

void fnBinSchTree(StNode*& rpoRoot)
{
  int nMaxSiz;
  cin >> nMaxSiz;

  for (int i = 0; i < nMaxSiz; ++i)
  {
    string sCmd;
    cin >> sCmd;
    if (sCmd[0] == 'i')
    {
      int nNo;
      cin >> nNo;
      StNode* poNewMe = new StNode(nNo);
      fnInsert(rpoRoot, poNewMe);
    }
    else if (sCmd[0] == 'f')
    {
      int nNo;
      cin >> nNo;
      if (fnFind(rpoRoot, nNo))
        cout << "yes" << endl;
      else
        cout << "no" << endl;
    }
    else if (sCmd[0] == 'd')
    {
      int nNo;
      cin >> nNo;
      StNode* poDelMe;
      if (poDelMe = fnFind(rpoRoot, nNo))
        fnDelete(rpoRoot, poDelMe);
      else;
    }
    else if (sCmd[0] == 'p')
    {
      fnInOrder(rpoRoot);
      cout << endl;
      fnPreOrder(rpoRoot);
      cout << endl;
    }
    else;
  }
}

void fnPstOrder(StNode* poNode)
{
  if (!poNode)  return;

  fnPstOrder(poNode->m_poLeft);
  fnPstOrder(poNode->m_poRigt);
  delete poNode;
}

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  StNode* poRoot = nullptr;

  fnBinSchTree(poRoot);
//fnPstOrder(poRoot);
  return 0;
}

Measured memory_bytes: 21860
Num = int(input())
Num_Array = list(map(int,input().split()))
Max_Num = -1
Min_Num = 1000000000000

for i in range(0,Num):

    if Num_Array[i] > Max_Num:
        Max_Num = Num_Array[i]

    if Num_Array[i] < Min_Num:
        Min_Num = Num_Array[i]

print(Max_Num - Min_Num)

Measured memory_bytes: 3064