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

public class Main 
{
	

	public static void main(String[] args) 
	{
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		
		char[][] b = new char[n][n];
		
		for(int y = 0; y < n; y++)
		{
			String s = sc.next();
			
			for(int x = 0; x < n; x++)
			{
				b[x][y] = s.charAt(x);
			}
		}
		
		int an = 0;
		for(int i = 0; i < n; i++)
		{ //offsets
			boolean good = true;
			for(int y = 0; y < n && good; y++)
			{
				for(int x = y+1; x < n && good; x++)
				{
					int rx = (x+i)%n;
					int ry = y%n;
					
					int rx2 = (y+i)%n;
					int ry2 = x%n;
					
//					if(i>0)
//					System.out.println(i+": " + rx + " " + ry);
					if(b[rx][ry] != b[rx2][ry2])
					{
						good = false;
						break;
					}
				}
				
			}
			if(good)
			{
				an+=n;
			}
			
		}
		System.out.println(an);
		

	}

}


Measured memory_bytes: 27232
def main():
    n = int(input())
    # n, m = map(int, input().split())
    a = list(map(int, input().split()))
    # s = input()
    # h = [int(input()) for _ in rane(n)]

    while True:
        currentmin = 10**10
        currentminIndex = 0
        for i in range(n):
            if currentmin > a[i] and a[i] != 0:
                currentmin = a[i]
                currentminIndex = i
        for i in range(n):
            if i != currentminIndex:
                a[i] = a[i] % currentmin
        count = 0
        for i in range(n):
            if a[i] != 0:
                count += 1
        if count == 1:
            break

    print(max(a))


if __name__ == '__main__':
    main()



Measured memory_bytes: 85112
#include <iostream>
#include <string>
#include <vector>

using namespace std;
using ll = long long int;

int main()
{
    int n;
    cin >> n;
    vector<ll> a(n);
    for(int i = 0; i < n; i++)
    {
        cin >> a[i];
    }
    ll all = a[0];
    for(int i = 1; i < n; i++)
    {
        all = all ^ a[i];
    }
    bool exist = false;
    for(int i = 0; i < n; i++)
    {
        if(a[i] == (all ^ a[i]))
        {
            exist = true;
            break;
        }
    }
    if(exist)
    {
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}

Measured memory_bytes: 1024
N,M = list(map(int, input().split()))
P = []
Y = []
for _ in range(M):
    p,y = list(map(int, input().split()))
    P.append(p)
    Y.append(y)
count = [0]*(N+1)
ans = [0]*(M+1)
data = [[p,y,i] for p,y,i in zip(P,Y,range(1,M+1))]

data.sort(key=lambda x: x[1])

for i in range(M):
    count[data[i][0]] += 1
    ans[data[i][2]] = count[data[i][0]]


for j in range(1,M+1):
    a = P[j-1]
    b = ans[j]
    print(str(a*(10**6)+b).zfill(12))






Measured memory_bytes: 77912
#include <iostream>
#include <string>
using namespace std;
int main(){
  string S;
  cin >> S;
  /*for(int i = 0; i < S.size(); i = i + 2){
    cout << i;
  }
  cout << endl;*/
  for(int i = 0; i < S.size(); i = i + 2){
    cout << S[i];
  }
  cout << endl;
  return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
ll n;
ll x[105],y[105],h[105];
ll z=0;
ll s;
int main(void){
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>x[i]>>y[i]>>h[i];
        if(h[i]!=0){
            s=i;
        }
    }
    for(int i=0;i<=100;i++){
        for(int j=0;j<=100;j++){
            ll H=h[s]+abs(x[s]-i)+abs(y[s]-j);
            bool t=true;
            for(int k=0;k<n;k++){
                if(max(H-abs(i-x[k])-abs(j-y[k]),z)!=h[k]){
                    t=false;
                }
            }
            if(t&&H!=0){
                cout<<i<<" "<<j<<" "<<H<<endl;
                return 0;
            }
        }
    }

}



Measured memory_bytes: 3624
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <vector>
#include <complex>
typedef long long int LL;
typedef unsigned long long int ULL;
using namespace std;

// 插入此處

void next(string &s) {
    int len = s.size();
    for (int i = len - 1; i > 0; i--) {
        if (s[i] <= s[i - 1] && s[i] != '9') {
            s[i] += 1;
            for (int j = i + 1; j < len; j++) {
                if (s[j - 1] > '0') {
                    s[j] = s[j - 1] - 1;
                } else {
                    s[j] = s[j - 1];
                }
            }
            return;
        }
    }
    if (s[0] < '9') {
        s[0] += 1;
        for (int i = 1; i < len; i++) {
            if (s[i - 1] > '0') {
                s[i] = s[i - 1] - 1;
            } else {
                s[i] = s[i - 1];
            }
        }
    } else if (s[0] == '9') {
        s = "";
        s.push_back('1');
        for (int i = 0; i < len; i++) {
            s.push_back('0');
        }
    }
}

int main() {
    int k;
    scanf("%d", &k);
    string s = "0";
    while (k--) {
        next(s);
    }
    cout << s << endl;
}


Measured memory_bytes: 888
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll,ll>;
using vl = vector<ll>;
using Map = map<ll,ll>;
using T = tuple<ll,ll,ll>;
using vvl = vector<vector<ll>>;
#define all(v) v.begin(), v.end()
#define prt(v) cout<<v<<"\n";
#define fi(v) get<0>(v)
#define se(v) get<1>(v)
#define th(v) get<2>(v)
#define endl "\n"
template <typename T> bool chmax(T &a, const T &b){if (a<b){a=b;return 1;}return 0;}
template <typename T> bool chmin(T &a, const T &b){if (a>b){a=b;return 1;}return 0;}
const ll INF=1LL<<62;
const ll MOD=1000000007;

ll N,Q,K;
vector<ll> a(100007,0);
vector<ll> b(100007,0);
vector<ll> c(100007,0);
vector<ll> x(100007,0);
vector<ll> y(100007,0);
vector<ll> d(100007,INF);
vector<vector<P>> G(100007, vector<P>(0));

void dfs(ll x){
    for(auto p: G[x]){
        ll s=p.first,t=p.second;
        if(d[s]==INF){d[s]=d[x]+t;dfs(s);}
    }
}

signed main(void){
    cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);
    cin >> N;
    for(ll i=0;i<N-1;++i){cin>>a[i]>>b[i]>>c[i];a[i]--;b[i]--;}
    for(ll i=0;i<N-1;++i){
        G[a[i]].emplace_back(P(b[i],c[i]));
        G[b[i]].emplace_back(P(a[i],c[i]));
    }
    cin>>Q>>K;K--;
    for(ll i=0;i<Q;++i){cin>>x[i]>>y[i];x[i]--;y[i]--;}
    d[K]=0;
    dfs(K);

    for(ll i=0;i<Q;++i)prt(d[x[i]]+d[y[i]])
    

    return 0;
}


Measured memory_bytes: 18304
D, G = map(int,input().split())
PC = [list(map(int, input().split())) for _ in range(D)]
comp_ans_ll = [0 for _ in range(D) ]
n_ans=float("inf")

def main():
  global n_ans
  for i in range(1<<D):
    comp_ans_l = [0 for _ in range(D) ]
    score = 0
    tmp_n_ans = 0
    for j in range(D):
      if (i>>j)&1:
        score += (j+1)*100*PC[j][0] + PC[j][1]
        tmp_n_ans+=PC[j][0]
        comp_ans_l[j] = 1
    if G <= score:
      n_ans = min(n_ans, tmp_n_ans)
    else:
      for k in range(D-1,-1,-1):
        if comp_ans_l[k]==0:
          for l in range(1,PC[k][0]):
            score += 100*(k+1)
            tmp_n_ans+=1
            if G <= score:
              n_ans = min(n_ans, tmp_n_ans)
              break
        if score>=G:
          break
  print(n_ans)

if __name__=="__main__":
  main()


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

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

    vector<int> S[m];
    rep(i,m) {
        int k;
        cin >> k;
        rep(j,k) {
            int s;
            cin >> s;
            s--;
            S[i].push_back(s);
        }
    }

    int P[m];
    rep(i,m) cin >> P[i];

    int ans = 0;
    rep(i,1<<n) {
        bool isAllOk = [&]{
            rep(j,m) {
                int tot = 0;
                for(auto s : S[j]) {
                    if(i>>s&1) tot++;
                }
                if (tot % 2 != P[j]) return false;
            }
            return true;
        }();
        if (isAllOk) ans++;
    }

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

Measured memory_bytes: 256
import java.util.*;
import java.lang.Math;
public class Main{
     public static void main(String[] args)
	{
		Scanner s1=new Scanner(System.in);
		int i,j,k=0;
		int n;
		double m,q;
		n=s1.nextInt();
		int[] a=new int[n];
		for(i=0;i<n;i++){
			a[i]=s1.nextInt();
		
			k=k+a[i];
        }
		int o=k/n;
		int w=k/n+1;
 
		int v=0;
		int d=0;
		for(j=0;j<n;j++)
		{
			m=(double)(o-a[j]);
			int b=(int)(Math.pow(m,2.0));
			v=v+b;
			q=(double)(w-a[j]);
			int c=(int)(Math.pow(q,2.0));
			d=d+c;
 
		}
		if(v<d){
			System.out.println(v);
        }
		else{
			System.out.println(d);
        }
     }
}

Measured memory_bytes: 21972
N = int(input())
hs = list(map(int, input().split()))

def watering(h_list):
  if h_list == []:
    return 0
  
  tmp = min(h_list)
  water = tmp
  h_list = list(map(lambda x:x-tmp, h_list))
  ind = h_list.index(0)
  water += watering(h_list[:ind])
  water += watering(h_list[(ind+1):])
  
  return water

print(watering(hs))

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define res register int
#define ll long long
//#define cccgift
//#define getchar()(p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++)
//char buf[1<<21],*p1=buf,*p2=buf;
template<typename T>
inline void read(T &x)
{
    static char ch;bool f=1;
    for(x=0,ch=getchar();!isdigit(ch);ch=getchar()) if(ch=='-') f=0;
    for(;isdigit(ch);x=(x<<1)+(x<<3)+(ch^48),ch=getchar());x=f?x:-x;
}
template<typename T>
void print(T x)
{
    if (x<0) x=-x,putchar('-');
    if (x>9) print(x/10);
    putchar(x%10+48);
}
template<typename T>
inline void print(T x,char ap) {print(x);if (ap) putchar(ap);}
template<typename T>
inline void chkmax(T &x,const T &y) {x=x<y?y:x;}
template<typename T>
inline void chkmin(T &x,const T &y) {x=x<y?x:y;}

int main()
{
	int n,r;
	cin>>n>>r;
	if(n>=10) print(r,'\n');else print(r+100*(10-n),'\n');
	return 0;
}
/* stuff you should look for
    * int overflow, array bounds
    * special cases (n=1?), set tle
    * do something instead of nothing and stay organized
*/ 

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

int n;

int main(){
	cin >> n;
	for (int i=0; i<=n/7; ++i){
		if((n-i*7)%4 == 0) {
			cout << "Yes";
			return 0;
		}
	}
	cout << "No";
	return 0;
}

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

int main() {
    string s;
    cin >> s;
    for(int i=0; i<s.size(); ++i) {
        char c = s[i];
        if(c == ',') {
            cout << ' ';
        } else {
            cout << c;
        }
    }
    cout << endl;
}


Measured memory_bytes: 256
import java.io.BufferedReader
import java.io.InputStreamReader
import java.io.PrintWriter

val br = BufferedReader(InputStreamReader(System.`in`))
val out = PrintWriter(System.out)

fun main() {
    br.use { out.use {
        solve()
        out.flush()
    } }
}

fun solve() {
    val n = readInteger()
    val ps = readIntegerList().map { it - 1 }
    var ans = 0
    var last = ps.first()
    for (i in 0 until (n - 1)) {
        if (last == i) {
            ans++
        } else {
            last = ps[i + 1]
        }
    }
    if (last == n - 1) ans++
    out.println(ans)
}

fun readInteger() = Integer.parseInt(br.readLine())
fun readLong() = java.lang.Long.parseLong(br.readLine())
fun readStringList() = br.readLine()!!.split(' ')
fun readIntegerList() = readStringList().map(Integer::parseInt)
fun readLongList() = readStringList().map(java.lang.Long::parseLong)
fun readDoubleList() = readStringList().map(java.lang.Double::parseDouble)


Measured memory_bytes: 52000
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#define LL long long
using namespace std;
LL n, K;
LL _min(LL x, LL y) { return x < y ? x : y; }
int main() {
	LL i, j, k;
	scanf("%lld%lld", &n, &K);
	LL ans = 0;
	for(i = K+1; i <= n; i++){
		LL p = (n+1)/i*K+_min((n+1)%i, K)-1;
		if(p < 0) p = 0;
		ans += n-p;
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 128
/* Bismillahirrahmanirrahim */
/* Author : Jehian Norman Saviero (@Reiva5) */
#include <bits/stdc++.h>
 
// MACROS SAMPAH
#define Jehian using
#define Norman namespace
#define Saviero std
 
Jehian Norman Saviero;
 
// MACROS TYPE
typedef long l;
typedef long long ll;
typedef unsigned long ul;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int,int> pi;
typedef pair<l,l> pl;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<l> vl;
typedef vector<ll> vll;
 
// MACROS FOR PRINT
#define nl printf("\n")
#define sp printf(" ")
 
// MACROS FOR ATTRIBUTE
#define fi first
#define se second
 
// MACROS FOR FUNCTION AND METHOD
#define eb emplace_back
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define ALL(x) (x).begin(), (x).end()
#define ALLN(x,n) (x), (x)+(n)
#define CUBE(x) (SQR(x)*(x))
#define SET(x,y) for (int _qwe = sizeof(x)/sizeof(x[0]); _qwe; ) x[--_qwe] = (y)
#define SQR(x) ((x)*(x))
#define SSORT(x,sz) sort(ALLN(x,sz))
#define RESET(x) memset((x), 0, sizeof(x))
#define VSORT(x) sort(ALL(x))
 
// MACROS READ INPUT
#define sci(x) scanf("%d", &x)
#define scl(x) scanf("%ld", &x)
#define scll(x) scanf("%lld", &x)
#define scul(x) scl(x)
#define scull(x) scll(x)

inline ll dist(pll &A, pll &B) {
	return abs(A.fi-B.fi) + abs(A.se-B.se);
}

int main() {
	int N;
	sci(N);
	pair<ll,pll> dat[4][N];
	pll pts[N];
	for (int i = 0; i < N; ++i) {
		pll P;
		scll(P.fi), scll(P.se);
		pts[i] = P;
		dat[0][i] = {P.fi+P.se, P};
		dat[1][i] = {-P.fi+P.se, P};
		dat[2][i] = {P.fi-P.se, P};
		dat[3][i] = {-P.fi-P.se, P};
	}
	pll MAX[4];
	for (int i = 0; i < 4; ++i) {
		MAX[i] = max_element(ALLN(dat[i], N))->se;
	}
	ll ans = 0;
	for (int i = 0; i < N; ++i) {
		for (int j = 0; j < 4; ++j) {
			ans = max(ans, dist(pts[i], MAX[j]));
		}
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 25728
#include<cstdio>
#include<cstdlib>
#include<cmath>

using namespace std;

int main()
{
	int a,b,c,sum;
	while(~scanf("%d %d %d",&a,&b,&c))
	{
		sum=a*100+b*10+c;
		if(sum%4==0)
			printf("YES\n");
		else
			printf("NO\n");
	}
	return 0;
}


Measured memory_bytes: 128
#include <iostream>

using namespace std;

bool isDivisor(int m, int n, int x, int y) {
    if (x == 0 && y == 0) return false;
    int mod = x * x + y * y;
    int p = x * m + y * n;
    int q = x * n - y * m;
    //cout << m << ',' << n << ',' << x << ',' << y << endl;
    return p % mod == 0 && q % mod == 0;
}

bool isPrime(int m, int n) {
    int c = 0;
    for (int x = -200; x <= 200; x++) {
        for (int y = -200; y <= 200; y++) {
            if (isDivisor(m, n, x, y)) {
                c++;
            }
        }
    }
    return c == 8;
}

int main() {
    int n; cin >> n;
    while (n--) {
        int m, n; cin >> m >> n;
        cout << (isPrime(m, n) ? 'P' : 'C') << endl;
    }
    return 0;
}

Measured memory_bytes: 1152
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()

N = I()
v = LI()

v = sorted(v,reverse=True)

ans = 0

for i in range(N-1):
    ans += v[i]/(2**(i+1))

print(ans + v[N-1]/(2**(N-1)))

Measured memory_bytes: 3064
#include <iostream>
#include <stdio.h>
#include <string>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <math.h>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <climits>
#include <bitset>
#include <list>
#include <map>
#include <set>

using namespace std;

typedef unsigned long long ull;
typedef long long ll;

int main(){
	int d;
	ll g;
	cin >> d >> g;
	g/=100;
	int p[d], c[d];
	for(int i=0; i<d; i++){
		cin >> p[i] >> c[i];
		c[i]/=100;
	}

	int ans=1000;
	for(int i=0; i<(1<<d); i++){
		int idx=-1;
		vector<int> v;
		for(int j=0; j<d; j++){
			if((i>>j)%2==0) idx=j;
			else v.push_back(j);
		}
		int solved=0, l=v.size();
		ll score=0;
		for(int j=0; j<l; j++){
			solved+=p[v[j]];
			score+=(v[j]+1)*p[v[j]]+c[v[j]];
		}

		if(score<g){
			if(idx==-1) continue;
			else if(g>score+(idx+1)*p[idx]) continue;
			else{
				solved+=(g-score+idx)/(idx+1);
			}
		}
		ans=min(ans, solved);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <set>
#include <queue>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <cstring>
#include <functional>
#include <climits>
#include <sstream>
#include <iomanip>
#include <map>
#include <stack>
#include <tuple>
#include <numeric>

using namespace std;

/*-----------------------------------------------------------------------------
　定義
 -------------------------------------------------------------------------------*/
#define REP(i, n)				for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n)			for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define INF						2e9
#define MOD						(1000 * 1000 * 1000 + 7)
#define Ceil(x, n)				(((((x))+((n)-1))/n))		/* Nの倍数に切り上げ割り算 */
#define CeilN(x, n)				(((((x))+((n)-1))/n)*n)		/* Nの倍数に切り上げ */
#define FloorN(x, n)			((x)-(x)%(n))				/* Nの倍数に切り下げ */
#define IsOdd(x)				(((x)&0x01UL) == 0x01UL)			
#define IsEven(x)				(!IsOdd((x)))						
#define	BitSetV(Val,Bit)		((Val) |= (Bit))			
#define	BitTstV(Val,Bit)		((Val) & (Bit))				
#define M_PI					3.14159265358979323846
typedef long long				ll;
typedef pair<ll, ll>			P;

/*-----------------------------------------------------------------------------
　処理
 -------------------------------------------------------------------------------*/
/* 素因数分解 */
map<ll, ll> factMap;
void primeFactor(ll n)
{
    if ((n % 2) == 0){
        while((n % 2) == 0) {
            factMap[2]++;
            n = n / 2;
        }
    }

    for(ll i = 3; i <= sqrt(n); i += 2){
        while ((n % i) == 0){
            factMap[i]++;
            n = n / i;
        }
    }

	if (n != 1) {
		factMap[n]++;
	}
}

// MODのべき乗
ll powMod(ll n, ll p) 
{
	ll res = 1;
	while (p) {
		if (p & 1) (res *= n) %= MOD;
		(n *= n) %= MOD;
		p >>= 1;
	}
	return res;
}

// MODの逆元
ll invMod(ll n) 
{
	return powMod(n, MOD - 2);
}

// メイン
int main()
{
	// 入力
	ll N, M;
	cin >> N >> M;

	// 素因数分解
	primeFactor(M);

	// コンビネーション
	// 各素数をN分割した結果(n+k-1Ck)の組み合わせ(乗算)
	ll ans = 1;
	for (auto one : factMap) {
		ll n = N + one.second - 1;
		ll r = min(one.second, N - 1);
		for (ll i = n; i >= n - r + 1; i--) {
			ans *= i;
			ans %= MOD;
		}
		for (ll i = r; i >= 1; i--) {
			ans = ans * invMod(i);
			ans %= MOD;
		}
	}

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



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

int main(){
 int n,m,sum;

 sum=0;
 cin>>n;
 m=n;
 do{
   sum+=m%10;
   m/=10;
 }while(m>0);

  if(n%sum==0){cout<<"Yes"<<endl;}
  if(n%sum!=0){cout<<"No"<<endl;}
 return 0;
}

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

char P[9][9];
char Q[9][9];

int main()
{
	int i, j;
	
	for (i = 0; i < 8; i++) {
		for (j = 0; j < 8; j++) {
			cin >> P[i][j];
			Q[j][7 - i] = P[i][j];
		}
	}
	
	cout << "90" << endl;
	
	for (i = 0; i < 8; i++) {
		for (j = 0; j < 8; j++) {
			cout << Q[i][j];
			P[j][7 - i] = Q[i][j];
		}
		cout << endl;
	}
	
	cout << "180" << endl;
	
	for (i = 0; i < 8; i++) {
		for (j = 0; j < 8; j++) {
			cout << P[i][j];
			Q[j][7 - i] = P[i][j];
		}
		cout << endl;
	}
	
	cout << "270" << endl;
	
	for (i = 0; i < 8; i++) {
		for (j = 0; j < 8; j++) {
			cout << Q[i][j];
			P[j][7 - i] = Q[i][j];
		}
		cout << endl;
	}
}

Measured memory_bytes: 1136
from collections import deque
readline = open(0).readline
writelines = open(1, 'w').writelines
Q = int(readline())
ans = []
A = deque()
def push(d, x):
    (A.append if d else A.appendleft)(x)
def access(p):
    ans.append("%d\n" % A[p])
def pop(d):
    (A.pop if d else A.popleft)()


C = [push, access, pop].__getitem__
for i in range(Q):
    t, *a=map(int, readline().split())
    C(t)(*a)
writelines(ans)



Measured memory_bytes: 22008
# -*- coding: utf-8 -*-
import fractions

A, B, C, D = map(int,input().split())

lcm = C * D // fractions.gcd(C, D)

maxC = B // C
maxD = B // D
maxlcm = B // lcm

minC = (A-1) // C
minD = (A-1) // D
minlcm = (A-1) // lcm

lcmB = (maxC + maxD - maxlcm)
lcmA = (minC + minD - minlcm)

print((B-A+1)-(lcmB-lcmA))



Measured memory_bytes: 5076
#include<iostream>
#include<algorithm>
using namespace std;
int main() {
  string s;
  cin >> s;
  sort(s.begin(), s.end()); // string型に対してはiterator,char型配列に対してはアドレス
  if(s[0] == s[1] && s[1] != s[2] && s[2] == s[3]) cout << "Yes";
  else cout << "No";
  return 0;
}
  

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

temp = 0
cnt = 0
for i in range(n-1):
    #print(temp)
    if A[i] < A[i+1]:
        if temp == 0:
            temp = 1
        elif temp == -1:
            temp = 0
            cnt += 1
        else:
            pass
    elif A[i] > A[i+1]:
        if temp == 0:
            temp = -1
        elif temp == 1:
            temp = 0
            cnt += 1
        else:
            pass
    else:
        pass
else:
    cnt += 1
print(cnt)

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

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

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

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

using namespace std;

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

typedef long long ll;
typedef long double R;
const R EPS=1e-9L; // [-1000,1000]->EPS=1e-8 [-10000,10000]->EPS=1e-7
inline int sgn(const R& r){return(r > EPS)-(r < -EPS);}
inline R sq(R x){return sqrt(max(x,0.0L));}

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

// Problem Specific Parameter:

int main() {
  int N, K; cin >> N >> K;
  vector<long long> v[100000];
  for(int i = 0; i < N; ++i) {
    int t, d; cin >> t >> d;
    t--;
    v[t].emplace_back(d);
  }

  vector<long long> q1, q2;
  for(int i = 0; i < N; ++i) {
    sort(v[i].rbegin(), v[i].rend());
    if(v[i].size()) {
      for(int j = 0; j < 1; ++j) {
        q1.emplace_back(v[i][j]);
      }
      for(int j = 1; j < v[i].size(); ++j) {
        q2.emplace_back(v[i][j]);
      }
    }
  }

  sort(q1.rbegin(), q1.rend());
  sort(q2.rbegin(), q2.rend());
  for(int i = 1; i < q2.size(); ++i) {
    q2[i] += q2[i-1];
  }

  long long ret = 0, make = 0;
  for(int i = 0; i < K && i < q1.size(); ++i) {
    make += q1[i];
    long long rest = K - i - 1;
    if(rest <= q2.size()) {
      long long odd = rest <= 0 ? 0 : q2[rest-1];
      ret = max(ret, make + odd + 1LL * (long long)pow(i+1, 2));
    }
  }
  cout << ret << endl;

  return 0;
}

Measured memory_bytes: 6904
#include <stdio.h>
#include <string.h>

int size;
char S[114514];

int from_left[114514], from_right[114514];

int main(void) {
	int i;
	if (scanf("%114513s", S) != 1) return 1;
	size = (int)strlen(S);
	from_left[0] = (S[0] == 'R');
	from_left[1] = (S[1] == 'R');
	from_right[size - 1] = (S[size - 1] == 'L');
	from_right[size - 2] = (S[size - 2] == 'L');
	for (i = 2; i < size; i++) {
		if (S[i] == 'R') {
			from_left[i] = 1;
			if (S[i - 1] == 'R') from_left[i] += from_left[i - 2];
		} else {
			from_left[i] = 0;
		}
	}
	for (i = size - 3; i >= 0; i--) {
		if (S[i] == 'L') {
			from_right[i] = 1;
			if (S[i + 1] == 'L') from_right[i] += from_right[i + 2];
		} else {
			from_right[i] = 0;
		}
	}
	for (i = 0; i < size; i++) {
		int answer = 0;
		if (i + 1 < size && S[i + 1] == 'L') {
			answer += from_left[i];
			if (i + 2 < size && S[i] == 'R') answer += from_right[i + 2];
		}
		if (i - 1 >= 0 && S[i - 1] == 'R') {
			answer += from_right[i];
			if (i - 2 >= 0 && S[i] == 'L') answer += from_left[i - 2];
		}
		printf("%d%c", answer, i + 1 < size ? ' ' : '\n');
	}
	return 0;
}


Measured memory_bytes: 1280
#include "bits/stdc++.h"
using namespace std;

#define int long long
#define all(x) x.begin(), x.end()


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

    int n;
    cin >> n;
    int a[n];

    for (int& i : a) {
        cin >> i;
    }
    
    sort(a, a + n);
    int N=a[n-1];
    int cnt[N+1];
    memset(cnt, 0 , sizeof(cnt));
    for (int i = 0; i < n; i++) {
        for (int j = a[i] ; j < N+1; j += a[i]) {
            cnt[j]++;
        }
    }
    int ans = 0;
    for (int i : a) {
        if (cnt[i] == 1) ans++;
    }
    cout << ans << endl;
}


Measured memory_bytes: 12936
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
using namespace std;
using namespace __gnu_pbds;
#define ll long long
#define pp pair<ll,ll>
typedef tree<pp,null_type,less<pp>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
#define ld long double
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin() , (x).end()
#define rep(i,a,b) for( ll i = a ; i < b ; i+=1 )
#define sz(v) (ll)(v.size())
#define hell (ll)1000000007
#define slld(x) scanf("%lld",&x)
ll t = 1;
const ll inf = hell ;
bool is(string s){
	string s2=s;
	reverse(all(s2));
	return s==s2;
}
void solve(){
	string s;
	cin>>s;
	string s1=s.substr(0,sz(s)/2);
	reverse(all(s));
	string s2=s.substr(0,sz(s)/2);
	is(s1) and is(s) and is(s2) ? cout<<"Yes" : cout << "No" ;
}
signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    //cin >> t ;
    while(t--){
        solve();
    }
    return 0 ;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define Z class
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1e9+7,MAXL=1LL<<61,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<ll,ll> P;

ll n;
vector<string> v;

void dfs(string s,int k,vector<int> a) {
  bool ff=1;
  rep(i,s.size()) {
    if(s[i]=='-') ff=0;
  }
  if(ff||k>=n) {
    v.pb(s);
    return;
  }
  REP(t,1,1<<a.size()) {
    if(!(t&1)) continue;
    string r=s;
    rep(i,a.size()) {
      if(t&(1<<i)) r[a[i]]=(char)(k+'a');
    }
    vector<int> b;
    rep(i,r.size()) {
      if(r[i]=='-') b.pb(i);
    }
    dfs(r,k+1,b);
  }
}

void Main() {
  cin >> n;
  vector<int> a;
  rep(i,n) a.pb(i);
  dfs(string(n,'-'),0,a);
  sort(all(v));
  v.erase(unique(all(v)),v.end());
  rep(i,v.size()) pr(v[i]);
}

int main(){ios::sync_with_stdio(0);cin.tie(0);Main();return 0;}


Measured memory_bytes: 7796
#include <bits/stdc++.h>
#define INF 1e+9
#define MOD (int)1e9+7
#define debug(x) cerr << #x << ": " << x << "\n";
using namespace std;
using ll = long long;
using P = pair<int, int>;

bool is_prime[100001];
int prime[100000], num[100001];

int main(void){
    is_prime[1] = false; is_prime[2] = true;
    prime[0] = 2;
    int pos = 1;
    for(int i = 3; i < 100001; i++){
        for(int j = 0; j < pos; j++){
            if(i % prime[j] == 0){
                is_prime[i] = false;
                break;
            }
            if(j == pos - 1){
                is_prime[i] = true;
                prime[pos] = i;
                pos++;
                break;
            }
        }
    }

    num[1] = 0;
    for(int i = 3; i <= 100000; i++){
        if(i % 2 == 0) continue;
        if(is_prime[i] and is_prime[(i + 1) / 2]){
            num[i] = num[i - 2] + 1;
        }else{
            num[i] = num[i - 2];
        }
        // if(i < 50) {debug(i);debug(num[i]);}
    }

    int Q; cin >> Q;
    int l[Q], r[Q];
    for(int i = 0; i < Q; i++){
        cin >> l[i] >> r[i];
    }

    for(int i = 0; i < Q; i++){
        // debug(num[l[i] - 2]); debug(num[r[i]]);
        if(l[i] == 1){
            cout << num[r[i]] << '\n';
        }else{
            cout << num[r[i]] - num[l[i] - 2] << '\n';
        }
    }
    return 0;
}

Measured memory_bytes: 1920
import math

def com(n, r):
  if r < 0 and r > n:
    return 0
  
  if r == 1:
    return n
  elif r == 2:
    return n * (n-1) / 2
  else:
    return n * (n-1) * (n-2) / 6

def pow(n, k):
  res = 1
  for i in range(k):
    res *= n

  return res

def solve(i, k, smaller):
  global P
  global N

  if i == P:
    if k == 0:
      return 1
    else:
      return 0

  if k == 0:
    return 1

  if smaller:
    return com(P-i, k) * pow(9, k)
  else:
    if (N[i] == '0'):
      return solve(i+1, k, False)
    else:      
      a = solve(i+1, k, True)
      b = solve(i+1, k-1, True) * (int(N[i]) - 1)
      c = solve(i+1, k-1, False)
      return a + b + c
    
N = input()
K = input()

P = len(N)

print(math.floor(solve(0, int(K), False)))

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

using namespace std;

const int N = 2e5 + 10;
string s[N];

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin >> n;
    map<string,int>mp;
    mp.clear();
    set<string>st;
    for(int i = 0;i < n;i++)
    {
        cin >> s[i];
        mp[s[i]] += 1;;
    }
    int dmax = 0;
    for(auto it : mp)
    {
        if(it.second > dmax)
        {
            dmax = it.second;
        }
    }
    for(auto it : mp)
    {
        if(it.second == dmax)cout <<it.first<<"\n";
    }

    return 0;
}

Measured memory_bytes: 25472
#include<stdio.h>

int main (void){

    int loan = 100000;

    int n ,i;


    scanf("%d",&n);

    for(i = 0 ;i < n ;i++){
        loan = loan / 100 * 105;

        if(loan % 1000 == 0){

        }else if(loan % 1000 != 0){
            loan = loan / 1000 * 1000 + 1000;
        }
        //printf("--%d--",loan);
    }

    printf("%d\n",loan);

    return 0;
}

Measured memory_bytes: 592
import java.util.*;
public class Main{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
  int r = sc.nextInt();
  int g = sc.nextInt();
  int b = sc.nextInt();
  if((10*g+b)%4 == 0)System.out.println("YES");
  else System.out.println("NO");
}
}

Measured memory_bytes: 23252
#include <iostream>

using namespace std;

int main(){
    int num[3];
    int temp, count=0;
    cin >> temp;
    num[0] = temp / 100;
    num[1] = (temp - num[0]*100) / 10;
    num[2] = temp - num[0]*100 - num[1]*10;
    
    for(int i=0; i<3; i++){
        if(num[i] == 1) count++; 
    }

    cout << count << endl;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define pb push_back
#define vi vector<int>
#define vvi vector<vi>
#define va vector<array<int,6>>
#define vva vector<va>

vector<string> toVs(string s){
	vector<string> ret;
	string buf = "";
	
	rep(i,s.size()){
		if(i+9<=s.size()&&s.substr(i,9)=="a list of"){
			buf+="<";
			i+=8;
		}
		else if(i+3<=s.size()&&s.substr(i,3)=="and"){
			buf+="&";
			i+=2;
		}
		else if(isalpha(s[i]))buf+=s[i];
		else if(s[i]==' '){
			ret.pb(buf);
			buf = "";
		}
	}
	if(buf.size())ret.pb(buf);
	return ret;
}


vector<char> toWordClass(vector<string> vs){
	vector<char> ret;
	rep(i,vs.size()){
		string s = vs[i];
		if(s=="<")ret.pb('L');
		else if(s=="&")ret.pb('A');
		else ret.pb('T');
	}
	return ret;
}


deque<string> dfs(int a,int b,int c,vector<vva> &bef,vector<string> &vs){
	if(a==b){
		if(vs[a]=="<"||vs[a]=="&")return deque<string>();
		deque<string> ret;
		ret.push_back(vs[a]);
		return ret;
	}
	
	array<int,3> l,r;
	rep(i,3)l[i] = bef[a][b][c][i];
	rep(i,3)r[i] = bef[a][b][c][i+3];
	
	deque<string> ret,y;
	ret = dfs(l[0],l[1],l[2],bef,vs);
	y   = dfs(r[0],r[1],r[2],bef,vs);
	
	for(auto &e:y){
		ret.push_back(e);
	}
	
	if(c==0){
		ret.push_front("(");
		ret.push_back(")");
	}
	
	return ret;
}


int main(){
	vector<pii> rule[3] = {
		{pii(4,3),pii(4,0),pii(4,1)},			//S
		{pii(3,2),pii(0,2),pii(3,1),pii(0,1)},	//P
		{pii(5,3),pii(5,0)}						//Q
	};
	
	int n;
	cin>>n;
	cin.ignore();
	while(n--){
		string s;
		getline(cin,s);
		vector<string> vs = toVs(s);
		int N = vs.size();
		vector<char> wc = toWordClass(vs);
		
		vector<vvi> dp(N,vvi(N,vi(6,0)));
		vector<vva> bef(N,vva(N,va(6,array<int,6>{-1,-1,-1,-1,-1,-1})));
		
		rep(i,N){
			if(wc[i]=='T')dp[i][i][3]=1;
			if(wc[i]=='L')dp[i][i][4]=1;
			if(wc[i]=='A')dp[i][i][5]=1;
		}
		
		for(int wid = 2;wid<=N;wid++){
			for(int l = 0;l<N;l++){
				int r = l+wid-1;
				if(r>=N)continue;
				rep(i,3){
					for(int p = l;p<=r-1;p++){
						rep(j,rule[i].size()){
							int x,y;
							tie(x,y) = rule[i][j];
							if(dp[l][p][x]!=0 && dp[p+1][r][y]!=0){
								dp[l][r][i]+=dp[l][p][x]*dp[p+1][r][y];
								if(dp[l][r][i]>2)dp[l][r][i] = 2;
								bef[l][r][i] = array<int,6>{l,p,x,p+1,r,y};
							}
						}
					}
				}
			}
		}
		
		if(dp[0][N-1][0]>=2){
			cout<<"AMBIGUOUS"<<endl;
			continue;
		}
		assert(dp[0][N-1][0]!=0);
		
		
		deque<string> ans = dfs(0,N-1,0,bef,vs);
		
		vector<string> a;
		for(auto &e:ans)a.pb(e);
		
		rep(i,a.size()){
			if(a[i]=="("||(i+1<a.size()&&a[i+1]==")")||i==a.size()-1)cout<<a[i];
			else cout<<a[i]<<" ";
		}
		cout<<endl;
	}
}

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

int main() {
	string s;
	cin >> s;
	for(int i = 0;i < s.size() - 1;i++){
		if(s.substr(i,2) == "AC"){
			cout << "Yes" << endl;
			return 0;
		}
	}
	cout << "No" << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<vector>
#include<deque>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<algorithm>
#include<functional>
#include<utility>
#include<bitset>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<cstdio>

using namespace std;

#define REP(i,n) for(int i=0;i<int(n);i++)
#define foreach(c,itr) for(__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)
typedef long long ll;

int a[110];
ll dp[110][25];

int main(void){

	int i,j;
	int N;
	cin >> N;
	for(i=1;i<=N;i++) cin >> a[i];
	dp[1][a[1]]=1;
	for(i=2;i<N;i++){
		for(j=0;j<=20;j++){
			if(j-a[i]>=0) dp[i][j]+=dp[i-1][j-a[i]];
			if(j+a[i]<=20) dp[i][j]+=dp[i-1][j+a[i]];
		}
	}

	cout << dp[N-1][a[N]] << endl;

	return 0;
}

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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int A, B, C;
  cin >> A >> B >> C;
  if (B <= C * A)
    cout << B / A << '\n';
  else
    cout << C << '\n';
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
	int N;
	cin >> N;
	vector<int> a(N);
	for (auto& x : a) cin >> x;
	sort(a.rbegin(), a.rend());
	a.push_back(0);
	int p = 0;
	while (a[p+1] > p+1) ++ p;
	int q = 0;
	while (a[p+q] > p) ++ q;
	if ((a[p] - p) % 2 == 1 && q % 2 == 1) {
		cout << "Second" << endl;
	} else {
		cout << "First" << endl;
	}
}


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

ll solve() {
    ll N;
    cin >> N;
    vector<ll> A(N);
    for ( int i = 0; i < N; i++ ) {
        cin >> A[i];
    }
    const ll MOD = 1e9 + 7;
    auto Add = [&](ll& x, ll y) { x = ( x + y % MOD ) % MOD; };
    auto Mul = [&](ll& x, ll y) { x = ( x * y % MOD ) % MOD; };
    auto Pow = [&](ll x, ll n) -> ll {
        ll t = x % MOD, r = 1;
        while ( n > 0 ) {
            if ( n & 1 ) Mul(r, t);
            Mul(t, t);
            n >>= 1;
        }
        return r;
    };
    auto Inv = [&](ll a) -> ll {
        return Pow(a, MOD - 2);
    };
    
    ll M = 61;
    vector<ll> d(M);
    for ( int i = 0; i < N; i++ ) {
        for ( int j = 0; j < M; j++ ) {
            if ( A[i] & (1LL << j) ) d[j]++;
        }
    }
    ll ans = 0;
    for ( ll j = 0; j < M; j++ ) {
        ll x = d[j] * (N-d[j]) % MOD;
        ll p = Pow(2, j);
        Mul(x, p);
        Add(ans, x);
    }
    return ans;
}

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

Measured memory_bytes: 2560
// #pragma GCC target("avx2")
#pragma GCC optimize("O3", "unroll-loops")

// #include <bits/extc++.h>
// using namespace __gnu_pbds;

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

#define int long long
#define double long double
// template <typename T>
// using pbds_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
using pii = pair<int, int>;
template<typename T>
using prior = std::priority_queue<T, vector<T>, greater<T>>;
template<typename T>
using Prior = std::priority_queue<T>;

#define X first
#define Y second
#define ALL(x) (x).begin(), (x).end()
#define eb emplace_back
#define pb push_back

#define fastIO() ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define RANDOM() random_device __rd; \
                 mt19937 __gen = mt19937(__rd()); \
                 uniform_int_distribution<int> __dis(1E5, 1E6); \
                 auto rnd = bind(__dis, __gen)

const int INF = 1E18;
const int mod = 1E9 + 7;
const int maxn = 1 << 18;

void exgcd(int a, int b, int &x, int &y) {
    if (b == 0) {x = __gcd(a, b), y = 0; return;}
    
    exgcd(b, a % b, y, x);
    y -= (a / b) * x;
}

int32_t main() {
    fastIO();
    
    int n, ans = INF;
    cin >> n;
    if (n == 1) ans = 1;
    if (~n & 1) n *= 2;
    
    for (int i = 1; i*i <= n; ++i) {
        if (n % i == 0 and __gcd(i, n/i) == 1) {
            int a = i, b = n / i, x, y;
            /// solve exgcd ///
            // cout << "check " << a << " " << b << "\n";
            
            /// ax + -by = 1 ///
            exgcd(a, -b, x, y);
            if (!x or y <= 0) x += b, y += a;
            // cout << "(" << a << ", " << -b << ") : (" << x << ", " << y << ")\n";
            if (x and y) ans = min(ans, b*y);
            
            /// bx + -ay = 1 ///
            exgcd(b, -a, x, y);
            if (!x or y <= 0) x += a, y += b;
            // cout << "(" << b << ", " << -a << ") : (" << x << ", " << y << ")\n";
            if (x and y) ans = min(ans, a*y);
        }
    }
    
    cout << ans << "\n";
    
    return 0;
}

Measured memory_bytes: 3532
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <queue>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

int main() {
    int n, m, r;
    cin >> n >> m >> r;
    vector<int> rs(r);
    for (int i = 0; i < r; ++i) {
        cin >> rs[i];
        --rs[i];
    }
    long long inf = (long long)numeric_limits<int>::max() * 2;
    vector<vector<long long>> dist(n, vector<long long>(n, inf));
    for (int i = 0; i < m; ++i) {
        int a, b, c;
        cin >> a >> b >> c;
        --a;
        --b;
        dist[a][b] = dist[b][a] = c;
    }
    for (int k = 0; k < n; ++k) {
        for (int i = 0; i < n; ++i) {
            for (int j = 0; j < n; ++j) {
                dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
            }
        }
    }
    sort(rs.begin(), rs.end());
    long long ans = numeric_limits<long long>::max();
    do {
        long long d = 0;
        for (int i = 0; i < r - 1; ++i) {
            d += dist[rs[i]][rs[i + 1]];
        }
        ans = min(ans, d);
    } while (next_permutation(rs.begin(), rs.end()));
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 512
#include <stdio.h>

int main() {

  long long i,j,k,n,m,l,a,b,c;
  long long A[101][101] = {0};
  long long B[101][101] = {0};
  long long C[101][101] = {0};

  scanf("%lld %lld %lld",&n,&m,&l);

  for(j=0; j<n; j++) {
    for(i=0; i<m; i++) {

      scanf("%lld", &a);
      A[j][i] = a;
    
    }
  }

  for(j=0; j<m; j++){
    for(i=0;i<l;i++){
      scanf("%lld",&b);
      B[j][i] = b;
    }
  }

    for(i=0 ;i<n; i++) {
      for(j=0; j<l; j++){
	C[i][j] = 0;
	for(k=0;k<m; k++) {
	   C[i][j] += A[i][k]*B[k][j];  
	   /*    printf("%d ",C[i][j]); */
	}
	/* printf("\n"); */
      }
    }


     for(i=0; i<n; i++) {
      for(j=0; j<l; j++) {
	printf("%lld",C[i][j]);
	if(j !=l-1) {
	  printf(" ");
	}
      }
      printf("\n");
      } 

    return 0;

  }

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

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

  cin >> n;
  vector<long long> a(3 * n);

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

  sort(a.begin(), a.end());

  long long ans = 0;
  int cnt = 0;
  for (int i = 3 * n - 2;; i -= 2) {
    cnt++;
    ans += a[i];
    if (cnt == n) break;
  }

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


Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std; 
long long fac[2000010], inv[2000010], finv[2000010]; 
long long MOD = 1000000007; 
void COMinit(){
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for(int i = 2; i < 2000005; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}
long long COM(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0); 
	int K; string S; 
	cin >> K >> S; 
	COMinit(); 
	long long pow25[2000010] = {}; 
	long long pow26[2000010] = {}; 
	pow25[0] = 1; pow26[0] = 1; 
	for(int i = 1; i < 2000005; i++){
		pow25[i] = pow25[i-1] * 25 % MOD; 
		pow26[i] = pow26[i-1] * 26 % MOD; 
	}
	int L = S.size(); 
	long long ans = 0; 
	for(int i = 0; i <= K; i++){
		long long tmp = pow25[i] * (MOD + COM(i + L, L) - COM(i - 1 + L, L)) % MOD; 
		tmp *= pow26[K - i]; tmp %= MOD; 
		ans += tmp; ans %= MOD; 
	}
	cout << ans << "\n"; 
}

Measured memory_bytes: 82404
use std::collections::HashMap;
use std::io::*;
use std::str::FromStr;

//https://qiita.com/tubo28/items/e6076e9040da57368845
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn factorial_2_prime_factorize(n: usize) -> HashMap<usize, usize> {
    let mut factors = HashMap::new();
    for i in 2..n + 1 {
        let mut a = 2;
        let mut temp_i = i;
        while a * a <= temp_i {
            while temp_i % a == 0 {
                let exp = factors.entry(a).or_insert(0);
                *exp += 1;
                temp_i /= a;
            }
            a += 1;
        }
        if temp_i != 1 {
            let exp = factors.entry(temp_i).or_insert(0);
            *exp += 1;
        }
    }
    factors
}
fn main() {
    let n: usize = read();
    let enums = factorial_2_prime_factorize(n);
    let mut ans = 1;
    for (_, v) in enums {
        ans *= v + 1;
        ans %= 1000_000_000 + 7;
    }
    println!("{}", ans);
}

Measured memory_bytes: 2184
import java.util.*;
import java.lang.*;
import java.math.*;
import java.io.*;

import static java.lang.Math.*;
import static java.util.Arrays.*;

public class Main{

	Scanner sc=new Scanner(System.in);

	int INF=1<<28;
	double EPS=1e-9;

	HashMap<Integer, Integer> map;
	int[] a;
	int w=4, h=2;

	void run(){
		a=new int[w*h];
		init();
		for(; sc.hasNext();){
			for(int i=0; i<w*h; i++){
				a[i]=sc.nextInt();
			}
			println(""+map.get(id(a)));
		}
	}

	void init(){

		LinkedList<S> que=new LinkedList<S>();
		map=new HashMap<Integer, Integer>();

		que.offer(new S(0, 0, new int[]{0, 1, 2, 3, 4, 5, 6, 7}));
		map.put(id(que.peek().a), 0);
		int[] dx={0, 0, -1, 1};
		int[] dy={-1, 1, 0, 0};

		for(; !que.isEmpty();){
			S s=que.poll();
			int p=s.y*w+s.x;
			for(int i=0; i<4; i++){
				int x2=s.x+dx[i];
				int y2=s.y+dy[i];
				int p2=y2*w+x2;
				if(x2>=0&&x2<w&&y2>=0&&y2<h){
					int[] a2=s.a.clone();
					int t=a2[p];
					a2[p]=a2[p2];
					a2[p2]=t;
					S s2=new S(x2, y2, a2);
					if(!map.containsKey(id(s2.a))){
						que.offer(s2);
						map.put(id(s2.a), map.get(id(s.a))+1);
					}
				}
			}
		}
		/*
		 * debug("here");
		 * debug(map.get(1234567));
		 * debug(map.get(10234567));
		 * debug(map.get(76543210));
		 */
	}

	int id(int[] a){
		int res=0;
		for(int e : a){
			res=res*10+e;
		}
		return res;
	}

	/*
	 * void solve(){
	 * int x=-1, y=-1;
	 * for(int i=0; i<w*h; i++){
	 * if(a[i]==0){
	 * x=i%w;
	 * y=i/w;
	 * }
	 * }
	 * 
	 * LinkedList<S> que=new LinkedList<S>();
	 * TreeSet<Integer> set=new TreeSet<Integer>();
	 * 
	 * que.offer(new S(x, y, a, 0));
	 * set.add(que.peek().id);
	 * int[] dx={0, 0, -1, 1};
	 * int[] dy={-1, 1, 0, 0};
	 * 
	 * for(; !que.isEmpty();){
	 * S s=que.poll();
	 * 
	 * if(s.id==1234567){
	 * println(""+s.cnt);
	 * return;
	 * }
	 * 
	 * int p=s.y*w+s.x;
	 * for(int i=0; i<4; i++){
	 * int x2=s.x+dx[i];
	 * int y2=s.y+dy[i];
	 * int p2=y2*w+x2;
	 * if(x2>=0&&x2<w&&y2>=0&&y2<h){
	 * int[] a2=s.a.clone();
	 * int t=a2[p];
	 * a2[p]=a2[p2];
	 * a2[p2]=t;
	 * S s2=new S(x2, y2, a2, s.cnt+1);
	 * if(!set.contains(s2.id)){
	 * que.offer(s2);
	 * set.add(s2.id);
	 * }
	 * }
	 * }
	 * }
	 * }
	 */

	class S{
		int x, y;
		int[] a;

		S(int x, int y, int[] a){
			this.x=x;
			this.y=y;
			this.a=a;
		}
	}

	void debug(Object... os){
		System.err.println(Arrays.deepToString(os));
	}

	void print(String s){
		System.out.print(s);
	}

	void println(String s){
		System.out.println(s);
	}

	public static void main(String[] args){
		// System.setOut(new PrintStream(new BufferedOutputStream(System.out)));
		new Main().run();
	}
}

Measured memory_bytes: 14000
#include <cstdio>

int n;

bool f(int mid, int flag) {
    int nn = n;
    for (int i = mid; i >= 1; i--) {
        if (nn >= i) {
            if (flag) {
                printf("%d\n", i);
            }
            nn -= i;
        }
        if (nn == 0) {
            return 1;
        }
    }
    return 0;
}

int main() {
    scanf("%d", &n);

    int lft = 0, rgt = n;
    int ans = 0;
    while (lft <= rgt) {
        int mid = (lft + rgt) / 2;

        if (f(mid, 0)) {
            ans = mid;
            rgt = mid - 1;
        }
        else {
            lft = mid + 1;
        }
    }

    f(ans, 1);

    return 0;
}

Measured memory_bytes: 128
import java.util.Scanner;


public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner (System.in);
		try{
			while(true){
				float x1,y1,x2,y2,x3,y3,xp,yp;
				x1=sc.nextFloat();y1=sc.nextFloat();x2=sc.nextFloat();y2=sc.nextFloat();
				x3=sc.nextFloat();y3=sc.nextFloat();xp=sc.nextFloat();yp=sc.nextFloat();
				x2-=x1;y2-=y1;x3-=x1;y3-=y1;xp-=x1;yp-=y1;
				boolean flag1 = (0<(yp*x2-y2*xp)*(y3*x2-y2*x3))&&(0>(yp*x2-y2*xp)*(yp*x3-y3*xp));
				boolean flag2;
				if(x2==x3){
					flag2=(Math.abs(xp)<Math.abs(x2));
				} else if(y2==y3){flag2=(Math.abs(yp)<Math.abs(y2));}
				else {flag2=(0 < ((y3-y2)/(x3-x2)) * (yp-y2-(y3-y2)*(xp-x2)/(x3-x2))*((y3-y2)/(x3-x2)) * (-y2-(y3-y2)*(-x2)/(x3-x2)));}
				if(flag1&&flag2){System.out.println("YES");}
				else {System.out.println("NO");}
			}
		} catch(Exception e){}
	}
}

Measured memory_bytes: 23324