akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
 
int main () {
  int64_t s;
  cin >> s;
  vector<int64_t> a(1000000);
  a.at(0) = s;
  int c = 0;
  if (s == 1 || s == 2 || s == 4) {
    cout << 4 << endl;
  }
  else {
  for (int i = 1; i < 1000001; i++) {
    if (a.at(i - 1) % 2 == 0) {
      a.at(i) = a.at(i - 1) / 2;
    }
    else {
      a.at(i) = a.at(i - 1) * 3 + 1;
    }
    if (a.at(i) == 4) {
      c++;
    }
    if (c == 2) {
      cout << i + 1 << endl;
      break;
    }
  }
  }
}

Measured memory_bytes: 11168
#include<iostream>
#include<algorithm>
#include<string>
#include<sstream>
using namespace std;
int main() {
  string s;
  cin >> s;
  long count = 0;
  long ans = 0;
  for(int i=0;i<s.length();i++){
    if(s[i]=='W'){
      ans += i - count;
      count ++;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 640
n = int(input())
n %= 10
if n  == 2 or n  == 4 or n  == 5 or n  == 7 or n  == 9:
    print("hon")
elif n == 0 or n  == 1 or n  == 6 or n  == 8:
    print("pon")
elif n == 3:
    print("bon")

Measured memory_bytes: 9172
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.NoSuchElementException;

public class Main {
	int a,b,h;
	public void solve() {
		a = nextInt();
		b = nextInt();
		h = nextInt();

		out.println((a + b) * h / 2);
	}

	public static void main(String[] args) {
		out.flush();
		new Main().solve();
		out.close();
	}

	/* Input */
	private static final InputStream in = System.in;
	private static final PrintWriter out = new PrintWriter(System.out);
	private final byte[] buffer = new byte[2048];
	private int p = 0;
	private int buflen = 0;

	private boolean hasNextByte() {
		if (p < buflen)
			return true;
		p = 0;
		try {
			buflen = in.read(buffer);
		} catch (IOException e) {
			e.printStackTrace();
		}
		if (buflen <= 0)
			return false;
		return true;
	}

	public boolean hasNext() {
		while (hasNextByte() && !isPrint(buffer[p])) {
			p++;
		}
		return hasNextByte();
	}

	private boolean isPrint(int ch) {
		if (ch >= '!' && ch <= '~')
			return true;
		return false;
	}

	private int nextByte() {
		if (!hasNextByte())
			return -1;
		return buffer[p++];
	}

	public String next() {
		if (!hasNext())
			throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = -1;
		while (isPrint((b = nextByte()))) {
			sb.appendCodePoint(b);
		}
		return sb.toString();
	}

	public int nextInt() {
		return Integer.parseInt(next());
	}

	public long nextLong() {
		return Long.parseLong(next());
	}

	public double nextDouble() {
		return Double.parseDouble(next());
	}
}

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

int f(int x){
  return x*x;
}

int main(){

  int d;

  while(cin>>d){
    int sum=0;
    for(int i=1;i*d<600;i++){
      sum+=d*f(d*i);
    }
    cout<<sum<<endl;
  }
  return 0;
}

Measured memory_bytes: 3016
using System;
using System.Linq;

namespace Main
{
    class Program
    {
        static void Main(string[] args)
        {
            //ここから
            //string[] str = Console.ReadLine().Split(' ');
            //int n = int.Parse(Console.ReadLine());

            string[] str = Console.ReadLine().Split(' ');
            int a = int.Parse(str[0]);
            int b = int.Parse(str[1]);
            int m = int.Parse(str[2]);

            int[] ap = new int[a];
            int[] bp = new int[b];

            str = Console.ReadLine().Split(' ');
            for(int i = 0; i < a; i++)
            {
                ap[i] = int.Parse(str[i]);
            }
            str = Console.ReadLine().Split(' ');
            for (int i = 0; i < b; i++)
            {
                bp[i] = int.Parse(str[i]);
            }

            int min = ap.Min()+bp.Min();

            for(int i = 0; i < m; i++)
            {
                str = Console.ReadLine().Split(' ');
                int temp = ap[int.Parse(str[0])-1] + bp[int.Parse(str[1])-1] - int.Parse(str[2]);
                if (temp < min) { min = temp; }
            }

            Console.WriteLine(min);
            //ここまで
        }
    }
}


Measured memory_bytes: 33372
import std.algorithm;
import std.array;
import std.container;
import std.conv;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

void scan(T...)(ref T a) {
    string[] ss = readln.split;
    foreach (i, t; T) a[i] = ss[i].to!t;
}
T read(T)() { return readln.chomp.to!T; }
T[] reads(T)() { return readln.split.to!(T[]); }
alias readint = read!int;
alias readints = reads!int;

void main() {
    int n, k; scan(n, k);
    string s = read!string;

    foreach (i, c; s.enumerate(1)) {
        write(i == k ? c.toLower() : c);
    }
    writeln();
}


Measured memory_bytes: 256
# abc 154
import sys
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
read = sys.stdin.buffer.read
sys.setrecursionlimit(10 ** 7)

N, K = map(int, readline().split())
P = list(map(int, readline().split()))

def cal_expected(p):
    expected = 0
    for i in range(1, p+1):
        expected += i / p
    return expected

# 期待値一覧の作成
expected_dict = {k:cal_expected(k) for k in set(P)}

import copy
from collections import deque
# 対象特定
ans_start = 0
dices_sum = 0
tmp_dices = None
for start in range(0, N-K+1):
    if tmp_dices == None:
        tmp_dices = deque(P[start:start+K])
        tmp_sum = sum(tmp_dices)
    else:
        removed = tmp_dices.popleft()
        tmp_dices.append(P[start+K-1])
        tmp_sum = tmp_sum - removed + P[start+K-1]
    if tmp_sum > dices_sum:
        ans_start = start
        dices_sum = tmp_sum

# 期待値計算
# answer = sum(map(cal_expected, dices))
answer = 0
dices = P[ans_start:ans_start+K]
for dice in dices:
    answer += expected_dict[dice]
print(answer)


Measured memory_bytes: 21188
#include "bits/stdc++.h"
#pragma GCC optimize("Ofast")

// Begin {{{
using namespace std;

#ifndef DEBUG
#define dump(...)
#endif

template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }

template <class T>
inline vector<T> make_v(const T &initvalue, int sz) {
    return vector<T>(sz, initvalue);
}

template <class T, class... Args>
inline auto make_v(const T &initvalue, int sz, Args... args) {
    return vector<decltype(make_v<T>(initvalue, args...))>(sz, make_v<T>(initvalue, args...));
}

constexpr int INF = 0x3f3f3f3f;
constexpr int64_t LINF = 0x3f3f3f3f3f3f3f3fLL;
// }}} End

int N, A, B, C;

vector<int> l;

int dfs(int idx = 0, int lenA = 0, int lenB = 0, int lenC = 0) {
    if (idx == N) {
        if (lenA && lenB && lenC) {
            return abs(A - lenA) + abs(B - lenB) + abs(C - lenC) - 30;
        } else {
            return INF;
        }
    }

    int ret = INF;
    chmin(ret, dfs(idx + 1, lenA, lenB, lenC));
    chmin(ret, dfs(idx + 1, lenA + l[idx], lenB, lenC) + 10);
    chmin(ret, dfs(idx + 1, lenA, lenB + l[idx], lenC) + 10);
    chmin(ret, dfs(idx + 1, lenA, lenB, lenC + l[idx]) + 10);

    return ret;
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    cin >> N >> A >> B >> C;

    l.resize(N);
    for (auto &li: l) cin >> li;

    cout << dfs() << "\n";

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define bug(x) cout<<#x<<" : "<<x<<endl
#define de puts("#")
#define int long long
using namespace std;
const int maxn=2505;
const int maxm=5005;
const int inf=1e18;
int n,m,p;
struct node{
	int to,val;
};
vector<node>G[maxn];
int dis[maxn];

signed main(){
	scanf("%lld %lld %lld",&n,&m,&p);
	for(int i=1,x,y,z;i<=m;i++){
		scanf("%lld %lld %lld",&x,&y,&z);
		G[x].push_back((node)<%y,z-p%>);
	}
	for(int i=2;i<=n;i++)dis[i]=-inf;
	dis[1]=0;
	for(int t=1;t<=n;t++)
		for(int i=1;i<=n;i++)
			for(int j=0;j<(int)G[i].size();j++){
				int to=G[i][j].to,val=G[i][j].val;
				if(dis[i]!=-inf&&dis[to]<dis[i]+val)dis[to]=dis[i]+val;
			}
	for(int t=1;t<=n;t++)
		for(int i=1;i<=n;i++)
			for(int j=0;j<(int)G[i].size();j++){
				int to=G[i][j].to,val=G[i][j].val;
				if(dis[i]!=-inf&&dis[to]<dis[i]+val)dis[to]=inf;
			}
	if(dis[n]>=inf)puts("-1");
	else printf("%lld\n",max(dis[n],0LL));
	return 0;
} 


Measured memory_bytes: 512
#include<iostream>
using namespace std;
int main(){
    int n,ans=0;
    cin>>n;
    int b[n-1];
    for(int i=0;i<n-1;i++)cin>>b[i];
    for(int i=0;i<n-2;i++)ans+=min(b[i],b[i+1]);
    cout<<ans+b[0]+b[n-2]<<endl;
    return 0;
}

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

#define rep(i, N) for (ll i = 0; i < N; i++)
#define rep1(i, N) for (ll i = 1; i <= N; i++)
#define repr(i, N) for (ll i = N-1; i >= 0; i--)
#define repr1(i, N) for (ll i = N; i > 0; i--)

#define MOD 1000000007

using ll = long long;
using namespace std;

typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<P> vpi;
typedef pair<ll,ll> Pl;
typedef vector<ll> vl;
typedef vector<Pl> vpl;

ll gcd(ll a, ll b){
    if(a < b) swap(a, b);
    if(b <= 0) return -1;
    ll r = a % b;
    while(r != 0){
        a = b;
        b = r;
        r = a % b;
    }
    return b;
}

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

ll A,B,N;

ll func(ll x_t){
    return ((ll)((long double)A/B*x_t) - A*(ll)((long double)x_t/B));
}


int main() {
    ll ans,num;
    cin >> A>>B>>N;
   
    ans = func(min(N, B-1));


    //string ans = ( flag ? "OK":"NG");
    cout << ans;
    //printf("%.8lf", ans);
    cout << "\n";
    return 0;
}


Measured memory_bytes: 3652
N = int(input())
flag = True
A = list(map(int, input().split()))
for a in A:
    if a % 2 == 0:
        if a % 3 == 0 or a % 5 == 0:
            continue
        else:
            flag = False
    else:
        continue
if flag:
    print("APPROVED")
else:
    print("DENIED")


Measured memory_bytes: 2940
#include <stdio.h>
#include <stdlib.h>
#include "time.h"
#include "unistd.h"
#include "string.h"
int ans;
int main(int argc, char* argv[]){
  long long int h,w;
  scanf("%lld %lld",&h,&w);
  long long int ans =h*w;
  if (h==1&&w!=1) {
    printf("1");
    return 0;
  }
  if (h!=1&&w==1) {
    printf("1");
    return 0;
  }
  if (ans%2==0) {
    printf("%lld",ans/2);
  }else{
    printf("%lld",ans/2+1);
  }
}


Measured memory_bytes: 128
n = int(input())
c = []
for i in range(n):#h:高さ
    c.append([str(m) for m in input().split()])
for i in range(n):
    c[i][0] = float(c[i][0])
ans = 0
for i in range(n):
    if c[i][1] == "JPY":
        ans += c[i][0]
    else:
        ans += c[i][0] * 3.8 * (10 ** 5)
print(ans)

Measured memory_bytes: 3064
N,M = map(int,(input().split()))
info = [[] for _ in range(N)]
for i in range(M):
    l,r,d = map(int,(input().split()))
    info[l-1].append([r-1,d])
    info[r-1].append([l-1,-d])

people = [-1]*(N)
flag = 0

not_visited = {}
for i in range(N):
    not_visited[i] = True

stack = list(range(N))

while stack:
    now = stack.pop()

    for j in info[now]:
        if not_visited[j[0]]:
            stack.append(j[0])
        
        if people[j[0]] == -1:
            people[j[0]] = people[now] + j[1] 
        else:
            if people[j[0]] != people[now] + j[1]:
                flag = -1

        not_visited[now] = False

if flag != -1:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 115484
//#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define trav(x,a) for (const auto& x: a)
#define sz(x) (int)(x).size()
#define mem(a,v) memset((a), (v), sizeof (a))
#define enl printf("\n")
#define case(t) printf("Case #%d: ", (t))
#define ni(n) scanf("%d", &(n))
#define nl(n) scanf("%lld", &(n))
#define nai(a, n) for (int _i = 0; _i < (n); _i++) ni(a[_i])
#define nal(a, n) for (int _i = 0; _i < (n); _i++) nl(a[_i])
#define pri(n) printf("%d\n", (n))
#define prl(n) printf("%lld\n", (n))
#define pii pair<int, int>
#define pll pair<long long, long long>
#define vii vector<pii>
#define vll vector<pll>
#define vi vector<int>
#define vl vector<long long>
#define pb push_back
#define mp make_pair
#define st first
#define nd second
#define ar array<int,3>
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef cc_hash_table<int,int,hash<int>> ht;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> oset;
const double pi = acos(-1);
const int mod = 1e9 + 7;
const int inf = 1e9 + 7;
const int N = 1e6 + 5;
const double eps = 1e-9;
int dp[105][105];
char tmp[105];
int a[105][105];

int main() {
  int h, w; scanf("%d %d", &h, &w);
  for (int i = 0; i < h; i++) {
    scanf("%s", tmp);
    for (int j = 0; j < w; j++)
      if (tmp[j] == '#')
        a[i][j] = 1;
      else
        a[i][j] = 0;
  }
  mem(dp, 0x3f);
  priority_queue<ar,vector<ar>,greater<ar>> pq;
  dp[0][0] = a[0][0];
  pq.push({a[0][0], 0, 0});
  while (!pq.empty()) {
    auto it = pq.top(); pq.pop();
    if (it[0] != dp[it[1]][it[2]])
      continue;
    if (it[1] != h-1) {
      int d = a[it[1]+1][it[2]] == 1 && a[it[1]][it[2]] == 0;
      if (dp[it[1]+1][it[2]] > it[0] + d) {
        dp[it[1]+1][it[2]] = it[0] + d;
        pq.push({dp[it[1]+1][it[2]], it[1]+1, it[2]});
      }
    }
    if (it[2] != w-1) {
      int d = a[it[1]][it[2]+1] == 1 && a[it[1]][it[2]] == 0;
      if (dp[it[1]][it[2]+1] > it[0] + d) {
        dp[it[1]][it[2]+1] = it[0] + d;
        pq.push({dp[it[1]][it[2]+1], it[1], it[2]+1});
      }
    }
  }
  printf("%d\n", dp[h-1][w-1]);
  return 0;
}


Measured memory_bytes: 384
while True:
  a,op,b = input().split()
  a = int(a)
  b = int(b)
  if op == '?':
    break
  elif op == '+':
    print(a + b)
  elif op == '-':
    print(a - b)
  elif op == '*':
    print(a * b)
  elif op == '/':
    print(a // b)


Measured memory_bytes: 5596
// https://atcoder.jp/contests/abc136/tasks/abc136_c

#include <iostream>
#include <vector>
#include <array>
#include <unordered_map>
#include <unordered_set>

using namespace std;

int main (int argc, char* argv[]) {
	int n;
	cin >> n;
	int prev = 0;
	for (int i = 0; i < n; i++) {
		int next;
		cin >> next;
		if (next > prev) --next;
		if (next < prev) {
			cout << "No" << endl;
			return 0;
		}
		prev = next;
	}
	cout << "Yes" << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<cstdlib>
#include<math.h>
#include<algorithm>
#include<string>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<deque>
#include<set>
#include<map>
#define REP(i, N) for(ll i = 0; i < N; ++i)
#define ALL(a) (a).begin(),(a).end()
#define pb push_back
#define INF 1000000000
#define MOD 1000000007
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
int qx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
int qy[8] = {0, 1, 1, 1, 0, -1, -1, -1};

int main(void) {
	ll X, Y;
	cin>>X>>Y;
	if(X < 2 && Y < 2) {
		cout<<"Brown"<<endl;
		return 0;
	}
	if(X < Y) {
		ll gomi = X;
		X = Y;
		Y = gomi;
	}
	if(X == Y) cout<<"Brown"<<endl;
	else if(X - Y == 1) cout<<"Brown"<<endl;
	else cout<<"Alice"<<endl;
}


Measured memory_bytes: 256
#include <stdio.h>
int main(void)
{
    int K,A,B;
    scanf("%d %d %d",&K,&A,&B);
    if(B/K-A/K >= 1 || B%K == 0 || A%K == 0){
        printf("OK");
    }else{
        printf("NG");
    }
}

Measured memory_bytes: 1720
n, m, x, y = gets.split.map(&:to_i)
xs = gets.split.map(&:to_i)
ys = gets.split.map(&:to_i)
a = (-100..100).to_a
zs = a.select { |e| e > x } & a.select { |e| e <= y } &
     a.select { |e| e > xs.max } & a.select { |e| e <= ys.min }
puts zs.empty? ? 'War' : 'No War'


Measured memory_bytes: 1788
#include<bits/stdc++.h>
#define ff first
#define ss second
#define len(x) (int)(x.size())
#define all(x) x.begin(), x.end()
using namespace std;
using ll = long long;
using ii = pair<int, int>;
#define MAXN 200010
#define MAXLOGN 20
#define comp(a, b) max((a), (b))
int st[MAXN][MAXLOGN];
int vs[MAXN];
void init(int* bg, int*en){
	int sz = int(en-bg);
	for(int i=0; i<sz; ++i) st[i][0] = bg[i];
	for(int j=1; 1 << j <= sz; ++j)
		for(int i=0; i + (1<<j) <= sz; ++i)
			st[i][j] = comp(st[i][j-1], st[i + (1<<(j-1))][j-1]);
}
int query(int l, int r){
	int k = (int) floor(log((double)r-l+1) / log(2.0));
	return comp(st[l][k], st[r-(1<<k)+1][k]);
}
int main(){
	ios::sync_with_stdio(0);
	vs[0]=-1e9;
	int n;
	cin >> n;
	for(int i=1; i<=n; ++i) cin >> vs[i];
	init(vs, vs+n+1);
	for(int i=1; i<=n; ++i){
		int res = query(0, i-1);
		if(i<n)
			res = max(res, query(i+1, n));
		cout << res << endl;
	}

}


Measured memory_bytes: 18048
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); i++)
#define repd(i,a,b) for (int i = (a); i < (b); i++)
typedef long long ll;
int main(void)
{
    int n, m, in;
    string key;
    set<int> A;
    set<int> B;
    vector<int> result;
    cin >> n;
    rep(i, n)
    {
        cin >> in;
        A.insert(in);
    }
    cin >> m;
    rep(i, m)
    {
        cin >> in;
        B.insert(in);
    }
    set_intersection(A.begin(), A.end(), B.begin(), B.end(), inserter(result, result.end()));
    
    rep(i, result.size())
    {
        cout << result[i] << endl;
    }
}



Measured memory_bytes: 21968
#include <bitset>
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <stack>
#include <algorithm>
#include <iostream>
#include <string>
#include <map>
#include <queue>
#include <stdio.h>
#include <math.h>

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

typedef vector<vector<int>> vvi;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;
typedef vector<ll> vll;

typedef pair<int, int> pii;

typedef queue<int> qi;
typedef queue<string> qs;


#define rep(i, n) for(int i=0; i<(n); ++i)
#define repp(i, a, b) for(int i = (a); i <= (b); i++)
#define repm(i, a, b) for(int i = (a); i >= (b); i--)

#define all(v) v.begin(), v.end()
//sort( all(v) )　などと使える

int main(){
    int n, m; cin >> n >> m;
    vector<ll> h(n);
    rep(i, n) cin >> h[i];
    vector<vector<int>> G(n);
    rep(i, m){
        int a, b; cin >> a >> b;
        a--; b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }

    int cnt = 0;
    rep(i, n){
        //
        bool flag = true;
        rep(j, G[i].size()){
            if(h[G[i][j]] >= h[i]) flag = false;
        }
        
        if(flag) cnt++;
    }

    cout << cnt << endl;
}

Measured memory_bytes: 9032
n, m = [int(i) for i in input().split() ]
x = [int(i) for i in input().split() ]
x.sort()
y = list( [x[i+1] - x[i] for i in range(m-1)])
y.sort(reverse=True)

if m <= n:
    print(0)
else:
    print(sum(y[n-1:]))

Measured memory_bytes: 13840
#coding:utf-8
#1_6_D 2015.4.5
n,m = map(int,input().split())
matrix = [list(map(int,input().split())) for i in range(n)]
vector = [int(input()) for i in range(m)]
for i in range(n):
    print(sum([matrix[i][j] * vector[j] for j in range(m)]))

Measured memory_bytes: 7032
#include <bits/stdc++.h>
#define MAX_INT 2100000000
#define rep(i,n) for (i=1;i<=(n);++i)
using namespace std;
typedef long long int ll;
/*
#ifdef COMPILE_IN_VCPP
#include <windows.h>
HWND GetConsoleHwnd(void)
{
#define MY_BUFSIZE 1024 // Buffer size for console window titles.
	HWND hwndFound;         // This is what is returned to the caller.
	char pszNewWindowTitle[MY_BUFSIZE]; // Contains fabricated// WindowTitle.
	char pszOldWindowTitle[MY_BUFSIZE]; // Contains original// WindowTitle.
	ULARGE_INTEGER nt;
	nt.QuadPart = GetTickCount64();
	GetConsoleTitle(pszOldWindowTitle, MY_BUFSIZE);
	wsprintf(pszNewWindowTitle, "%d%d/%d", nt.HighPart, nt.LowPart, GetCurrentProcessId());
	SetConsoleTitle(pszNewWindowTitle);
	Sleep(40);
	hwndFound = FindWindow(NULL, pszNewWindowTitle);
	SetConsoleTitle(pszOldWindowTitle);
	return(hwndFound);
}
#endif
*/
ll mod = 1e9 + 7;
// abc145c                                                       

int main(void)
{
	std::cout << std::fixed << std::setprecision(10);
	int n, x[10], y[10], i, j, k;
	long double ans = 0;
	cin >> n;
	int f = 1;
	for (i = 1; i <= n;i++)
	{
		f *= i;
	}
	for (i = 1; i <= n; i++)
	{
		cin >> x[i] >> y[i];
	}
	int array[] = { 1,2,3,4,5,6,7,8 };
	do {
		long double dis=0;
		for (int i = 0; i < n-1; i++) {
			//i,i+1
			//printf("(%d,%d)", array[i], array[i+1]);
			dis += sqrt((x[array[i]]- x[array[i + 1]]) * (x[array[i]] - x[array[i + 1]]) + (y[array[i]]- y[array[i + 1]]) * (y[array[i]] - y[array[i + 1]]));
		}
		ans += dis;
	} while (next_permutation(array, array + n));
	cout << ans /f << endl;
}

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

signed main(){
  string S;
  cin>>S;
  rep(i,S.size()){
    if(i%2==0){
      if(S[i]=='L'){
        cout<<"No"<<endl;
        return 0;
      }
    }
    if(i%2==1){
      if(S[i]=='R'){
        cout<<"No"<<endl;
        return 0;
      }
    }
  }
  cout<<"Yes"<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cassert>
typedef long long lint;
const int N=20;
const int mod=1e9+7;
int n,m,q,hbit[1<<N];
int limit[N+1][N+1],dp[2][1<<N];

template <class T> inline void apadd(T &x,const T y){
	x+y<mod?x=x+y:x=x+y-mod;
}

inline int nxi(){
	int x=0;
	char c;
	while((c=getchar())>'9'||c<'0');
	while(x=x*10-48+c,(c=getchar())>='0'&&c<='9');
	return x;
}

void init(){
	for(int i=2; i<1<<n; ++i){
		hbit[i]=hbit[i>>1]+1;
	}
}

int main(){
#ifdef LOCAL
	//freopen("d.in","r",stdin);
#endif
	memset(limit,-1,sizeof(limit));
	n=nxi(),m=nxi(),q=nxi();
	--n;
	init();
	for(int i=1; i<=q; ++i){
		const int a=nxi(),b=nxi(),c=nxi();
		limit[a][b]=c;
	}
	dp[0][0]=1;
	for(int i=1; i<=m; ++i){
		for(int j=0; j<n; ++j){
			int p=j&1;
			memset(dp[p^1],0,sizeof(dp[p^1]));
			for(int k=0; k<1<<n; ++k){
				if(!dp[p][k]) continue;
				if((k>>j&1)==0&&limit[i][j+1]!=1){
					apadd(dp[p^1][k],dp[p][k]);
					//dp[p^1][k]=(dp[p^1][k]+dp[p][k])%mod;
				}
				if(limit[i][j+1]!=0){
					int lbit=((k>>j)&-(k>>j))<<j;
					int tgt=k^(1<<j)^lbit;
					apadd(dp[p^1][tgt],dp[p][k]);
					//dp[p^1][tgt]=(dp[p^1][tgt]+dp[p][k])%mod;
				}
			}
		}
		if(n&1){
			memcpy(dp[0],dp[1],sizeof(dp[1]));
		}
	}
	lint ans=0;
	for(int i=0; i<1<<n; ++i){
		ans+=dp[0][i];
	}
	printf("%lld\n",ans%mod);
	return 0;
}


Measured memory_bytes: 12544
#include <bits/stdc++.h>
#define F first
#define S second
#define mp make_pair
#define pb push_back
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pi;
const ll inf = 1e18+5;
ll n, k, ans, fact[100005], inv[100005], ifact[100005];
const ll mod = 1e9+7;
ll add(ll x, ll y){
	return (x%mod + y%mod + mod)%mod;
}
ll mult(ll x, ll y){
	return (x%mod * y%mod + mod)%mod;
}
ll sub(ll x,ll y){
	return (x%mod - y%mod + mod)%mod;
}
ll nck (ll nn, ll kk ){
	//if(nn < kk)return 0;
	//if (nn <0 || kk< 0)return 0;
	//if (nn ==kk)return 1;
	return(fact[nn]*(ifact[nn-kk] *ifact[kk]%mod)%mod);
}
int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);
	cin >> n >> k;
	vector<ll> a(n);
	for (ll i = 0; i < n; i++)cin >> a[i];
	sort(a.begin(), a.end());
	k -= 1;
	//~ vector<ll> pre(n);
	//~ for (ll i = 0; i < n; i++)pre[i] = (i == 0? a[i]: pre[i-1]+a[i]);
	fact[0] =1;
	fact[1] =1;
	inv[1] =1;
	for (ll i = 2; i<= n; i++){
		inv[i] = mod-inv[mod%i]*(mod/i)%mod;
		fact[i] = mult(fact[i-1], i);
	}
	ifact[0] =1,ifact[1] =1;
	for (ll i= 2; i<=n;i++){
		ifact[i] = ifact[i-1] *inv[i] %mod;
	}
	//for each guy, we consider it to be max element, we have to find the number of sets that 
	//can be made this way, and the respective mins of those sets
	for (ll i = k; i < n; i++){
		ll numways = nck(i, k);// i choose k-1
		ans = add(ans, mult(numways, a[i]));
		//~ ans -= pre[infront-1];
	}
	for (ll i = 0; i < n-k; i++){ //for each guy we want to consider it being the min
		ll bigg = n-i-1;
		ll numways = nck(bigg, k); //bigg choose k-1
		ans = sub(ans, mult(numways, a[i]));
	}
	cout << ans;
}


Measured memory_bytes: 3328
#include<iostream>
#include <climits>
using namespace std;
int aji(int L,int num){
    int i;
    int aji;
    aji = L + num -1;
    return aji;
}
//0に近い林檎をとればOK　その後味の合計
int main(){
    int N,L;
    int i,temp_aji;
    int taste,temp;
    int apple[200];
    int eaten;
    int dif,temp_dif = INT_MAX;
    int ans = 0;

    cin >> N >> L;
    for(i= 0;i<200;i++){
        apple[i] = 0;
    }
    for(i= 0;i<N;i++){
        apple[i] = aji(L,i+1);
    }


    if (apple[0]>0){
        eaten = 0;
    }
    else if(apple[N-1] < 0){
        eaten = N-1;
    }
    else if (apple[0] <= 0 && apple[N-1] >= 0){
        for(i=0;i<N;i++){
            dif = abs(0 - apple[i]);
            if (temp_dif > dif){
                temp = temp_dif;
                temp_dif = dif;
                dif = temp;
                eaten = i;
            }
        }
    }
    
    apple[eaten] = 0;
    for (i=0;i<N;i++){
        ans = ans + apple[i];
    }
    printf("%d\n",ans);
    

    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;

int n, k, p[5001];
long long c[5001];

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cin >> n >> k;
	for(int i = 1; i <= n; i++) cin >> p[i];
	for(int i = 1; i <= n; i++) cin >> c[i];
	long long ans = LLONG_MIN;
	for(int i = 1; i <= n; i++){
		vector<long long> cnt = {c[i]};
		long long cur = c[i];
		int x = p[i];
		while(x != i){
			cur += c[x];
			cnt.push_back(cur);
			x = p[x];
		}
		for(int i = 0; i < (int)cnt.size(); i++)
			if(cnt.back() <= 0 && i + 1 <= k) ans = max(ans, cnt[i]);
			else if(cnt.back() > 0 && i + 1 <= k)
				ans = max(ans, (k - i - 1) / (int)cnt.size() * cnt.back() + cnt[i]);
	}
	cout << ans << '\n';
	return 0;
}

Measured memory_bytes: 3776
from collections import defaultdict
from functools import reduce

def main():
  m = 10 ** 9 + 7
  n = int(input())
  current = defaultdict(int)
  current['TTT'] = 1
  for i in range(n):
    wip = defaultdict(int)

    for c in 'AGCT':
      for k, v in current.items():
        if k + c in ['ATGC', 'AGTC', 'AGGC']:
          continue
        z = k[1:]+c
        if z in ['AGC', 'ACG', 'GAC']:
          continue
        wip[z] = (wip[z] + v) % m

    current = wip
  
  print(reduce(lambda acc, x: (acc + x) % m, wip.values()))

main()

Measured memory_bytes: 9496
#include <iostream>
using namespace std;
#define REP(i, n) for (int i = 0; i < n; i++)

int A[101][101];

int main() {
  int H, W;
  char a;
  cin >> H >> W;
  REP(j, H) {
    REP(i, W) {
      cin >> a;
      A[j][i] = a == '#' ? 1 : 0;
    }
  }
  REP(j, H) {
    int c = 0;
    REP(i, W) {
      if (A[j][i] == 0) {
        c++;
      }
    }
    if (c == W) {
      REP(i, W) { A[j][i] = -1; }
    }
  }

  REP(i, W) {
    int c = 0;
    REP(j, H) {
      if (A[j][i] == 0 || A[j][i] == -1) {
        c++;
      }
    }
    if (c == H) {
      REP(j, H) { A[j][i] = -1; }
    }
  }

  REP(j, H) {
    int c = 0;
    REP(i, W) {
      if (A[j][i] == -1) {
        c++;
        continue;
      }
      cout << (A[j][i] == 0 ? '.' : '#');
    }
    if (c != W)
      cout << endl;
  }
}

Measured memory_bytes: 256
/* LETS SEE IF U CAN PULL IT UP THIS TIME OR NOT */
/* WORK HARD MAN ! IT DEFINETELY AIN'T EASY FOR THE PRIZE IT HOLDS .... */
/* GET YOUR ASS TO WORK ALREADY */
#include<bits/stdc++.h>

#define fast ios_base::sync_with_stdio(false); cin.tie(nullptr); cin.tie(nullptr);
#define int long long
#define pb emplace_back
#define range(v) v.begin(),v.end()
#define mod 1000000007
#define inf 1e15
#define pii pair<int,int>
#define ff first
#define ss second
// #define N --

using namespace std;

int32_t main() {
	fast
	int k;
	vector<int> v(3);
	for (int &i : v)
		cin >> i;
	cin >> k;
	int ans = 0, val = 1, i = 0;
	while (k > 0) {
		ans += (val * min(k, v[i]));
		k -= v[i];
		val--, i++;
	}

	cout << ans;

}

Measured memory_bytes: 3648
#include<cstdio>
#include<cstring>
#include<cmath>
#include<bitset>
#include<iostream>
#include<algorithm>
#include<string>
#include<utility>
#include<tuple>
#include<vector>
#include<list>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<numeric>
#include<functional>
#include<iomanip>
#include<random>

#define IOS ios::sync_with_stdio(false),cin.tie(0)
#define REP(i,n) for(int i = 0;i < n;i++)
#define FOR(i,a,b) for(int i = a;i < b;i++)
#define MEM(a,b) memset(a,b,sizeof(a))
#define ALL(x) (x).begin(),(x).end()
#define LMAX 9223372036854775807
#define LMIN -9223372036854775808

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<ull, ull> UP;
typedef tuple<int, int, int> T;

struct UnionFind {
	vector<int> data;
	UnionFind(int size) : data(size, -1){}
	void unionSet(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;
		}
	}
	bool findSet(int x, int y) {
		return root(x) == root(y);
	}
	int root(int x) {
		return data[x] < 0 ? x : data[x] = root(data[x]);
	}
	int size(int x) {
		return -data[root(x)];
	}
};

int gcd(int a, int b) {
	if (a < b)swap(a, b);
	int k = a % b;
	if (k == 1)return 1;
	if (k == 0)return b;
	int ans = gcd(b, k);
	return ans;
}
int digisum(ll a) {
	int sum = 0;
	while (a) {
		sum += a % 10;
		a /= 10;
	}
	return sum;
}


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



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

int main() {
  int A,B,C,K;
  cin >> A >> B >> C >> K;
  int s=0;
  if(A>=B){
    rep(i,K+1){
      B=B*2;
      s++;
      if(A<B){
        break;
      }
    }
  }
  int t=0;
  if(B>=C){
    rep(i,K+1){
      C=C*2;
      t++;
      if(B<C){
        break;
      }
    }
  }
  if(s+t<=K){
    cout << "Yes" <<endl;
  }
  else{
    cout << "No" <<endl;
  }
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<pair<int, int> > vpii;
typedef pair<int, int> pii;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
#define INF 1000000000
#define MOD 1000000007LL
#define EPSILON 0.00001
#define f first
#define s second
#define pb push_back
#define mp make_pair

#define FOR(i, a, b) for (int i=(a); i<=(signed)(b); i++)
#define F0R(i, a) for (int i=0; i<(signed)(a); i++)
#define RFOR(i, a, b) for (int i=(a); i >= b; i--)

#define MN 200005
ll n;
bool chk(ll x){
    //cout << "checking " << x << "\n";
    ll ree = n;
    while(ree % x == 0) ree /= x;
    return ree%x==1;
}

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

    cin >> n;
    if(n == 2){
        cout << "1\n";
        return 0;
    }
    int cnt = 2; //for k=n, n-1
    for(ll i=2; i*i<=n; ++i){
        if(n % i == 0){
            if(chk(i)) ++cnt;
            if(i*i != n && chk(n/i)) ++cnt;
        }
        if((n-1)%i == 0){
            ++cnt;
            if(i*i != (n-1)) ++cnt;
        }
    }
    cout << cnt << "\n";

    return 0;
}


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

int n;
vector<vector<pair<int,int>>> v;
vector<int> a;

bool judge(int bit){
  rep(i,n){
    if(!(bit&(1<<i))) continue;
    rep(j,a[i]){
      if(v[i][j].second){
        if(!(bit&(1<<v[i][j].first))) return false;
      }else{
        if(bit&(1<<v[i][j].first)) return false;
      }
    }
  }
  return true;
}

int main(){
  cin>>n;
  v.resize(n);
  a.resize(n);
  rep(i,n){
    cin>>a[i];
    v[i].resize(a[i]);
    rep(j,a[i]) {
      cin>>v[i][j].first>>v[i][j].second;
      v[i][j].first--;
    }
  }
  
  int ans = 0;
  rep(bit,1<<n){
    int res = 0;
    if(judge(bit)){
      rep(j,n){
        if(bit&1<<j) res++;
      }
    }  
    ans = max(ans,res);
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <cmath>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
constexpr ll INF = 1ll << 55;

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

// multi-dimensional vector (require c++14)
template <typename T, typename U>
static inline vector<U> make_nd_vector(T &&n, U &&val) noexcept {
  static_assert(is_integral<T>::value,
                "[make_nd_vector] 1st argument must be an integer type");
  return vector<U>(forward<T>(n), forward<U>(val));
}
template <typename T, typename... Args>
static inline decltype(auto) make_nd_vector(T &&n, Args &&... args) noexcept {
  static_assert(is_integral<T>::value,
                "[make_nd_vector] 1st argument must be an integer type");
  return vector<decltype(make_nd_vector(forward<Args>(args)...))>(
      forward<T>(n), make_nd_vector(forward<Args>(args)...));
}
//
// Print from Iterator
template <typename ite>
void print_ite(ite start, ite end, char sp = ' ', char en = '\n') {
  for (auto i = start; i != end; i++)
    cout << *i << sp;
  cout << en;
}
//
inline void Yes(bool condition) { cout << (condition ? "Yes\n" : "No\n"); }

int main() {
  int n;
  cin >> n;
  ll acc = 1;
  bool over = false;
  bool zero = false;
  for (int i = 0; i < n; i++) {
    ll a;
    cin >> a;
    if (a == 0)
      zero = true;
    if ((a > (ll)1e9 && acc > (ll)1e9) || (acc > (ll)1e18) || (a > (ll)1e18)) {
      over = true;
    }
    acc *= a;
    if (acc > (ll)1e18)
      over = true;
  }
  if (zero) {
    cout << 0 << endl;
    return 0;
  }
  if (over) {
    cout << -1 << endl;
    return 0;
  }
  cout << acc << endl;
}


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

const int INF = 1001001001;

int main() {
  int n, x, y;
  cin >> n >> x >> y;
  --x; --y;
  vector<int> ans(n);
  rep(sv,n) {
    vector<int> dist(n, INF);
    queue<int> q;
    auto push = [&](int v, int d) {
      if (dist[v] != INF) return;
      dist[v] = d;
      q.push(v);
    };
    push(sv, 0);
    while (!q.empty()) {
      int v = q.front(); q.pop();
      int d = dist[v];
      if (v-1 >= 0) push(v-1, d+1);
      if (v+1 < n) push(v+1, d+1);
      if (v == x) push(y, d+1);
      if (v == y) push(x, d+1);
    }
    rep(i,n) ans[dist[i]]++;
  }
  rep(i,n) ans[i] /= 2;
  for (int i = 1; i <= n-1; ++i) {
    cout << ans[i] << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main( void )
{

	unsigned char Dice1[ 6 ];
	unsigned char Dice2[ 6 ];
	unsigned char trade;
	unsigned char calc;
	unsigned char i;

	for( i = 0; i < 6; i++ ) {
		scanf("%d",&Dice1[i]);
	}
	for( i = 0; i < 6; i++ ) {
		scanf("%d",&Dice2[i]);
	}

	for( i = 1; i <= 6; i++ ){
		calc = i % 2;
		/*????????¢??¨????????¢?????°?????????????????£????????¨????????¢????????????*/
		switch( calc ){
		case 0:/*??¶??°???????????¢*/
			trade = Dice2[ 0 ];
			Dice2[ 0 ] = Dice2[ 2 ];
			Dice2[ 2 ] = Dice2[ 5 ];
			Dice2[ 5 ] = Dice2[ 3 ];
			Dice2[ 3 ] = trade;
			break;
		case 1:/*?\???°???????????¢*/
			trade = Dice2[ 0 ];
			Dice2[ 0 ] = Dice2[ 1 ];
			Dice2[ 1 ] = Dice2[ 5 ];
			Dice2[ 5 ] = Dice2[ 4 ];
			Dice2[ 4 ] = trade;
			break;
		default:
			break;
		}

		/*?????¢??¨?????¢????????´??????????????????????????¨????????´??¢??????????????????????????????*/
		if( ( Dice1[ 0 ] == Dice2[ 0 ] ) && ( Dice1[ 5 ] == Dice2[ 5 ] ) ){
			if( ( Dice1[ 1 ] == Dice2[ 1 ] ) && ( Dice1[ 2 ] == Dice2[ 2 ] ) ){
				if( ( Dice1[ 4 ] == Dice2[ 4 ] ) && ( Dice1[ 3 ] == Dice2[ 3 ] ) ){
					printf("Yes\n");
					return 0;
				}
			}else if( ( Dice1[ 1 ] == Dice2[ 2 ] ) && ( Dice1[ 2 ] == Dice2[ 4 ] ) ){
				if( ( Dice1[ 4 ] == Dice2[ 3 ] ) && ( Dice1[ 3 ] == Dice2[ 1 ] ) ){
					printf("Yes\n");
					return 0;
				}
			}else if( ( Dice1[ 1 ] == Dice2[ 4 ] ) && ( Dice1[ 2 ] == Dice2[ 3 ] ) ){
				if( ( Dice1[ 4 ] == Dice2[ 1 ] ) && ( Dice1[ 3 ] == Dice2[ 2 ] ) ){
					printf("Yes\n");
					return 0;
				}
			}else if( ( Dice1[ 1 ] == Dice2[ 3 ] ) && ( Dice1[ 2 ] == Dice2[ 1 ] ) ){
				if( ( Dice1[ 4 ] == Dice2[ 2 ] ) && ( Dice1[ 3 ] == Dice2[ 4 ] ) ){
					printf("Yes\n");
					return 0;
				}
			}
		}
	}
	printf("No\n");

	return 0;
}

Measured memory_bytes: 580
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, x, n) for (int i = x; i < (n); i++)
#define all(n) begin(n), end(n)
struct cww
{
    cww()
    {
        ios::sync_with_stdio(false);
        cin.tie(0);
    }
} star;
const long long INF = numeric_limits<long long>::max();
typedef long long ll;
typedef vector<int> vint;
typedef vector<char> vchar;
typedef vector<vector<int>> vvint;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef unsigned long long ull;
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 <typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }

template <typename T, typename... Ts>
auto make_v(size_t a, Ts... ts)
{
    return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template <typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T &t, const V &v) { t = v; }

template <typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T &t, const V &v)
{
    for (auto &e : t)
        fill_v(e, v);
}
int main()
{
    int N, K;
    cin >> N >> K;
    vvint graph = make_v<int>(N, N);
    vint deg(N, N - 1);
    fill_v(graph, 1);
    if (K > ((N - 1) * (N - 2) / 2))
    {
        cout << -1;
        return 0;
    }
    int a = 0;
    while (a < K)
    {
        for (int c = 2 * N - 3; c >= 1; c--)
        {
            for (int i = min(c, N - 1); i >= 0; i--)
            {
                int j = c - i;
                if (j > N - 1 or i == j or graph[i][j] == 0 or deg[i] == 1 or deg[j] == 1)
                    continue;
                graph[i][j] = 0;
                deg[i]--;
                graph[j][i] = 0;
                deg[j]--;
                a++;
                if (a >= K)
                    goto L;
            }
        }
    }
L:;
    int M = 0;

    for (int i = 0; i < N; i++)
    {
        for (int j = i + 1; j < N; j++)
        {
            if (graph[i][j] == 1)
                M++;
        }
    }
    cout << M << endl;
    for (int i = 0; i < N; i++)
    {
        for (int j = i + 1; j < N; j++)
        {
            if (graph[i][j] == 1)
                cout << i + 1 << " " << j + 1 << "\n";
        }
    }
    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#include <unordered_map>
#include <unordered_set>
#include <math.h>
using namespace std;

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
typedef long long ll;
//No change above here

const ll maxi = 2 * 1e5 + 5;
ll mod = 5;
double pi = 3.141592653589793238;

//function for power
ll power(ll x, ll n) {
	ll res = 1;
	x %= mod;
	while (n) {
		if (n & 1)
			res = (res * x) % mod;
		x = (x * x) % mod;
		n >>= 1;
	}
	return res;
}

ll sum_digits(ll n)
{
	ll ret = 0;
	while (n)
	{
		ret += n % 10;
		n /= 10;
	}
	return ret;
}

ll gcd(ll a, ll b)
{
	if (a == 0)
		return b;
	else
		return gcd(b % a, a);
}

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

ll max_subarray(vector<int>& v)
{
	if (v.empty())
		return 0;
	ll glob = v[0], loc = v[0];
	for (int i = 1; i < v.size(); ++i)
	{
		loc = max(v[i] + 0LL, loc + v[i]);
		glob = max(loc, glob);
	}
	return glob;
}

long long num_digits(long long x)
{
	long long ans = 0;
	while (x)
	{
		++ans;
		x /= 10;
	}
	return ans == 0 ? 1 : ans;
}

vector<int> topological_sort(vector<vector<int>>& graph, int n, vector<int>& indegree)
{
	vector<int> ans;
	stack<int> s;
	for (int i = 0; i < n; ++i)
		if (indegree[i] == 0)
			s.push(i);
	while (!s.empty())
	{
		int x = s.top();
		s.pop();
		ans.push_back(x);
		for (auto& adj : graph[x])
			if (--indegree[adj] == 0)
				s.push(adj);
	}
	return ans;
}

ll dir[4][2] = { {1, 0}, {-1, 0}, {0, 1}, {0, -1} };

ll p, q;
bool valid(ll i, ll j) { return i >= 1 && i <= p && j >= 1 && j <= q; }


//declare needed things here

//cabacc
//abc
int main()
{
	IOS;
	ll ans=INT_MAX;
	string s1, s2;
	cin >> s1 >> s2;
	for (int i = 0; i <= s1.length()-s2.length(); ++i)
	{
		ll sum = 0;
		for (int j = 0; j < s2.length(); ++j)
			if (s1[i+j] != s2[j])
				++sum;
		ans = min(ans, sum);
	}
	cout << ans << endl;
	return 0;
}


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

using ll = long long;
using ull = unsigned long long;
using ld = long double;
#define REP(NAME, NUM) for (int NAME = 0; NAME < (NUM); ++NAME)
#define BREP(NAME, NUM) for (int NAME = (NUM)-1; NAME >= 0; --NAME)
#define VEC(TYPE, A, NAME, INIT) vector<TYPE> NAME(A, INIT)
#define VEC2(TYPE, A, B, NAME, INIT) vector<vector<TYPE>> NAME(A, vector<TYPE>(B, (INIT)))

int main()
{
    //-----------------
    int n;
    cin >> n;
    map<int, ull,greater<int>> m;
    REP(i, n) {
        ull a;
        cin >> a;
        ++m[a];
    }
    int ans = 0;
    for( auto& mm : m )
    {
        if( mm.second <= 0 )
            continue;
        int beki = 0;
        int aa = mm.first;
        while (aa > 0)
        {
            ++beki;
            aa >>= 1;
        }
        auto seek = (1 << beki) - mm.first;
        if( seek == mm.first )
        {
            ans += mm.second / 2;
            continue;
        }
        auto& mmm = m[seek];
        if ( mmm > 0 )
        {
            int num = min(mm.second, mmm);
            ans += num;
            mmm -= num;
        }
    }
    cout << ans << endl;
    //----------------
return 0;
}

Measured memory_bytes: 25216
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair< ll, ll > Pi;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep2(i,n) for(int i=1;i<=(n);i++)
#define rep3(i,i0,n) for(int i=i0;i<(n);i++)
#define pb push_back
#define mod 1000000007
const ll INF = 1LL << 60;
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; }
ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}
#define all(x) x.begin(), x.end()
#define mp make_pair
bool compare(Pi a, Pi b) {
    if(a.first != b.first){
        return a.first < b.first;
        
    }else{
        return a.second < b.second;
    }
}


bool In_map(ll y,ll x,ll h,ll w){
    if(y<0 || x<0 || y>=h || x>=w){
        return 0;
    }else{
        return 1;
    }
}
const vector<ll> dx{1,0,-1,0};
const vector<ll> dy{0,1,0,-1};


int main() {
    ll A,B,C,D,E,F;
    cin >>A>>B>>C>>D>>E>>F;
    A*=100;
    B*=100;
    ll ans1=A;
    ll ans2=0;
    ll now=0;
    rep(i,31){
        if(A*i>F) break;
        rep(j,31){
            ll w=A*i+B*j;
            if(w>F)break;
            rep(k,3001){
                if(w+k*C>F)break;
                if(k*C>E*w/100) break;
                rep(m,3001){
                    ll s=k*C+m*D;
                    if(w+s>F)break;
                    if(s>E*w/100) break;
                    if((ans1+ans2)*s>ans2*(w+s)){
                        ans1=w;
                        ans2=s;
                    }
                }
            }
        }
    }
    
    cout << ans1+ans2<<" "<<ans2 << endl;


    return 0;
    

}

Measured memory_bytes: 3632
# N個の石, 石の状態は長さNの文字列Sで表される, '.'なら白, '#'なら黒
# 黒い石のすぐ右に白い石があるような箇所がないようにした

"方針：ある場所を起点にそこから右の白を黒に(その点も含む)、そこより左を黒を全て白に"
N = int(input())
S = str(input())

black = [0]
white = [0]

for i in range(N):
    if S[i] == '#':  # 黒なら
        black.append(black[-1] + 1)
        white.append(white[-1])
    else:
        black.append(black[-1])
        white.append(white[-1]+1)

ans = N
for i in range(N+1):
    ans = min(ans, black[i] + (white[-1]-white[i]))

print(ans)

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

int main() {
    int n; cin >> n;
    string s; cin >> s;
    int ans = 0;
    for (int i = 0; i < n - 2; i++) {
        if (s[i]=='A'&&s[i+1]=='B'&&s[i+2]=='C') ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
m=[0,0,0,0,0,0,0,0,0]
a=[]
for i in range(3):
  a+=list(map(int,input().split()))

n=int(input())
for i in range(n):
  b=int(input())
  for j in range(9):
    if b==a[j]:
      m[j]=1
      break

ans=0
for i in range(3):
  if m[i]==1 and m[i+3]==1 and m[i+6]==1:
    ans=1
    break
  if m[i*3]==1 and m[i*3+1]==1 and m[i*3+2]==1:
    ans=1
    break
    
if m[0]==1 and m[4]==1 and m[8]==1:
  ans=1
if m[2]==1 and m[4]==1 and m[6]==1:
  ans=1
  
if ans:
  print("Yes")
else:
  print("No")

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

void solve()
{
    long long int n;
    cin >> n;
    long long int a[n];
    map<long long int, long long int> m;
    long long int sum = 0;
    for (long long int i = 0; i < n; i++)
    {
        cin >> a[i];
        m[a[i]]++;
        sum += a[i];
    }
    long long int q, c, d;
    cin >> q;
    long long int count = 0;
    for (int i = 0; i < q; i++)
    {
        cin >> c >> d;
        count = m[c];
        m[c] = 0;
        m[d] += count;
        sum = sum + (d - c) * count;
        cout << sum << endl;
    }
}

int main()
{
    int t = 1;
    //cin >> t;
    while (t--)
    {
        solve();
    }
    return 0;
}

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

int main(){
    int n;
    int ja,ma,en;
    while(1){
        cin >> n;
        if(n == 0) break;
        for(int i=0;i<n;i++){
            cin >> ma >> en >> ja;
            if(ma == 100 || en == 100 || ja == 100){
                cout << "A" << endl;
            }
            else if((ma + en) / 2 >= 90){
                cout << "A" << endl;
            }
            else if((ma + en + ja) / 3 >= 80){
                cout << "A" << endl;
            }
            else if((ma + en + ja) / 3 >= 70){
                cout << "B" << endl;
            }
            else if((ma + en + ja) / 3 >= 50 && (ma >= 80 || en >= 80)){
                cout << "B" << endl;
            }
            else {
                cout << "C" << endl;
            }
        }
    }
}

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

using namespace std;

#define all(v)				((v).begin()), ((v).end())
#define allr(v)				((v).rbegin()), ((v).rend())
#define sz(v)				((int)((v).size()))
#define rep(i, v)		for(int i=0;i<sz(v);++i)
#define lp(i, n)		for(int i=0;i<(int)(n);++i)
#define lpi(i, j, n)	for(int i=(j);i<(int)(n);++i)
#define lpd(i, j, n)	for(int i=(j);i>=(int)(n);--i)
#define ll long long
#define pb					push_back
#define fIO ios_base::sync_with_stdio(0);cin.tie(0);

const ll inf = 1e8;
const double pi = 3.1415926535897;


const double EPS = (1e-7);
int dcmp(double x, double y) {	return fabs(x-y) <= EPS ? 0 : x < y ? -1 : 1;	}


typedef vector<int>                vi;
typedef vector<pair<int,int>>      vii;
typedef vector<ll>                 vll;
typedef vector<double>             vd;
typedef vector< vi >               vvi;
typedef vector< vd >               vvd;
typedef vector<string>             vs;

/**
    * PLEASEEE READDD PROBLEEEM CARFULLY ****
    * Always check for OVERFLOW ll vs int
    * Always check for array bounds
    * Check for function return
    * READ OUTPUT SECTION AGAIN!!!
**/

const int N = 1e5 + 5;
int a[N], b[N], c[N], dp[N][4];
int n;

int sol(int idx, int prev) {
    if(idx == n) return 0;

    int & ret = dp[idx][prev];
    if(ret != -1) return ret;

    for(int i = 1; i <= 3; i++) {
        int curr = (i == 1 ? a[idx] : i == 2 ? b[idx] : c[idx]);
        if(i != prev) ret = max(ret, sol(idx + 1, i) + curr);
    }
    return ret;
}

int main(){
    fIO

    memset(dp, -1, sizeof(dp));

    cin >> n;
    for(int i = 0; i < n; i++) cin >> a[i] >> b[i] >> c[i];

    cout << sol(0, 0);
}







Measured memory_bytes: 10752