akhauriyash/Code-Regression huggingface dataset:
#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream>
#include <random>
#include<map>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include<fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
using namespace std;
#define Ma_PI 3.141592653589793
#define eps 0.00000001
#define LONG_INF 3000000000000000000
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007
#define MOD 998244353
#define REP(i,n) for(long long i = 0;i < n;++i)    
#define seg_size 524288
double dot(complex<double> a, complex<double> b) {
	return a.real() * b.real() + a.imag() * b.imag();
}
double gyaku_dot(complex<double> a, complex<double> b) {
	return a.real() * b.imag() - a.imag() * b.real();
}
double leng(complex<double> a) {
	return sqrt(a.real() * a.real() + a.imag() * a.imag());
}
double angles(complex<double> a, complex<double> b) {
	double cosine = dot(a, b) / (leng(a) * leng(b));
	double sine = gyaku_dot(a, b) / (leng(a) * leng(b));
	double kaku = acos(cosine);
	if (sine <= 0) {
		kaku = 2 * Ma_PI - kaku;
	}
	return kaku;
}
vector<int> convex_hull(vector<complex<double>> a) {
	vector<int> ans;
	double now_minnest = a[0].real();
	int now_itr = 0;
	REP(i, a.size()) {
		if (now_minnest > a[i].real()) {
			now_minnest = a[i].real();
			now_itr = i;
		}
	}
	ans.push_back(now_itr);
	complex<double> ba(0, 1);
	while (true) {
		int now_go = 0;
		double now_min = 0;
		int starter = ans[ans.size() - 1];
		for (int i = 0; i < a.size(); ++i) {
			if (i != starter) {
				double goa = angles(ba, a[i] - a[starter]);
				if (goa > now_min) {
					now_min = goa;
					now_go = i;
				}
			}
		}
		if (now_go == ans[0]) break;
		ans.push_back(now_go);
		ba = complex<double>(a[now_go] - a[starter]);
	}
	return ans;
}
long long gcd(long long a, long long b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}
int gogo[26] = {};
int main(){
	string s;
	cin >> s;
	REP(i, s.length()) {
		gogo[s[i] - 'a'] = 1;
	}
	REP(i, 26) {
		if (gogo[i] == 0) {
			cout << (char)('a' + i) << endl;
			return 0;
		}
	}
	cout << "None";
}


Measured memory_bytes: 512
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
#include <functional>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

template<typename T> void chmin(T &a, T b) { if (a > b) a = b; }
template<typename T> void chmax(T &a, T b) { if (a < b) a = b; }

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }

int main(void){
    ll x, y = 100;
    cin >> x;
    int ans = 0;
    while (y < x){
        y += y / 100;
        ans++;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3636
#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
using namespace std;
#define MAX 2000000
#define INFTY (1<<30)

int H,A[MAX+1];

void maxHeapify(int i){
    int l,r,largest;
    l = 2 * i;
    r = 2 * i + 1;

    if(l<=H && A[l]>A[i] )  largest = l;
    else largest = i;
    if(r<=H && A[r]>A[largest]) largest = r;

    if(largest != i){
        swap(A[i], A[largest]);
        maxHeapify(largest);
    }
}



int extract(){
    int maxv;
    if( H < 1 ) return -INFTY;
    maxv = A[1];
    A[1] = A[H--];
    maxHeapify(1);
    return maxv;
}

void increaseKey(int i, int key){
    if(key < A[i]) return;
    A[i] = key;
    while(i>1 && A[i/2]<A[i]){
        swap(A[i],A[i/2]);
        i=i/2;
    }
}


void insert(int key){
    H++;
    A[H] = -INFTY;
    increaseKey(H,key);
}



int main(){
    int key;
    char com[10];
    while(1){
        scanf("%s",com);
        if(com[0] == 'e' && com[1] == 'n') break;
        if(com[0] == 'i'){
            scanf("%d",&key);
            insert(key);
        }else printf("%d\n",extract());

    }
    return 0;
}




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

ll a[114514];

int main() {
	ll n,m;
	cin>>n>>m;
	for(int i=0;i<n;i++)cin>>a[i];
	ll num=a[0]/2;
	ll cnt=0;
	while(num%2==0){
		cnt++;
		num/=2;
	}
	ll lcm=a[0]/2;
	for(int i=1;i<n;i++){
		num=a[i]/2;
		ll x=num;
		ll cnta=0;
		while(num%2==0){
			cnta++;
			num/=2;
		}
		if(cnt!=cnta){
			cout<<0<<endl;
			return 0;
		}
		lcm=x/__gcd(x,lcm)*lcm;
		if(lcm>m){
			cout<<0<<endl;
			return 0;
		}
	}
	ll ans=m/lcm;
	ans=(ans+1)/2;
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int f[200010],n,k;
int l[200010],r[200010];
int sum[200010];
int main()
{
	scanf("%d%d",&n,&k);
	for(int i=1;i<=k;i++)
	{
		scanf("%d%d",&l[i],&r[i]);
	}
	sum[1]=1;
	f[1]=1;
	for(int i=2;i<=n;i++)
	{
		for(int j=1;j<=k;j++)
		{
			f[i]+=sum[max(i-l[j],0)]-sum[max(i-r[j]-1,0)];
			f[i]=(f[i]%998244353+998244353)%998244353;
		}
		sum[i]=sum[i-1]+f[i];
		sum[i]%=998244353;
	}
	printf("%d",f[n]);
	return 0;
}

Measured memory_bytes: 5376
from itertools import permutations
import math

def f_len(a, b):
    x1, y1 = a
    x2, y2 = b
    return math.sqrt((x1 - x2)**2 + (y1 - y2)**2)

n = int(input())
xy = [list(map(int, input().split())) for _ in range(n)]
ans = 0
for case in permutations(range(n)):
    temp = 0
    for i in range(1, n):
        temp += f_len(xy[case[i]], xy[case[i-1]])
    ans += temp
ans /= math.factorial(n)
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(I,A,B) for(ll I = ll(A); I < ll(B); ++I)

int main(){

	ll n,ans=0;
	cin >> n;
	vector<ll> a(n);
	FOR(i,0,n)cin >> a[i];
	FOR(i,0,n)FOR(j,i+1,n){
		ans += a[i]*a[j];
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
import java.io.IOException;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws IOException {

		new Main().run();
	}

	private void run() throws IOException {
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		char[] name = scanner.next().toCharArray();
		int namelen = name.length;
		int ans = 0;
		loop: while (n-- > 0) {
			char[] c = scanner.next().toCharArray();
			int clne = c.length;
			for (int i = 0; i < clne - namelen + 1; i++) {
				lo: for (int j = 1; (namelen - 1) * j + i < clne; j++) {
					for (int k = 0; k < namelen; k++) {
						if (name[k] != c[i + j * k])
							continue lo;
					}
					ans++;
					continue loop;
				}
			}
		}
		System.out.println(ans);

	}
}

Measured memory_bytes: 20536
M, K = map(int, input().split())

if M < 2:
    if K != 0:
        print(-1)
    else:
        anss = []
        for A in range(2**M):
            anss += [A, A]
        print(' '.join(map(str, anss)))
else:
    if K > 2**M - 1:
        print(-1)
    else:
        anss = []
        for A in range(2**M):
            if A == K: continue
            anss.append(A)
        anss = anss + [K] + anss[::-1] + [K]
        print(' '.join(map(str, anss)))


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

using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;
using LL = long long;
using VL = vector<LL>;
using VVL = vector<VL>;
using PLL = pair<LL, LL>;
using VS = vector<string>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))

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

#define FF first
#define SS second
template<class S, class T>
istream& operator>>(istream& is, pair<S,T>& p){
  return is >> p.FF >> p.SS;
}
template<class S, class T>
ostream& operator<<(ostream& os, const pair<S,T>& p){
  return os << p.FF << " " << p.SS;
}
template<class T>
void maxi(T& x, T y){
  if(x < y) x = y;
}
template<class T>
void mini(T& x, T y){
  if(x > y) x = y;
}


const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL MOD = 1e9+7;

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

  int R, G;
  cin >> R >> G;
  cout << G - R + G << endl;

  return 0;
}


Measured memory_bytes: 256
N, M = map(int, input().split())
rec = []
for i in range(M):
    p, S = map(str, input().split())
    p = int(p)
    rec.append([p,S])
N_list = [False for i in range(N)]
WA_cnt=[0 for i in range(N)]
penalty = AC_cnt = 0
for i in range(M):
    if rec[i][1] == "AC":
        if N_list[rec[i][0]-1] == False:
            AC_cnt += 1
            N_list[rec[i][0]-1] = True
            penalty += WA_cnt[rec[i][0]-1] 
    if rec[i][1] == "WA":
        if N_list[rec[i][0]-1] == False:
            WA_cnt[rec[i][0]-1] += 1
print(AC_cnt, penalty)

Measured memory_bytes: 23684
A,B,C,X,Y=map(int,input().split())
N=max(X,Y)
pay=0
for i in range(N+1):
    c=i*2
    a=max(0,X-i)
    b=max(0,Y-i)
    if pay==0:
        pay=A*a+B*b+C*c
    else:
        pay=min(pay,A*a+B*b+C*c)
print(pay)

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

int main(){
  int d;
  cin >> d;
  vector<int> c(26);
  vector<vector<int>> s(d,vector<int>(26));
  int i,j;
  for(i=0;i<26;i++){
    cin >> c.at(i);
  }
  for(j=0;j<d;j++){
    for(i=0;i<26;i++){
      cin >> s.at(j).at(i);
    }
  }
  
  vector<int> t(d),last(26,-1);
  int v=0;
  for(j=0;j<d;j++){
    cin >> t.at(j);
    t.at(j)--;
    last.at(t.at(j))=j;
    v += s.at(j).at(t.at(j));
    for(i=0;i<26;i++){
      v -= c.at(i)*(j-last.at(i));
    }
    cout << v << endl;
  }
}

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

using namespace std;

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
	
	int n;
	cin >> n;

	vector<int> a(n + 1), b(n + 1);

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

	for(int i = n; i > 0; i--) {
		int tot = 0;
		for(int j = 2 * i; j <= n; j += i) {
			tot += b[j];
		}
		if(tot % 2 == a[i] % 2) {
			b[i] = 0;
		}
		else {
			b[i] = 1;
		}
	}
    
	vector<int> v;
	for(int i = 1; i <= n; i++) {
		if(b[i] == 1) v.push_back(i);
	}

	cout << v.size() << '\n';
	for(auto i : v) cout << i << ' ';

    return 0;   
}

Measured memory_bytes: 3192
#include <bits/stdc++.h>
using namespace std;
using pii=pair<int,int>;
using ll=long long;
using pll=pair<ll,ll>;

#define fi first
#define se second
#define pb push_back
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define MOD 1000000007

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 (b<a) { a=b; return 1; } return 0; }

int main() {
	int a,b,c,d,e;
	cin >> a >> b >> c >> d >> e;
	int f;
	if(a == 0) f = 1;
	else if(b==0) f = 2;
	else if(c==0) f = 3;
	else if(d == 0) f = 4;
	else if(e == 0) f = 5;
	cout << f << endl;

  return 0;
}


Measured memory_bytes: 3600
#include <functional>
#include <algorithm>
#include <iostream>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <tuple>
#include <set>
#include <map>

#define FOR0(var, max) for (ul (var) = 0; (var) < (max); ++(var))
#define FORi(var, min, max) for (ul (var) = (min); (var) < (max); ++(var))
#define FORi_INV(var, min, max) for (ul (var) = (max) - 1; (var) + 1 > (min); --(var))
#define FORITER(var, iter) for (auto (iter) = (var).begin(); (iter) != (var).end(); (iter)++)
#define FORITER_INV(var, iter) for (auto (iter) = (var).rbegin(); (iter) != (var).rend(); (iter)++)

#define LTLT(a, b, c) (((a) < (b)) && ((b) < (c)))
#define LELT(a, b, c) (((a) <= (b)) && ((b) < (c)))
#define LTLE(a, b, c) (((a) < (b)) && ((b) <= (c)))
#define LELE(a, b, c) (((a) <= (b)) && ((b) <= (c)))

using namespace std;

using uc = unsigned char;
using ui = unsigned int;
using ul = unsigned long long int;

using sc = signed char;
using si = signed int;
using sl = signed long long int;

template <class T>
T gcd(T a, T b) {
  while (b) {
    T t = a % b;
    a = b;
    b = t;
  }
  return a;
}

/* (identity element, operation) */
template <class T>
using Monoid = pair<T, function<T(T, T)>>;

template <class T, ul K>
class SegmentTree {
  const Monoid<T> monoid;
  const ul N = (1 << K);
  T tree[2 * (1 << K) - 1];

  ui parent(ui i) {
    if (i == 0) {
      return 0;
    }
    return (i - 1) / 2;
  }

  ui child1(ui i) {
    return i * 2 + 1;
  }

  ui child2(ui i) {
    return i * 2 + 2;
  }

  bool is_leaf(ui i) {
    return (N - 1 <= i);
  }

  void propagate_from_leaf(ui i) {
    ui cur = N - 1 + i;
    while (cur != 0) {
      cur = parent(cur);
      auto x1 = tree[child1(cur)];
      auto x2 = tree[child2(cur)];
      tree[cur] = monoid.second(x1, x2);
    }
  }

  T query_impl(ui a, ui b, ui k, ui l, ui r) {
    if (r <= a || b <= l) {
      return monoid.first;
    } else if (a <= l && r <= b) {
      return tree[k];
    } else {
      auto ta = query_impl(a, b, child1(k), l, (l + r) / 2);
      auto tb = query_impl(a, b, child2(k), (l + r) / 2, r);
      return monoid.second(ta, tb);
    }
  }
public:
  /* Initialize Segment Tree with Monoid `_monoid` */
  SegmentTree(const Monoid<T>& _monoid) : monoid(_monoid) {
    FOR0(i, 2 * (1 << K) - 1) {
      tree[i] = monoid.first;
    }
  }

  void update(ui i, T x) {
    tree[N - 1 + i] = x;
    propagate_from_leaf(i);
  }

  // [a, b)
  T query(ui a, ui b) {
    return query_impl(a, b, 0, 0, N);
  }
};

const static ul NMAX = 100000;
const static ul AiMAX = 1000000000;

static ul N;
static ul Ai[NMAX];

void solve(void) {
  ui res = 0;
  FOR0(i, N) {
    res ^= Ai[i] & 1;
  }
  cout << (res ? "NO" : "YES") << endl;
}

int main(void) {
  cin >> N;
  FOR0(i, N) {
    cin >> Ai[i];
  }
  solve();
  return 0;
}

Measured memory_bytes: 1024
#include <algorithm>
#include <cassert>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>

using namespace std;
using ll = long long;

constexpr ll infl = 10000000000000007LL;
constexpr int inf = 1000000007;

int main() {
    int n;
    cin >> n;
    string s;
    cin >> s;
    vector<vector<int>> len(n, vector<int>(n));
    int ans = 0;
    for (int i = 0; i < n; ++i) {
        len[i].back() = len.back()[i] = (int)(s[i] == s.back());
        if (i != n - 1)
            ans = max(ans, len[i].back());
    }
    for (int i = 0; i < n - 1; ++i) {
        len[i][i + 1] = len[i + 1][i] = (int)(s[i] == s[i + 1]);
        ans = max(ans, len[i][i + 1]);
    }
    for (int i = n - 2; i >= 0; --i) {
        for (int j = n - 2; j >= 0; --j) {
            if (abs(i - j) == 1)
                continue;
            if (s[i] == s[j])
                len[i][j] = min(abs(i - j), len[i + 1][j + 1] + 1);
            if (i != j)
                ans = max(ans, len[i][j]);
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 98176
#include <iostream>
#include <string>

using namespace std;

int main(){
    int a, b, output;
    string op;

	while (1){
 	   cin >> a; cin >> op; cin >> b;
        if("?" == op){
            break;
        }else if("+" == op){
            output = a + b;
		}else if("-" == op){
            output = a - b;
        }else if("*" == op){
            output = a * b;
        }else if("/" == op){
            output = a / b;
        }else{
            break;
        }
    	cout << output << endl;
	}

    return 0;
}


Measured memory_bytes: 3164
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <fstream>
#include <numeric>
#include <iomanip>
#include <bitset>
#include <list>
#include <stdexcept>
#include <functional>
#include <utility>
#include <ctime>
#include <random>
#include <cassert>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
#define MEM(a,b) memset((a),(b),sizeof(a))
const LL INF = 1e9 + 7;
const int N = 2e5 + 10;
vector<int> v1[N];
vector<int> v2[N];
int main()
{
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	string s1, s2;
	cin >> s1 >> s2;
	for (int i = 0; i < s1.length(); i++)
	{
		if (s1[i] != s2[i])
		{
			char c1 = s1[i];
			char c2 = s2[i];
			for (int j = 0; j < s1.length(); j++)
			{
				if (s1[j] == c1) s1[j] = c2;
				else if (s1[j] == c2) s1[j] = c1;
				if (j <= i && s1[j] != s2[j]) puts("No"), exit(0);
			}
		}
	}
	if (s1 == s2) puts("Yes");
	else puts("No");
	return 0;
}


Measured memory_bytes: 10248
#include<bits/stdc++.h>
#define N 500005
using namespace std;
int n,a[N];
int main(){
	scanf("%d",&n);
	for (int i=1;i<=n;i++) scanf("%d",&a[i]);
	int ans=0;
	for (int i=1;i<n;i++){
		if (a[i]==i){
			swap(a[i],a[i+1]);
			ans++;
		}
	}
	if (a[n]==n) ans++;
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
int main(){
  long long A,B;
  cin>>A>>B;
  A--;
  uint64_t C,D;
  if(A==-1)C=0;
  else if(A%4==1)C=1;
  else if(A%4==2)C=A+1;
  else if(A%4==3)C=0;
  else C=A;
  if(B%4==1)D=1;
  else if(B%4==2)D=B+1;
  else if(B%4==3)D=0;
  else D=B;
  cout<<(C^D)<<endl;
}

Measured memory_bytes: 3576
#include <bits/stdc++.h>
using namespace std;
#define mp make_pair
#define pb push_back
typedef  long long ll;
int gcd(int f , int s){if(s==0)return f;else return gcd(s,f%s);}
int const N = 1000006;
ll const M = 1020;
long double const ep = .000000000000000001;
int frq[N] , frq1[N];
int main() {
	
	int a;cin >> a;
	int mx = 0 , tot = 0 , mx1 = 0 , tot1 = 0;
	for(int i = 0 ; i < a ; i++){
		int t;cin >> t;
		if(i%2==0){
			frq[t]++;
			tot++;
		}
		else{
			frq1[t]++;
			tot1++;
		}
	}
	vector<pair<int , int> > v , v1;
	v.pb(mp(0,0));
	v1.pb(mp(0,0));
	for(int i = 0 ; i < 100001; i++){
		if(frq[i]!=0)v.pb(mp(frq[i] , i));
		if(frq1[i]!=0)v1.pb(mp(frq1[i] , i));
	}
	sort(v.rbegin() , v.rend());
	sort(v1.rbegin() , v1.rend());

	mx = v[0].first ;
	mx1 = v1[0].first;
	int lol = mx + mx1;
	if(v[0].second == v1[0].second){
		lol = max(mx + v1[1].first , mx1 + v[1].first);
	}
	cout << tot + tot1 - lol; 
	return 0;
}

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

//#define int long long
typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = mod * mod;
const int INF_N = 1e+9;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
#define all(v) (v).begin(),(v).end()
typedef pair<ll, ll> LP;
typedef long double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-12;
const ld pi = acos(-1.0);
//typedef vector<vector<ll>> mat;
typedef vector<int> vec;

//繰り返し二乗法
ll mod_pow(ll a, ll n, ll m) {
	ll res = 1;
	while (n) {
		if (n & 1)res = res * a%m;
		a = a * a%m; n >>= 1;
	}
	return res;
}

struct modint {
	ll n;
	modint() :n(0) { ; }
	modint(ll m) :n(m) {
		if (n >= mod)n %= mod;
		else if (n < 0)n = (n%mod + mod) % mod;
	}
	operator int() { return n; }
};
bool operator==(modint a, modint b) { return a.n == b.n; }
modint operator+=(modint &a, modint b) { a.n += b.n; if (a.n >= mod)a.n -= mod; return a; }
modint operator-=(modint &a, modint b) { a.n -= b.n; if (a.n < 0)a.n += mod; return a; }
modint operator*=(modint &a, modint b) { a.n = ((ll)a.n*b.n) % mod; return a; }
modint operator+(modint a, modint b) { return a += b; }
modint operator-(modint a, modint b) { return a -= b; }
modint operator*(modint a, modint b) { return a *= b; }
modint operator^(modint a, int n) {
	if (n == 0)return modint(1);
	modint res = (a*a) ^ (n / 2);
	if (n % 2)res = res * a;
	return res;
}

//逆元(Eucledean algorithm)
ll inv(ll a, ll p) {
	return (a == 1 ? 1 : (1 - p * inv(p%a, a)) / a + p);
}
modint operator/(modint a, modint b) { return a * modint(inv(b, mod)); }

const int max_n = 1 << 18;
modint fact[max_n], factinv[max_n];
void init_f() {
	fact[0] = modint(1);
	for (int i = 0; i < max_n - 1; i++) {
		fact[i + 1] = fact[i] * modint(i + 1);
	}
	factinv[max_n - 1] = modint(1) / fact[max_n - 1];
	for (int i = max_n - 2; i >= 0; i--) {
		factinv[i] = factinv[i + 1] * modint(i + 1);
	}
}
modint comb(int a, int b) {
	if (a < 0 || b < 0 || a < b)return 0;
	return fact[a] * factinv[b] * factinv[a - b];
}
using mP = pair<modint, modint>;

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




void solve() {
    int N; cin >> N;
    string s; cin >> s;
    vec l(10, -1), r(10, -1);
    rep(i, N){
        if(l[s[i]-'0'] == -1) l[s[i]-'0'] = i;
        r[s[i]-'0'] = i;
    }
    vector<set<pair<char, char>>> v(10);
    Rep(i, 1, N-1){
        rep(j, 10){
            rep(k, 10){
                if(l[j] != -1 && l[j] < i && r[k] > i){
                    v[s[i]-'0'].insert(make_pair(j, k));
                }
            }
        }
    }
    ll res = 0;
    rep(i, 10){
        res += v[i].size();
    }
    cout << res << endl;
}

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  //cout << fixed << setprecision(10);
  //init_f();
  //init();
  //int t; cin >> t; rep(i, t)solve();
  solve();
//   stop
    return 0;
}


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

int main(){
    int n,rank;
    char mark;
    int card[4][14]={{}, {}, {}, {}};
    
    std::cin>>n;
    
    for(int c=0; c<n;c++){
        std::cin>>mark>>rank;
        
        if(mark=='S'){
            card[0][rank]=1;
        }else if (mark=='H'){
            card[1][rank]=1;
        }else if (mark=='C'){
            card[2][rank]=1;
        }else if (mark=='D'){
            card[3][rank]=1;
        }
    }
    
    for(int i=0; i<4;i++){
        for(int j=1; j<14;j++){
            if(card[i][j]==0){
                if(i==0){
                   std::cout<< "S "<<j<<std::endl;
                }else if(i==1){
                    std::cout<< "H "<<j<<std::endl;
                }else if(i==2){
                    std::cout<< "C "<<j<<std::endl;
                }else if(i==3){
                    std::cout<< "D "<<j<<std::endl;
                }
            }
        }
        
    }
    
    //std::cout<<std::endl;

    return 0;
}


Measured memory_bytes: 3120
#include<bits/stdc++.h>
using namespace std;
#define LL long long
#define ULL unsigned long long
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define pll pair<LL,LL>
#define x first
#define y second
#define pi acosl(-1)
#define sqr(x) ((x)*(x))
#define pdd pair<double,double>
#define MEMS(x) memset(x,-1,sizeof(x))
#define MEM(x) memset(x,0,sizeof(x))
#define less Less
#define EPS 1e-4
#define arg ARG
#define cpdd const pdd
#define rank Rank
#define MXN 200005
int tot[2005][2005];
int h[2005][2005];
int v[2005][2005];
int main(){ 
    int n,m,q;
    scanf("%d %d %d",&n,&m,&q);
    char c[2005][2005];
    for(int i = 1;i<=n;i++){
        scanf("%s",c[i]+1);
        for(int j=1;j<=m;j++){
            if(c[i][j]=='1')tot[i][j]++;
        }
    }
    for(int i= 2;i<=n;i++){
        for(int j=1;j<=m;j++){
            if(c[i][j]=='1'&&c[i-1][j]=='1')h[i][j]++;
        }
    }
    for(int i =1;i<=n;i++){
        for(int j=2;j<=m;j++){
            if(c[i][j]=='1'&&c[i][j-1]=='1')v[i][j]++;
        }
    }
    for(int i = 1;i<=n;i++){
        for(int j=1;j<=m;j++){
            tot[i][j]+=tot[i-1][j]+tot[i][j-1]-tot[i-1][j-1];
            h[i][j]+=h[i-1][j]+h[i][j-1]-h[i-1][j-1];
            v[i][j]+=v[i-1][j]+v[i][j-1]-v[i-1][j-1];
        }
    }
    while(q--){
        int a,b,c,d;
        scanf("%d %d %d %d",&a,&b,&c,&d);
        LL res=tot[c][d]-tot[a-1][d]-tot[c][b-1]+tot[a-1][b-1];
        //printf("%lld\n",res);
        res-=h[c][d]-h[c][b-1]-h[a][d]+h[a][b-1];
        //printf("%lld\n",res);
        res-=v[c][d]-v[c][b]-v[a-1][d]+v[a-1][b];
        printf("%lld\n",res);
    }
}
/**/

Measured memory_bytes: 52864
#include<iostream>
using namespace std;
struct Node{
Node(){
left=right=0;
}
Node(int tmp,Node* l=0,Node *r=0){
data=tmp;
left=l;
right=r;
}
Node *left;
Node *right;
int data;
};
class tree{
public:
tree(){
first = 0;
}
void insert(int tmp){
if(!first){
first=new Node(tmp);
return;
}
Node *link = first;
while(true){
if(link->data<tmp)
{
if(link->right)link=link->right;
else{
link->right=new Node(tmp);
return;
}
}
else if(link->data>tmp)
{
if(link->left)link=link->left;
else
{
link->left=new Node(tmp);
return;
}
}
else return;
}
}
void pre(Node *tmp){
if(!tmp)return;
cout<<' '<<tmp->data;
pre(tmp->left);
pre(tmp->right);
}
void in(Node *tmp){
if(!tmp)return;
in(tmp->left);
cout<<' '<<tmp->data;
in(tmp->right);
}
void print(){
in(first);
cout<<endl;
pre(first);
cout<<endl;
}
void find(int tmp)
{
if(!first){
cout<<"no"<<endl;
return;
}
Node *link = first;
while(true){
if(link->data<tmp)
{
if(link->right)link=link->right;
else{
cout<<"no"<<endl;
return;
}
}
else if(link->data>tmp)
{
if(link->left)link=link->left;
else
{
cout<<"no"<<endl;
return;
}
}
else{
cout<<"yes"<<endl;
return;
}
}
}
void del(int tmp){
if(!first)return;
Node *link = first;
Node *parent=NULL;
while(true){
if(link->data>tmp){
parent = link;
if(link->left)link=link->left	;
else return;
}
else if(link->data<tmp){
parent = link;
if(link->right)link=link->right	;
else return;
}
else break;
}
Node *bedel;
if(link->left&&link->right)
{
	bedel = link->right;
parent=NULL;
while(bedel->left){
parent=bedel;
bedel=bedel->left;
}
if(!bedel->right){
if(!parent){
link->data=bedel->data;
link->right=NULL;
delete bedel;
return;
}
else
{
parent->left=NULL;
link->data=bedel->data;
delete bedel;
return;
}}
else{
if(!parent){
link->data=bedel->data;
link->right=bedel->right;
delete bedel;
return;
}
else{
link->data=bedel->data;
parent->left=bedel->right;
delete bedel;
return;
}
}

}
else if(link->left){
if(parent){
	if(parent->left==link){
parent->left=link->left;
}
else parent->right=link->left;
delete link;
return;
}
first=first->left;
delete link;
}
else
 {
if(parent){
	if(parent->left==link){
parent->left=link->right;
}
else parent->right=link->right;
delete link;
return;
}
first=first->right;
delete link;
}
}
private:Node*first;
};
int main(){
	char s[30];
	int n,tmp;
	tree a;
	cin>>n;
	while(n--){
		cin>>s;
		switch(s[0]){
			case 'i':cin>>tmp;a.insert(tmp);break;
			case 'p':a.print();break;
			case 'd':cin>>tmp;a.del(tmp);break;
			case 'f':cin>>tmp;a.find(tmp);break;
			default:break;
			}
		}
	return 0;
	}


Measured memory_bytes: 15560
import java.util.Scanner;
import java.util.Stack;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        sc.close();

        Stack<Integer> stack = new Stack<>();
        int ans = 0;
        int leftIndex = 0;
        int rightIndex = 1;
        while (rightIndex < s.length()) {
            if (s.charAt(leftIndex) != s.charAt(rightIndex)) {
                ans += 2;
                if (stack.empty()) {
                    leftIndex = rightIndex + 1;
                    rightIndex = rightIndex + 2;
                } else {
                    leftIndex = stack.pop();
                    rightIndex = rightIndex + 1;
                }
            } else {
                stack.push(leftIndex);
                leftIndex = rightIndex;
                rightIndex = rightIndex + 1;
            }
        }
        System.out.println(ans);
    }

}


Measured memory_bytes: 27828
x,y=map(int,input().split())

a=[1,3,5,7,8,10,12]
b=[4,6,9,11]
c=[2]

x_group=''
y_group=''

for i in range(len(a)):
  if x==a[i]:
    x_group='a'
  if y==a[i]:
    y_group='a'
    
for i in range(len(b)):
  if x==b[i]:
    x_group='b'
  if y==b[i]:
    y_group='b'

for i in range(len(c)):
  if x==c[i]:
    x_group='c'
  if y==c[i]:
    y_group='c'
    
if x_group==y_group:
  print('Yes')
else:
  print('No')

Measured memory_bytes: 3064
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<sstream>
#include<iterator>
using namespace std;
typedef  long long int lint;
typedef pair<int, int> IP;
typedef pair<lint, lint> LLP;
typedef pair<char, char>CP;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define sort(v) sort((v).begin(), (v).end())
#define reverse(v) reverse((v).begin(), (v).end())
#define upper(v,hoge) upper_bound(v.begin(),v.end(),hoge)
#define lower(v,hoge) lower_bound(v.begin(),v.end(),hoge)
#define llower(v,hoge) *lower_bound(v.begin(), v.end(), hoge)
#define lupper(v,hoge) *upper_bound(v.begin(), v.end(), hoge)

bool kai(string S) {
	bool ans = true;
	int N = S.size();
	for (int i = 0; i <= (N - 1) / 2; i++) {
		if (S[i] != S[N - 1 - i]) {
			ans = false;
		}
	}
	return ans;
}

int main() {
	string S;
	cin >> S;
	int N = S.size();
	string A, B;
	A = S.substr(0, (N - 1) / 2);
	B = S.substr((N + 1) / 2, (N - 1) / 2);
	//cout << S << ' ' << A << ' ' << B << endl;
	if (kai(S) && kai(A) && kai(B)) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
}


Measured memory_bytes: 256
/*
 * http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_4_D&lang=jp
 */

import java.util.*;
import java.util.Arrays;


class Main {

  int n=0, k=0;
  int[] W;

  void printArray(int[] a) {
    System.out.print(a[0]);
    for (int i = 1; i < a.length; i++) {
      System.out.print(" " + a[i]);
    }
  }

  int solve2(int i, int t, int max) {
    if (i >= n) return 0;
    if (t == k-1) {
      int sum = 0;
      for (; i < n; i++) {
        sum += W[i];
      }
      return sum;
    }
    int sum = 0;
    int min = Integer.MAX_VALUE;
    sum += W[i];
    for (; i < n - (k-1-t); i++) {
      if (sum + W[i+1] >= max) break;
      sum += W[i+1];
    }
    for (; i < n - (k-1-t); i++) {
      min = Math.min(min, Math.max(sum, solve2(i+1, t+1, max)));
      sum += W[i+1];
      max = sum;
    }

    return min;
  }
boolean solve3(int p) {
    int space = p;
    int rk = k;
    for (int i = 0; i < W.length; i++) {
      space -= W[i];
      if (space < 0) {
        rk--;
        if (rk == 0) {
          //return solve3(upper+1);
          return false;
        }
        space = p;
        space -= W[i];
      }
    }
    return true;
  }

  int solve(int lower, int upper) {
    int mid = (upper + lower) / 2;
    if (lower+1 >= upper) return upper;
    if (solve3(mid)) return solve(lower, mid);
    else return solve(mid, upper);
  }

  void run() {
    Scanner sc = new Scanner(System.in);
    n = sc.nextInt();
    k = sc.nextInt();
    W = new int[n];
    //T = new int[k];
    int max = 0, sum = 0;
    for (int i = 0; i < n; i++) {
      W[i] = sc.nextInt();
      max = Math.max(max, W[i]);
      sum += W[i];
    }

    if (solve3(max)) System.out.println(max);
    else System.out.println(solve(max, sum));

    //System.out.println(solve2(0, 0, 0));
  }
static public void main(String[] args) {
    new Main().run();
  }
}


Measured memory_bytes: 71036
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <cctype>
#include <set>
#define R register
#define IN inline
#define W while
#define IN inline
#define gc getchar()
#define MX 200500
template <class T>
IN void in(T &x)
{
    x = 0; R char c = gc;
    W (!isdigit(c)) c = gc;
    W (isdigit(c))
    x = (x << 1) + (x << 3) + c - 48, c = gc;
}
int col[MX][2], fat[MX], bel[MX], dot;
struct Vertex
{int id;};
IN bool operator < (const Vertex &x, const Vertex &y)
{
    int x0 = col[x.id][0], x1 = col[x.id][1], y0 = col[y.id][0], y1 = col[y.id][1];
    return 1ll * x0 * y1 > 1ll * x1 * y0 || 
    (1ll * x0 * y1 == 1ll * x1 * y0 && x.id > y.id);
}
std::set <Vertex> st;
long long ans;
namespace DSU
{
    int find(R int now) {return bel[now] == now ? now : bel[now] = find(bel[now]);}
    IN void combine(const int &from, const int &to) {bel[from] = find(to); col[to][0] += col[from][0], col[to][1] += col[from][1];}
}
int main(void)
{
    in(dot); R int a, now, fa;
    for (R int i = 2; i <= dot; ++i) in(fat[i]);
    for (R int i = 1; i <= dot; ++i) in(a), ++col[i][a], bel[i] = i;
    for (R int i = 2; i <= dot; ++i) st.insert({i});
    W (!st.empty())
    {
        now = DSU::find(st.begin() -> id);
        st.erase(st.begin());
        fa = DSU::find(fat[now]); st.erase({fa});
        ans += 1ll * col[fa][1] * col[now][0];
        DSU::combine(now, fa);
        if(fa != 1) st.insert({fa});
    }
    printf("%lld", ans);
}

Measured memory_bytes: 12800
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Main main = new Main();
		main.run();
	}

	int N;
	String S;
	public void run() {
		Scanner sc = new Scanner(System.in);
		N = sc.nextInt();
		S = sc.next();
		if(N % 2 != 0) {
			System.out.println("No");
		} else {
			String s1 = S.substring(0, N/2);
			String s2 = S.substring(N/2, N);
			if(s1.equals(s2)) {
				System.out.println("Yes");
			} else {
				System.out.println("No");
			}
		}
		sc.close();
	}
}


Measured memory_bytes: 22612
from bisect import bisect_right
s = input()
t = input()

n = len(s)

if set(list(t)) != (set(list(s)) & set(list(t))): ans = -1
else:
    dct = {}

    for i, ss in enumerate(s):
        if ss in dct:
            dct[ss].append(i)
        else: dct[ss] = [i]
    idx = -1
    ans = 0
    for tt in t:
        m = bisect_right(dct[tt], idx)
        if m == len(dct[tt]):
            idx = dct[tt][0]
            ans += n
        else:
            idx = dct[tt][m]
    ans += idx + 1

print(ans)

Measured memory_bytes: 13576
#include<bits/stdc++.h>
#define for_int(i,a,b) for(int i=(a);i<=(b);++i)
#define rep_int(i,a,b) for(int i=(a);i>=(b);--i)
#define for_ll(i,a,b) for(ll i=(a);i<=(b);++i)
#define rep_ll(i,a,b) for(ll i=(a);i>=(b);--i)
#define ull unsigned long long
#define ll long long
#define db double
#define HPMAX 1005
#define KMP_MAX 1005
#define prime_MAX 1e6+5
#define quick_pow_mod 1e9+7
#define PII pair<int,int>
using namespace std;
//快读
int read() {
	char c = getchar();
	int x = 0, f = 1;
	for (; !isdigit(c); c = getchar())
		if (c == '-')
			f = -1;
	for (; isdigit(c); c = getchar())
		x = x * 10 + c - 48;
	return x * f;
}
string s, t;
int ans;
int main() {
	cin >> s >> t;
	if (s == t) cout << 0 << endl;
	else {
		for (int i = 0; i < s.size(); ++i)
			if (s[i] != t[i]) ans++;
		cout << ans << endl;
	}
	return 0;
}

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

int main(){
  int a,b,c;
  double S,l,h,d;
  cin>>a>>b>>c;
  d=(acos(-1)*c)/180;
  S=a*b*sin(d)/2;
  l=a+b+sqrt(a*a+b*b-2*a*b*cos(d));
  h=b*sin(d);

  printf("%lf\n%lf\n%lf\n",S,l,h);
    
  return 0;
}
    



Measured memory_bytes: 3456
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC144A
{
    class Program
    {
        static void Main(string[] args)
        {
          
                int a, b, c, d;
                var word = Console.ReadLine().Split(' ');
                a = int.Parse(word[0]);
                b = int.Parse(word[1]);
            if (a >= 10 || b >= 10)
                Console.WriteLine("-1");
            else
                Console.WriteLine(a * b);


            Console.ReadKey();
            }
        }
    }

Measured memory_bytes: 11092
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i = (int)(n - 1); i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) int(x.size())
#define get_unique(x) x.erase(unique(all(x)), x.end());
typedef long long ll;
typedef complex<double> Complex;
const int INF = 1e9;
const ll MOD = 1e9 + 7;
const ll LINF = 1e18;
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 (b < a) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

struct UnionFind {
    vector<int> data;
    UnionFind(int size) : data(size, -1) {
    }
    int root(int x) {
        return (data[x] < 0) ? x : data[x] = root(data[x]);
    }
    bool unite(int x, int y) {
        x = root(x);
        y = root(y);
        if (x != y) {
            if (data[y] < data[x]) swap(x, y);
            data[x] += data[y];
            data[y] = x;
        }
        return x != y;
    }
    bool find(int x, int y) {
        return root(x) == root(y);
    }
    int size(int x) {
        return -data[root(x)];
    }
};
int main() {
    int n, m, k;
    cin >> n >> m >> k;
    UnionFind uf(n);
    vector<int> a(m), b(m), c(k), d(k);
    rep(i, m) {
        cin >> a[i] >> b[i];
        a[i]--;
        b[i]--;
        uf.unite(a[i], b[i]);
    }
    rep(i, k) {
        cin >> c[i] >> d[i];
        c[i]--;
        d[i]--;
    }
    vector<int> cntfr(n), cntbl(n);
    rep(i, m) {
        cntfr[a[i]]++;
        cntfr[b[i]]++;
    }
    rep(i, k) {
        if (uf.find(c[i], d[i])) {
            cntbl[c[i]]++;
            cntbl[d[i]]++;
        }
    }
    rep(i, n) {
        cout << uf.size(i) - 1 - cntfr[i] - cntbl[i] << " \n"[i == n - 1];
    }
}


Measured memory_bytes: 3584
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b;
    scanf("%d %d",&a,&b);
    
    int arr[2*a-1];
    
    int x=b-a+1;
    
    for(int i=0;i<2*a-1;i++)
    {
        arr[i]=x;
        x++;
    }
    for(int i=0;i<2*a-1;i++)
    {
        if(arr[i]>=-1000000&&arr[i]<=1000000)
        cout<<arr[i]<<" ";
    }
}

Measured memory_bytes: 256
import java.util.Scanner;

// 22
public class Main {
    static int chocolate(int ai, int d) {
        int eated = 1;
        for(int i = 1; i <= d; i++) {
            if(d < i * ai + 1) break;
            ++eated;
        }

        return eated;
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int d = sc.nextInt();
        int x = sc.nextInt();
        int[] a = new int[n];
        for(int i = 0; i < n; i++)
            a[i] = sc.nextInt();

        int count = 0;
        for(int i = 0; i < n; i++)
            count += chocolate(a[i], d);

        System.out.println(count + x);
    }

}


Measured memory_bytes: 35960
S = input()
S = S[::-1]

divide = ["dream", "dreamer", "erase", "eraser"]

for i, r in enumerate(divide):
    divide[i] = r[::-1]

#a : 開始インデックス
#b : 終了インデックス

a = 0
while a < len(S):
    can = False
    for i in range(4):
        d = divide[i]
        b = a + len(d)
        if S[a:b] == d:
            can = True
            a = b
            break
    if can == False:
        break

if can:
    print("YES")
else:
    print("NO")


Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(x) (x).begin(),(x).end()
template <class T> inline bool chmin(T &a, T b) {if (a > b){a = b;return true;}return false;}
template <class T> inline bool chmax(T &a, T b) {if (a < b){a = b;return true;}return false;}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a,b,c,d,e,f; cin>>a>>b>>c>>d>>e>>f;
    // 到達可能な水の量
    set<int> wat;
    for(int x=0; x<=f; x++){
        for(int y=0; y<=f; y++){
            if(a*100*x+b*100*y <= f) wat.insert(a*100*x+b*100*y);
        }
    }
    // それぞれに対して砂糖を溶かせるだけ溶かし、最濃をつくる
    double deg = -1;
    pair<int, int> ans;
    for(auto w : wat){
        // 砂糖の限界量
        int cap = min(w*e / 100, f-w);
        // 作れる砂糖量が一番多いやつを全探索する
        int sugar = 0;
        for(int x=0; x<=f; x++){
            for(int y=0; y<=f; y++){
                if(c*x + d*y <= cap){
                    sugar = max(sugar, c*x + d*y);
                }
            }
        }
        // このときの濃度
        double deg2 = (double)100*sugar/(double)(w+sugar);
        // cerr<<w<<" "<<cap<<" "<<sugar<<" "<<deg2<<endl;
        if(deg<deg2){
            deg = deg2;
            ans = make_pair(sugar+w, sugar);
        }
    }
    cout<<ans.first<<" "<<ans.second<<endl;
}
// arc083_a.exe

Measured memory_bytes: 256
from collections import deque

def bfs():
    d = [[float("inf")] * w for i in range(h)]

    dx = [1, 0, -1, 0]
    dy = [0, 1, 0, -1]

    que = deque([])
    que.append((sx, sy))
    d[sx][sy] = 0

    while que:
        p = que.popleft()
        if p[0] == gx and p[1] == gy:
            break
        for i in range(4):
            nx = p[0] + dx[i]
            ny = p[1] + dy[i]

            if 0 <= nx and nx < h and 0 <= ny and ny < w and\
                maze[nx][ny] != "#" and d[nx][ny] == float("inf"):
                que.append((nx, ny))
                d[nx][ny] = d[p[0]][p[1]] + 1

    return d[gx][gy]

h, w = map(int, input().split())
maze = [list(input()) for i in range(h)]
sx, sy = 0, 0
gx, gy = h - 1, w - 1

black = 0
for i in range(h):
    for j in range(w):
        if maze[i][j] == "#":
            black += 1

res = bfs()
if 0 < res < float("inf"):
    print(h * w - res - black - 1)
else:
    print(-1)

Measured memory_bytes: 3444
n=int(input())
xy=[list(map(int,input().split())) for _ in range(n)]
m=39
ans=[]
if sum(xy[0])%2==0:ans.append(1)
for i in range(m):
    ans.append(2**i)
c=sum(xy[0])%2
for x,y in xy:
    if (x+y)%2!=c:exit(print(-1))
print(len(ans))
print(*ans[::-1])
def chk(s):
    a=[]
    for d in ans[::-1]:
        if abs(s-d)<abs(s+d):
            a.append(-1)
            s-=d
        else:
            a.append(1)
            s+=d
    return a
xpy,xmy=[],[]
for x,y in xy:
    xpy=chk(x+y)
    xmy=chk(x-y)
    s=[]
    for p,m in zip(xpy,xmy):
        if p==1 and m==1:s.append('L')
        if p==-1 and m==-1:s.append('R')
        if p==1 and m==-1:s.append('D')
        if p==-1 and m==1:s.append('U')
    print(*s,sep='')

Measured memory_bytes: 4692
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,k,n) for(int i = (int)(k); i < (int)(n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) a.begin(), a.end()
#define MS(m,v) memset(m,v,sizeof(m))
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> pii;
const int MOD = 1e9 + 7;
template<class T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template<class T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template<class T>
istream& operator >> (istream& is, vector<T>& v)
{
	for (auto &i : v) is >> i;
	return is;
}
template<class T>
ostream& operator<<(ostream& os, vector<T>& v)
{
	const string delimiter = "\n";
	REP(i, v.size())
	{
		os << v[i];
		if (i != v.size() - 1) os << delimiter;
	}
	return os;
}
/*--------------------template--------------------*/

int main()
{
	cin.sync_with_stdio(false); cout << fixed << setprecision(10);
	vector<vi> c(3, vi(3));
	cin >> c;
	bool f = true;
	int d1 = c[0][0] - c[0][1];
	int d2 = c[0][1] - c[0][2];
	int d3 = c[0][0] - c[1][0];
	int d4 = c[1][0] - c[2][0];
	REP(i, 3)
	{
		if (c[i][0] - c[i][1] != d1) f = false;
		if (c[i][1] - c[i][2] != d2) f = false;
		if (c[0][i] - c[1][i] != d3) f = false;
		if (c[1][i] - c[2][i] != d4) f = false;
	}
	cout << (f ? "Yes" : "No") << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
bool prime(int);
int main()
{
while (true){
	bool dp[1000001] = { false };
	int a[31];
	int n, v;
	cin >> n >> v;
	if (n == 0){
		break;
	}
	for (int i = 0; i < n; i++){
		cin >> a[i];
	}
	dp[0] = true;
	for (int i = 0; i < n; i++){
		for (int i2 = 0; i2 <= v - a[i]; i2++){
			if (dp[i2]){
				dp[i2 + a[i]] = true;
			}
		}
	}

	bool flag = true;
	for (int i = 1000000; i > 0; i--){
		if (dp[i] && !prime(i)){
			flag = false;
			cout << i << endl;
			break;
		}
	}
	if (flag)
		cout << "NA" << endl;
}

}
bool prime(int x){
	for (int i = 2; i * i <= x; i++)
		if (x % i == 0) return true;
	return false;
}

Measured memory_bytes: 2148
#include<bits/stdc++.h>
using namespace std;
int main(){
    for(int i=0;;i++){
        int x,y;
        cin>>x>>y;
        if(x==0&&y==0){
            break;
        }
        if(x<=y){
            cout<<x<<" "<<y<<endl;
        }
        else{
            cout<<y<<" "<<x<<endl;
        }
    }
    return 0;
}


Measured memory_bytes: 2988
//Date and time of submission: 
 
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const ll N=1e5+5;

int main() {
	ios_base::sync_with_stdio(false); 
	cin.tie(NULL);
	string s;
	cin>>s;
	ll cnt=0;
	for(char ch: s)
	cnt+=(ch=='o');
	cout<<700+(cnt*100);
	return 0;
}


Measured memory_bytes: 256
import fractions

n = int(input())
a = list(map(int,input().split()))

ans = a[0]
for i in range(1, n):
    ans = ans * a[i] // fractions.gcd(ans, a[i])

c = ans -1

#print(c)
ans = 0
for val in a:
    ans += c%val
print(ans)


Measured memory_bytes: 66992
ls = []
while True:
    x,y = map(int,input().split())
    if x == y == 0:
        break
    if x > y :
        tmp = y
        y = x
        x = tmp
    ls.append([x,y])

for i in range(len(ls)):
    print("{} {}".format(ls[i][0],ls[i][1]))



Measured memory_bytes: 6016
#include <iostream>
#include <vector>
#include <cstdio>
#include <map>
using namespace std;

int main() {
    char s[8001];
    int x, y;

    scanf("%s %d %d", &s, &x, &y);

    int p = 0;
    while (s[p] == 'F') p++;

    vector<int> yoko, tate;
    int d = 1, cont = 0;
    for (int i=p; s[i] != '\0'; i++) {
        if (s[i] == 'F') cont++;
        else if (i == 0 || s[i-1] == 'F') {
            if (d == 1) yoko.push_back(cont);
            else        tate.push_back(cont);
            cont = 0;
            d *= -1;
        }
        else d *= -1;
    }
    if (d == 1) yoko.push_back(cont);
    else        tate.push_back(cont);
    
    map<int, bool> prev, curr;
    prev[p] = true;
    for (auto it_v = yoko.begin(); it_v != yoko.end(); it_v++) {
        for (auto it_m = prev.begin(); it_m != prev.end(); it_m++) {
            curr[it_m->first + *it_v] = true;
            curr[it_m->first - *it_v] = true;
        }
        prev = curr;
        curr.clear();
    }

    if (prev.find(x) == prev.end()) {
        cout << "No" << endl;
        return 0;
    }

    prev.clear();
    prev[0] = true;
    for (auto it_v = tate.begin(); it_v != tate.end(); it_v++) {
        for (auto it_m = prev.begin(); it_m != prev.end(); it_m++) {
            curr[it_m->first + *it_v] = true;
            curr[it_m->first - *it_v] = true;
        }
        prev = curr;
        curr.clear();
    }

    if (prev.find(y) == prev.end()) cout << "No" << endl;
    else cout << "Yes" << endl;

    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i <(n) ; ++i)
#define pb push_back
#define P pair<int,int>
using namespace std;
using ll = long long;
// using mod = int 1000000000 + 7;
void self_max(int &a,int b){
	a = max(a,b);
}

void self_min(int &a,int b){
	a = min(a,b);
}

int main(){
	int n; cin >> n;
	unordered_map<string,int> m;
	while(n--){
		string s; cin >> s;
		m[s]++;
	}

	cout << "AC x " << m["AC"] << endl;
	cout << "WA x " << m["WA"] << endl;
	cout << "TLE x " << m["TLE"] << endl;
	cout << "RE x " << m["RE"] << endl;


	return 0;
}
		     

Measured memory_bytes: 3640
#include <iostream>
#include <string>

using namespace std;

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


Measured memory_bytes: 256