akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
int main(){
  int i,j,N,v,A[1000],k;
  
  scanf("%d",&N);
  
  for(i=0;i<=N-1;i++){
    scanf("%d",&A[i]);
  }
  
  for(i=0;i<=N-1;i++){
    v=A[i];
    j=i-1;
    while(j>=0 && A[j]>v){ //ソート済みの中でvより大きい要素を後ろに1つ移動させる。
      A[j+1]=A[j];
      j--;
    }
    A[j+1]=v;
    for(k=0;k<N-1;k++){
      printf("%d ",A[k]);
    }
    printf("%d\n",A[N-1]);
  }
  return 0;
}

Measured memory_bytes: 600
# https://atcoder.jp/contests/abc114/tasks/abc114_c
# C - 755
import itertools

n = int(input().split()[0])
k = len(str(n))
c = 0

if k >= 3:
    for j in range(3, k+1):
        p_gen = itertools.product([3, 5, 7], repeat=j)
        for p in p_gen:
            x = 0
            for k_i in range(j):
                x += p[k_i] * 10**k_i
            if x <= n and len(set(list(str(x)))) == 3:
                c += 1

print(c)

Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <map>
#include <string>

#define reps(i,s,n) for(int (i) = (s); (i) < (n); (i)++)
#define rep(i,n) reps(i,0,n)
using namespace std;
using ll = long long;

int main(){
    string s;
    cin >> s;
    int len = s.length()-7;

    rep(i,7){
        if( s.substr(0,i) + s.substr(i+len,7-i) == "keyence"){
            cout << "YES"<< endl;
            return 0;
        }
    }
    cout << "NO" << endl;

    return 0;
}

Measured memory_bytes: 3620
fun main(args: Array<String>) {
  val (n, k) = readLine()!!.split(" ").map { it.toInt() }
  val vs = readLine()!!.split(" ").map { it.toInt() }
  var max = 0
  for (s in 0..n) {
    for (t in s..n) {
      val ws = mutableListOf<Int>()
      for (i in 0 until s) {
        ws.add(vs[i])
      }
      for (i in t until n) {
        ws.add(vs[i])
      }
      if (ws.size > k) continue
      ws.sort()
      for (i in 0 until Math.min(ws.size, k - ws.size)) {
        if (ws[i] < 0) {
          ws[i] = 0
        }
      }
      max = Math.max(max, ws.sum())
    }
  }
  println(max)
}

Measured memory_bytes: 39544
import std.stdio;
 
long[1001][10] dp;

void init_dp(int comb, int limit) {  
  dp[0][0] = 1;
  for(long i = 0; i <= 100; i++)
    for(long j = limit; j >= 0; j--)
      for(long k = comb; k >= 1; k--)
        if (j - i >= 0) {
          dp[k][j] += dp[k - 1][j - i];
        }
}
 
void main() {
  init_dp(9, 1000);
  while(true) {
    int n, m;
    readf("%d %d\n", &n, &m);
    if ((n + m) == 0) break;
    dp[n][m].writeln;
  }
}

Measured memory_bytes: 1148
#include <stdio.h>

int main(){
  int i,x,y,z;
  
  i = 1;
  while(1){
    scanf("%d %d",&x,&y);
    if(x==0 && y == 0){
      break;
    }
    if(x > y){
      z = x;
      x = y;
      y = z;
    }
    printf("%d %d\n",x,y);
    i++;
  }

  return 0;
}

Measured memory_bytes: 600
from collections import deque
import sys
input = sys.stdin.readline


n, m, l = map(int, input().split())
info = [list(map(int, input().split())) for i in range(m)]
graph = [[] for i in range(n)]
 
for i in range(m):
    a, b, cost = info[i]
    if cost > l:
        continue
    a -= 1
    b -= 1
    graph[a].append((b, cost))
    graph[b].append((a, cost))


def warshall_floid(graph):
    n = len(graph)
    INF = 10**18
    dp = [[INF]*n for i in range(n)]
    for i in range(n):
        dp[i][i] = 0

    for i in range(n):
        for j, cost in graph[i]:
            dp[i][j] = cost
            dp[j][i] = cost

    for k in range(n):
        for i in range(n):
            for j in range(n):
                dp[i][j] = min(dp[i][j], dp[i][k] + dp[k][j])

    return dp

def warshall_floid2(matrix):
    n = len(matrix)
    dp = matrix
    for k in range(n):
        for i in range(n):
            for j in range(n):
                dp[i][j] = min(dp[i][j], dp[i][k] + dp[k][j])
    return dp

dp1 = warshall_floid(graph)
INF = 10**18
dp2 = [[INF]*n for i in range(n)]
for i in range(n):
    for j in range(n):
        if dp1[i][j] <= l:
            dp2[i][j] = 1
ans = warshall_floid2(dp2)         

q = int(input())
query = [list(map(int, input().split())) for i in range(q)]
for i in range(q):
    a, b = query[i]
    a -= 1
    b -= 1
    if ans[a][b] == 10**18:
        print(-1)
    else:
        print(ans[a][b] - 1)

Measured memory_bytes: 74332
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
typedef long long ll;
struct fun{
    int a;
    int b;
    int c;
}ff[30];
bool cmp(const fun &x,const fun &y){
    return x.a<y.a;
}
int f[30];
void qian(int x){
    if(x!=-1)
        printf(" %d",ff[x].a);
    else
        return ;
    qian(ff[x].b);
    qian(ff[x].c);
}
void zhong(int x){
    if(x!=-1)
        zhong(ff[x].b);
    else
        return ;
    printf(" %d",ff[x].a);
    zhong(ff[x].c);
}
void hou(int x){
    if(x!=-1)
        hou(ff[x].b);
    else
        return ;
    if(x!=-1)
        hou(ff[x].c);
    else
        return ;
    printf(" %d",ff[x].a);
}
int main(){
    int n;
    int q;
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        scanf("%d%d%d",&ff[i].a,&ff[i].b,&ff[i].c);
        if(ff[i].b==-1&&ff[i].c==-1){
            f[ff[i].a]=1;
            continue;
        }
        if(ff[i].b>=0)
            f[ff[i].b]=1;
        if(ff[i].c>=0)
            f[ff[i].c]=1;
    }
    sort(ff,ff+n,cmp);
    if(n==1){
        printf("Preorder\n 0\n");
        printf("Inorder\n 0\n");
        printf("Postorder\n 0\n");
        return 0;
    }
    for(int i=0;i<n;i++)
        if(!f[i]){
            q=i;
            break;
        }
    printf("Preorder\n");
    qian(q);
    printf("\n");
    printf("Inorder\n");
    zhong(q);
    printf("\n");
    printf("Postorder\n");
    hou(q);
    printf("\n");
    return 0;
}



Measured memory_bytes: 3228
#### import ####
import sys
import math
from collections import defaultdict

#### 設定 ####
sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

#### 定数 ####
mod = 10**9 + 7

#### 読み込み ####
def I(): return int(input())
def II(): return map(int, input().split())
def III(): return list(map(int, input().split()))
def Line(N):
    read_all = [tuple(map(int, input().split())) for _ in range(N)]
    return map(list,zip(*read_all))

#################

N = I()
x,y,h = Line(N)

for i in range(N):
    if h[i]!=0:
        x0,y0,h0 = x[i],y[i],h[i]
        break

for cx in range(101):
    for cy in range(101):
        H = abs(x0-cx)+abs(y0-cy)+h0
        flag = True
        for i in range(N):
            if max(H-abs(x[i]-cx)-abs(y[i]-cy),0)!=h[i]:
                flag = False
                break
        if flag:
            break
    else:
        continue
    break

print(cx,cy,H)

Measured memory_bytes: 42480
# B - Five Dishes
# sys.stdin.readline()
import sys
import math
input = sys.stdin.readline
each_time = [int(input()) for i in range(5)]
wait_time = [10*math.ceil(i/10)-i for i in each_time]
result = [i + k for i,k in zip(each_time, wait_time)]
result[wait_time.index(max(wait_time))] = each_time[wait_time.index(max(wait_time))]
print(sum(result))

Measured memory_bytes: 3064
#include <stdio.h>
#include <unistd.h>
#include <math.h>
#include <stdlib.h>
#include <string.h>
/* void swap(int* a, int* b) { */
/*   int tmp; */
/*   tmp = *a; */
/*   *a = b; */
/*   *b = tmp; */
/* } */
int compare_int(const void *a, const void *b)
{
    return *(long long int*)a - *(long long int*)b;
}
int f(int n){
  switch(n%2) {
  case 0:
    return n/2;
    break;
  case 1:
    return 3*n+1;
    break;
  }
  
}
int main(){
  //long long int N, M,i,j,Q,k, A, B, T;
  long long int x[20] ={0};
  long long int v[20] ={0};
  long long int ans[20] ={0};
  long long int s = 0;
  //int flag = 0;
  //long long int K, S, cnt=0, cnt2=0;
  char str[120] = {0};
  long long int len[120];
  int lenstr;
  int L[1000000];
  long long int c[200000];
  long long int t[100000];
  int i, j;
  char S[300000] = {0};
  int SS[300000] = {0};
  //long long int A[100000];
  long long int cnt = 0;
  int max, min, min_cost=9999;
  scanf("%d", &s);

  long long a_i_1 = s;
  L[0] = s;
  for (i = 1; i < 1000000; i++) {
    /* long long int a_i = f() */
    L[i] = f(L[i-1]);
  }
  /* for (i = 0; i < 3; i++) { */
  /*   scanf("%d", &x[i]); */
  /* } */

  int kdkssd = 0;
  /* qsort(x, 3, sizeof(long long int), compare_int); */
  for (i = 0; i < 1000000; i++) {
    for (j = 0; j < 1000000; j++) {
      if (L[i] == L[j] && i != j) {
        printf("%d\n", j+1);
        return 0;
      }
    }
  }

  /* for (i = 0; i < 1000000;i++) { */
  /*   if (L[i] == 4) { */
  /*     kdkssd += 1; */
  /*   } */
  /*   if (kdkssd == 2) { */
  /*     printf("%d/n", i+1); */
  /*     return 0; */
  /*   } */
  /* } */
  /* double a = (float)x[0]; */
  /* double b = (float)x[1]; */
  /* printf("%d\n", x[0]*x[1]/2); */
  /* //printf("%d\n", cnt); */
  return 0;
}


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

using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<ll> vll;
// #define int long long
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000               // 2e9
#define LLINF 2000000000000000000ll  // 2e18 (llmax:9e18)
#define fi first
#define sec second
#define all(x) (x).begin(), (x).end()
#define sq(x) ((x) * (x))
#define dmp(x) cerr << #x << ": " << x << endl;

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

template <class T>
using MaxHeap = priority_queue<T>;
template <class T>
using MinHeap = priority_queue<T, vector<T>, greater<T>>;
template <class T>
vector<T> vect(int len, T elem) {
  return vector<T>(len, elem);
}

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << p.fi << ',' << p.sec;
  return os;
}
template <class T, class U>
istream &operator>>(istream &is, pair<T, U> &p) {
  is >> p.fi >> p.sec;
  return is;
}
template <class T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
  for (int i = 0; i < vec.size(); i++) {
    os << vec[i];
    if (i + 1 < vec.size()) os << ' ';
  }
  return os;
}
template <class T>
istream &operator>>(istream &is, vector<T> &vec) {
  for (int i = 0; i < vec.size(); i++) is >> vec[i];
  return is;
}
void fastio() {
  cin.tie(0);
  ios::sync_with_stdio(0);
  cout << fixed << setprecision(20);
}

#define endl "\n"

void solve() {
  ll N, K;
  cin >> N >> K;
  N %= K;
  cout << min(N, K - N) << endl;
  return;
}

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


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

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

  int a = 0;
  int ans = 0;
  for (int i = 1; i <= N; i++) {
    cin >> a;
    if (a * i % 2 == 1) ans++;
  }
  cout << ans << endl;
  return 0;
}

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

int N;
int A[210];

int main() {
	cin >> N;
	for (int i = 0; i < N; i++)cin >> A[i];

	int counter = 0;
	while (true) {
		bool flag = true;
		for (int i = 0; i < N; i++) {
			if (A[i] % 2 != 0)flag = false;
		}
		if (flag) {
			for (int i = 0; i < N; i++) A[i] = A[i] / 2;
			counter++;
		}
		else
			break;
	}
	cout << counter << endl;
}

Measured memory_bytes: 764
#include<bits/stdc++.h>
#include <iomanip>
#include <iostream>
using namespace std;
using ll = unsigned long long;
const long long INF = 1LL << 60;
 
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;
}
 
ll min(ll a, ll b){
    if(a < b) return a;
    else return b;
}
 
int main(void){
    int N, D; cin >> N >> D;
    int ans = N / (2 * D + 1);
    if(N % (2 * D + 1) != 0) ans++;
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define rep(i,a,b) for(ll i=a;i<=b;i++)
#define repn(i,n) for(ll i=0;i<n;i++)
#define all(v) v.begin(),v.end()
#define bac(i,a,b) for(ll i=a;i>=b;i--)
#define sz(v) (ll)v.size()
using namespace std;

ll MOD=1e9+7;
ll g,h,l;
const ll N=100005;

ll add(ll a,ll b); ll mul(ll a,ll b); ll binpo(ll a,ll b);

int main(){
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    ll n,k;
    cin>>n>>k;
    n = n - n/k*k;
    cout<<min(n,abs(n-k));
}

ll add(ll a,ll b)
{
    return (a%MOD+b%MOD)%MOD ;
}
ll mul(ll a,ll b)
{
    return (a* 1ll *b)%MOD ;
}
ll binpo(ll a,ll b)
{
    int ans = 1 ;
    while(b)
    {
        if( b % 2 != 0)
        {
            ans = mul(ans,a);
        }
        a = mul(a,a);
        b = b/2;
    }
    return ans;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef  long long int ll;
#define len(x)           x.length()
#define pb                push_back
#define mp                make_pair
#define all(x)            (x).begin(),(x).end()
#define M                 1000000007
#define MM                998244353
#define ff                first
#define ss                second
#define pii               pair<int,int>
#define mii               map<int,int>
#define psi               pair<string,int>
#define pis               pair<int,string>
#define GCD(x,y)          (__gcd((x), (y)))
#define LCM(x,y)          (((x)/__gcd((x), (y)))*(y))
#define mem0(x)           memset(x, 0, sizeof (x))
#define mem1(x)           memset(x, -1, sizeof (x))
#define IOS ios::sync_with_stdio(0);cin.tie(0); cout.tie(0);

//coded by Avijit Mandal 

int main(){
   IOS;
   ll i,j,k,t1,t2,n,m;
   cin>>n>>m;
   ll dp[n+1][m+1];char grid[n][m];
   for(i=0;i<n;i++){
      for(j=0;j<m;j++)cin>>grid[i][j];
   }
   for(i=0;i<=n;i++){
      for(j=0;j<=m;j++){
         if(i==0||j==0)dp[i][j]=0;
         else if(i==1  && j==1)dp[i][j]=1;
         else if(grid[i-1][j-1]=='#')dp[i][j]=-1;
         else{
            t1=t2=0;
            if(dp[i-1][j]!=-1)t1=dp[i-1][j];
            if(dp[i][j-1]!=-1)t2=dp[i][j-1];
            dp[i][j]=(t1%M+t2%M)%M;
         }
      }
   }
   cout<<dp[n][m]<<"\n";


}


Measured memory_bytes: 9088
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
#define REP(i,num,n) for(ll i=num, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((ll)(x).size())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define MEMSET(v, h) memset((v), h, sizeof(v))
#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
typedef long long ll;
ll INF = 1e18;
using namespace std;

std::vector<ll> divisor(ll n)//nの約数を列挙
{
  std::vector<ll> ret;
  for(ll i=1 ; i*i<=n ; ++i)
  {
    if(n%i == 0)
    {
      ret.push_back(i);
      if(i!=1 && i*i!=n)
      {
        ret.push_back(n/i);
      }
    }
  }
  return ret;
}

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

  auto ret = divisor(N);
  ll ans = 0;

  for(auto s: ret){
    if(s==1)continue;
    if(N%(s-1) != (ll)N/(s-1))continue;
    ans += s-1;
  }
  
  if(N!=1 and (N%(N-1) == (ll)N/(N-1))) ans += N-1;
  if(N==1)ans = 0;
  
  cout << ans << endl;



  return 0;
}


Measured memory_bytes: 384
#include <iostream>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef long double ld;
#define mod 1000000007
#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)
#define setA0(a) for(ull i =0;i<n;i++){a[i] = 0;}
#define aout(a) for(auto x : a){cout<<x<<' ';} 
#define ain(a) for(ull i =0;i<n;i++){cin>>a[i];}
#define NofSetBits(x) __builtin_popcount(x);
#define InpGrph(g,e) while(e--){ll x;ll y;cin>>x>>y ;g[x].pub(y);g[y].pub(x);}
#define FastIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);








int main(){
  FastIO;
  ll n;
  cin>>n;
  bool y=0;
  ll mat[n][2];
  for(ll i=0;i<n;i++){
  	cin>>mat[i][0]>>mat[i][1];
  	if(i>=2){
  		if(mat[i][0]==mat[i][1]&&mat[i-1][0]==mat[i-1][1]&&mat[i-2][0]==mat[i-2][1]){
  			y=1;
  		}
  	}
  }
  cout<<((y)?"Yes\n":"No\n");
  return 0;
}


Measured memory_bytes: 3608
#include <stdio.h>

int main() {
  int N, i, in1, in2, in3, a, b, c;

  scanf("%d", &N);

  for(i = 0; i < N; ++i) {

    scanf("%d %d %d", &in1, &in2, &in3);

    if(in1 >= in2 && in1 >= in3) {
      a = in2;
      b = in3;
      c = in1;
    } else if(in2 >= in1 && in2 >= in3) {
      a = in1;
      b = in3;
      c = in2;
    } else if(in3 >= in1 && in3 >= in2) {
      a = in1;
      b = in2;
      c = in3;
    }

    if(a*a + b*b == c*c) {
      printf("YES\n");
    } else {
      printf("NO\n");
    }
  }
  return 0;
}

Measured memory_bytes: 580
#!/usr/bin python3
# -*- coding: utf-8 -*-

import sys
input = sys.stdin.readline

def main():
    X, Y, A, B, C = map(int, input().split())
    P = list(map(int, input().split()))
    Q = list(map(int, input().split()))
    R = list(map(int, input().split()))
    P.sort(reverse = True)
    Q.sort(reverse = True)
    R.extend(P[:X])
    R.extend(Q[:Y])
    R.sort(reverse = True)

    print(sum(R[:X+Y]))

if __name__ == '__main__':
    main()

Measured memory_bytes: 23216
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <queue>
#include <stack>
#include <bitset>
#include <set>
#include <chrono>
#include <string>
#include <assert.h>

using namespace std;

#define endl '\n'

const int maxn = 2000001;
const int mod = 998244353;

int fak[maxn];
int inv[maxn];

int modpow(int a, int n)
{
    int b = 1;

    while (n)
    {
        if (n & 1)
        {
            b = 1LL * a * b % mod;
        }

        n >>= 1;
        a = 1LL * a * a % mod;
    }

    return b;
}

int inverse(int a)
{
    return modpow(a, mod - 2);
}

int pre()
{
    fak[0] = inv[0] = 1;

    for (int i = 1; i < maxn; ++i)
    {
        fak[i] = 1LL * i * fak[i - 1] % mod;
        inv[i] = inverse(fak[i]);
    }
}

int comb(int n, int k)
{
    if (k > n || k < 0)
        return 0;
    return 1LL * fak[n] * inv[k] % mod * inv[n - k] % mod;
}

void add(int &a, int b)
{
    a += b;
    if (a >= mod)
        a -= mod;
}

void sub(int &a, int b)
{
    a -= b;
    if (a < 0)
        a += mod;
}

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

    pre();

    int n, m;
    cin >> n >> m;

    int to_rem = 0;

    for (int i = 0; i < m; ++i)
    {
        add(to_rem, comb(n - 2 + i, n - 2));
    }

    to_rem = 1LL * to_rem * n % mod;

    int ans = 0;

    for (int i = 0; i <= min(n, m); ++i)
    {
        if ((3 * m - i) % 2)
            continue;

        int t = (3 * m - i) / 2;

        int cur = comb(n - 1 + t, t);
        cur = 1LL * cur * comb(n, i) % mod;
        add(ans, cur);
    }

    sub(ans, to_rem);

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 15872
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scn=new Scanner(System.in);
		int lenHour=scn.nextInt(),
			lenMin=scn.nextInt();
		double hour=scn.nextDouble()/6*Math.PI,
			   min=scn.nextDouble()/30*Math.PI;
		
		hour+=min/12;
		
		System.out.println(Math.sqrt(lenHour*lenHour+lenMin*lenMin-2*lenMin*lenHour*Math.cos(min-hour)));
	}

}


Measured memory_bytes: 37476
#include <iostream>
#include <algorithm>
#include <cfenv>
#include <cmath>
using namespace std;
typedef long long ll;
int main(void){
    ll n,a,b,c,d,e,mn;
    cin >> n >> a >> b >> c >> d >> e;
    mn = min(a,min(b,min(c,min(d,e))));
    if(n % mn == 0) mn = n/mn;
    else mn = n/mn+1;
    mn += 4;
    cout << mn << endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#define NMAX 10
#define FMAX 3628800
#define min(a, b) ((a) < (b) ? (a) : (b))

int hash(int *a, int asize);
void rev_sort(int l, int r, int *a, int asize);
void bfs(int *a, int asize, char *memo, int depth);
int main (void)
{
  int i, n, fact = 1, res = 9, a[NMAX], b[NMAX];
  char memo1[FMAX], memo2[FMAX];
  scanf("%d", &n);
  for (i = 0; i < n; i++) {
    scanf("%d", &a[i]);
    fact *= i + 1;
    b[i] = i + 1;
  }
  for (i = 0; i < fact; i++) memo1[i] = memo2[i] = 20;
  memo1[hash(a, n)] = memo2[hash(b, n)] = 0;
  bfs(a, n, memo1, 0);
  bfs(b, n, memo2, 0);
  for (i = 0; i < fact; i++) res = min(res, memo1[i] + memo2[i]);
  printf("%d\n", res);
}

int hash(int *a, int asize)
{
  int i, j, res = 0, fact = 1;
  for (i = 0; i < asize; i++) {
    int grade = 0;
    for (j = i + 1; j < asize; j++) if (a[i] < a[j]) grade++;
    res += grade * fact;
    fact *= asize - i;
  }
  return res;
}

void rev_sort(int l, int r, int *a, int asize)
{
  int i;
  for (i = 0; i < asize; i++) {
    int temp;
    if (l + i >= r - i) break;
    temp = a[l+i];
    a[l+i] = a[r-i];
    a[r-i] = temp;
  }
}

void bfs(int *a, int asize, char *memo, int depth)
{
  int i, j;
  if (depth >= 4) return;
  for (i = 0; i < asize; i++) {
    for (j = i + 1; j < asize; j++) {
      int h;
      rev_sort(i, j, a, asize);
      h = hash(a, asize);
      if (memo[h] > depth + 1) {
        memo[h] = depth + 1;
        bfs(a, asize, memo, depth + 1);
      }
      rev_sort(i, j, a, asize);
    }
  }
}


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



typedef unsigned long ul;
typedef unsigned long long ull;
typedef long long ll;
typedef vector<ll> vint;
typedef vector< vector<ll> > vvint;
typedef vector< vector< vector<ll> > > vvvint;
typedef vector<string> vstring;
typedef vector< vector<string> > vvstring;
typedef vector<char> vchar;
typedef vector< vector<char> > vvchar;
typedef vector<long double> vdouble;
typedef vector< vector<long double> > vvdouble;
typedef vector< vector< vector<long double> > > vvvdouble;
typedef pair<ll,ll> pint;
typedef vector<pint> vpint;
typedef vector<bool> vbool;

#define rep(i,n) for(ll i=0;i<n;i++)
#define repf(i,f,n) for(ll i=f;i<n;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define ALL(obj) (obj).begin(), (obj).end()
// #define LLONG_MAX 9223372036854775806
#define vmax(vec) *max_element(vec.begin(), vec.end())
#define vmin(vec) *min_element(vec.begin(), vec.end())
#define vsort(vec) sort(vec.begin(), vec.end())
#define vsortgr(vec) sort(vec.begin(), vec.end(), greater<ll>())
#define MOD 1000000007
// #define MOD 998244353
// #define MOD LLONG_MAX
const double PI=3.14159265358979323846;

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 dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0,};




void printv(vint &v){
  for(auto e:v) cout<<e<<" ";
  cout<<endl;
}


int main() {


  cout<<fixed<<setprecision(10);

  string s,t; cin>>s>>t;
  ll a,b; cin>>a>>b;

  string u; cin>>u;

  if(s == u){
    cout<<a-1<<" "<<b<<endl;
  }else cout<<a<<" "<<b-1<<endl;


}

//


Measured memory_bytes: 256
# coding: utf-8


def ncr(n, r, mod):
    ret = 1
    for i in range(1, r+1):
        ret = (ret * (n-i+1) * pow(i, mod-2, mod)) % mod
    return ret


def solve(*args: str) -> str:
    n, a, b = map(int, args[0].split())
    mod = 10**9+7
    return str((pow(2, n, mod) - 1 - ncr(n, a, mod) - ncr(n, b, mod)) % mod)


if __name__ == "__main__":
    print(solve(*(open(0).read().splitlines())))


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

int main()
{
  int n;
  cin >> n;
  int num = 0;
  for(int i = 105;i <= n;i = i + 2){
    int cnt = 0;
    for(int j = 1;j <= i;j++){
      int t = i;
      if(t%j == 0) cnt++;
    }
    if(cnt == 8) num++;
  }
  cout << num << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int main(){
	int a,b,c=1;
	cin>>a>>b;
	
	for(int i=0;i<a;i++){
		if(c*2>c+b){
			c=c+b;
		}else{
			c=c*2;
		}
	}
	cout<<c<<endl;

}

Measured memory_bytes: 256
import static java.lang.Math.max;
import static java.lang.Math.min;
import java.util.Scanner;


public class Main {

  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);
    final int h = scanner.nextInt();
    final int n = scanner.nextInt();
    final int[] a = new int[n];
    final int[] b = new int[n];
    int max = 0;

    for (int i = 0; i < n; i++) {
      a[i] = scanner.nextInt();
      b[i] = scanner.nextInt();
      max = max(max, a[i]);
    }

    final long[][] dp = new long[n][h+max];

    dp[0][0] = b[0];
    for (int i = 1; i < h+max; i++) {
      dp[0][i] = b[0] * (long) Math.ceil((double) i /(double) a[0]);
    }
    for (int i = 1; i < n; i++) {
      for (int j = 0; j < h+max ; j++) {
        if(j > a[i]) {
          dp[i][j] = min(dp[i][j-a[i]] + b[i] , dp[i-1][j]);
        } else {
          dp[i][j] = min(dp[i-1][j], b[i]);
        }
      }
    }

    long min = Long.MAX_VALUE;
    for (int i = h; i < h+max; i++) {
      min = min(min, dp[n-1][i]);
    }
    System.out.println(min);

//    for (int i = 0; i < n; i++) {
//      for (int j = 0; j < h + max; j++) {
//        System.out.print(dp[i][j]);
//      }
//      System.out.println();
//    }

  }
}


Measured memory_bytes: 135184
def solve(s, t):
    dic1, dic2 = {}, {}
    for x, y in zip(s, t):
        if x in dic1:
            if dic1[x] != y:
                return False
        else:
            dic1[x] = y
        if y in dic2:
            if dic2[y] != x:
                return False
        else:
            dic2[y] = x
    return True


s = input()
t = input()

print('Yes' if solve(s, t) else 'No')

Measured memory_bytes: 3632
using System.Linq;
using System.Text;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Security.Cryptography.X509Certificates;
using System.Diagnostics;
using System.Reflection.Metadata;
using System.Threading;
using System.Runtime.InteropServices.ComTypes;

namespace AtCoder
{
    class Program
    {

        struct Point
        {
            public int left;
            public int right;

            public Point(int left, int right)
            {

                this.left = left;
                this.right = right;

            }

        }


        const int BiggestMod = 1000000007;

        public static void Main()
        {

            var buf = Console.ReadLine().Select(x => int.Parse(x.ToString()));
            if (buf.Sum() % 9 == 0) Console.WriteLine("Yes");
            else Console.WriteLine("No");

        }

    }

}

Measured memory_bytes: 33452
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;

int main() {
  cin.tie(nullptr); ios::sync_with_stdio(false);
  int M, D; cin >> M >> D;
  int res = 0;
  for (int m = 1; m <= M; ++m) for (int d = 1; d <= D; ++d) {
    int a = d / 10, b = d % 10;
    res += a >= 2 and b >= 2 and a * b == m;
  }
  cout << res << '\n';
}

Measured memory_bytes: 256
#include <iostream>
#include <string.h>
#include <vector>
#include <algorithm>
#include <cmath>
#include <map>
#include <functional>
#include <cassert>
#include <utility>
#include <stack>
#include <queue>
using namespace std;
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,n1,n2) for(int i=n1;i<n2;i++)
typedef long long ll;
typedef pair<int,int> Pii;
const int INF=(1<<30)-1;
const int MAX=310;
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a/gcd(a, b)*b;}
bool check(ll N,const vector<string> S){
	for(int i=1;i<N;i++){
		for(int j=0;j<i;j++){
			if(S[i][j]!=S[j][i])return false;
		}
	}
	return true;
}

void solve(ll N,vector<string> S){
	int ans=0;
	for(int i=0;i<N;i++){
		if(check(N,S))ans+=N;
		for(int i=0;i<N;i++)S[i]=S[i].substr(1)+S[i].substr(0,1);
	}
	cout<<ans<<endl;
}
int main(){
	long long N;
	scanf("%lld",&N);
	vector<string> S(N-1+1);
	for(int i = 0 ; i <= N-1 ; i++){
		cin >> S[i];
	}
	solve(N, S);
	return 0;
}


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

#define rep(i,n) for(int i=0; i<n; i++)
#define rept(i,a,b) for(int i=a; i<b; i++)
#define all(x) (x).begin(),(x).end()

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> P;
typedef map<int,int> mp;

const int MOD = 1e9 + 7;


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


    string s;
    cin >> s;

    ll len = s.size();
    vi ans(len, 0);
    
    int odd = 0, even = 0;
    int j = 0;
    rep(i, len-1){
        if(s[i] == 'R'){
        j++;
        if(j % 2 == 0){
            even++;
        }else{
            odd++;
        }
        }

        if(s[i+1] == 'L' && s[i] != s[i+1] && s[i] == 'R'){
            if(j % 2 == 0){
                ans[i] += even;
                ans[i+1] += odd;
            }else{
                ans[i] += odd;
                ans[i+1] += even;
            }
            even= 0;
            odd = 0;
            j = 0;
        }
    }

    odd = 0; even = 0;
    j = 0;
    for(int i = len - 1; i > 0; i--){
        if(s[i] == 'L'){
        j++;
        if(j % 2 == 0){
            even++;
        }else{
            odd++;
        }
        }

        if(s[i-1] == 'R' && s[i] != s[i-1]){
            if(j % 2 == 0){
                ans[i] += even;
                ans[i-1] += odd;
            }else{
                ans[i] += odd;
                ans[i-1] += even;
            }
            even= 0;
            odd = 0;
            j = 0;
        }
    }

    rep(i, len){
        cout << ans[i] << " ";
    }
    cout << endl;

    return 0;
}



Measured memory_bytes: 1104
#include<iostream>
using namespace std;
int main (){
  int N, K;
  cin >> N >> K ;
  string S;
  cin >> S;
  if(S[K-1]=='A'){S[K-1]='a';}
  else if(S[K-1]=='B'){S[K-1]='b';}
  else if(S[K-1]=='C'){S[K-1]='c';} 
  cout << S << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
#define int long long
#define ull unsigned long long
#define ld long double
#define rep(a) rep1(i,a)
#define rep1(i,a) rep2(i,0,a)
#define rep2(i,b,a) for(int i=(b); i<((int)(a)); i++)
#define rep3(i,b,a) for(int i=(b); i>=((int)(a)); i--)
#define all(a) a.begin(),a.end()
#define pii pair<int,int>
#define pb push_back
#define mp make_pair
#define sz(a) ((int)a.size())
#define pow2(x) (1ll<<(x))
#define print0(a) cout << (a) << ' '
#define print1(a) cout << (a) << '\n'
#define print2(a,b) cout << (a) << ' ',print1(b)
#define print3(a,b,c) cout << (a) << ' ',print2(b,c)
#define print4(a,b,c,d) cout << (a) << ' ',print3(b,c,d)
#ifdef i_am_noob
#define debug(a) print1(a)
#else
#define debug(a) 
#endif
#define ordered_set tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>
 
using namespace std;
using namespace __gnu_pbds;
 
const int Mod=1000000007,Mod2=998244353;
const int MOD=Mod2;
 
inline int add(int a, int b){return (a+b>=MOD?a+b-MOD:a+b);}
inline int sub(int a, int b){return (a+MOD-b>=MOD?a-b:a+MOD-b);}
int Pow(int a, int b){
	if(!b) return 1;
	int tmp=Pow(a*a%MOD,b>>1);
	return (b&1?tmp*a%MOD:tmp);
}
inline int inverse(int n){return Pow(n,MOD-2);}
 
const int maxn=200005;
//i_am_noob
int n,x[8],y[8],per[8];
ld k,ans=0;

int fact(int n){return (n?fact(n-1)*n:1);}

signed main(){
	ios_base::sync_with_stdio(0),cin.tie(0);
	cin >> n;
	rep(n) cin >> x[i] >> y[i];
	rep(n) per[i]=i;
	while(1){
		k=0;
		rep(n-1) k+=sqrt((x[per[i]]-x[per[i+1]])*(x[per[i]]-x[per[i+1]])+(y[per[i]]-y[per[i+1]])*(y[per[i]]-y[per[i+1]]));
		ans+=k;
		if(!next_permutation(per,per+n)) break;
	}
	ans=ans/fact(n);
	cout << fixed << setprecision(12) << ans << '\n';
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define mod 1000000009
#define ll long long
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define set0(a) memset ((a), 0 , sizeof(a))
#define set1(a) memset((a),-1,sizeof (a))
#define pi pair<int, int>
#define ps pair<string, string>
#define pl pair<long, long>
#define pll pair<long long, long long>
#define vll vector<long long>
#define vl vector<long>
#define vi vector<int>
#define vs vector<string>
#define vps vector< ps >
#define vpi vector< pi >
#define vpl vector< pl >
#define vpll vector< pll >
#define flash  ios_base::sync_with_stdio(false); cin.tie(NULL);
#define tc(t,T) for(long long t=0;t<T;t++)
#define rep(i,s,n,d) for(long long i=s;i<n;i=i+d)
#define meax 100007
 vll a(meax,0);
  vll b(meax,meax);
  ll sum1=0;
ll maximize(ll i,ll n,ll prev){

    if(b[i]!=meax){
        return b[i];
    }
    if(i>=n){
        return meax;
    }

    if(i==n-1){
            b[i]=0;
        return b[i];
    }
    ll d1=maximize(i+1,n,a[i]);
    ll d2=maximize(i+2,n,a[i]);
    b[i]=min(abs(a[i]-a[i+1])+d1,abs(a[i+2]-a[i])+d2);
    return b[i];


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

    rep(i,0,n,1){
        cin>>a[i];
    }
    ll d=maximize(0,n,a[0]);
    cout<<d<<endl;
}


Measured memory_bytes: 9468
#include<stdio.h>
 
int main(void)
{
  int a, b;
  int c;
  
  scanf("%d%d",&a, &b);
  
  if(a >= 13){
    printf("%d",b);
  }
  if((a <= 12)&&(a >= 6)){
    c = b / 2;
    printf("%d",c);
  }
  if(a <= 5){
    c = 0;
    printf("%d",c);
  }
  return 0;
}

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

count = 0

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

print(count)


Measured memory_bytes: 3060
open Printf
open Scanf

let id x = x
let tuple x y = (x, y)
             
module Dice =
  struct
    type t = {tp:int; ft:int; lt:int; rt:int; bk:int; bm:int}

    let create x1 x2 x3 x4 x5 x6 =
      {tp = x1; ft = x2; lt = x3; rt = x4; bk = x5; bm = x6}

    let roll d = function
        'S' -> {d with tp = d.bk; ft = d.tp; bm = d.ft; bk = d.bm}
      | 'E' -> {d with tp = d.rt; lt = d.tp; bm = d.lt; rt = d.bm}
      | 'W' -> {d with tp = d.lt; rt = d.tp; bm = d.rt; lt = d.bm}
      | 'N' -> {d with tp = d.ft; bk = d.tp; bm = d.bk; ft = d.bm}
      | _ -> failwith "roll"

    let rollx d dirs =
      let rd = ref d in
      String.iter (fun c -> rd := roll !rd c) dirs;
      !rd

    let top d = d.tp
    let front d = d.ft
    let left d = d.lt
  end

let () =
  let d = scanf "%d %d %d %d %d %d " Dice.create in
  let q = scanf "%d " id in
  let rec loop x =
    if x = 0 then ()
    else
      let tp, ft = scanf "%d %d " tuple in
      let ht = Hashtbl.create 100 in
      let rec dfs u =
        if Hashtbl.mem ht u then None
        else
          if Dice.top u = tp && Dice.front u = ft then Some u
          else begin
              Hashtbl.add ht u true;
              List.fold_left (fun vo c ->
                              match dfs (Dice.roll u c) with
                                Some v -> Some v
                              | None -> vo
                             ) None ['N'; 'S'; 'E'; 'W']
            end
      in
      (match dfs d with
         None -> failwith "dfs"
       | Some d' -> printf "%d\n" (Dice.left d'));
      loop (x-1)
  in
  loop q

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

int main(){
  int n;
  cin >> n;
  
  int p[n] = {};
  for(int i=0; i<n; i++){
    cin >> p[i];
  }
  
  sort(p, p+n);
  
  int ans = 0;
  for(int i=0; i<n-1; i++){
    ans += p[i];
  }
  ans += p[n-1]/2;
  
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<bool> vb;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define INT(str) stoi((str), 0)
#define INTB(str) stoi((str), 0, 2) // 2進数の文字列を int に
//cout << fixed << setprecision(15);

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

  int ac=0, wa=0, tle=0, re=0;
  rep(i, N) {
    string s;
    cin >> s;
    ac += s == "AC";
    wa += s == "WA";
    tle += s == "TLE";
    re += s == "RE";
  }

  cout << "AC x " << ac << endl;
  cout << "WA x " << wa << endl;
  cout << "TLE x " << tle << endl;
  cout << "RE x " << re << endl;
}


Measured memory_bytes: 3636
fn main() {
    let n:i32 = read();
    let ps:Vec<i32> = read_vec();
    let mut counter = 0;
    for (k,p) in ps.iter().enumerate() {
        if (k+1) != *p as usize { counter += 1 }
    }
    println!{"{}", if counter>2 {"NO"} else {"YES"}}
}

fn read<T: std::str::FromStr>() -> T{
    let mut buf = String::new();
    std::io::stdin().read_line(&mut buf).ok();
    buf.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T>{
    let mut buf = String::new();
    std::io::stdin().read_line(&mut buf).ok();
    buf.trim().split_whitespace()
        .map(|e| e.parse().ok().unwrap()).collect()
}

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


int main() {
	int N;
	string S;
	cin >> N >> S;
	int ans = 0;
	for (int i = 0; i < N; ++i) {
		vector<int>A(26);
		vector<int>B(26);
		for (int j = 0; j < N; ++j) {
			if (j < i) {
				A[S[j] - 'a']++;
			}
			else {
				B[S[j] - 'a']++;
			}
		}
		int anstmp = 0;
		for (int j = 0; j < 26; ++j) {
			if (A[j] > 0 && B[j] > 0) {
				++anstmp;
			}
		}
		ans = max(ans, anstmp);
	}
	cout << ans << endl;
}


Measured memory_bytes: 3632
k = int(input())
mod = 7 % k
ans = 1
for i in range(k):
    if k % 2 == 0:
        ans = -1
        break
    if mod == 0:
        break
    mod = (mod*10+7)%k
    ans += 1
if mod != 0:
    ans = -1
print(ans)

Measured memory_bytes: 63232
#include <iostream>
using namespace std;
int main(void){
    int n,a,b,c,d,sumx,sumy,x,y;
    cin>>n>>a>>b>>c>>d;
    if(n%a!=0) x=n/a+1;
    else x=n/a;
    sumx=x*b;
    if(n%c!=0) y=n/c+1;
    else y=n/c;
    sumy=y*d;
    if(sumx<sumy) cout <<sumx<<endl;
    else cout<<sumy<<endl;
}



Measured memory_bytes: 3084
h, w, a, b = map(int, input().split())
mat = [[0 for j in range(w)] for i in range(h)]
for i in range(b, h):
    for j in range(a):
        mat[i][j] = 1
for i in range(b):
    for j in range(a, w):
        mat[i][j] = 1
for _ in mat:
    print(*_,sep='')


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

int main() {
  string num;
  cin >> num;

  string op;
  for (int bit = 0; bit < (1<<3); bit++) {
    int sum = num[0] - '0';
    string str = "";
    for (int i = 0; i < 3; i++) {
      if (bit & (1<<i)) {
        sum += num[i + 1] - '0';
        str += "+";
      } else {
        sum -= num[i + 1] - '0';
        str += "-";
      }
    }
    if (sum == 7) {
      op = str;
      break;
    }
  }

  for (int i = 0; i < 3; i++) {
    if (i == 0) cout << num[0];
    cout << op[i] << num[i + 1];
  }
  cout << "=7" << endl;
}

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

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()



int main() {
    int h, w;
    cin >> h >> w;
    vector<int> p(26, 0);
    rep (i, h) {
        string s;
        cin >> s;
        rep (j, w) {
            int x = s[j] - 'a';
            p[x]++;
        }
    }
    int four, two, one;
    four = two = one = 0;
    rep (i, 26) {
        four += p[i] / 4;
        p[i] = p[i] % 4;
        two += p[i] / 2;
        p[i] = p[i] % 2;
        one += p[i];
    }
    int n = h / 2;
    int m = w / 2;
    if (h % 2 == 0 && w % 2 == 0) {
        if (n * m == four) {
            cout << "Yes" << endl;
        } else {
            cout << "No" << endl;
        }
    } else if (h % 2 == 0  || w % 2 == 0) {
        if (one == 0 && four >= n * m) {
            cout << "Yes" << endl;
        } else {
            cout << "No" << endl;
        }
    } else {
        if (one == 1 && four >= n * m) {
            cout << "Yes" << endl;
        } else {
            cout << "No" << endl;
        }
    }
}




Measured memory_bytes: 256
n = gets.to_i
d = gets.chomp.split(" ").map(&:to_i);

sum = 0
i = 0
len = d.length
while i < len
	j = i + 1;
	while j < len
		sum = sum + d[i] * d[j]
		j = j + 1
	end
	i = i + 1
end
print sum

Measured memory_bytes: 1788
<?php
$inputNum = getInput();

for ($i=1; $i <= $inputNum; $i++) {
    if (($i % 3 == 0) || preg_match('/3/', $i)) {
        $conditionMatchedNum[] = $i;
    }
}

echo sprintf(' %s', implode(' ', $conditionMatchedNum)), PHP_EOL;

function getInput()
{
    return trim(fgets(STDIN));
}

Measured memory_bytes: 16180
import sys
input=sys.stdin.readline
def main():
	R,C,K=map(int,input().split())
	lis=[[0]*(C) for i in range(R)]
	for i in range(K):
		a,b,c=map(int,input().split())
		lis[a-1][b-1]=c
	dp0=[[0]*(C+1) for i in range(R+1)]
	dp1=[[0]*(C+1) for i in range(R+1)]
	dp2=[[0]*(C+1) for i in range(R+1)]
	dp3=[[0]*(C+1) for i in range(R+1)]
	for i in range(1,R+1):
		for j in range(1,C+1):
			for x,y in ((dp0,0),(dp1,dp0),(dp2,dp1),(dp3,dp2)):
				t=lis[i-1][j-1]
				x[i][j]=max(x[i-1][j],x[i][j])
				x[i][j]=max(x[i][j-1],x[i][j])
				if t!=0:
					dp1[i][j]=max(dp1[i][j],x[i-1][j]+t)
					if y!=0:
						x[i][j]=max(x[i][j],y[i][j-1]+t)
	print(max(dp0[-1][-1],dp1[-1][-1],dp2[-1][-1],dp3[-1][-1]))
if __name__ == '__main__':
	main()

Measured memory_bytes: 422036
#include"bits/stdc++.h"
#include<boost/multi_array.hpp>
#include<boost/optional.hpp>
#include<boost/range/irange.hpp>
#include<boost/range/algorithm.hpp>
#include<boost/range/adaptors.hpp>
using namespace std;
namespace adaptor = boost::adaptors;

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++)
#define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--)
typedef long long ll;

int tempmin = INT_MAX;

void dfs(int x, int N, vector<int> E){
	if(x > 10*N){return;}
  	int K = E.size();
  	if(x < N){
		rep(i,K){
          	if(10*x+E[i]!=0){
      			dfs(10*x+E[i], N, E);
            }
        }
    }
 	else{
      tempmin = min(tempmin, x);
    } 
  	return;
}

void Main()
{
  int N, K;
  cin >> N >> K;
  vector<int> D(K);
  rep(i,K) {cin >> D[i];}
  vector<int> E(10-K);
  int k = 0;
  int flag;
  rep(j,10){
    flag = 0;
  	rep(i,K) {
    	if(D[i] == j){
        	flag = 1;
        }
    }
	if(!flag){
    	E[k] = j;
    	k++;
    }
  }
  
  // 本編
  dfs(0, N, E);
  cout << tempmin << endl;
  return;
}

int main()
{
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
	return 0;
}


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

int maxtime(int x) {
	return (x + 9) / 10 * 10;
}
int retime(int x) {
	return maxtime(x) - x;
}

int main() {
	int a, b, c, d, e;
	cin >> a >> b >> c >> d >> e ;
	int A = maxtime(a) + maxtime(b) + maxtime(c) + maxtime(d) + maxtime(e);
	int B = A - max({ retime(a), retime(b), retime(c), retime(d), retime(e) });
	cout << B << endl;
}

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

int val[]={0,300000,200000,100000};

int main(){

    int a,b;
    scanf("%d%d",&a,&b);
    int ans=0;
    if(a<=3) ans+=val[a];
    if(b<=3) ans+=val[b];
    if(a==1 && b==1) ans+=400000;
    printf("%d\n",ans);

    return 0;
}

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

# define p(s) std::cout << s << endl;
# define printIf(j,s1,s2) cout << (j ? s1 : s2) << endl;
# define YES(j) cout << (j ? "YES" : "NO") << endl;
# define Yes(j) std::cout << (j ? "Yes" : "No") << endl;



int main()
{
    long long int a,b,c,x,y;cin >> a >> b >> c >> x >> y;

    // バラ買戦略
    long long int mi = a*x + b*y;

    // ハーフで余りなく
    long long z = min(x,y);
    long long int mi2 = c*z*2+a*(x-z)+b*(y-z);

    // ハーフでぎゃんぜめ
    z = max(x,y);
    long long int mi3 = c*z*2;

    mi = min(mi,mi2);
    mi = min(mi,mi3);
    p(mi)
} 

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

int main(){
	int T,A,B;
  	cin >> T >> A >> B;
  	int planA = T * A;
  
  	if (planA <= B){
    	cout << planA << endl;
    }
  	else{
    	cout << B << endl;
    }
}



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

#include <climits>
#include <cmath>
#include <cstring>

#include <iomanip>

using namespace std;

#define FAST       			ios_base :: sync_with_stdio(false); cin.tie(NULL); 
#define endl "\n"

typedef long long int  ll;
typedef unsigned long long int ull;

class graph
{
	vector<vector<int> > adjList;
	int nodes;

	public:
		graph(int n)
		{
			nodes = n;
			adjList.resize(n+1);
		}

		void addEdge(int u, int v)
		{
			adjList[u].push_back(v);
			adjList[v].push_back(u);
		}

		ll get()
		{
		    int ans = 0;
		    int count = 1;
			vector<bool> v(nodes+1 , false);
			find(-1 , 1 , v , ans , count);
			
			return ans;
		}

		void find(int parent , int current , vector<bool>& v , int& ans , int count)
		{
			v[current] = true;
            if(count == nodes)
                ans++;
			for(auto n : adjList[current])
			{
				if(n != parent && v[n] == false)
				{
					find(current , n , v , ans , count+1);
				}
			}
			v[current] = false;
		}
};

int main()
{
	FAST;
	int n,edge;
	cin >> n >> edge;
	graph g(n);
	while(edge--)
	{
		int u,v;
		cin >> u >> v;
		g.addEdge(u , v);
	}

	cout << g.get();
	return 0;
}

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

int main() {
    int a[5], idx, num1 = 10;
    rep(i, 5) cin >> a[i];
    rep(i, 5) {
        int num = a[i] % 10;
        if (num && num1 > num) {
            num1 = num;
            idx = i;
        }
    }
    int sum = 0;
    rep(i, 5) {
        if (i == idx) {
            sum += a[i];
        } else {
            int num = a[i] % 10;
            if (num) a[i] = a[i] / 10 * 10 + 10;
            sum += a[i];
        }
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<functional>
#include<vector>
#include<queue>
#include<stack>
#include<set>
#include<map>
using namespace std;
#define MOD 1000000007
#define f(i,n) for(int i=0;i<int(n);i++)
#define N 200000
#define pi 3.14159265358979324

int main() {
	long double a, b, c;
	long double x, y, z;
	scanf("%Lf %Lf %LF", &a, &b, &c);

	x = a * a*b;
	if (c < (x/2)) {
		y = (c * 2) / (a*b);
		z = atan(b / y);

	}
	else {
		c = x - c;
		y = (c * 2) / (a*a);
		z = atan(y / a);
	}
	z = z * 180;
	z = z / pi;
	printf("%.10Lf\n", z);


	return 0;
}

Measured memory_bytes: 128
long long int A[999999],r=0,s=0;
#define tri(a,b,c) (a<b+c)
int compare(const void *a, const void *b){
	long long int val=*(long long int*)b - *(long long int*)a;
	return val<0?-1:val>0?1:0;
}
main(){
	int N,i=0;
	scanf("%d",&N);
	if(N<6)puts("0"),exit(0);
	for(i=0;i<N;i++)scanf("%lld",A+i);
	qsort(A,N,8,compare);
	for(i=0;i<N-5;i++) //single*2
		if(tri(A[i],A[i+1],A[i+2])){s=A[i]+A[i+1]+A[i+2];break;}
	if(s)for(i+=3;i<N-2;i++)
		if(tri(A[i],A[i+1],A[i+2])){r=s+A[i]+A[i+1]+A[i+2];break;}
	for(s=i=0;i<N-5;i++)
		if(
			(tri(A[i],A[i+1],A[i+4])&&tri(A[i+2],A[i+3],A[i+5]))|| //type3 AABBAB
			(tri(A[i],A[i+1],A[i+5])&&tri(A[i+2],A[i+3],A[i+4]))|| //type4 AABBBA
			(tri(A[i],A[i+3],A[i+4])&&tri(A[i+1],A[i+2],A[i+5]))   //type8 ABBAAB
		){s=A[i]+A[i+1]+A[i+2]+A[i+3]+A[i+4]+A[i+5];r=r>s?r:s;break;}
	printf("%lld\n",r);exit(0);
}

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

int main()
{
	int a,b;
	int n;
	int m;
	while(cin>>a>>b)
	{
		n = b-a-1;
		m = a-n*(1+n)/2;
		m=-m;
		cout<<m<<"\n";
	}
}

Measured memory_bytes: 256