akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;

class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int[] N = new int[6];
			for(int i=0;i<6;i++)N[i]=Integer.parseInt(sc.next());
		String order = sc.next();
		char[] charOrder = order.toCharArray();
		Dice dice = new Dice(N);
		
		for(char c: charOrder)dice.roll(c);
		

		System.out.println(dice.getNow());

		sc.close();
	}

}

class Dice{
	private int[] roll=new int[6];
	private int[] nowRoll= new int[6];
	Dice(int[] N){
		for(int i = 0;i<6;i++){
			this.roll[i]=N[i];
			this.nowRoll[i]=N[i];
		}
	}

	public int getNow(){
		return nowRoll[0];
	}

	public void roll(char c){
		//int dir;
		int[] tmpRoll=new int[6];
		for(int i=0;i<6;i++)tmpRoll[i]=this.nowRoll[i];

		if(c=='E'){
			this.nowRoll[0]=tmpRoll[3];
			//this.nowRoll[1]=tmpRoll[1];
			this.nowRoll[2]=tmpRoll[0];
			this.nowRoll[3]=tmpRoll[5];
			//this.nowRoll[4]=tmpRoll[4];
			this.nowRoll[5]=tmpRoll[2];
		}
		if(c=='N'){
			this.nowRoll[0]=tmpRoll[1];
			this.nowRoll[1]=tmpRoll[5];
			//this.nowRoll[2]=tmpRoll[2];
			//this.nowRoll[3]=tmpRoll[3];
			this.nowRoll[4]=tmpRoll[0];
			this.nowRoll[5]=tmpRoll[4];
		}
		if(c=='S'){
			this.nowRoll[0]=tmpRoll[4];
			this.nowRoll[1]=tmpRoll[0];
			//this.nowRoll[2]=tmpRoll[2];
			//this.nowRoll[3]=tmpRoll[3];
			this.nowRoll[4]=tmpRoll[5];
			this.nowRoll[5]=tmpRoll[1];
		}
		if(c=='W'){
			this.nowRoll[0]=tmpRoll[2];
			//this.nowRoll[1]=tmpRoll[1];
			this.nowRoll[2]=tmpRoll[5];
			this.nowRoll[3]=tmpRoll[0];
			//this.nowRoll[4]=tmpRoll[4];
			this.nowRoll[5]=tmpRoll[3];
		}

	}

}

Measured memory_bytes: 26224
#include <bits/stdc++.h>
#define int long long
using namespace std;
vector<pair<int,int> >D;
int n,m;
signed main()
{
	cin>>n>>m;
	D.resize(n);
	for(int i=0;i<n;i++)cin>>D[i].first>>D[i].second;
	sort(D.begin(),D.end());
	int ans=0;
	for(int i=0;i<n;i++)
	{
		if(m<=D[i].second)
		{
			ans+=m*D[i].first;
			cout<<ans<<endl;
			return 0;
		} 
		else ans+=D[i].second*D[i].first;
		m-=D[i].second;
	}
	return 0;
} 

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> P;

#define EACH(i,a) for (auto& i : a)
#define FOR(i,a,b) for (ll i=(a);i<(b);i++)
#define RFOR(i,a,b) for (ll i=(b)-1;i>=(a);i--)
#define REP(i,n) for (ll i=0;i<(n);i++)
#define RREP(i,n) for (ll i=(n)-1;i>=0;i--)
#define debug(x) cout<<#x<<": "<<x<<endl
#define pb push_back
#define ALL(a) (a).begin(),(a).end()

const ll linf = 1e18;
const int inf = 1e9;
const double eps = 1e-12;
const double pi = acos(-1);

template<typename T>
istream& operator>>(istream& is, vector<T>& vec) {
    EACH(x,vec) is >> x;
    return is;
}
template<typename T>
ostream& operator<<(ostream& os, vector<T>& vec) {
    REP(i,vec.size()) {
        if (i) os << " ";
        os << vec[i];
    }
    return os;
}
template<typename T>
ostream& operator<<(ostream& os, vector< vector<T> >& vec) {
    REP(i,vec.size()) {
        if (i) os << endl;
        os << vec[i];
    }
    return os;
}

int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
    ll Q; cin >> Q;
    while ( Q-- ) {
        vector<ll> len(3); cin >> len;
        sort(ALL(len));
        if (len[0] * len[0] + len[1] * len[1] == len[2] * len[2]) {
            cout << "YES" << endl;
        }
        else {
            cout << "NO" << endl;
        }
    }
}

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

using namespace std;
#define all(a)a.begin(),a.end()
using ll=long long;
const int INF = 1<<30;
const ll INFll =1LL<<62;
const int mod= int(1e9)+7;
using P = pair<ll,ll>;
using ld=long double;

ll modpow(ll N, ll P,ll M){
    if(P==0) return 1;
    if(P%2==0){
        ll t =modpow(N, P/2,M);
        return t*t % M;
    }
    return N * modpow(N, P-1, M)%M;
}

ll f2(ll now,ll k){
    return now%k;
}

int main() {
    ll n;cin >>n;
    string s;cin >>s;
    ll cnt=0;
    for (int i = 0; i < n; ++i) {
        if(s[i]=='1')cnt++;
    }
    reverse(all(s));
    ll rb=0;
    ll a=1;
    for (int j = 0; j <n; ++j) {
        ll num=s[j]-'0';
        num*=a;
        num%=(cnt+1);
        rb+=num;
        rb%=(cnt+1);
        a*=2;a%=(cnt+1);
    }
    ll rs=0;
    a=1;
    if(cnt-1!=0) {
        for (int j = 0; j < n; ++j) {
            ll num = s[j] - '0';
            num *= a;
            num %= (cnt - 1);
            rs += num;
            rs %= (cnt - 1);
            a *= 2;
            a %= (cnt - 1);
        }
    }
    reverse(all(s));
    for (int i = 0; i <n; ++i) {
        ll res=0;
        ll q;
        if(s[i]=='1'){
            s[i]='0';
            q=cnt-1;
        }
        else {
            s[i]='1';
            q=cnt+1;
        }
        if(q==0){
            cout <<0<<endl;
            continue;
        }
        ll e=modpow(2,n-i-1,q);
        ll now;
        if(s[i]=='1')now=(rb+e)%q;
        else now=(rs-e)%q;
        if(now<0)now+=q;
        res++;
//        cout <<s<<" "<<now<<endl;
        while(now>0) {
//            cout <<now<<endl;
            ll k = __builtin_popcountll(now);
            now=f2(now, k);
            res++;
        }
        cout <<res<<endl;
        if(s[i]=='1')s[i]='0';
        else s[i]='1';
    }
}


Measured memory_bytes: 3672
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n,a,ans;
  cin >> n;
  for(int i=0;i<n;i++){
    cin >> a;
    if(i==0){
      ans=a;
    }
    ans=__gcd(ans, a);
  }
  cout << ans << endl;
  return 0;
}


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

typedef vector<int> vi;
typedef vector<bool> vb;
typedef pair<int,int> pii;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<bool> > vvb;
typedef map<int, bool> mib;

typedef long long ll;
typedef vector<long long> vl;
typedef pair<long long,long long> pll;
typedef vector<pair<long long,long long> > vpll;

typedef vector<string> vs;

typedef long double ld;

#define _GLIBCXX_DEBUG

#define REP(i,n) for (int i = 0; i < (n); ++i)
#define REPD(i,n) for (int i = (n-1); i >= 0; --i)
#define FORE(i, s, n) for (int i = (s); i <= (int)(n); i++)
#define debug(x) cerr << #x << ": " << x << '\n'
#define debug2(x, y) cerr << #x << ": " << x << ", " << #y << ": " << y << '\n'
#define debug3(x, y, z) cerr << #x << ": " << x << ", " << #y << ": " << y << ", " << #z << ": " << z << '\n'
#define hyphen() cerr << "--\n"

#define ALL(vec) (vec).begin(), (vec).end()
#define REVALL(vec) (vec).rbegin(), (vec).rend()

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

#define fst first
#define snd second
#define pb push_back
#define mp(x,y) make_pair((x),(y))

const int MOD = (int)1e9 + 7;
const int INF = numeric_limits<int>::max();

signed main() {
    int a, b, c, d, e;

    cin >> a >> b >> c >> d >> e;

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

    if (b== 0) {
        cout << 2 << endl;
    }

    if (c == 0) {
        cout << 3<< endl;
    }

    if (d == 0) {
        cout << 4 << endl;
    }

        if (e == 0) {
        cout << 5 << endl;
    }


}


Measured memory_bytes: 3628
class UnionFind:
    def __init__(self, n):
        self._n = n
        self._table = [-1]*n

    def _root(self, x):
        stack = []
        while self._table[x] >= 0:
            stack.append(x)
            x = self._table[x]
        for y in stack:
            self._table[y] = x
        return x
    
    def unite(self, x, y):
        x, y = self._root(x), self._root(y)
        if x == y:
            return
        if x > y:
            x, y = y, x
        self._table[x] += self._table[y]
        self._table[y] = x

    def same(self, x, y):
        return self._root(x) == self._root(y)

    def count_members(self, x):
        return -self._table[self._root(x)]

    def count_groups(self):
        return len({self._root(i) for i in range(self._n)})

    def __iter__(self):
        return (self._root(i) for i in range(self._n))

    def __str__(self):
        return str([self._root(i) for i in range(self._n)])

    def __repr__(self):
        return repr([self._root(i) for i in range(self._n)])

n, m, *AB = map(int, open(0).read().split())
uf = UnionFind(n)
for a, b in zip(AB[::2], AB[1::2]):
    uf.unite(a-1, b-1)
print(uf.count_groups()-1)

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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,n,m) for(int i=(int)(n); i<=(int)(m); i++)
#define RFOR(i,n,m) for(int i=(int)(n); i>=(int)(m); i--)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

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

#define ld long double
#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

using namespace std;

/* Some Libraries */

//-------------------------------------------------

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s,t; cin>>s>>t;
    rep(i,s.size()){
        if (s==t){
            cout<<"Yes\n";
            return 0;
        }
        char c = s[s.size()-1];
        RFOR(j,s.size()-2,0) s[j+1]=s[j];
        s[0] = c;
    }
    cout<<"No\n";
    return 0;
}


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

using namespace std;

int main()
{
	int N;
	int sum = 0;
	int min = -1;
	cin >> N;
	
	vector<int> s(N);
	for (int i = 0; i < N; i++)
	{
		cin >> s[i];
		sum += s[i];
	}

	sort(s.begin(), s.end());
	for (int i = 0; i < N; i++)
	{
		if (s[i] % 10 != 0)
		{
			min = s[i];
			break;
		}
	}

	if (sum % 10 == 0)
	{
		if (min == -1)
			cout << 0 << endl;
		else
			cout << sum - min << endl;
	}
	else
		cout << sum << endl;

	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int n,q,num,fish,i,j,vic=0,max=0,get[1000000];
	
	scanf("%d %d",&n,&q);
	
	for(i=1;i<=n;i++){
		get[i]=0;
	}
	for(i=0;i<q;i++){
		scanf("%d %d",&num,&fish);
		get[num]+=fish;
		if(fish<0 && num==vic){
			max=0;
			for(j=n;j>0;j--){
				if(max<=get[j]){
					max=get[j];
					vic=j;
				}
			}
		}else if(get[num]>max || (get[num]==max && vic>num)){
			max=get[num];
			vic=num;
		}
		printf("%d %d\n",vic,get[vic]);
	}
	
	return 0;
}

Measured memory_bytes: 4500
#include "bits/stdc++.h"
#include <math.h>
#include <time.h>
using namespace std;
const long long mod = 1000000007;
#define dump(x)                             \
    if (dbg) {                              \
        cout << #x << " = " << (x) << endl; \
    }
bool dbg = false;
long long gcd(long long a, long long b){
   if (a % b == 0)
   {
       return(b);
   }
   else
   {
       return(gcd(b, a % b));
   }
}
long long lcm(long long a, long long b){
   return (a / gcd(a, b))* b;
}
//---------------------------------------------------------------------------------------------------
/*ここからいじる*/
//---------------------------------------------------------------------------------------------------

void solve(){
}
int main(){
    int n;
    cin >> n;
    vector<int>ln(n);
    int sum = 0;
    int num = 0;
    for(int i = 0; i < n; i++){
        cin >> ln.at(i);
        sum += ln.at(i);
        num = max(num, ln.at(i));
    }
    if(sum > num * 2){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }

    solve();
    return 0;
}



Measured memory_bytes: 256
from bisect import bisect_left

n, k = map(int, input().split())
x = list(map(int, input().split()))
ans = 0
min_dis = 10 ** 20
a = 0
for i in range(n - k + 1):
    dis = x[i + k - 1] - x[i] + min(abs(x[i]), abs(x[i + k - 1]))
    if min_dis > dis:
        ans = dis
        min_dis = dis
print(ans)


Measured memory_bytes: 14480
#include <bits/stdc++.h>
#define llong long long
#define mp make_pair
#define f first
#define s second

using namespace::std;

int main()
{
    ios::sync_with_stdio(false);
    ifstream fin("input.txt");
    string str;
    cin >> str;
    llong N = str.size();
    llong answ = N * (N - 1) / 2 + 1;
    vector<llong> cnt(26);
    for (int i = 0; i < N; i++) {
        cnt[str[i] - 'a']++;
    }
    for (int i = 0; i < 26; i++) {
        answ -= cnt[i] * (cnt[i] - 1) / 2;
    }
    cout << answ;
}


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

//template
#define rep(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define ALL(v) (v).begin(),(v).end()
typedef long long int ll;
const int inf = 0x3fffffff; const ll INF = 0x1fffffffffffffff; const double eps=1e-12;
template<typename T>inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<typename T>inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
//end



int main(){
   int n; cin>>n;
   vector<int> a(n); rep(i,0,n)cin>>a[i];
   sort(ALL(a));
   int ma=0; ll sum=0;
   rep(i,0,n){
      if(2*sum<a[i]){
         chmax(ma,i);
      }
      sum+=a[i];
   }
   cout<<n-ma<<endl;
   return 0;
}

Measured memory_bytes: 640
def main():
    m = int(input())
    arr = [list(map(int, input().split())) for _ in range(m)]
    ans = 0
    sm = 0
    tmp = 0
    for i in range(m):
        sm += arr[i][0] * arr[i][1]
        tmp += arr[i][1]
    ans += tmp-1
    ans += (sm-1)//9
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 39144
#include<stdio.h>
#include<math.h>
int main(void) {
    double r, pi, len, area;
    scanf("%lf", &r);
    pi = 3.141592653589;
    area = pi * pow(r,2);
    len = 2 * pi * r;

    printf("%lf %lf\n", area, len);

    return 0;
}



Measured memory_bytes: 2100
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define endl '\n'
typedef vector<vector<ll>> matrix;
const ll INF = 1e18;
const int MAX = 2e5+4;
const int MOD = 1e9+7;
//vector<int> dp(MAX);
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	ll a,b,c,d;
	cin >> a >> b >> c >> d;
	ll cnt=0;
  	ll e=c/__gcd(c,d)*d;
  	cnt+=b/c-(a-1)/c;
  	cnt+=b/d-(a-1)/d;
 	cnt-=b/e-(a-1)/e;
	cout << b-(a-1)-cnt;
	return 0;
}

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

using namespace std;

int main()
{
    string S;
    int Q,R,N;
    cin>>S;
    N=stoi(S);
 if (S.length()==4){
     Q=N/100;
     R=N%100;
    if((Q>12||Q==0)&&R>0&&R<=12){
        cout<<"YYMM";
    }
    else if((R>12||R==0)&&Q>0&&Q<=12){
        cout<<"MMYY";
    }
    
    else if(R>=1&&R<=12&&Q>=1&&Q<=12){
        cout<<"AMBIGUOUS";
    }
    else{
        cout<<"NA";
    }
 }
    return 0;
}

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

using ll = long long;

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

    ll X; cin >>X;

    ll XX = 2*X;
    ll s = 0;
    for (int i = 1;; i++) {
        s += i<<1;
        if (s >= XX) {
            cout << i << endl;
            return 0;
        }
    }
}


Measured memory_bytes: 256
#include<stdio.h>
#include<string>
#include<iostream>

using namespace std;

string inp_s;

long long readNumber() {
	long long temp_func;
	scanf("%lld", &temp_func);
	return temp_func;
};
long long printNumber(long long temp_func) {
	printf("%lld ", temp_func);
	return 0;
};

int main() {
	
	cin >> inp_s;
	
	if (inp_s == "ABC") {
		
		cout << "ARC";
		
	} else {
		
		cout << "ABC";
		
	};
	
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define rrep(i,n) for (int i = n-1; i >= 0; i--)
#define rep2(i,s,n) for (int i = s; i < n; ++i)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define tmax(a,b,c) max(a,max(b,c))
#define tmin(a,b,c) min(a,min(b,c))
#define pb push_back
#define eb emplace_back
#define vi vector<int>
#define vvi vector<vector<int>>
#define vl vector<ll>
#define vs vector<string>
#define vc vector<char>
#define vb vector<bool>
#define vp vector<P>
using namespace std;
using ll = long long;
using P = pair<int,int>;
using LP = pair<ll,ll>;
template<class T> istream& operator>>(istream& is,vector<T>& v) { for(T& t:v){is>>t;} return is; }
template<class T> ostream& operator<<(ostream& os,const vector<T>& v) { for(T t:v){os<<t<<" ";} os<<"\n"; return os; }
void Yes(bool b) { cout << (b ? "Yes" : "No") << endl; }
void YES(bool b) { cout << (b ? "YES" : "NO") << endl; }
template<class T> inline bool chmin(T& a,T b) {if(a > b){a = b; return true;} return false;}
template<class T> inline bool chmax(T& a,T b) {if(a < b){a = b; return true;} return false;}
const int inf = 1001001001;
const ll linf = 1001001001001001001;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);
    int n;
    cin >> n;
    vi x(n),y(n);
    rep(i,n) cin >> x[i] >> y[i];
    vi v;
    rep(i,n) v.pb(i);
    double sum = 0;
    int cnt = 0;
    auto f = [&](int i,int j) {
        return sqrt((double)(x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j]));
    };
    do {
        rep(i,n-1) sum += f(v[i],v[i+1]);
        cnt++;
    } while (next_permutation(all(v)));
    double ans = sum/cnt;
    cout << fixed << setprecision(10) << ans << endl;
}


Measured memory_bytes: 256
#pragma region include
#include <iostream>
#include <iomanip>
#include <stdio.h>

#include <sstream>
#include <algorithm>
#include <iterator>
#include <cmath>
#include <complex>

#include <string>
#include <cstring>
#include <vector>
#include <tuple>
#include <bitset>

#include <queue>
#include <complex>
#include <set>
#include <map>
#include <stack>
#include <list>

#include <fstream>
#include <random>
//#include <time.h>
#include <ctime>
#pragma endregion //#include
/////////
#define REP(i, x, n) for(int i = x; i < n; ++i)
#define rep(i,n) REP(i,0,n)
#define ALL(X) X.begin(), X.end()
/////////
#pragma region typedef
typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;
typedef std::pair<LL,LL> PLL;//
typedef std::pair<int,int> PII;//
#pragma endregion //typedef
////定数
const int INF = (int)1e9;
const LL MOD = (LL)1e9+7;
const LL LINF = (LL)4e18+20;
const LD PI = acos(-1.0);
const double EPS = 1e-9;
/////////
using namespace::std;

void solve(){
	string str;
	cin >> str;
	int size = str.size();
	cout << str.substr(0,str.size()-8) << endl;
}

#pragma region main
signed main(void){
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	std::cout << std::fixed;//小数を10進数表示
	cout << setprecision(16);//小数点以下の桁数を指定//coutとcerrで別	

	solve();
}
#pragma endregion //main()

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#include <complex>
#include <stdio.h>
#include <time.h>
#include <numeric>
#include <random>
#include <unordered_map>
#include <unordered_set>
#define int long long
#define all(a) a.begin(),a.end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define pb push_back
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef long double ld;
typedef complex<ld> com;
constexpr int inf = 1000000000;
constexpr ll INF = 1000000000000000000;
constexpr ld EPS = 1e-12;
constexpr ld PI = 3.141592653589793238;
template<class T, class U> inline bool chmax(T &a, const U &b) { if (a < b) { a = b; return true; } return false; }
template<class T, class U> inline bool chmin(T &a, const U &b) { if (a > b) { a = b; return true; } return false; }


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

	int n, m, l;
	cin >> n >> m >> l;
	vector<vector<int>> dis(n, vector<int>(n, INF));
	rep(i, n) dis[i][i] = 0;
	rep(i, m) {
		int a, b, c;
		cin >> a >> b >> c;
		a--; b--;
		chmin(dis[a][b], c);
		chmin(dis[b][a], c);
	}
	rep(k, n) rep(i, n) rep(j, n) chmin(dis[i][j], dis[i][k] + dis[k][j]);
	vector<vector<int>> ans(n, vector<int>(n, inf));
	rep(i, n) rep(j, n) if (dis[i][j] <= l) ans[i][j] = 1;
  	rep(i, n) ans[i][i] = 0;
	rep(k, n) rep(i, n) rep(j, n) chmin(ans[i][j], ans[i][k] + ans[k][j]);
	int q;
	cin >> q;
	rep(_, q) {
		int s, t;
		cin >> s >> t;
		s--; t--;
		cout << (ans[s][t] == inf ? -1 : ans[s][t] - 1) << '\n';
	}
}


Measured memory_bytes: 1920
N = int(input())

def primeFact(n) :
    primeList = {}
    for m in range(2, n + 1) :
        k = m
        for i in range(2, k + 1) :
            if k % i == 0 :
                if not i in primeList :
                    primeList[i] = 0
                while k % i == 0 :
                    primeList[i] += 1
                    k //= i
    return primeList

def dictFilter (filter, dic) :
    return { key : val for key, val in dic.items() if filter(key, val)}

primeN = primeFact(N)
prime75 = len(dictFilter(lambda key, val : val + 1 >= 75, primeN))
prime25 = len(dictFilter(lambda key, val : val + 1 >= 25, primeN))
prime15 = len(dictFilter(lambda key, val : val + 1 >= 15, primeN))
prime5 = len(dictFilter(lambda key, val : val + 1 >= 5, primeN))
prime3 = len(dictFilter(lambda key, val : val + 1 >= 3, primeN))

ans = 0
ans += prime75
ans += prime25 * (prime3 - 1)
ans += prime15 * (prime5 - 1)
ans += prime5 * (prime5 - 1) * (prime3 - 2) // 2

print(ans)


Measured memory_bytes: 3192
import std.stdio;
import std.string;
import std.conv;
import std.typecons;
import std.algorithm;
import std.functional;
import std.bigint;
import std.numeric;
import std.array;
import std.math;
import std.range;
import std.container;
import std.ascii;
import std.concurrency;
void times(alias fun)(int n) {
    foreach(i; 0..n) fun();
}
auto rep(alias fun, T = typeof(fun()))(int n) {
    T[] res = new T[n];
    foreach(ref e; res) e = fun();
    return res;
}

long INF = long.max/3;
void main() {
    int N, A, B;
    readf("%d %d %d\n", &N, &A, &B);
    int S = 10*100 + 1;
    long[][] dp = S.rep!(() => S.rep!(() => INF));
    dp[0][0] = 0;
    foreach(_; 0..N) {
        int a, b, c;
        readf("%d %d %d\n", &a, &b, &c);
        foreach(i; (S-a).iota.retro) foreach(j; (S-b).iota.retro) {
            dp[i+a][j+b] = min(dp[i+a][j+b], dp[i][j] + c);
        }
    }

    long ans = INF;
    foreach(i; 1..S) foreach(j; 1..S) {
        if (i*B == j*A) ans = min(ans, dp[i][j]);
    }
    writeln(ans==INF?-1:ans);
}

// ----------------------------------------------

// fold was added in D 2.071.0
static if (__VERSION__ < 2071) {
    template fold(fun...) if (fun.length >= 1) {
        auto fold(R, S...)(R r, S seed) {
            static if (S.length < 2) {
                return reduce!fun(seed, r);
            } else {
                return reduce!fun(tuple(seed), r);
            }
        }
    }
}

// minElement/maxElement was added in D 2.072.0
static if (__VERSION__ < 2072) {
    auto minElement(alias map, Range)(Range r)
    if (isInputRange!Range && !isInfinite!Range)
    {
        alias mapFun = unaryFun!map;
        auto element = r.front;
        auto minimum = mapFun(element);
        r.popFront;
        foreach(a; r) {
            auto b = mapFun(a);
            if (b < minimum) {
                element = a;
                minimum = b;
            }
        }
        return element;
    }
    auto maxElement(alias map, Range)(Range r)
    if (isInputRange!Range && !isInfinite!Range)
    {
        alias mapFun = unaryFun!map;
        auto element = r.front;
        auto maximum = mapFun(element);
        r.popFront;
        foreach(a; r) {
            auto b = mapFun(a);
            if (b > maximum) {
                element = a;
                maximum = b;
            }
        }
        return element;
    }
}


Measured memory_bytes: 10364
import sys
import numpy as np
sys.setrecursionlimit(20000000)
input = sys.stdin.readline
s = input()
ans = 0
tmp = 0
for i in range(len(s)):
        if s[i] in ["A","T","C","G"]:
                tmp += 1
        else:
                ans = max(ans,tmp)
                tmp = 0
ans = max(ans,tmp)
print(ans)

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

using namespace std;

typedef long long int ll;
const int INF = 1<<30;
const long long LINF = 1LL<<60;

int main(){
    string s;
    cin >> s;
    int ans = 0;
    for(int i = 0; i < s.size(); i++){
        if(s[i] == 'o'){
            ans++;
        }
    }
    ans += 15 - s.size();
    cout << (ans >= 8? "YES":"NO") << endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

#define CAKE 4
#define DONUT 7
int main(){
  int n;

  scanf( "%d", &n );

  if ( n < CAKE ){
    puts( "No" ); //printf( "%d\n", n );
    return 0;
  }else if ( n % CAKE == 0 ){
    puts( "Yes" ); //printf( "1:%d\n", n % CAKE );
    return 0;
  }else if ( n % DONUT == 0 ){
    puts( "Yes" ); //printf( "2:%d\n", n % DONUT );
    return 0;
  // }else if ( ( n % DONUT ) % CAKE == 0 ) {
  //   puts( "Yes" ); //printf( "3:%d\n", ( n % DONUT ) % CAKE );
  //   return 0;
  // }else if ( ( n % CAKE ) % DONUT == 0 ) {
  //   puts( "Yes" ); printf( "4:%d\n", ( n % CAKE ) % DONUT );
  //   return 0;
  }else {
    int n_temp = n - CAKE;
    while( n_temp > 0 ){
      if ( n_temp % DONUT == 0 ){
        puts( "Yes" ); //printf( "3:%d\n", ( n % DONUT ) % CAKE );
        return 0;
      }
      n_temp -= CAKE;
    }
    n_temp = n - DONUT;
    while( n_temp > 0 ){
      if ( n_temp % CAKE == 0 ){
        puts( "Yes" ); //printf( "3:%d\n", ( n % DONUT ) % CAKE );
        return 0;
      }
      n_temp -= DONUT;
    }
  }

  puts( "No" );
  return 0;
}

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


#include "boost/multiprecision/cpp_int.hpp"
#include "boost/multiprecision/cpp_dec_float.hpp"
namespace mp = boost::multiprecision;
typedef mp::cpp_int LL;
typedef mp::number<mp::cpp_dec_float<1024>> DD;// 仮数部が1024ビットの浮動小数点数型(TLEしたら小さくする)

 
typedef long double dd;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
typedef pair<dd,dd> d_d;
ll inf=(ll)1E16;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define rrep(i,r,l) for(ll i=r;i>=l;i--)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define fi first
#define se second
#define endl "\n"  //インタラクティブで消す！！！！！！！！！！！！！！！！！！！！！
#define SORT(v) sort(v.begin(),v.end())
#define ERASE(v) v.erase(unique(v.begin(),v.end()),v.end())
#define POSL(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define POSU(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
template<class T,class S>
inline bool chmax(T &a, S b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}
template<class T,class S>
inline bool chmin(T &a, S b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}

void mod_print(ll k){
    ll P=1000;
    rep(y,1,P){
        ll x=mod(y*k);
        if(x+P>=i_7){
            x-=i_7;
        }
        if(abs(x)<=P){
            //cout<<x<<"/"<<y;
            cout<<setprecision(5)<<(dd)x/(dd)y;
            return;
        }
    }
    cout<<"nun"<<endl;
}
#define all(c) c.begin(),c.end()
//////////////////////////


ll po(ll i,ll p){
    if(p==0)return 1;
    else{
        i=mod(i);
        if(p==1)return i;
        if(p%2==0)return po(mod(i*i),p/2);
        return mod(i*po(i,p-1));
    }
}
ll bunbo(ll n){
    return po(n,i_5);
}


#define N 2000004
ll kai[N];
ll kai2[N];
void calc(){
    kai[0]=1;
    kai2[0]=1;
    rep(i,1,N-1){
        kai[i]=mod(kai[i-1]*i);
    }
    kai2[N-1]=po(kai[N-1],i_5);
    for(ll i=N-2;i>=0;i--){
        kai2[i]=mod(kai2[i+1]*(i+1));
    }
}
ll comb(ll n,ll k){
    if(n<k)return 0;
    if(n==0)return 1;
    return mod(mod(kai[n]*kai2[n-k])*kai2[k]);
}
ll P(ll n,ll k){
    if(n<k)return 0;
    if(n==0)return 1;
    return mod(mod(kai[n]*kai2[n-k]));
}


int main(){fastio
    calc();
    ll n,m;cin>>n>>m;
    ll sum=0;
    rep(i,0,n){
        ll add=comb(n,i);
        add=mod(add*P(m-i,n-i));
        if(i%2==1)add=-add;
        Add(sum,add);
    }
    sum=mod(sum*P(m,n));
    cout<<mod(sum)<<endl;
    
    
    return 0;
}


Measured memory_bytes: 34884
#include <bits/stdc++.h>
#define endl "\n"
using namespace std;
typedef long long int lli;
int main()
{
    ios::sync_with_stdio(0); 
    cin.tie(0); cout.tie(0);
    lli n,k;
    cin>>n>>k;
    lli i,j,a[n+1],dp[n+1];
    
    for(i=1;i<=n;i++) cin>>a[i];
    for(i=1;i<=n;i++) dp[i]=1e9;
    dp[1]=0;
    
    for(i=1;i<=n;i++) for(j=i-1;j>=max(i-k,1LL);j--) dp[i]=min(dp[i],dp[j]+abs(a[i]-a[j]));
    
    cout<<dp[n];
    return 0;
}

Measured memory_bytes: 1792
<?php
//error_reporting(0);
//$N = trim(fgets(STDIN));
list($N,$K) = explode(" ",trim(fgets(STDIN)));
$A = array_map('intval',explode(" ",trim(fgets(STDIN))));
//function chmax(&$a,$b) {if ($a<$b){$a=$b;return true;}return false;}
//function chmix(&$a,$b) {if ($a>$b){$a=$b;return true;}return false;}

//https://atcoder.jp/contests/abc155/submissions/10145564
$N=(int)$N;
$K=(int)$K;

$z=0;
$p=array();
$m=array();
foreach($A as $v) {
  if ($v == 0) {$z++;continue;}
  if ($v > 0) $p[]=$v;
  else $m[]=$v*-1;
}
sort($p);
sort($m);
$pc=count($p);
$mc=count($m);


function cnt($x)
{
  global $p,$m,$z,$N,$K,$pc,$mc;
  if ($x == 0) {
    return $pc * $mc;
  }
  $res = 0;
  if ($x > 0) {
    $res = $pc * $mc;
    $res += $z * ($N - $z);
    $res += intdiv($z * ($z - 1),2);
    $r=0;
    for($i=$pc-1;$i>=0;--$i) {
      while($r < $i && ($p[$r] * $p[$i]) < $x) {
        ++$r;
      }
      $res += min($i,$r);
    }
    $r = 0;
    for($i=$mc-1;$i>=0;--$i) {
      while($r < $i && ($m[$r] * $m[$i]) < $x) {
        ++$r;
      }
      $res += min($i,$r);
    }
  } else {
    $r = $mc - 1;
    for($i=0;$i<$pc;++$i) {
      while($r >= 0 && ($p[$i] * $m[$r]) > ($x*-1)) {
        --$r;
      }
      $res += $mc - $r - 1;
    }
  }
  return $res;
}
$lo = -1000000000000000000;
$hi =  1000000000000000000;
while($lo < $hi) {
  $md = $lo + intdiv((int)($hi - $lo +1),2);
  //printf("md %d cnt(md) %d\n",$md,cnt($md));
  if (cnt($md)>=$K) $hi = $md - 1;
  else $lo = $md;
}
printf("%d\n",$lo);


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

int arr[110];

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

    int tot = 0;
    for (int i = 1; i <= n; ++i) {
        cin >> arr[i];
        tot += arr[i];
    }

    double avg = tot / (double) n;
    int p = ceil(avg), q = floor(avg);

    int res1 = 0, res2 = 0;
    for (int i = 1; i <= n; ++i) {
        int x = abs(p - arr[i]), y = abs(q - arr[i]);
        res1 += x * x;
        res2 += y * y;
    }

    cout << min(res1, res2) << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, fail;
  cin >> N;
  fail = 0;
  for (int i = 0; i < N; i++) {
    int A;
    cin >> A;
    if (A % 2 == 0) {
      if (A % 3 == 0 || A % 5 == 0) {
        continue;
      }
      else {
        fail += 1;
      }
    }
  }
  if (fail == 0) {
    cout << "APPROVED" << endl;
  }
  else {
    cout << "DENIED" << endl;
  }
}

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

int main() {
  ios::sync_with_stdio(0); cin.tie(0);
  int n;
  cin >> n;
  vector<int> a(n + 1), b(n);
  for(auto & x : a) {
    cin >> x;
  }
  for(auto & x : b) {
    cin >> x;
  }

  long long ans = 0;
  for(int i = 0; i < n; ++i) {
    int m = min(b[i], a[i]);
    a[i] -= m;
    b[i] -= m;
    ans += m;
    m = min(b[i], a[i + 1]);
    a[i + 1] -= m;
    ans += m;
  }
  cout << ans << '\n';
  
}


Measured memory_bytes: 1024
#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <string>
#include <cstring>
#include <utility>
#include <algorithm>
#include <functional>
#include <deque>
#include <cctype>
#include <ctime>
#include <cstdlib>
#include <iomanip>
using namespace std;

int main(){
   ;
    //サンプルコード;;
    //ABC099-A;;
    ;;
    int n;;;
    cin >> n;;;
    ;;
    if(n<1000){ cout << ("ABC") << endl;;;}
    else { cout << ("ABD") << endl;;;}
}

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

int main(int argc, char* argv[]){
  int32_t n;
  int64_t x;
  vector<int64_t> a;
  cin >> n >> x;  
  for (int32_t i = 0; i < n; i++){
    int64_t a_i;
    cin >> a_i;
    a.push_back(a_i);
  }

  sort(a.begin(), a.end());
  int64_t sum(0);
  int64_t n_s(0);
  for(auto a_i: a){
    sum += a_i;
    if (sum <= x){
      n_s++;
    } else {
      break;
    }
  }
  if (sum == x){
    std::cout << n_s << std::endl;
  } else if (sum < x){
    std::cout << n_s - 1 << std::endl;
  } else{
    std::cout << n_s << std::endl;
  }
  return 0;
}




Measured memory_bytes: 256
#include<iostream>
#include<vector>

using namespace std;

int main(){
    int n;
    cin>>n;
    vector<int> a(n,0);
    for(int i=0;i<n;++i){
        cin>>a[i];
    }
    
    int ans=0;
    while(true){
        bool flag=true;
        for(int i=0;i<n;i++){
            if(a[i]%2!=0) flag=false;
            a[i]/=2;
        }
        if(flag) ans++;
        else break;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
def slve():
	a = input()
	b = input() 
	a_chars = {}
	b_chars = {}

	for i in a:
		if i not in a_chars:
			a_chars[i] = 1
		else:
			a_chars[i] += 1

	for i in b:
		if i not in b_chars:
			b_chars[i] = 1
		else:
			b_chars[i] += 1

	a_l = [v for (k,v) in a_chars.items()]
	b_l = [v for (k,v) in b_chars.items()]
	a_l.sort()
	b_l.sort()
	for i in range(len(a_l)):
		if a_l[i] != b_l[i]:
			print("No")
			return 

	print("Yes")


slve()




Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define pb push_back
#define f(i,x,n) for(int i=x;i<n;i++)
#define all(c) c.begin(),c.end()
#define int ll
using ll = long long;
using pii = pair<int,int>;
const int MOD = 1e9+7, N = 2e5 + 10; 

int a[N],pre[N];

int32_t main(){
   ios::sync_with_stdio(false);
   cin.tie(NULL);
   int n;
   cin >> n;
   pre[0] = 0;
   f(i,1,n+1){
      cin >> a[i];
      pre[i] = pre[i-1]+a[i];
   }
   int ans = 1e18;
   f(i,1,n+1){
      ans = min(ans,abs(pre[i]-(pre[n]-pre[i])));
   }
   cout << ans << '\n';
   return 0;
} 

Measured memory_bytes: 3328
A = int(input())
B = int(input())
C = int(input())
X = int(input())

ans = 0
for i in range(A+1):
    for j in range(B+1):
        for k in range(C+1):
            if i*500 + j*100 + k*50 == X:
                ans += 1

print(ans)

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

#define REP(i,num) for(int i=0;i<(num);++i)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto& x:c){cout<<x<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

using namespace std;
using ll = long long;

constexpr ll atcoder_mod = 1e9+7;

template<typename T=int>
T in(){T x; cin >> x; return (x);}
template<typename T=int,typename C=vector<T>>
C vecin(int N){C x(N);REP(i,N){x[i]=in<T>();}return move(x);}

void vout(){cout << endl;}
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){cout << ' ' << h;vout(forward<Tail>(t)...);}
void out(){cout << endl;}
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){cout << h;vout(forward<Tail>(t)...);}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	int N=in();
	string S=in<string>();
	vector<int> V(N);
	REP(i,N){
		V[i] = S[i];
	}
	V.erase(unique(ALL(V)),V.end());
	
	out(V.size());
	return 0;
}

Measured memory_bytes: 848
#include <bits/stdc++.h>
using namespace std;
int n;
int main() {
    cin >> n;
    vector<string> s(n);
    vector<int> t(n, 0);
    for(int i = 0; i < n; ++i) {
        cin >> s.at(i) >> t.at(i);
    }
    string x;
    cin >> x;
    int no = 0;
    for(int i = 0; i < n; ++i) {
        if(s.at(i) == x) {
            no = i;
            break;
        }
    }

    int sum = 0;
    for(int i = no+1; i < n; ++i) {
        sum += t.at(i);
    }

    cout << sum << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
#define all(x) x.begin(),x.end()
#define rep(i,j,n) for (long long i = j; i < (long long)(n); i++)
#define _GLIBCXX_DEBUG
#define MOD 1000000007
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; }
//(a+b-1)/b
//priority_queue<ll, vector<ll>, greater<ll>> q;
using pl = pair<ll,ll>;
using vvb=vector<vector<bool>>;
using vb= vector<bool>;
ll modpow(ll a,ll b,ll p){
	if(b==0) return 1;
	if(b%2==0){
		ll t=modpow(a,b/2,p);
		return t*t%p;
	}
	return a*(modpow(a,b-1,p))%p;
} 
//cout << fixed << setprecision(桁数);
//__builtin_popcount()
signed main(){
	ll a,b,c,d; cin>>a>>b>>c>>d;
	ll x=c-a;
	ll y=d-b;
	cout<<c-y<<" "<<d+x<<" "<<a-y<<" "<<b+x<<endl;




	

	return 0;
}


Measured memory_bytes: 3636
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <iomanip>
#include <stack>
#include <queue>
#include <numeric>
#include <map>
#include <unordered_map>
#include <set>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define pb push_back
#define mod 1000000007
using ll = long long;
using namespace std;

int main(){
  int N;
  cin >> N;
  if(N < 1200) cout << "ABC" << endl;
  else if(N < 2800) cout << "ARC" << endl;
  else cout << "AGC" << endl;
  return 0;
}


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

    int main()
    {
        int n,k;
        cin>>n>>k;
        int x=n/k;
        if(n<k)
        {
            cout<<1<<endl;
            return 0;
        }
        if(n%k==0)
        {
            cout<<0<<endl;
            return 0;
        }
        cout<<1<<endl;
    }


Measured memory_bytes: 256
//インクルード(アルファベット順)
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<iterator>//集合演算(積集合,和集合,差集合など)
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm(c++17)
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
#include<unordered_map>//イテレータあるけど順序保持しないmap
#include<unordered_set>//イテレータあるけど順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列

using namespace std;
typedef long long ll;

//マクロ
//forループ関係
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
//xにはvectorなどのコンテナ
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x)) //最大値を求める
#define MIN(x) *min_element(ALL(x)) //最小値を求める
//定数
#define INF 1000000000000 //10^12:極めて大きい値,∞
#define MOD 1000000007 //10^9+7:合同式の法
#define MAXR 100000 //10^5:配列の最大のrange(素数列挙などで使用)
//略記
#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素



signed main(){
  int K;
  string S;
  cin>>K>>S;
  if(S.length()<=K){
    cout<<S;
  }else{
    string out=S.substr(0,K)+"...";
    cout<<out;
  }

}

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

#define MAX 100002

int n;
int m;
int q;

int a[MAX];

set<int> s;
deque<int> v;
bool can[MAX];

multiset<int> mp;
int id[MAX];

int main(){
	cin >> n >> m >> q;
	for (int i = 0; i < q; i++){
		scanf("%d", &a[i]);
	}
	reverse(a, a + q);
	for (int i = 0; i < q; i++){
		if (s.count(a[i])==0){
			v.push_back(a[i]);
			s.insert(a[i]);
		}
	}
	for (int i = 1; i <= m; i++){
		if (s.count(i) == 0){
			v.push_back(i);
		}
	}
	int maxx = INT_MAX;
	can[v.size()] = true;
	for (int i = v.size() - 1; i >= 0; i--){
		if (maxx > v[i]){
			maxx = v[i];
			can[i] = true;
		}
		else{
			break;
		}
	}
	s.clear();
	for (int i = 0; i < v.size(); i++){
		id[v[i]] = i;
	}
	for (int i = 0; i < n; i++){
		mp.insert(0);
	}
	int L = -1;
	for (int i = 0; i < q; i++){
		int ID = id[a[i]];
		if (mp.count(ID)){
			auto k = mp.find(ID);
			mp.erase(k);
			mp.insert(ID + 1);
			continue;
		}
		if (ID <= L){
			continue;
		}
		L = max(L, ID);
	}
	for (auto it = mp.begin(); it != mp.end(); it++){
		if (can[(*it)] == false){
			puts("No");
			return 0;
		}
	}
	puts("Yes");
	return 0;
}

Measured memory_bytes: 6272
#include <iostream>
#include <vector>
#include <cmath>
#include <queue>
#include <deque>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <unordered_map>
#include <iomanip>
#include <sstream>
#include <numeric>
using namespace std;
#define ll long long int
#define ld long double
#define vi vector<ll>
#define vvi vector<vi>
#define vs vector<string>
#define pi pair<ll,ll>
#define pb push_back
#define pf push_front
#define eb emplace_back
#define mp make_pair
#define fs first
#define se second
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL);
int main() {
    ll n;
    cin>>n;
    vi a(n);
    vi b(n);
    vi c(n);
    for(ll i=0;i<n;i++){
        cin>>a[i]>>b[i]>>c[i];
    }
    vvi v(3,vi(n,0));
    v[0][0] = a[0];
    v[1][0] = b[0];
    v[2][0] = c[0];
    for(ll i=1;i<n;i++){
        v[0][i] = max(v[1][i-1],v[2][i-1]) + a[i];
        v[1][i] = max(v[0][i-1],v[2][i-1]) + b[i];
        v[2][i] = max(v[0][i-1],v[1][i-1]) + c[i];
    }
    cout<<max({v[0][n-1],v[1][n-1],v[2][n-1]});
}




Measured memory_bytes: 5760
#include <cstdio>
typedef long long ll;
inline int rd(){
    int x=0,p=1;
    char a=getchar();
    while((a<48||a>57)&&a!='-')a=getchar();
    if(a=='-')p=-p,a=getchar();
    while(a>47&&a<58)x=(x<<1)+(x<<3)+(a&15),a=getchar();
    return x*p;
}
const int N=3002;
const ll mod=1e9+7;
int n,q;
int a[N];
ll f[N][N],ans;
inline ll fpow(ll b,ll p=mod-2){
	ll ans=1,tmp=b;
	while(p){
		if(p&1)ans=ans*tmp%mod;
		tmp=tmp*tmp%mod;
		p>>=1;
	}
	return ans;
}
int main(){
	n=rd(),q=rd();
	for(int i=1;i<=n;i++)a[i]=rd();
	for(int i=1;i<=n;i++)
		for(int j=1;j<=n;j++)
			f[i][j]=a[i]<a[j];
	ll inv=fpow(2);
	for(int i=1,x,y;i<=q;i++){
		x=rd(),y=rd();
		f[x][y]=f[y][x]=(f[x][y]+f[y][x])%mod*inv%mod;
		for(int j=1;j<=n;j++)
			if(j!=x&&j!=y){
				f[x][j]=f[y][j]=(f[x][j]+f[y][j])%mod*inv%mod;
				f[j][x]=f[j][y]=(f[j][x]+f[j][y])%mod*inv%mod;
			}
	}
	for(int i=1;i<=n;i++)
		for(int j=1;j<i;j++)
			ans=(ans+f[i][j])%mod;
	printf("%lld\n",ans*fpow(2,q)%mod);
    return 0;
}

Measured memory_bytes: 70528
K=int(input())
def gcd(p,q):
    if p%q==0:
        return q
    return gcd(q,p%q)
S=0
for i in range(K):
    for j in range(K):
        for k in range(K):
            S+=gcd(i+1,gcd(j+1,k+1))
print(S)

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

class Main {
	public static void main(String[] args) throws IOException{
		
		String[] ArrayX = new String[3];
		int[] Numbers = new int[3];
		int cnt = 0;
		
		BufferedReader br =
				new BufferedReader(new InputStreamReader(System.in));
		
		String str = br.readLine();
		ArrayX = str.split(" ");
		
		Numbers[0] = Integer.parseInt(ArrayX[0]);
		Numbers[1] = Integer.parseInt(ArrayX[1]);
		Numbers[2] = Integer.parseInt(ArrayX[2]);
		
		if(Numbers[0]<=Numbers[1]) {
			for(int i = Numbers[0]; i<=Numbers[1]; i++) {
				if(Numbers[2]%i==0){
					cnt++;
				}
			}
		}
		else
			cnt = 0;
		
			System.out.println(cnt);
	}
}

Measured memory_bytes: 24384
#include <algorithm>
#include <cstring>
#include <iostream>
#include <vector>
#include <cmath>
#include <math.h>
#include <stdio.h>
#include <iomanip>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <string>
#define rep(i,n) for (int i = 0; i < (n); ++i)

using namespace std;
const int MOD = 1000000007;


typedef long long int ll; 
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;

void floatOutPutSetup(){
    cout << fixed;
    cout << setprecision(10);
}

int main(){
    int a,b;
    cin>>a>>b;

    rep(i, 1009){
        double tmp1,tmp2;
        tmp1=double(i)*0.08;
        tmp2=double(i)*0.1;
        if(int(floor(tmp1))==a&&int(floor(tmp2))==b){
            cout<<i;
            return 0;
        }
    }
    cout<<-1;


    return 0;
}

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

int main() {
    cin.tie(0);ios::sync_with_stdio(false);
    string s; cin >> s;
    for (int i = 0; i < s.size(); i++)
        if (s[i] == '1')
            s[i] = '9';
        else
            s[i] = '1';
    cout << s << endl;
    return 0;
}


Measured memory_bytes: 256
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
 
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))

sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

# a, b = MAP()
a = INT()
b = INT()
l = [1, 2, 3]

l.remove(a)
l.remove(b)

print(l[0])

Measured memory_bytes: 5144
from collections import namedtuple

Point = namedtuple('Point', ('x', 'y', 'h'))

def main():
    n = int(input())
    points = [read_point() for _ in range(n)]
    print(*solve(points))

def solve(points):
    for p in points:
        if p.h != 0:
            base = p
            break

    for x in range(0, 101 + 1):
        for y in range(0, 100 + 1):
            h = base.h + abs(base.x - x) + abs(base.y - y)
            for p in points:
                ph = max(h - abs(x - p.x) - abs(y - p.y), 0)
                if ph != p.h:
                    break
            else:
                return Point(x, y, h)

def read_point():
    x, y, h = map(int, input().split())
    return Point(x, y, h)

main()


Measured memory_bytes: 3436
S = input()
T = input()

N = len(S)
A = []
B = []
X = {}
Y = {}
x = 0
y = 0

for n in range(N):
    if S[n] not in X:
        X[S[n]] = x
        A.append(x)
        x += 1
    if T[n] not in Y:
        Y[T[n]] = y
        B.append(y)
        y += 1
    if S[n] in X:
        A.append(X[S[n]])
    if T[n] in Y:
        B.append(Y[T[n]])
        
if A == B:
    print('Yes')
else:
    print('No')

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

int main () {
 int n,m; cin >> n >> m;
 vector<bool> flag(n,0); flag[0]=1;
 vector<int> mount(n,1);
 rep(i,m){
   int x,y; cin >> x >> y; x--;y--;
   if(mount[x]>=2 && flag[x]==1){
     flag[y]=1;
   }
   else if(mount[x]==1 && flag[x]==1){
     flag[x]=0;flag[y]=1;
   }
   mount[x]--;
   mount[y]++;
 }
 int cnt=0;
 rep(i,n){
   if(flag[i]==1)cnt++;
 }
 cout << cnt << endl;
}


Measured memory_bytes: 3684
import sys
import math
def get_array(): return list(map(int, sys.stdin.readline().strip().split()))
def get_ints(): return map(int, sys.stdin.readline().strip().split())
def input(): return sys.stdin.readline().strip()
n=int(input())
a=get_array()
a.sort(reverse=True)
b=[a[0]]
for i in range(1,n//2):
    b.append(a[i]*2)
if n%2==0:
    print(sum(b))
else:
    print(sum(b)+a[i+1])

Measured memory_bytes: 94864