akhauriyash/Code-Regression huggingface dataset:
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
//#include <cstdio>
//#include <iomanip>//"cout<<fixed<<setprecision(n)<<sth<<endl;"
//#include <string>//"reverse(s's it,s's it)"
//#include <functional>//"greater<T>" "sort(a,a+n,greater<int>());""
//#include <cmath>//"abs" "sqrt"
//#include <numeric>//"accumulate(inputit,inputit,init,(optional) object)"
//#include <algorithm>//"lower_bound(it,it,v)" "next_permutation(a,a+n)"
//"reverse(v's it,v's it)"(v: vector)
using namespace std;
#define pb push_back//also for STRING
#define fi first
#define sc second
#define mp make_pair
#define is insert
#define ps push//TMP//stack,(priority) queue,
#define fr front//TMP//queue//for priority, use top().
typedef long long ll;//not necessarily
typedef pair<int,int> pii;
//Add other types in the same way.
const ll M=1000000007;//can be changed
int mod(int a){	return (a+M)%M;	}//M can be a variable
void plmod(ll &a,ll b){	a=(a+b+M)%M;	return;	}
void mnmod(ll &a,ll b){	a=(a-b+M)%M;	return;	}
void mlmod(ll &a,ll b){	a=(a*b)%M;  	return;	}
//Caution! you may need sth larger than "+M"!
void chmax(int &a,int b){	a=max(a,b);	return;	}
void chmin(int &a,int b){	a=min(a,b);	return;	}
//These 2 could be better in long long

int main(){
	string a;
	cin>>a;
	ll c[26];
	fill(c,c+26,0);	
	for(int i=0;i<a.size();++i) ++c[a[i]-'a'];
	ll ans=(((ll)a.size()*((ll)a.size()-1))/2)+1;
	for(int j=0;j<26;++j){
		ans-=((c[j]*(c[j]-1))/2);
	}
	printf("%lld\n",ans);
}

Measured memory_bytes: 640
import Control.Monad
import Data.List
main = do
  n <- readLn
  [s, t] <- transpose . map words <$> replicateM n getLine
  x <- getLine
  let idx = head [i | (a, i) <- zip s [0..], a == x]
  print . sum . drop (idx + 1) $ map read t

Measured memory_bytes: 1020
import sys
sys.setrecursionlimit(10**9)
def input():
    return sys.stdin.readline().rstrip()

def main():
    A,B=map(int,input().split())
    if A<10 and B<10:
        print(A*B)
    else:
        print(-1)


if __name__ == '__main__':
    main()


Measured memory_bytes: 38384
//
//  main.cpp
//  ALDS1_6
//
//  Created by ptyuan on 2018/10/31.
//  Copyright © 2018 YY. All rights reserved.
//

#include <iostream>
#include <cstdlib>
#include <cstdio>
using namespace std;
int n = 0;

void CountingSort(int *A, int *B, int k) {
    int *C = (int *)malloc(sizeof(int) * k + 1);
    for (int i = 0; i <= k; i++) {
        C[i] = 0;
    }
    
    for (int i = 1; i <= n; i++) {
        C[A[i]]++;
    }
    
    for (int i = 1; i <= k; i++) {
        C[i] += C[i - 1];
    }
    
    for (int j = n; j >= 1; j--) {
        B[C[A[j]]] = A[j];
        C[A[j]]--;
    }
    free(C);
}

int main(int argc, const char * argv[]) {
    scanf("%d", &n);
    int *A = (int *)malloc(sizeof(int) * n + 1);
    int *B = (int *)malloc(sizeof(int) * n + 1);
    int _max = 0;
    for (int i = 1; i <= n; ++i) {
        scanf("%d", A + i);
        _max = max(_max, A[i]);
    }
    CountingSort(A, B, _max);
    for (int i = 1; i <= n; ++i) {
        if (i > 1) {
            printf(" ");
        }
        printf("%d", *(B + i));
    }
    printf("\n");
    free(A);
    free(B);
    return 0;
}



Measured memory_bytes: 18400
#include <bits/stdc++.h>
using namespace std;
#define REP(i,b,e) for(int i=(b);i<(e);++i)
#define RREP(i,b,e) for(int i=(b)-1;i>=e;--i)
#define rep(i,e) for(int i=0;i<(e);++i)

constexpr int MOD = 1000000007;
constexpr int INF = 1LL << 30;
constexpr long long LLINF = 1LL << 62;
constexpr double EPS = 1e-9;

struct Initializer {
  Initializer() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << fixed << setprecision(15) << boolalpha;
  }
} initializer;

template<typename T>
istream &operator>>(istream &is, vector<T> &vec) {
  for (T &x : vec) is >> x;
  return is;
}

template<typename T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
  os << "[";
  for (auto it = vec.begin(); it != vec.end(); ++it) {
    if (it != vec.begin()) os << ", ";
    os << *it;
  }
  return os << "]";
}

template<typename T, typename U>
ostream &operator<<(ostream &os, const pair<T, U> &pa) {
  return os << "(" << pa.first << ", " << pa.second << ")";
}

template<typename T>
ostream &operator<<(ostream &os, const set<T> &se) {
  os << "{";
  for (auto it = se.begin(); it != se.end(); ++it) {
    if (it != se.begin()) os << ", ";
    os << *it;
  }
  return os << "}";
}

template<typename T, typename U>
ostream &operator<<(ostream &os, const map<T, U> &ma) {
  os << "{";
  for (auto it = ma.begin(); it != ma.end(); ++it) {
    if (it != ma.begin()) os << ", ";
    os << it->first << ": " << it->second;
  }
  return os << "}";
}

inline void print(void) { cout<<'\n'; }
template<class T> inline void print(const T &x) { cout<<x<<'\n'; }
template<class T, class... U> inline void print(const T &x, const U&... y) { cout<<x<<" "; print(y...); }
#define dump(...) cout<<#__VA_ARGS__<<": [L_"<<__LINE__<<"]"<<'\n'; print(__VA_ARGS__);cout<<'\n';

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


int main() {
  int n; cin>>n;
  int f = 1;
  REP(i, 1, n+1) f *= i;
  vector<int> x(n), y(n);
  rep(i, n) cin>>x[i]>>y[i];
  long double ans = 0;
  vector<int> v(n);
  iota(v.begin(), v.end(), 0);
  do {
    long double d = 0;
    REP(i, 1, n) {
      d += sqrt((x[v[i-1]]-x[v[i]])*(x[v[i-1]]-x[v[i]]) + (y[v[i-1]]-y[v[i]])*(y[v[i-1]]-y[v[i]]));
    }
    ans += d;
  } while (next_permutation(v.begin(), v.end()));
  ans /= f;
  print(ans);

  return 0;
}

Measured memory_bytes: 256
#include"iostream"
using namespace std;
int main()
{
	int a, b;
	cin >> a >> b;
	if (a > b)cout << "a > b" << endl;
	if (a < b)cout << "a < b" << endl;
	if (a == b)cout << "a == b" << endl;
	return 0;
}


Measured memory_bytes: 3092
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <vector>

using namespace std;

int main() {
	int A, B, C, D;

	cin >> A >> B >> C >> D;

	if (A + B > C + D) {
		cout << "Left";

	}
	else if (A + B == C + D) {
		cout << "Balanced";

	}
	else {
		cout << "Right";
	}
}

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

/* 大文字を小文字に変換 */
char tolower(char c) {return (c + 0x20);}
/* 小文字を大文字に変換 */
char toupr(char c) {return (c - 0x20);}

// if('A'<=s[i] && s[i]<='Z') s[i] += 'a'-'A';

/*
string s = "abcdefg"
s.substr(4) "efg"
s.substr(0,3) "abc"
s.substr(2,4) "cdef"
*/

void maxHeapify(vector<ll> &A, int i){
    int H = A.size();
    int l = 2*i+1; int r = 2*i+2;
    // 右の子、自分、左の子で最大のインデックスを選択する
    int largest;
    if(l < H && A[l] > A[i]){
        largest = l;
    }else{
        largest = i;
    }
    if(r < H && A[r] > A[largest]){
        largest = r;
    }
    if(largest != i){
        swap(A[i], A[largest]);
        maxHeapify(A, largest);
    }
}

void buildMaxHeap(vector<ll> &A){
    int H = A.size();
    for(int i=H/2; i>=0; i--){
        maxHeapify(A, i);
    }
}

void insert(vector<ll> &A, int k){
    A.push_back(k);
    int i = A.size()-1;
    while(i>=0 && A[(i-1)/2] < A[i]){
        swap(A[(i-1)/2], A[i]);
        i = (i-1)/2;
    }
}

void extract(vector<ll> &A){
    cout << A[0] << endl;
    A[0] = A[A.size()-1]; A.pop_back();
    maxHeapify(A, 0);
}

int main()
{
    ll x;
    vector<ll> A;
    while(true){
        string command; cin >> command;
        if(command == "insert"){
            scanf("%ld", &x);
            insert(A, x);
        }else if(command == "extract"){
            extract(A);
        }else if(command == "end"){
            break;
        }
    }
}


Measured memory_bytes: 11404
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<iostream>
#include<algorithm>
using namespace std;
const int N=100010;
int a[N];
struct node { int sum,x; } sum1[N],sum2[N];
bool cmp(node n1,node n2) { return n1.sum>n2.sum; }
int main() {
	int n; scanf("%d",&n);
	for(int i=1;i<=n;i++) scanf("%d",&a[i]);
	int ans=0;
	for(int i=1;i<=n;i+=2) { sum1[a[i]].x=a[i],sum1[a[i]].sum++; }
	sort(sum1+1,sum1+1+100000,cmp);
	for(int i=2;i<=n;i+=2) { sum2[a[i]].x=a[i],sum2[a[i]].sum++; }
	sort(sum2+1,sum2+1+100000,cmp);
	if(sum1[1].x!=sum2[1].x) ans=n-sum1[1].sum-sum2[1].sum;
	else {
		int t1=(n+1)/2-sum1[1].sum+n/2-sum2[2].sum;
		ans=min(t1,(n+1)/2-sum1[2].sum+n/2-sum2[1].sum);
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 2176
package main

import (
	"fmt"
	"strconv"
)

func main() {
	var a, b, k int
	fmt.Scan(&a, &b, &k)

	takahashi := true
	for i := 0; i < k; i++ {
		if takahashi {
			if a % 2 != 0 {
				a--
			}
			passingNumber := a / 2
			a -= passingNumber
			b += passingNumber
		} else {
			if b % 2 != 0 {
				b--
			}
			passingNumber := b / 2
			b -= passingNumber
			a += passingNumber
		}
		takahashi = !takahashi
	}

	fmt.Println(strconv.Itoa(a), strconv.Itoa(b))

}

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

#define ll long long
#define pb push_back

const int maxn = 2e3 + 20;
const int mod = 924844033;

int dp[maxn][maxn][2][2] , t[maxn] , fac[maxn] , pd[maxn] , tmp[maxn];

void mkay(int &a)
{
	if(a >= mod)
		a -= mod;
	else if(a < 0)
		a += mod;
}

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

	fac[0] = 1;
	for(int i = 1; i < maxn; i++)
		fac[i] = 1LL * fac[i - 1] * i % mod;

	int n , k;
	cin >> n >> k;

	for(int i = 0; i < n; i++)
		t[i % k]++;

	dp[1][0][0][0] = 1;

	for(int i = 2; i <= n; i++)
		for(int j = 0; j <= i; j++)
		{
			if(!j)
			{
				dp[i][j][0][0] = 1;
				continue;
			}

			for(int x = 0; x < 2; x++)
				for(int y = 0; y < 2; y++)
					mkay(dp[i][j][0][0] += dp[i - 1][j][x][y]);
			mkay(dp[i][j][0][1] = dp[i - 1][j - 1][0][1] + dp[i - 1][j - 1][0][0]);
			mkay(dp[i][j][1][0] = dp[i - 1][j - 1][1][0] + dp[i - 1][j - 1][0][0]);

			if(j >= 2)
				mkay(dp[i][j][1][1] = dp[i - 1][j - 2][0][0]);

			int s = 0;
			for(int x = 0; x < 2; x++)
				for(int y = 0; y < 2; y++)
					mkay(s += dp[i][j][x][y]);
		}

	int sum = 0;
	pd[0] = 1;

	for(int i = 0; i < k; i++)
	{
		for(int j = 0; j <= t[i]; j++)
			for(int k = 0; k <= sum; k++)
			{
				int s = 0;
				for(int x = 0; x < 2; x++)
					for(int y = 0; y < 2; y++)
						mkay(s += dp[t[i]][j][x][y]);
				
				mkay(tmp[j + k] += 1LL * s * pd[k] % mod);
			}

		sum += t[i];

		for(int j = 0; j <= sum; j++)
			pd[j] = tmp[j] , tmp[j] = 0;
	}

	int res = 0;
	for(int i = 0; i <= n; i++)
	{
		tmp[i] = (i % 2? 1 : -1);

		mkay(res += (1LL * -tmp[i] * fac[n - i] % mod) * pd[i] % mod);
	}

	cout << res << endl;
}









Measured memory_bytes: 61952
import java.util.*;
import java.io.*;
public class Main {

	public static void main(String[] args) throws Exception{
		int num = 998244353;

		// TODO Auto-generated method stub
 		BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
 		PrintWriter out = new PrintWriter(System.out);
 		char a = bf.readLine().charAt(0);
 		if (Character.isUpperCase(a)){
 			out.println("A");
 		}
 		else{
 			out.println("a");
 		}
 		
 		
 		
 		out.println();
	 		
 		out.close();
 		
 		
 		
 	}
}
 	
 
//StringJoiner sj = new StringJoiner(" "); 
//sj.add(strings)
//sj.toString() gives string of those stuff w spaces or whatever that sequence is

 		
 		
 		
 		
	




Measured memory_bytes: 25332
from collections import deque
n, q = map(int, input().split())
g = [[] for i in range(n)]
k = []
for i in range(n-1):
  a,b = map(int, input().split())
  g[a-1].append(b-1)
  g[b-1].append(a-1)
for i in range(q):
  a,b = map(int, input().split())
  k.append([a-1,b])
m = [-1]*n
m[0] = 0
m1 = [-1]*n
q = deque()
q.append(0)
while len(q):
  d = q.popleft()
  for i in g[d]:
    if m[i] == -1:
      m[i] = m[d]+1
      m1[i] = d
      q.append(i)
kyori = [[] for i in range(max(m)+1)]
for i,j in enumerate(m):
  kyori[j].append(i)
ans= [0]*n
for i,j in k:
  ans[i]+=j
for i in kyori[1:]:
  for j in i:
    ans[j] = ans[j] + ans[m1[j]]
print(' '.join(map(str,ans)))

Measured memory_bytes: 132944
#include <bits/stdc++.h>
using namespace std;
 
int main() {
	
   int N;
   
   cin >> N;
   
   vector<int> X(N);
   for (int i=0; i<N; i++){
   cin >> X.at(i);
   }
    
    int p=0;
    for (int i=0; i<N; i++){
        p += X.at(i);
    }
    p = p/N;
    
    int sum1=0;
    for (int i=0; i<N ;i++){
     sum1 += (X.at(i)-p)*(X.at(i)-p);
    }
    int sum2=0;
    for (int i=0; i<N; i++){
        sum2 += (X.at(i)-p-1)*(X.at(i)-p-1);
    }
    cout << min(sum1,sum2)<< endl;
    
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cassert>
#include <stack>
#include <limits>
#include <array>
#include <unordered_map>
#include <unordered_set>
#include <memory>
#include <numeric>
//#include <tuple>

constexpr long long mod = static_cast<long long>(1e9 + 7);

using Edges = std::vector<std::vector<int>>;

bool has_cycle(int i, std::vector<std::pair<bool, bool>>& memo, const Edges& edges) {
    memo[i].first = true;
    bool ans = false;
    for(auto v: edges[i]) {
        if(!memo[v].first) ans |= has_cycle(v, memo, edges);
        else ans |= !memo[v].second;
    }
    memo[i].second = true;

    return ans;
}

int main() {
    int V, E;
    std::cin >> V >> E;
    Edges edges(V, std::vector<int>());
    while(E--) {
        int s, t;
        std::cin >> s >> t;
        edges[s].push_back(t);
    }

    std::vector<std::pair<bool, bool>> memo(V, std::make_pair(false, false));
    bool ans = false;
    for(int i = 0; i < V; ++i) {
        if(!memo[i].first) {
            ans |= has_cycle(i, memo, edges);
        }
    }

    if(ans) std::cout << 1 << std::endl;
    else std::cout << 0 << std::endl;

    return 0;
}



Measured memory_bytes: 3148
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0; i<(n); ++i)
typedef long long ll;
ll x,m;
string s;
int main(){
  cin >> x;
  ll d=0;
  while(x>=500){
    x-=500;
    d+=1000;
  }
  while(x>=5){
    x-=5;
    d+=5;
  }
  cout << d;
}

Measured memory_bytes: 256
s = input().split() #s_1 s_2を分割して取得し、sに値を入れる

a = int(s[0])
b = int(s[1])
m = 2019

for i in range(a,b+1):
    for j in range(i+1,b+1):
        m = min((i*j)%2019 ,m)
        if m == 0: 
            break
    if m == 0:
        break

print(m)



Measured memory_bytes: 2940
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <queue>
#include <vector>
#include <map>
#include <set>

using namespace std;

typedef pair<int , int> P2;
typedef pair<pair<int , int> , int> P3;
typedef pair<pair<int , int> , pair<int , int> > P4;
#define Fst first
#define Snd second
#define PB(a) push_back(a)
#define MP(a , b) make_pair((a) , (b))
#define M3P(a , b , c) make_pair(make_pair((a) , (b)) , (c))
#define M4P(a , b , c , d) make_pair(make_pair((a) , (b)) , make_pair((c) , (d)))
#define repp(i,a,b) for(int i = (int)(a) ; i < (int)(b) ; ++i)
#define repm(i,a,b) for(int i = (int)(a) ; i > (int)(b) ; --i)
#define repv(t,it,v) for(vector<t>::iterator it = v.begin() ; it != v.end() ; ++it)

int H , W;
char c[333][333];
int s[666][333];
int ans;
int dp[333][333];

int main(){
	scanf("%d%d" , &H , &W);
	repp(i,0,H){
		repp(j,1,W+1){
			scanf(" %c" , &c[i][j]);
		}
	}
	repp(j,1,W){
		repp(i,0,H){
			repp(k,0,H-i){
				s[H+i][k+1] = s[H+i][k] + (c[i+k][j] == c[k][j+1] ? 1 : 0);
				s[H-i][k+1] = s[H-i][k] + (c[k][j] == c[i+k][j+1] ? 1 : 0);
			}
		}
		dp[H][H] = 0;
		repm(p,H-1,-1){
			dp[p][H] = dp[p+1][H] + s[p+1][p+1];
			dp[H][p] = dp[H][p+1] + s[H+H-p-1][p+1];
		}
		repm(p,H-1,-1){
			repm(q,H-1,-1){
				dp[p][q] = min(dp[p+1][q] + s[H+p+1-q][min(p+1,q)] , dp[p][q+1] + s[H+p-q-1][min(p,q+1)]);
			}
		}
		ans += dp[0][0];
	}
	printf("%d\n" , ans);
	return 0;
}


Measured memory_bytes: 1536
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 2e5 + 7;
    /*
    {
       Md: Saroar Zahan Sojib
       Green University of Bangladesh
       https://web.facebook.com/sojib.bdb
    }
   */


// Driver program to test above function
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    int k;
    string s;
    cin>>k>>s;
    if(k>=s.size())cout<<s<<endl;
    else
    {
        for(int i=0;i<k;i++)
        {
           cout<<s[i];
        }
          cout<<"..."<<endl;
    }



    return 0;
}


Measured memory_bytes: 3612
import java.util.Scanner;

public class Main {
	private Scanner sc;
	
	public static void main(String[] args) {
		new Main();
	}
	
	public Main() {
		sc = new Scanner(System.in);
		
		while (sc.hasNextLine() == true) {
			String line = sc.nextLine();
			int[][] map = new int[10][10];
			
			for (int i = 0; i < map.length; i++) {
				map[0][i] = line.charAt(i) - '0';
			}
			
			for (int j = 1; j < map.length; j++) {
				for (int i = 0; i < (map.length - j); i++) {
					map[j][i] = (map[j - 1][i] + map[j - 1][i + 1]) % 10;
				}
			}

			System.out.println(map[9][0]);
		}
	}
}

Measured memory_bytes: 26044
import math
n = int(input())
a = list(map(int, input().split()))

def lcm(a,b):
    return a * b // math.gcd(a,b)

p = 1000000007

k = 1
for i in range(n):
    k = lcm(k,a[i])

k %= p

ans = 0
for i in range(n):
    ans += k * pow(a[i],p-2,p)
    ans %= p

print(ans)


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

int main() {
  int X, N;
  cin >> X >> N;
  vector<int> P(N);
  for (int i = 0; i < N; i++) cin >> P.at(i);
  set<int> SE;
  for (auto p : P) SE.insert(p);
  int ans = 0, mi = 1e9;
  for (int i = -1000; i <= 1000; i++) {
    if (SE.count(i)) continue;
    if (abs(X - i) < mi) ans = i, mi = abs(X - i);
  }
  cout << ans << "\n";
}

Measured memory_bytes: 3648
#include <iostream>
#include <algorithm>
#include <numeric>
#include <utility>
#include <map>
#include <vector>
#include <climits>
#include <cmath>
#include <stdlib.h>

#define max_n 100001
#define mod 1000000007

using namespace std;

int main()
{
    int n; cin >> n;
    vector<long long> v(n), cum(n);
    for (int i = 0; i < n; i++)
    {
        cin >> v[i];
    }

    long long ans = 0; 
    cum[0] = v[0];
    for (int i = 1; i < n; i++)
    {
        cum[i] = (cum[i - 1] + v[i]) % mod;
    }
    for (int i = 0; i < n; i++)
    {
        ans = (ans + (v[i] * (cum[n - 1] - cum[i] + mod) % mod) % mod) % mod;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 6352
import java.util.Scanner;

public class Main {


    void solve() {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] dams = new int[N]; // A
        long allSum = 0;
        for (int i = 0; i < N; i++) {
            dams[i] = sc.nextInt();
            allSum += (long)dams[i];
        }

        long[] rains =  new long[N]; // x
        long sumWithoutX0 = 0;
        for (int i = 1; i < N; i+=2) {
            sumWithoutX0 += (long)dams[i] * 2;
        }
        rains[0] = allSum - sumWithoutX0;
        System.out.print(rains[0] + " ");

        for (int i = 1; i < N; i++) {
            rains[i] = 2 * dams[i - 1] - rains[i - 1];
            System.out.print(rains[i] + " ");
        }
    }

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



Measured memory_bytes: 65728
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pli = pair<ll, int>;
template <typename T>
using Graph = vector<vector<T>>;
const int MOD = 1e9 + 7;

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

    string S;
    cin >> S;
    deque<char> s, invs;
    for (int i = 0; i < S.length(); ++i) {
        s.push_back(S[i]);
        invs.push_front(S[i]);
    }

    bool isinv = false;
    int Q;
    cin >> Q;
    for (int i = 0; i < Q; ++i) {
        int T;
        cin >> T;
        if (T == 1)
            isinv ^= 1;
        else {
            int F;
            char C;
            cin >> F >> C;
            if (isinv ^ F == 1) {
                s.push_front(C);
                invs.push_back(C);
            } else {
                s.push_back(C);
                invs.push_front(C);
            }
        }
    }

    if (isinv)
        for (auto i : invs)
            cout << i;
    else
        for (auto i : s)
            cout << i;
    cout << endl;
    return 0;
}


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

#define inf 1 << 30

long long dp[105][100005];

long long v[1000];
long long w[1000];


long long recur(long long i,long long j)
{
    /*cout << i << " " << j << "\n";*/
    if(j < 0)
    {
        return -inf;
    }
    if(i == 0 && j == 0)
    {
        return 0;
    }
    else if(dp[i][j] != -1)
    {
        return dp[i][j];
    }
    else
    {
        dp[i][j] = max(recur(i-1,j),recur(i-1,j - w[i]) + v[i]);
    }
    return dp[i][j];
}


int main()
{
    long long n,W;
    cin >> n >> W;
    long long i,j;
    for(i=1;i<=n;i++)
    {
        for(j=1;j<=W;j++)
        {
            dp[i][j] = -1; 
        }
    }
    for(i=1;i<=n;i++)
    {
        cin >> w[i] >> v[i];
    }
    
    cout << recur(n,W);
}

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

using namespace std;

using ll = long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vi = vector<int>;
using vl = vector<ll>;

using _loop_int = int;
#define REP(i,n) for(_loop_int i=0; i<(_loop_int)(n); i++)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a); i<(_loop_int)(b); i++)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1; i>=(_loop_int)(a); i--)

#define CHMIN(a,b) (a)=min((a),(b))
#define CHMAX(a,b) (a)=max((a),(b))
#define ALL(v) (v).begin(),(v).end()

#define DEBUG(x) cerr<<#x<<": "<<(x)<<endl
#define DEBUG_VEC(v) cerr<<#v<<": ";REP(__i,(v).size())cerr<<((v)[__i])<<", ";cerr<<endl

const ll MOD = 1000000007ll;

ll n,h,d;
ll fact[1252525];
ll dp[1252525];
ll sum[1252525];

int main(){
    cin>>n>>h>>d;
    fact[0] = 1;
    FOR(i,1,n+1)fact[i]=i*fact[i-1]%MOD;

    ll a = fact[n];
    ll m = 0;
    REP(i,n+1)m = (m+fact[i])%MOD;

    dp[0] = a;
    sum[1] = (sum[0] + dp[0]) % MOD;
    FOR(i,1,d){
        dp[i] = dp[i-1]*m%MOD;
        sum[i+1] = (sum[i] + dp[i]) % MOD;
    }
    FOR(i,d,h){
        dp[i] = (sum[i]-sum[i-d]+MOD)*(m-1)%MOD;
        sum[i+1] = (sum[i] + dp[i]) % MOD;
    }
    printf("%lld\n",dp[h-1]);
    return 0;
}


Measured memory_bytes: 28928
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N,A;
  cin >> N >> A;
 
  int n = N % 500;
  if (A >499 || n == 0 || n < A +1) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
# coding: utf-8
import sys
# import random
# import bisect
# import math
import numpy as np
# from fractions import gcd
# import itertools

"""Template"""


class IP:
    """
    入力を取得するクラス
    """

    def __init__(self):
        self.input = sys.stdin.readline

    def I(self):
        """
        1文字の取得に使います
        :return: int
        """
        return int(self.input())

    def S(self):
        """
        1文字の取得(str
        :return: str
        """
        return self.input()

    def IL(self):
        """
        1行を空白で区切りリストにします(int
        :return: リスト
        """
        return list(map(int, self.input().split()))

    def SL(self):
        """
        1行の文字列を空白区切りでリストにします
        :return: リスト
        """
        return list(map(str, self.input().split()))

    def ILS(self, n):
        """
        1列丸々取得します(int
        :param n: 行数
        :return: リスト
        """
        return [int(self.input()) for _ in range(n)]

    def SLS(self, n):
        """
        1列丸々取得します（str
        :param n: 行数
        :return: リスト
        """
        return [self.input() for _ in range(n)]

    def SILS(self, n):
        """
        Some Int LineS
        横に複数、縦にも複数
        :param n: 行数
        :return: list
        """
        return [self.IL() for _ in range(n)]

    def SSLS(self, n):
        """
        Some String LineS
        :param n: 行数
        :return: list
        """
        return [self.SL() for _ in range(n)]


class Idea:
    def __init__(self):
        pass

    def S(self, s, r=0, m=-1):
        """
        ソート関係行います。色々な設定あります。
        :param s: 元となるリスト
        :param r: reversするかどうか 0=False 1=True
        :param m: （2次元配列）何番目のインデックスのソートなのか
        :return: None
        """
        r = bool(r)
        if m == -1:
            s.sort(reverse=r)
        else:
            s.sort(reverse=r, key=lambda x: x[m])

    def ceil(self, x, y):
        """
        Round up
        小数点切り上げ割り算
        :param x: int
        :param y: int
        :return: int
        """
        return -(-x // y)

    def ave(self, a):
        """
        平均を求めます
        :param a: list
        :return: int
        """
        return sum(a) / len(a)

    def gcd(self, x, y):
        if y == 0:
            return x
        else:
            return self.gcd(y, x % y)

    def lcm(self, x, y):
        return (x * y) // self.gcd(x, y)


"""ここからメインコード"""


def make_divisors(n):
    # divisors = []
    for i in range(2, int(n ** 0.5) + 1):
        if n % i == 0:
            # divisors.append(i)
            return i
            # if i != n // i:
            #     divisors.append(n//i)


def n_to_10(X, n):
    if int(X / n):
        return n_to_10(int(X / n), n) + str(X % n)
    return str(X % n)


def main():
    ip = IP()
    id = Idea()
    """この下から書いてね"""
    n = int(input())
    a = ip.IL()
    b = ip.IL()
    c = ip.IL()
    memo = a[0]
    ans = 0
    for i in range(1, n):
        if memo + 1 == a[i]:
            ans += c[memo-1]
        memo = a[i]
        # print(i, ans)
    print(sum(b) + ans)


main()


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

int XOR(int n, int m){
  int ans=0, k=0;
  while(int(n/(pow(2,k)))!=0 || int(m/(pow(2,k)))!=0){
    if(int(n/(pow(2,k)))%2 != int(m/(pow(2,k)))%2){
      ans += pow(2,k);
    }
    k++;
  }
  return ans;
}

int main(){
  int N; cin >>N;
  int a[N], ans;
  for(int i=0;i<N;i++){
    cin >>a[i];
    if(i==0){
      ans = a[0];
    } else {
      ans = XOR(ans, a[i]);
    }
  }

  if(ans == 0) cout << "Yes" << endl;
  else cout << "No" << endl;

  return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <algorithm>
#include <iomanip>
#include <string.h>

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

typedef long long lint;

using namespace std;

int main(){
  int a[5];
  int k;
  REP(i,5)cin>>a[i];
  cin>>k;
  bool f=true;
  REP(i,5)FOR(j,i+1,5){
    if(a[j]-a[i]>k)f=false;
  }
  cout<<(f?"Yay!":":(")<<endl;
  return 0;
}


Measured memory_bytes: 256
# https://atcoder.jp/contests/abc155/tasks/abc155_a

read row ; A=($row) ; a=A[0] ; b=A[1]; c=A[2]
memo[$a]=1 ; memo[$b]=1 ; memo[$c]=1
num=${#memo[*]}
if [ $((num)) -eq $((2)) ] ; then
  echo "Yes"
else
  echo "No"
fi


Measured memory_bytes: 1144
#include <bits/stdc++.h>
#define N 200007
#define inf 922337203685000000ll
using namespace std;
typedef long long ll;

inline ll rd() {
  ll x = 0;
  bool f = 0;
  char c = getchar();
  while (!isdigit(c)) {
    if (c == '-') f = 1;
    c = getchar();
  }
  while (isdigit(c)) {
    x = x * 10 + (c ^ 48);
    c = getchar();
  }
  return f ? -x : x;
}

priority_queue<pair<int, int> > qa, qb;

int n, a[N], b[N];

inline void print() {
  puts("Yes");
  for (int i = 1; i <= n; ++i) printf("%d ", b[i]);
}

int main() {
  n = rd();
  for (int i = 1; i <= n; ++i) a[i] = rd();
  for (int i = 1; i <= n; ++i) b[i] = rd();
  reverse(b + 1, b + 1 + n);
  int x, l = 0, r, L, R;
  for (int i = 1; i <= n; ++i)
    if (a[i] == b[i]) l ? ++r : l = r = i;
  x = a[l];
  if (!l) {print(); return 0;}
  for (int i = 1; i <= n; ++i)
    if (a[i] == x || b[i] == x) {L = i; break;}
  for (int i = n; i; --i)
    if (a[i] == x || b[i] == x) {R = i; break;}
  if (L - 1 + n - R < (r - l + 1)) {puts("No"); return 0;}
  int lim = min(L - 1, r - l + 1);
  for (int i = 1; i <= lim; ++i) swap(b[i], b[l + i - 1]);
  if (lim == r - l + 1) {print(); return 0;}
  lim = r - l + 1 - lim;
  for (int i = 1; i <= lim; ++i) swap(b[n - i + 1], b[r - i + 1]);
  print();
  return 0;
}


Measured memory_bytes: 5232
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5+5;
const int INF = 1e9;
#define PII pair<int, int>
int rock[maxn];
int dp[maxn];
void do_dp(int n, int k){
	priority_queue<PII, vector<PII>, greater<PII>> pq;
	pq.push(make_pair(0, 1));
	int rh, rn;
	while(!pq.empty()){
		tie(rh, rn) = pq.top(); pq.pop();
		if(dp[rn] != 1e9) continue;
		dp[rn] = rh;
		for(int i = rn + 1; i < rn + 1 + k; i++){
			pq.push(make_pair(rh + abs(rock[i] - rock[rn]), i));	
		}
	}
}
int main(int argc, char const *argv[])
{
	int n, k; scanf("%d %d", &n, &k);
	for(int i = 1; i <= n; i++){
		scanf("%d", &rock[i]);
	}

	fill(dp, dp + n + 1, INF);

	do_dp(n, k);
	printf("%d\n", dp[n]);

	return 0;
}

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

const int N = (int) 2e6 + 10 ;
const long long inf = (long long) 2e18 ;

int lft[N] , rgt[N] , n , k ;
int l = 0 , r = 0 ;
long long lsum[N] , rsum[N] ;

long long R() {
    long long ans = inf , cur = 0 ;
    for( int i = 1 ; i <= r ; i++ ) {
        if( i > k ) break ;
        if( k - i > l ) continue ;
        cur = rgt[i] ;
        if(i < k)cur += rgt[i] + lft[k - i] ;
        ans = min( ans , cur ) ;
    }
    return ans ;
}

long long L() {
    long long ans = inf , cur = 0 ;
    for( int i = 1 ; i <= l ; i++ ) {
        if( i > k ) break ;
        if( k - i > r ) continue ;
        cur = lft[i] ;
        if(i < k)cur += lft[i] + rgt[k - i] ;
        ans = min( ans , cur ) ;
    }
    return ans ;
}

int main(){
//    freopen("in.txt" , "r" , stdin ) ;
    memset( lft , 0 , sizeof(lft)) ;
    memset( rgt , 0 , sizeof(rgt)) ;

    scanf("%d %d" , &n , &k ) ;
    for( int i = 1 ; i <= n ; i++ ) {
        int x ; scanf("%d" , &x ) ;
        if( x >= 0 ) rgt[++r] = x ;
        else lft[++l] = -x ;
    }

    sort(lft + 1 , lft + 1 + l) ;
    sort(rgt + 1 , rgt + 1 + r) ;

    long long ans = min( R() , L() ) ;
    printf("%lld\n" , ans ) ;
    return 0 ;
}


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

int main()
{
    std::string o, e;
    std::cin >> o;
    std::cin >> e;
    for (size_t i = 0; i < e.size(); ++i)
    {
        std::cout << o[i] << e[i];
    }
    if (o.size() != e.size())
    {
        std::cout << o.back();
    }
    std::cout << std::endl;
    return 0;
}


Measured memory_bytes: 3572
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <queue>

#define INF 100000000

using namespace std;

int main()
{
    int a, b, c;
    cin >> a >> b >> c;
    int cnt = 0;
    while (b > 0 && c > 0)
    {
        b--;
        c--;
        cnt += 2;
        if (b == 0 && c > 0) //一回しか入らない
        {
            c--;
            cnt++;
        }
    }
    if (b > c)
    {
        while (b > 0)
        {
            b--;
            cnt++;
        }
    }
    else
    {
        while (a > 0 && c > 0)
        {
            a--;
            c--;
            cnt++;
        }
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<queue>
#include<string>
#include<cmath>
#include<cstdio>
#include<cctype>
#include<cstring>
#include<iomanip>
#include<cstdlib>
#include<ctime>
#include<set>
#include<map>
#include<utility>
#include<vector>
#include<stack>
#include<sstream>
#include<algorithm>
using namespace std;
/****************************/
#define ll long long
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int,int>
#define vpii vector<pair<int,int> >
#define qi queue<int>
#define mii map<int,int>
#define msi map<string,int>
#define vs vector<string>
#define vc vector<char>
/****************************/
#define rep(i,n) for(ll i=0;i<(n);i++)
#define rep2(i,n) for(ll i=(n)-1;i>=0;i--)
#define rep3(i,a,n) for(ll i=(a);i<(n);i++)
#define rep4(i,a,n) for(ll i=(a)-1;i>=n;i--)
#define mp make_pair
#define pb push_back
#define st first
#define nd second
#define pi 3.1415926535897932384626433832795
#define zero(n) memset(n,0,sizeof(n));
#define SZ(n) n.size()
#define sn st.nd 
int dx[4]={1,-1,0,0};
int dy[4]={0,0,1,-1};
/****************************/
ll n;
ll a[110];
int main()
{
	cin>>n;
	rep(i,n)
	{
		cin>>a[i];
	}
	ll now=1000,stock=0;
	rep(i,n)
	{
		now+=stock*a[i];
		if(a[i]<a[i+1])
		{
			stock=now/a[i];
			now%=a[i];
		}
		else
		{
			stock=0;
		}
	}
	cout<<now;
	return 0;
}

Measured memory_bytes: 3584
<?php
  $N = trim(fgets(STDIN));
  $str = trim(fgets(STDIN));
  $list = range('A', 'Z');
  for($i=0;$i<strlen($str);$i++) {
      for($j=0;$j<26;$j++) {
          if($str[$i]==$list[$j]) {
              if($j+$N<=25) {
                echo $list[$j+$N];    
              }
              else {
                  echo $list[$j+$N-26];
              }
          }
      }
  }
  ?>


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

int main(){
    ll int num=100;
    ll int x;
    ll int cnt=0;
    cin>>x;
    while(1){
        if(num>=x){
            cout<<cnt<<endl;
            break;
        }
        cnt++;
        num*=1.01;
    }
    return 0;
}

Measured memory_bytes: 3648
from collections import deque
N, M = map(int, input().split())
A = deque()
[A.append(int(input())) for _ in range(M)]

dp = [0]*(N+3)
dp[0] = 1

for i in range(N+1):
    if A:
        a = A[0]
    else:
        a = 0
    if len(A) >= 2:
        b = A[1]
    else:
        b = 0

    dp[i] = dp[i] % (10**9 + 7)
    if not i+1 == a:
        dp[i+1] += dp[i]
    else:
        A.popleft()
    if not i+2 == b and not i+2 == a:
        dp[i+2] += dp[i]
print(dp[N])


Measured memory_bytes: 52824
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define all(x) (x).begin(),(x).end()
using namespace std;
const int INF=1145141919,MOD=1e9+7;
const int64_t LINF=8931145141919364364,LMOD=998244353;
// const int dy[]={0,-1,0,1,1,-1,-1,1};
// const int dx[]={1,0,-1,0,1,1,-1,-1};

int dp[3010][3010][2];
int main() {
	int n, t; cin >> n >> t;
	int a[n], b[n]; rep(i,n) cin >> a[i] >> b[i];
	for(int i = 0; i < n; ++i) {
		for(int j = 0; j < t; ++j) {
			dp[i + 1][j][0] = max(dp[i + 1][j][0], dp[i][j][0]);
			dp[i + 1][j][1] = max(dp[i + 1][j][1], dp[i][j][1]);
			if(j + a[i] < t) dp[i + 1][j + a[i]][0] = max(dp[i + 1][j + a[i]][0], dp[i][j][0] + b[i]);
			if(j + a[i] < t) dp[i + 1][j + a[i]][1] = max(dp[i + 1][j + a[i]][1], dp[i][j][1] + b[i]);
			if(j < t) dp[i + 1][j][1] = max(dp[i + 1][j][1], dp[i][j][0] + b[i]);
			// cout << i << " " << j << " " << dp[i][j][0] << endl;
		}
	}
	int ans = 0;
	rep(j,t) ans = max(ans, dp[n][j][1]);
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 70784
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<queue>
using namespace std;
#define SIZE 300
#define INF 1000000
typedef pair<int, int>pii;
class maxflow
{
public:
	vector<int>pat[SIZE];
	vector<int>cap[SIZE];
	vector<int>rev[SIZE];
	bool flag[SIZE];
	int dist[SIZE];
	int now[SIZE], ind[SIZE];
	int idx[SIZE];
	int flow;
	int gd;
	void adde(int s, int t, int cp)//多重辺は消してから s->tの容量cpの辺をはる
	{
		pat[s].push_back(t);
		pat[t].push_back(s);
		cap[s].push_back(cp);
		cap[t].push_back(0);
		rev[s].push_back(pat[t].size() - 1);
		rev[t].push_back(pat[s].size() - 1);
	}
	void blockflow(int node, int len, int go, int pt)//ブロックフローを求めて流す
	{
		if (pt == len)
		{
			if (node != go)return;
			int mini = INF, rr = -1;
			for (int i = 0; i < pt; i++)if (cap[now[i]][ind[i]] < mini)mini = cap[now[i]][ind[i]], rr = i;
			for (int i = 0; i < pt; i++)cap[now[i]][ind[i]] -= mini, cap[pat[now[i]][ind[i]]][rev[now[i]][ind[i]]] += mini;
			flow += mini;//mini==INFになったら非有界
			gd = rr;
			return;
		}
		now[pt] = node;
		for (int i = idx[node]; i < pat[node].size(); i++)
		{
			if (dist[pat[node][i]] == dist[node] + 1 && cap[node][i]>0)
			{
				ind[pt] = i;
				blockflow(pat[node][i], len, go, pt + 1);
				if (gd < pt)break;
				else gd = INF;
			}
			idx[node]++;
		}
	}
	void dinic(int st, int go, int num)//dinicのアルゴリズムで最大流を求める 変数flowにmaxflowの値が入る
	{
		flow = 0;
		for (;;)
		{
			queue<pii>que;
			fill(dist, dist + num, INF);
			fill(flag, flag + num, false);
			que.push(make_pair(st, 0));
			for (;;)
			{
				if (que.empty())break;
				pii z = que.front();
				que.pop();
				if (flag[z.first])continue;
				flag[z.first] = true;
				dist[z.first] = z.second;
				for (int i = 0; i < pat[z.first].size(); i++)
				{
					if (dist[pat[z.first][i]]>z.second + 1 && cap[z.first][i] > 0)
					{
						dist[pat[z.first][i]] = z.second + 1;
						que.push(make_pair(pat[z.first][i], z.second + 1));
					}
				}
			}
			if (dist[go] == INF)return;
			gd = INF;
			fill(idx, idx + SIZE, 0);
			blockflow(st, dist[go], go, 0);
		}
	}
	vector<int>getcut(int st, int go, int num)//頂点iがmincutのst側なら1 そうでなければ0
	{
		dinic(st, go, num);
		vector<int>ret;
		for (int i = 0; i < num; i++)ret.push_back(flag[i]);
		return ret;
	}
};
maxflow gr;
int a[111], b[111], c[111], d[111];
int main()
{
	int num;
	scanf("%d", &num);
	for (int i = 0; i < num; i++)scanf("%d%d", &a[i], &b[i]);
	for (int i = 0; i < num; i++)scanf("%d%d", &c[i], &d[i]);
	for (int i = 0; i < num; i++)for (int j = 0; j < num; j++)if (a[i] < c[j] && b[i] < d[j])gr.adde(i + 2, j + num + 2, 1);
	for (int i = 0; i < num; i++)gr.adde(0, i + 2, 1), gr.adde(i + num + 2, 1, 1);
	gr.dinic(0, 1, num + num + 2);
	printf("%d\n", gr.flow);
}


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

int main()
{
	int n,a,b,c,house,sum,mins;
	while (cin >> n, n) {
		vector< vector<int> > road(10, vector<int>(10, 10001));
		for (int i = 0; i < 10; i++)
			road[i][i] = 0;
		for (int i = 0; i < n; i++) {
			cin >> a >> b >> c;
			road[a][b] = road[b][a] = c;
		}
		for (int k = 0; k < 10; k++) {
			for (int i = 0; i < 10; i++) {
				for (int j = 0; j < 10; j++) {
					if (road[i][k] != 10001 && road[k][j] != 10001)
						if (road[i][j] > road[i][k] + road[k][j]) road[i][j] = road[i][k] + road[k][j];
				}
			}
		}
		house = 0;
		mins = 100001;
		for (int i = 0; i < 10; i++) {
			sum = 0;
			for (int j = 0; j < 10; j++) {
				if(road[i][j] != 10001)
					sum += road[i][j];
			}
			if (sum != 0 && mins > sum) {
				mins = sum;
				house = i;
			}
		}
		cout << house << " " << mins << endl;
	}
	return 0;
}

Measured memory_bytes: 1216
module WeightedDirectedGraph
  (Weight : sig
    type t
    val inf : t (* オーバーフローの恐れはないので，max_intとか突っ込んでも良い *)
    val zero : t
    val neg_inf : t (* オーバーフローの恐れはないので，min_intとか突っ込んでも良い *)
    val ( + ) : t -> t -> t
    val compare : t -> t -> int
  end) :
sig
  type 'a church_list = { fold : 'b. ('a -> 'b -> 'b) -> 'b -> 'b }

  val warshall_floyd :
    (* 頂点の数n *)
    int ->
    (* 辺のリスト *)
    (* 頂点は0からn-1までの整数でなくてはならない *)
    (int * int * Weight.t) church_list ->
    (* 辿り着けなければinf，負閉路を含む経路があればneg_infを返す関数 *)
    (int -> int -> Weight.t)
end =
struct
  type 'a church_list = { fold : 'b. ('a -> 'b -> 'b) -> 'b -> 'b }

  let warshall_floyd n es =
    let d = Array.make_matrix n n Weight.inf in
    for v = 0 to n - 1 do
      d.(v).(v) <- Weight.zero
    done;
    es.fold (fun (u, v, c) () ->
      (* c < d.(u).(v) *)
      if 0 < Weight.compare d.(u).(v) c
      then d.(u).(v) <- c) ();
    for i = 0 to n - 1 do
      for j = 0 to n - 1 do
        for k = 0 to n - 1 do
          let open Weight in
          if 
            (* 経路がない場合は更新しない *)
            0 < Weight.compare inf d.(j).(i)
            && 0 < Weight.compare inf d.(i).(k)
            (* d.(j).(i) + d.(i).(k) < d.(j).(k) *)
            && 0 < Weight.compare d.(j).(k) (d.(j).(i) + d.(i).(k))
          then d.(j).(k) <- d.(j).(i) + d.(i).(k)
        done
      done
    done;
    for i = 0 to n - 1 do
      (* 頂点iを通る負閉路がある *)
      if 0 < Weight.compare Weight.zero d.(i).(i) then
        for j = 0 to n - 1 do
          for k = 0 to n - 1 do
            (* 負閉路を通る経路があれば，最短距離を負の無限大で更新 *)
            let open Weight in
            if 0 < Weight.compare inf d.(j).(i) && 0 < Weight.compare inf d.(i).(k)
            then d.(j).(k) <- Weight.neg_inf
          done
        done
    done;
    fun u v -> try d.(u).(v) with _ -> Weight.inf
end

module G = WeightedDirectedGraph (struct
  type t = int
  let zero = 0
  let ( + ) = ( + )
  let inf = max_int
  let neg_inf = min_int
  let compare = compare
end)

let rec select acc trace = function
  | [] -> acc
  | x :: xs -> select ((trace, x, xs) :: acc) (x :: trace) xs
let select xs = select [] [] xs

let rec perm n xs =
  match n, xs with
  | 0, _ -> [[]]
  | _, [] -> []
  | n, xs ->
      List.concat @@
      List.map (fun (xs, x, ys) ->
        List.map (fun xs -> x :: xs) @@
        perm (n - 1) @@
        List.rev_append xs ys) @@
      select xs
(* 与えられたリストからn要素を選ぶ順列を列挙 *)
let perm : int -> 'a list -> 'a list list = fun n xs -> perm n @@ List.rev xs

let () = Scanf.scanf "%d %d %d\n" @@ fun n m r ->
  let rs = Array.init r @@ fun _ -> Scanf.scanf "%d " pred in
  let abcs = Array.init m @@ fun _ -> Scanf.scanf "%d %d %d\n" @@ fun a b c -> a - 1, b - 1, c in
  let d = G.warshall_floyd n { G.fold = fun f -> Array.fold_right (fun ((a, b, c) as e) acc -> f (b, a, c) @@ f e acc) abcs } in
  Printf.printf "%d\n" @@
  List.fold_left (fun acc (r :: rs) ->
    min acc @@
    snd @@
    List.fold_left (fun (r, a) s -> (s, d r s + a)) (r, 0) rs) max_int @@
  perm r @@
  Array.to_list rs


Measured memory_bytes: 13184
#include <bits/stdc++.h>
int main()
{
    using namespace std;
    int K, n(10);
    unsigned int t;
    unsigned int x;
    cin >> K;
    unsigned int result[K];
    queue<unsigned int> m_queue;
    for (int i = 1; i < 10; i++)
    {
        m_queue.push(i);
    }
    for (int i = 0; i < K; i++)
    {
        x = m_queue.front();
        result[i] = x;
        m_queue.pop();
        t = 10 * x + x % 10;
        if (n <= K)
        {
            if (x % 10 != 0)
            {
                m_queue.push(t - 1);
                n++;
            }
            m_queue.push(t);
            n++;
            if (x % 10 != 9)
            {
                m_queue.push(t + 1);
                n++;
            }
        }
    }
    cout << result[K - 1] << endl;
}

Measured memory_bytes: 896
from itertools import combinations

def appliquer(a, cb, n, m, x, c):
	cout = 0
	l = [0]*m
	# ~ print(l, a)
	# ~ print("c",c) 
	# ~ print("cb",cb)
	for i in cb:
		for j in range(m):
			# ~ print("a[i][j] = ",a[i][j])
			l[j]+=a[i][j]
		cout+=c[i]
	# ~ print(cb, cout, l,x)
	return cout if all(i>=x for i in l ) else -1

n,m,y = (int(i) for i in input().split())

c = [0]*n
a = []
for i in range(n):
	t = [int(i) for i in input().split()]
	c[i] = t[0]
	a.append(t[1:])
	
rng = [i for i in range(n)]

ans = 100000000

for x in range (1,n+1):
	comb = list(combinations(rng, x))
	for cb in comb:
		cout = appliquer(a, cb, n, m, y, c)
		if cout>=0:
			ans = min(ans, cout)
			# ~ print(cb,"->",cout)
			
print(ans if ans != 100000000 else -1)


Measured memory_bytes: 9360
import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.typecons;
import std.numeric, std.math;
import core.bitop;

string FMT_F = "%.10f";

static string[] s_rd;
T RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
string RDR()() { return readln.chomp; }
T[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; }
size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }

bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
bool minimize(T)(ref T x, T y) { if (x > y) { x = y; return true; } else { return false; } }
bool maximize(T)(ref T x, T y) { if (x < y) { x = y; return true; } else { return false; } }

long mod = 10^^9 + 7;
void moda(ref long x, long y) { x = (x + y) % mod; }
void mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(ref long x, long y) { x = (x * y) % mod; }

void main()
{
	auto n = RD;
	auto a = RDR.ARR;
	
	long f(long x)
	{
		auto dp = new long[](n+1);
		dp[1] = x;
		long cnt;
		foreach (i; 1..n)
		{
			dp[i+1] = dp[i] + a[i];
			if (-sgn(dp[i+1]) != sgn(dp[i]))
			{
				cnt += abs(dp[i+1]) + 1;
				dp[i+1] = -sgn(dp[i]);
			}
		}
		//stderr.writeln(dp);
		//stderr.writeln(cnt);
		return cnt;
	}
	auto x1 = a[0] == 0 ? 1 : a[0];
	auto x2 = a[0] == 0 ? -1 : -sgn(a[0]);
	long ans1 = f(x1) + (a[0] == 0 ? 1 : 0);
	long ans2 = f(x2) + abs(a[0]) + 1;
	writeln(min(ans1, ans2));
	stdout.flush();
}

Measured memory_bytes: 7172
#include <stdio.h>
#include <math.h>
#define ll long long
int main()
{
    ll n, ans = 0;
    scanf("%lld", &n);
    ll h[n];
    for (int i = 0; i < n; i++)
    {
        scanf("%lld", &h[i]);
    }
    ll arr[n];
    arr[0] = 0;
    arr[1] = fabs(h[1] - h[0]);
    for (int i = 2; i < n; i++)
    {
        arr[i] = fmin(arr[i - 1] + fabs(h[i] - h[i - 1]), arr[i - 2] + fabs(h[i] - h[i - 2]));
    }

    printf("%lld\n", arr[n - 1]);
    return 0;
}

Measured memory_bytes: 1792
gets
array_1 = gets.chomp.split(" ").map(&:to_i).sort.uniq
gets
array_2 = gets.chomp.split(" ").map(&:to_i).sort.uniq

def binary_search(val, array)
  left = 0
  right = array.length

  while left < right do
    mid = (left+right) / 2
    if array[mid] == val
      return true
    elsif val < array[mid]
      right = mid
    else
      left = mid + 1
    end
  end
end

ans = 0
array_1.each do |val|
  if binary_search(val, array_2)
    ans += 1
  end
end

p ans

Measured memory_bytes: 23112
#include <bits/stdc++.h>
#include <iostream>
#include <cstring> 
using namespace std ;
int main()
{
	string a,b ;
	cin >> a ;
	if(a[2]==a[3]&&a[4]==a[5])
		printf("Yes") ;
	else 
		printf("No") ;
		return 0 ;
}

Measured memory_bytes: 256
N, K = map(int, input().split())
x = list(map(int, input().split()))
ans = 10**9
for i in range(N - K + 1):
  cost1 = abs(x[i]) + abs(x[i + K - 1] - x[i])
  if cost1 < ans:
    ans = cost1
  cost2 = abs(x[i + K - 1]) + abs(x[i + K - 1] - x[i])
  if cost2 < ans:
    ans = cost2
print(ans)


Measured memory_bytes: 14392
package main

import (
	"bufio"
	"fmt"
	"io"
	"math"
	"os"
	"strconv"
)

const (
	initialBufSize = 100000
	maxBufSize     = 1000000
)

var sc *bufio.Scanner

func initScanner(r io.Reader) *bufio.Scanner {
	buf := make([]byte, initialBufSize)

	sc := bufio.NewScanner(r)
	sc.Buffer(buf, maxBufSize)
	sc.Split(bufio.ScanWords) // bufio.ScanLines
	return sc
}

func main() {
	sc = initScanner(os.Stdin)
	fmt.Println(resolve(parseProblem()))
}

func parseProblem() (a, b, ab, x, y int) {
	return scanInt(sc), scanInt(sc), scanInt(sc), scanInt(sc), scanInt(sc)
}

func resolve(a, b, ab, x, y int) int {
	minCost := math.MaxInt64
	for i := 0; i <= max(x, y); i++ {
		v := cost(a, b, ab, 2*i, x, y)
		if v < minCost {
			minCost = v
		}
	}
	return minCost
}

func cost(a, b, ab, n, x, y int) int {
	return ab*n + max(0, x-n/2)*a + max(0, y-n/2)*b
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

// snip-scan-funcs
func scanInt(sc *bufio.Scanner) int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return int(i)
}
func scanString(sc *bufio.Scanner) string {
	sc.Scan()
	return sc.Text()
}


Measured memory_bytes: 1784
#include<iostream>

using namespace std;

int main()
{
    int n, m;
    cin >> n >> m;
    bool *b = new bool[n];
    int correct = 0;
    int *penalty = new int[n];
    int tp = 0;

    for (int i = 0; i < n; i++) {
        b[i] = false;
        penalty[i] = 0;
    }
    for (int i = 0; i < m; i++) {
        int num;
        string ret;
        cin >> num >> ret;
        if (b[num - 1] == false && ret == "WA") {
            penalty[num - 1]++;
        } else if (b[num - 1] == false && ret == "AC") {
            b[num - 1] = true;
        }
    }

    for (int i = 0; i < n; i++) {
        if (b[i] == true) {
            correct++;
            tp += penalty[i];
        }
    }

    cout << correct << " " << tp << endl;

    return 0;
}


Measured memory_bytes: 768