akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<stdlib.h>
 
struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
Node root;
Node treeSearch(Node, int);
void insert(int);
void inorder(Node);
void preorder(Node);

int main(){
  int r, i, x;
  char com[20];
  scanf("%d", &r);
 
  for ( i = 0; i < r; i++ ){
    scanf("%s", com);
    if (com[0] == 'f'){
      scanf("%d", &x);
      Node t = treeSearch(root, x);
      if (t != NULL) printf("yes\n");
      else printf("no\n");
    } else if (com[0] == 'i'){
      scanf("%d", &x);
      insert(x);
    } else if (com[0] == 'p'){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }
  }
 
  return 0;
}

Node treeSearch(Node x, int k){
  while(x!=NULL&&k!=x->key){
    if(k<x->key)
      x=x->left;
    else
      x=x->right;
  }
    return x;
}
void insert(int k){
  Node y = NULL;
  Node x = root;
  Node z;
 
  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NULL;
  z->right = NULL;
 
  while(x!=NULL){
    y=x;
    if(z->key < x->key)
      x=x->left;
    else
      x=x->right;
  }
 
  z->parent=y;
 
  if(y==NULL)
    root=z;
  else if(z->key < y->key)
    y->left=z;
  else
    y->right=z;
}
 
 
void inorder(Node x){
  if(x!=NULL){
    inorder(x->left);
    printf(" %d",x->key);
    inorder(x->right);
  }
}
 
void preorder(Node x){
  if(x!=NULL){
    printf(" %d",x->key);
    preorder(x->left);
    preorder(x->right);
  }
   
}
 

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

string c;
int ar[11];

int main(){
ios::sync_with_stdio(0), cin.tie(NULL), cout.tie(NULL);
        cin >> c;
        for (int i = 0; i < c.size(); i++) {
                if (c[i] == 'A') ar[i] = 1;
                if (c[i] == 'T') ar[i] = 1;
                if (c[i] == 'C') ar[i] = 1;
                if (c[i] == 'G') ar[i] = 1;
        }
        for (int i = 1; i < c.size(); i++) {
                if (ar[i]) {
                        ar[i] += ar[i - 1];
                }
        }
        int mx = 0;
        for (int i = 0; i < c.size(); i++)
                mx = max(mx, ar[i]);
        cout << mx;
return 0;
}


Measured memory_bytes: 256
from itertools import permutations

e = [int(input()) for _ in range(5)]

ans = float('inf')
for perm in permutations(e):
    p = list(perm)
    t = 0
    for i in range(5):
        r = p[i] % 10
        if r == 0 or i == 4:
            t += p[i]
        else:
            t += p[i] + 10 - r
    ans = min(ans, t)
print(ans)


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

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

int map[110];
int main(){
    int n, m, x;
    cin >> n >> m >> x;
    
    rep(i,110-1){
        map[i] = 0;
    }
    
    rep(i,m){
        int in;
        cin >> in;
        map[in] = 1;
    }
    
    int costa=0, costb=0;
    
    rep(i,x){
        costa += map[i];
    }
    
    REP(i,x+1,n+1){
        costb += map[i];
    }
//    
//    cout << "a" << costa <<endl;
//    
//    cout << "b" << costb <<endl;
     
    if(costa > costb) cout << costb << endl;
    else cout << costa << endl; 

return 0;
}


Measured memory_bytes: 256
// author : Kartikey Tewari
// date: 2020-02-13   23:10:09
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define endl '\n'
using namespace std;

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

    int h,a;
    cin >> h >> a;
    int b=h/a;
    if (h%a!=0)
    {
        b++;
    }   
    cout << b << endl;

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
  int log[5001] = {0};
  int n;
  while(cin >>n,n){
    int ans = -9999999;
    for(int i=0; i<n; i++){
      cin >>log[i+1];
      log[i+1]+=log[i];
    }
    for(int i=0; i<=n; i++){
      for(int j=i+1; j<=n; j++){
	if(ans < log[j]-log[i]){ans = log[j]-log[i];}
      }
    }
    cout <<ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 1184
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
#define LIMIT 1000000007 //10^9+7
#define rep(i, n) for(int i=0; i<(int)n; i++)
#define all(v) (v).begin(), (v).end()

template<class H>
void CIN(H& h){cin>>h;}
template<class H, class... T>
void CIN(H &h, T&... t){cin>>h;CIN(t...);}

int main(){
	vi z(5);
  rep(i,5)cin>>z[i];
  int k;cin>>k;

  bool ok = false;
  for(int i=0; i<5; i++){
    for(int j=i+1; j<5; j++){
      if(z[j]-z[i]>k)ok=true;
    }
  }


  cout<<(ok?":(":"Yay!")<<endl;
}

Measured memory_bytes: 3572
#include <iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<iomanip>

using namespace std;

int main()
{
	setprecision(20);
	int n;
	cin >> n;
	int a[5000], b[5000], c[5000];
	for (int i = 1; i <= n; i++)
		cin >> a[i] >> b[i];
	double sum = 0;
	for (int i = 1; i <= n; i++)
		c[i] = i;
	int j = 0;
	double k = 0;
	for (int i = 2; i <= n; i++)
		k += (double)sqrt((a[c[i]] - a[c[i - 1]]) * (a[c[i]] - a[c[i - 1]]) + (b[c[i]] - b[c[i - 1]]) * (b[c[i]] - b[c[i - 1]]));
	
	sum += k;

	while ((next_permutation(c + 1, c + n + 1))){
		
		double k = 0;
		for (int i = 2; i <= n; i++) 
			k+= (double)sqrt((a[c[i]] - a[c[i - 1]]) * (a[c[i]] - a[c[i - 1]]) + (b[c[i]] - b[c[i - 1]]) * (b[c[i]] - b[c[i - 1]]));
			
			sum += k;
		}
	int pr = 1;
	for (int i = 2; i <= n; i++)
		pr *= i;
	cout << setprecision(20)<< sum/pr;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
long long n,m,s[200000],a[200000];
int main()
{
    ios::sync_with_stdio(0);
    cin>>n;
    for(int i=2; i<=n; i++)
    {
        cin>>a[i];
        s[a[i]]++;
    }
    for(int i=1; i<=n; i++)
    {
        cout<<s[i]<<endl;
    }
}


Measured memory_bytes: 6668
#include<iostream>
#include<string>
#include<string.h>
#include<map>
#include<set>
#include<vector>
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue> 
using namespace std;
int main() 
{int n;
 cin>>n;
 cout<<n*800-n/15*200; 
 
 system("pause");
 return 0;
}        

Measured memory_bytes: 504
using System;
using System.Linq;
class Hello
{
    public static void Main()
    {
        int n = int.Parse(Console.ReadLine());
        int k = int.Parse(Console.ReadLine());
        var x = Console.ReadLine().Split().Select(int.Parse);
        var sum = x.Sum(e => Math.Min(e * 2, Math.Abs(e - k) * 2));
        Console.WriteLine(sum);
    }
}


Measured memory_bytes: 13396
#include <vector>
#include <list>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <cassert>
using namespace std;
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
const double EPS = 1e-10;
const double PI  = acos(-1.0);

int dfs(vvi &neighbors,int index,vi &b,map<pair<ll,int>,int> &dp,ll mask){
	if(index==neighbors.size()){
		return 0;
	}
	if(EXIST(dp,make_pair(mask,index))){
		return dp[make_pair(mask,index)];
	}
	int ret=0;
	REP(i,(mask&(1LL<<index))?1:2){
		ll newmask=mask;
		newmask|=(1LL<<index);
		if(i){
			REP(j,neighbors[index].size()){
				newmask|=(1LL<<neighbors[index][j]);
			}
		}
		ret=max(ret,dfs(neighbors,index+1,b,dp,newmask)+(i?b[index]:0));
	}
	return dp[make_pair(mask,index)]=ret;
}
int main(){
	int n;
	while(cin>>n,n){
		vs a(n);
		vi b(n),c(n);
		vector<vector<string> > d(n);
		REP(i,n){
			cin>>a[i]>>b[i]>>c[i];
			REP(j,c[i]){
				string dd;
				cin>>dd;
				d[i].push_back(dd);
			}
		}
		vvi neighbors(n);
		REP(i,n){
			REP(j,n){
				if(find(ALL(d[i]),a[j])!=d[i].end()){
					neighbors[i].push_back(j);
				}
			}
		}

		map<pair<ll,int>,int> dp;
		int ans=0;
		dp[make_pair(1,0)]=b[0];
		ll mask=1;
		REP(j,neighbors[0].size()){
			mask|=(1LL<<neighbors[0][j]);
		}
		ans=dfs(neighbors,1,b,dp,mask)+b[0];
		cout<<ans<<endl;
	}
}

Measured memory_bytes: 16144
import java.io.BufferedReader
import java.io.BufferedWriter

fun main() = Case().exec(::solve)
//fun main() = TestExecutor.assert(testCase) { Case(it.r, it.w).exec(::solve) }

/** https://atcoder.jp/contests/abc176/tasks/abc176_e **/
fun solve(c: Case) {
    val (h, w, m) = c.intList()
    val targets = (0 until m).map { c.intList().map { it - 1 } }
    val hScores = targets.map { it[0] }.groupingBy { it }.eachCount()
    val wScores = targets.map { it[1] }.groupingBy { it }.eachCount()

    val hMax = hScores.entries.maxBy { it.value }!!.value
    val hMaxRows = hScores.entries.filter { it.value == hMax }.map { it.key }.toSet()
    val wMax = wScores.entries.maxBy { it.value }!!.value
    val wMaxRows = wScores.entries.filter { it.value == wMax }.map { it.key }.toSet()

    if (hMaxRows.size * wMaxRows.size > targets.size) {
        c.println((hMax + wMax).toString())
        return
    }
    val mPosSet = targets.map { it[0] to it[1] }.toSet()
    hMaxRows.forEach { h ->
        wMaxRows.forEach { w ->
            if (!mPosSet.contains(h to w)) {
                c.println((hMax + wMax).toString())
                return
            }
        }
    }
    c.println((hMax + wMax - 1).toString())
}

class Case(
    private val input: BufferedReader = System.`in`.bufferedReader(),
    private val out: BufferedWriter = System.out.bufferedWriter()
) {
    fun exec(fn: (Case) -> Unit) = input.use { out.use { execInThread(fn) } }
    private fun execInThread(fn: (Case) -> Unit) =
        Thread(null, { fn(this) }, "solve", 64 * 1024 * 1024)
            .apply { setUncaughtExceptionHandler { _, e -> e.printStackTrace(); kotlin.system.exitProcess(1) } }
            .apply { start() }.join()

    fun println(c: CharSequence?) = out.appendln(c)
    fun string(): String = input.readLine().trimEnd()
    fun long(): Long = input.readLine().toLong()
    fun intList(): List<Int> = input.readLine().split(" ").map { it.toInt() }
    fun longList(): List<Long> = input.readLine().split(" ").map { it.toLong() }
}

Measured memory_bytes: 187904
// 問題の URL を書いておく
// 

#include <algorithm>
#include <array>
#include <bitset>
#include <cmath>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>

using namespace std;

//#define ENABLE_PRINT

#if defined(ENABLE_PRINT)

#define Print(v) \
do {\
    cout << #v << ": " << v << endl; \
}while(0)

#define PrintVec(v) \
do {\
    for(int __i = 0; __i < v.size(); ++__i) \
    { \
        cout << #v << "[" << __i << "]: " << v[__i] << endl; \
    }\
}while(0)

#else

#define Print(v) ((void)0)
#define PrintVec(v) ((void)0)

#endif

#define rep(i, n) for(int i = 0; i < (int)(n); ++i)

using ll = int64_t;

int main(int, const char**)
{
    int x;
    cin >> x;
    cout << (x >= 30 ? "Yes" : "No") << endl;
    return 0;
}


Measured memory_bytes: 3592
import math
def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

check = False
s = int(input())
if s < 3:
    print(0)
    check = True
count = 0

if check == False:
    for i in range(2,s):
        try:
            count += combinations_count(s-i*3+(i-1), i-1)
        except ValueError:
            break
    print((count+1) % (10**9+7))   

Measured memory_bytes: 9196
module Main where

import Control.Applicative
import Control.Monad
import Data.List
import qualified Data.ByteString.Char8 as B

readi b | Just (n, _) <- B.readInt b = n

slice :: Int -> [a] -> [a]
slice d xs = unfoldr f xs
  where
    f []     = Nothing
    f (y:ys) = Just (y, drop (d - 1) ys)

main :: IO ()
main = do
    n <- readLn :: IO Int
    as <- B.words <$> B.getLine :: IO [B.ByteString]

    let ods = slice 2 as
    let evs = slice 2 (tail as)

    let ans = if odd n
        then reverse ods ++ evs
        else reverse evs ++ ods

    B.putStrLn $ B.unwords ans

Measured memory_bytes: 48380
#include <bits/stdc++.h>
#define N 1000005
#define ll long long int 	
#define MP make_pair
#define pb push_back
#define ppb pop_back
#define sp " "
#define endl "\n"
#define fi first
#define se second
#define ii pair<int,int>
#define lli pair<ll,ll>
#define fast cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(false)
#define fast2 freopen ("badhair.gir","r",stdin);freopen ("badhair.cik","w",stdout);
#define mod 1000000007
#define fs(x,y) for(ll i=1;i<=y;i++) cin>>x[i]
#define fo(i,x,y) for(ll i=x;i<=y;i++)
#define INF 1000000000005
using namespace std;

ll n,m,ar[N],sum,t,ans[N],cnt[N];



int main()
{
	fast;
	cin>>n>>m;
	ans[1]=1;
	for(int i=1;i<=n;i++)
		cnt[i]=1;
	for(int i=1;i<=m;i++)
	{
		int a,b;
		cin>>a>>b;
		cnt[b]++;
		cnt[a]--;
		if(ans[a])
			ans[b]=1;
		if(!cnt[a])
			ans[a]=0;
	}
	for(int i=1;i<=n;i++)
	{
		// cout<<cnt[i]<<sp<<ans[i]<<endl;
		if(ans[i])
			sum++;
	}
		cout<<sum<<endl;
}



/*     cd onedrive\desktop\kod
cls

Sinav:21-22 aralik
Aciklama: Muhtemelen 25 aralik
*/

Measured memory_bytes: 7168
#include <iostream>

using namespace std;

int main() {
  int xy[2];
  cin >> xy[0] >> xy[1];

  int f = xy[0] < xy[1];
  while (xy[1 - f]) {
    xy[f] %= xy[1 - f];
    f ^= 1;
  }
  cout << xy[f] << endl;
  return 0;
}



Measured memory_bytes: 3088
#include <cstdio>
#include <cstdlib>
#include <utility>
#include <typeinfo>
#include <cmath>
#include <numeric>
#include <algorithm>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <vector>
#include <string>
#define REP(i,n) for(int i=0;i<n;i++)
typedef long long ll;
using namespace std;
typedef vector<ll> vl;
typedef pair<ll,ll> pll;
typedef vector<pll> vpll;
typedef vector<string> vs;

int main() 
{
	int n;
	while(scanf("%d",&n)&&n)
	{
		pair<double,string> ans[50];
		REP(i,n)
		{
			char name[21];
			double p,a,b,c,d,e,f,s,m;
			scanf("%s%lf%lf%lf%lf%lf%lf%lf%lf%lf",name,&p,&a,&b,&c,&d,&e,&f,&s,&m);
			ans[i]=make_pair(-(f*s*m-p)/(a+b+c+m*(d+e)),name);
		}
		sort(ans,ans+n);
		
//		int mi(0);
//		REP(i,n)if(ans[i].first<0)mi++;
//		reverse(ans,ans+mi);
//		rotate(ans,ans+mi,ans+n);
		
		REP(i,n){printf("%s\n",ans[i].second.c_str());}
		printf("#\n");
	}
	return 0;
}

Measured memory_bytes: 1248
#include<bits/stdc++.h>
using namespace std;
int main(){
int s;
  cin>>s;
  if(s==22){
    cout<<"Christmas Eve Eve Eve";
  }
  else if(s==23){
    cout<<"Christmas Eve Eve ";
  }
  else if(s==24){
    cout<<"Christmas Eve ";
  }
  else{
    cout<<"Christmas";
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define inf 1001001001
#define mod 1000000007
#define mod2 998244353
#define pi acos(-1)
#define all(x) (x).begin(),(x).end()
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 dx[4] = {0,-1,0,1};
int dy[4] = {-1,0,1,0};
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int x, y;
    bool flag = false;
    cin >> x;
    cin >> y;
    rep(i, x + 1) {
      if (2*i + 4*(x - i) == y) {
        cout << "Yes" << endl;
        flag = true;
        break;
      }
    }
    if (!flag) {
      cout << "No" << endl;
    }
}

Measured memory_bytes: 3608
#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[3];
  REP(i,3)cin>>A[i];
  sort(A,A+3);
  cout<<((A[0]==A[1] and A[1]!=A[2])or(A[1]==A[2] and A[1]!=A[0]) ?"Yes":"No")<<endl;
  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 P = pair<int, int>;
using ll = long long;

int main(){
	string s;
  	cin >> s;
  	
  	if(s.back() == 's') s.push_back('e');
  	s.push_back('s');
  	
  	cout << s << endl;
}

Measured memory_bytes: 3628
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    Scanner sc = new Scanner(System.in);
  
    public static void main(String[] args) {
        new Main(); 
    }
  
    public Main() {
    	new B().doIt();
    }
    class B{
    	void doIt(){
    		int n = sc.nextInt();
    		int m = sc.nextInt();
    		String a[] = new String [n];
    		for(int i = 0;i < n;i++){
    			a[i] = sc.next();
    		}
    		Arrays.sort(a);
    		for(int i = 0;i < n;i++){
    			System.out.print(a[i]);
    		}
    		System.out.println();
    	}
    }
}

Measured memory_bytes: 10132
#include <cstdio>
#include <algorithm>

using namespace std;

#define chmin(a,b) a=min(a,b)
#define rep(i,x) for(int i=0;i<(x);++i)

const int inf = 1e9;

int d[10][10];
int N;

void wf()
{
	rep(k, 10) rep(i, 10) rep(j, 10) {
		chmin(d[i][j], d[i][k] + d[j][k]);
	}
}

int main()
{
	while (scanf("%d", &N), N) {
		fill(d[0], d[10], inf);
		rep(i, 10) d[i][i] = 0;

		rep(i, N) {
			int a, b, c; scanf("%d %d %d", &a, &b, &c);
			d[a][b] = d[b][a] = c;
		}

		wf();

		int mi = inf, a;

		rep(i, 10) {
			int sum = 0;
			rep(j, 10) {
				if (d[i][j] != inf) sum += d[i][j];
			}
			if (sum != 0 && mi > sum) {
				mi = sum;
				a = i;
			}
		}

		printf("%d %d\n", a, mi);
	}
}

Measured memory_bytes: 1028
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <numeric>
#include <queue>
#include <map> 
#include <set>
#include <string>
#include <functional>
#include <list>
#include <random>
#include <time.h>
#include <iomanip>
#include <assert.h>
#define int long long
#define double long double
#define oku7 1000000007
#define MAXN (int)1e+5 * 2+1
#define LL_MAX 9223372036854775807	//ない環境用
#define LL_HALFMAX 9223372036854775807 / 2	//ない環境用

using namespace std;
std::mt19937 mt((int)time(0));

int dx[4] = { 0, 1, 0, -1 }; // x軸方向への変位
int dy[4] = { 1, 0, -1, 0 }; // y軸方向への変位

int nC2(int n) {
	return n * (n - 1) / 2;
}

signed main() {
	int ans = 0;
	int N, M;
	int A[1000000], sum[1000000];
	cin >> N >> M;
	int s = 0;
	for (int i = 0; i < N; i++) {
		cin >> A[i];
		s += A[i];
		sum[i] = s;
	}
	map<int, int> ma;
	for (int i = 0; i < N; i++) {
		ma[sum[i] % M]++;
		if (sum[i] % M == 0) ans++;
	}
	for (pair<int, int> p : ma) {
		if (p.second >= 2) ans += nC2(p.second);
	}

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

Measured memory_bytes: 10368
#include <bits/stdc++.h>
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rrep(i, n) for(int i = ((int)(n)-1); i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define fill(x, y) memset(x, y, sizeof(x))
 
using namespace std;
 
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; }
 
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> P;
 
const int INF = 1e9;
const int MOD = 1e9+7;
const double EPS = 1.0e-12;
const double PI = acos(-1.0);

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

	vi p,ans;
	rep(i,s.size()) if(s[i] == '0') p.push_back(i);
	int i = n,flag = 1;
	while(i > 0){
		int d = *lower_bound(all(p),max(0,i-m));
		if(i == d) { flag = 0; break; }
		ans.push_back(i-d);
		i = d;
	}
	if(flag){
		reverse(all(ans));
		for(int i = 0; i < ans.size(); i++){
			cout << ans[i] << (i!=ans.size()-1?" ":"\n");
		}
	}else{
		cout << -1 << endl;
	}
	return 0;
}

Measured memory_bytes: 1592
#include<bits/stdc++.h>
#define mo 1000000007
using namespace std;
long long n,i,j,jc[200005],ny[200005],x[200005],y[200005],f[4005][4005],ans;
long long read(){
	char ch=getchar();
	long long xx=0;
	while(ch<'0'||ch>'9')
		ch=getchar();
	while(ch>='0'&&ch<='9'){
		xx=xx*10+ch-'0';
		ch=getchar();
	}
	return xx;
}
long long ksm(long long u,long long v){
	long long o=1;
	while(v){
		if(v&1)
			o=o*u%mo;
		u=u*u%mo;
		v>>=1;
	}
	return o;
}
long long C(long long u,long long v){
	return jc[u]*ny[v]%mo*ny[u-v]%mo;
}
int main(){
	n=read();
	jc[0]=1;ny[0]=1;
	for(i=1;i<=8000;i++){
		jc[i]=jc[i-1]*i%mo;
		ny[i]=ksm(jc[i],mo-2);
	}
	for(i=1;i<=n;i++){
		x[i]=read();
		y[i]=read();
		f[-x[i]+2001][-y[i]+2001]++;
	}
	for(i=1;i<=4001;i++)
		for(j=1;j<=4001;j++)
			f[i][j]=(f[i][j]+f[i-1][j]+f[i][j-1])%mo;
	for(i=1;i<=n;i++)
		ans=(ans+f[x[i]+2001][y[i]+2001])%mo;
	for(i=1;i<=n;i++)
		ans=(ans-C(x[i]+y[i]<<1,x[i]<<1)+mo)%mo;
	ans=ans*ksm(2,mo-2)%mo;
	printf("%lld\n",ans);
	return 0;
}

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

struct BipartiteMatching {
    int n;
    vector<vector<int>> g;
    vector<int> match;
    vector<bool> used;
    BipartiteMatching(int n) : n(n), g(n), match(n), used(n) {}
    void addEdge(int u, int v) {
        g[u].push_back(v);
        g[v].push_back(u);
    }
    int maxmimumMatching(void) {
        int res = 0;
        match.assign(n, -1);
        fill(match.begin(), match.end(), -1);
        for(int v = 0; v < n; ++v){
            if (match[v] < 0) {
                used.assign(n, false);
                if (augument(v)) res++;
            }
        }
        return res;
    }
    bool augument(int v) {
        used[v] = true;
        for (int u : g[v]) {
            int w = match[u];
            if (w < 0 || (!used[w] && augument(w))) {
                match[v] = u; 
                match[u] = v;
                return true;
            }
        }
        return false;
    }
};

#include <iostream>
int main() {
    int X, Y, E;
    while (cin >> X >> Y >> E) {
        BipartiteMatching bm(X + Y);
        for (int i = 0; i < E; ++i) {
            int x, y;
            cin >> x >> y;
            bm.addEdge(x , y + X);
        }
        cout << bm.maxmimumMatching() << endl;
    }
}

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


int main(){
    int A,B;cin>>A>>B;
    int ans=0;
    for(int i=A;i<B+1;++i){
        int listOfDigits[5];
        int tmp=i;
        for(int j=0;j<5;j++){
            
            listOfDigits[j]=tmp%10;
            tmp/=10;
        }
        if(listOfDigits[0]==listOfDigits[4]&&
            listOfDigits[1]==listOfDigits[3]){
                ans++;
            }
    }

    
    cout<<ans<<endl;
}

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

int main() {
  ll h;
  cin >> h;
  ll cnt = 0;
  while(h != 0) {
    // cout << h << endl;
    h = h / 2;
    ++ cnt;
  }
  ll ans = 1;
  rep(i, cnt) {
    ans = ans*2;
  }
  cout << ans -1 << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <tuple>
#include <queue>
#include <stack>
#include <set>
#include <map>

using namespace std;

class Solver {
};

int main() {
	while (true) {
		int n;
		cin >> n;
		if (n == 0)break;

		vector<long>vals;
		long now = 1;
		while (true) {
			long val = (now * (now + 1) * (now + 2)) / 6;
			if (val > n)break;
			vals.emplace_back(val);
			now++;
		}
		vector<int> cnts(n + 1, 1e9);
		vector<int> oddCnts(n + 1, 1e9);
		cnts[0] = 0;
		oddCnts[0] = 0;
		for (int i = 0; i < vals.size(); i++) {
			for (int j = 0; j <= n; j++) {
				if (j + vals[i] <= n) {
					cnts[j + vals[i]] = min(cnts[j + vals[i]], cnts[j] + 1);
				}
				if (vals[i] % 2 == 1 && j + vals[i] <= n) {
					oddCnts[j + vals[i]]
						= min(oddCnts[j + vals[i]], oddCnts[j] + 1);
				}
			}
		}
		cout << cnts[n] << ' ' << oddCnts[n] << endl;
	}
}


Measured memory_bytes: 14072
import java.util.Scanner;

public class Main {
    public static void main(String... args) {
        Scanner sc = new Scanner(System.in);
        while(true) {
            int m = sc.nextInt();
            int f = sc.nextInt();
            int r = sc.nextInt();
            if(m == -1 && f == -1 && r == -1) break;
            if(m == -1 || f == -1) { System.out.println('F'); continue; }
            if(m + f >= 80) { System.out.println('A'); continue; }
            if(m + f >= 65) { System.out.println('B'); continue; }
            if(m + f >= 50) { System.out.println('C'); continue; }
            if(m + f >= 30) {
                if(r >= 50) System.out.println('C');
                else System.out.println('D');
                continue;
            }
            System.out.println('F');

        }
    }
}



Measured memory_bytes: 26340
// Problem : A - Coffee
// Contest : AtCoder Beginner Contest 160
// URL : https://atcoder.jp/contests/abc160/tasks/abc160_a
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

// Author - Sumit 
 
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long 
#define int ll
#define ps push
#define pb emplace_back
#define INF 10000000000000LL
#define MOD 1000000007
#define mp make_pair
#define rep(i,a,b) for (int i = a; i < b; i++)
#define repd(i,a,b) for (int i = a; i >= b; i--)
#define all(v) v.begin(),v.end()
#define pii pair<int,int>
#define F first
#define S second
#define mii map<int,int>
#define vi vector<int>
#define vvi vector<vi>
#define vpii vector<pair<int,int>>
#define itr :: iterator it
#define WL(t) while(t --)
#define gcd(a,b) __gcd((a),(b))
#define lcm(a,b) ((a)*(b))/gcd((a),(b))
#define lower(v,x) (lower_bound(all(v),x)-v.begin())
#define upper(v,x) (upper_bound(all(v),x)-v.begin())
#define debug(x) cout << x << "\n";
#define debug2(x,y) cout << x << " " << y << "\n";
#define debug3(x,y,z) cout << x << " " << y << " " << z << endl;
 
template<typename T, typename U> inline void remin(T &x, U y) { if(y < x) x = y; }
template<typename T, typename U> inline void remax(T &x, U y) { if(x < y) x = y; }
template<typename T> T pow(T a,T b, int m){T ans=1; while(b>0){ if(b%2==1) ans=(ans*a)%m; b/=2; a=(a*a)%m; } return ans%m; }
 
void solve(){
    string s;
    cin>>s;
    if(s[2]==s[3] && s[4]==s[5]){
    	debug("Yes");
    }else{
    	debug("No");
    }
}
 
signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    
    int t=1;
    //cin>>t;
    while(t--){
        solve();
    }
}

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

int
main()
{
  unsigned N;
  vector<int> A{};
  cin >> N;
  A.resize(N);
  for (size_t i = 0; i < N; i++) {
    cin >> A[i];
  }

  uint64_t stools = 0;
  int a, b;
  for (size_t i = 1; i < N; i++) {
    a = A[i];
    b = A[i - 1];
    stools += max(0, b - a);
    A[i] = max(b, a);
  }
  cout << stools << endl;
  return 0;
}


Measured memory_bytes: 3636
//! ----------------------------------------------
//! Framework <https://github.com/vain0x/procon>
//!
//! See the bottom of file for solution.
//! ----------------------------------------------

#![allow(unused_imports)]
#![allow(non_snake_case)]

use std::cell::RefCell;
use std::cmp::{max, min, Ordering};
use std::collections::*;
use std::fmt::{Debug, Display, Formatter, Write as FmtWrite};
use std::io::{stderr, stdin, BufRead, Write};
use std::mem::{replace, swap};
use std::ops::*;
use std::rc::Rc;

/// Print values to standard error if debug mode.
#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), stderr());
            writeln!(err, "\x1B[33m{}\x1B[0m = {:?}", e, $e).unwrap()
        })*
    };
}

/// Read from standard input and parse each word.
/// - `read!(T, U, ..)` parses a line as a tuple of words.
/// - `read![[T]]` parses a line as an array of words.
/// - `read![..; N]` parses `N` lines, using `read!(..)` repeatedly.
#[allow(unused_macros)]
macro_rules! read {
    ([$t:ty] ; $n:expr) =>
        ((0..$n).map(|_| read!([$t])).collect::<Vec<_>>());
    ($($t:ty),+ ; $n:expr) =>
        ((0..$n).map(|_| read!($($t),+)).collect::<Vec<_>>());
    ([$t:ty]) =>
        (rl().split_whitespace().map(|w| w.parse().unwrap()).collect::<Vec<$t>>());
    ($($t:ty),*) => {{
        let buf = rl();
        let mut w = buf.split_whitespace();
        ($(w.next().unwrap().parse::<$t>().unwrap()),*)
    }};
}

/// Read a line from standard input.
#[allow(dead_code)]
fn rl() -> String {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();

    #[allow(deprecated)]
    buf.trim_right().to_owned()
}

// -----------------------------------------------
// Solution
// -----------------------------------------------

const P: i64 = 1_000_000_007;

pub fn pow(x: i64, n: usize) -> i64 {
    let (mut x, mut y, mut n) = (x % P, 1_i64, n);
    while n > 0 {
        if n % 2 != 0 {
            y = (y * x) % P;
            n -= 1;
        }

        x = (x * x) % P;
        n /= 2;
    }
    y
}

fn inv(x: i64) -> i64 {
    pow(x, (P - 2) as usize)
}

fn main() {
    let (N, K) = read!(usize, usize);

    let mut fact = vec![0; N + 2];
    fact[0] = 1;
    for i in 1..fact.len() {
        fact[i] = fact[i - 1] * i as i64 % P;
    }

    for i in 1..K + 1 {
        let count = if N - K < i - 1 {
            0
        } else {
            let mut u = fact[K - 1];
            u *= inv(fact[K - i]);
            u %= P;
            u *= inv(fact[i - 1]);
            u %= P;

            let mut r = fact[N - K + 1];
            r *= inv(fact[N + 1 - K - i]);
            r %= P;
            r *= inv(fact[i]);
            r %= P;

            u * r % P
        };
        println!("{}", count)
    }
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define reprep(i,j,w,h) rep(j,h)rep(i,w)
#define rrep(i,m, n) for(int i = m; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define aall(x,n) (x).begin(),(x).begin()+(n)
#define VEC(type,name,n) std::vector<type> a(n);rep(i,n)std::cin >> a[i];
#define pb push_back
#define pf push_front
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define sum accumulate
#define keta fixed<<setprecision
#define vvector(name,typ,m,n,a)vector<vector<typ> > name(m,vector<typ> (n,a))
#define vvvector(name,t,l,m,n,a) vector<vector<vector<t> > > name(l, vector<vector<t> >(m, vector<int>(n,a)));
typedef long long ll;
const int INF = 2000000000;
const long INF64 = 1000000000000000ll;
const ll MOD = 1000000007LL;
int main(){
    int n;
    string s;
    std::cin >> n;
    std::cin >> s;
    rep(i,s.size()){
        int ss=s[i]-'A';
        ss=(ss+n)%26;
        s[i]=ss+'A';
    }
    std::cout << s << std::endl;
    
}

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

#define FOR(i, a, b) for (int i = a; i < b; i++)
#define REP(i, n) FOR(i, 0, n)
int main()
{
    int a,b,c,d;
    cin >>a>>b>>c>>d;
    int start = max(a, c);
    int end  = min(b, d);
    if((end - start) > 0){
        cout << end - start << endl;
    }else{
        cout << 0 << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <queue>
using namespace std;  
#define MAXN 1001  
typedef struct NODE  
{  
    int x;  
    int y;  
    int step;  
}S;  
queue<S> q;  
int f[4][2] = {{-1,0},{1,0},{0,-1},{0,1}};  
int vis[MAXN][MAXN] = {0};  
char map[MAXN][MAXN];
int X, Y;  
bool IsValid(int i,int j)   
{  
    return (i >= 1 && i <= X) && (j >= 1 && j <= Y);
}    
int bfs()  
{  
    S s;    
    s.x = 1;    
    s.y = 1;    
    s.step = 0;   
    vis[1][1] = 1;    
    q.push(s);   
    while (!q.empty())  
    {  
        struct NODE t_s,tmp;   
        t_s = q.front();    
        q.pop();   
        for (int i=0;i<4;i++)   
        {    
            tmp.x = t_s.x + f[i][0] ;    
            tmp.y = t_s.y + f[i][1] ;    
            tmp.step = t_s.step + 1;    
            if (IsValid(tmp.x, tmp.y) && vis[tmp.x][tmp.y] == 0 && map[tmp.x][tmp.y] == '.')   
            {    
                vis[tmp.x][tmp.y] = 1;   
                if (tmp.x == X && tmp.y == Y)  
                    return tmp.step;    
                q.push(tmp);    
            }   
        }   
    }   
    return -1;  
}  
int main()  
{  
	int i,j;
    int x, y;  
    int counter = 0;
    scanf("%d %d", &X, &Y);  
    for(i = 1; i <= X; i++)  
    { 
    	getchar();
    	for(j = 1 ; j <= Y ; j++)
		{
			scanf("%c", &map[i][j]);  
			if(map[i][j] == '#')
			{
				counter++;
			}
		}
    }  
    int count = bfs();
    if(count == -1)
	{
		printf("-1\n");
	}
	else
	{
		 printf("%d\n",X * Y - counter - count - 1);
	}
    return 0;  
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int main()
{
    ll test,i,j=0,k,m;
    cin>>i>>j>>m;
    if(j==i && i!=m || j==m && m!=i || i==m && i!=j )cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
#include<string>
#include<vector>
#include<queue>
using namespace std;
const int mod = 1000000007;
#define ll long long

int main()
{
	int N; cin >> N;
	int j = 1;
	ll sum = 0;
	while (sum < N) {
		sum += j;
		j++;
	}
	sum -= N;
	for (int i = 1; i < j; i++) {
		if (i != sum) {
			cout << i << endl;
		}
	}
}

Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
typedef long long ll;
typedef double dd;
#define For(i,j,k) for (int i=(int)j;i<=(int)k;++i)
#define Forr(i,j,k) for (int i=(int)j;i>=(int)k;--i)
#define Set(a,p) memset(a,p,sizeof(a))
using namespace std;

template<typename T>bool chkmax(T &a,T b) { return a<b?a=b,1:0; }
template<typename T>bool chkmin(T &a,T b) { return a>b?a=b,1:0; }

const int maxn=25000+100;
const int maxk=500+10;
const int K=500;
const int modd=1e9+7;
int n,m,k;
int Ans;
int a[maxn],dp1[maxn][maxk],dp2[maxn][maxk];
int fac[maxk],inv[maxk],lst[maxk];

inline void file() {
	freopen("ARC100F.in","r",stdin);
	freopen("ARC100F.out","w",stdout);
}

inline int read() {
	int x=0,p=1;
	char c=getchar();
	while (!isdigit(c)) { if (c=='-') p=-1; c=getchar();}
	while (isdigit(c)) { x=(x<<1)+(x<<3)+(c-'0'); c=getchar();}
	return x*p;
}

inline int quick(int a,int b) {
	int s=1;
	while (b) {
		if (b%2==1) s=1ll*s*a%modd;
		a=1ll*a*a%modd; b/=2;
	}
	return s;
}

inline void Add(int &a,int b) {
	a+=b; a=(a>=modd?a-modd:a); a=(a<0?a+modd:a);
}

inline void init() {
	fac[0]=inv[0]=1;
	For (i,1,K) fac[i]=1ll*fac[i-1]*i%modd;
	inv[K]=quick(fac[K],modd-2);
	Forr (i,K-1,1) inv[i]=1ll*inv[i+1]*(i+1)%modd;
}

inline void solve1() {
	dp1[0][0]=1;
	For (i,0,n-1) {
		int sum1=0,sum2=0;
		Forr (j,k-1,0) {
			Add(sum1,dp1[i][j]);
			if (j) Add(dp1[i+1][j],sum1);
			if (j<k-1) Add(dp1[i+1][j+1],1ll*(k-j)*dp1[i][j]%modd);
		}
		Forr (j,k-1,0) {
			if (j>=m) Add(dp2[i][j],dp1[i][j]);
			Add(sum2,dp2[i][j]);
			if (j) Add(dp2[i+1][j],sum2);
			if (j<k-1) Add(dp2[i+1][j+1],1ll*(k-j)*dp2[i][j]%modd);
		}
	}
	For (j,m,k-1) Add(dp2[n][j],dp1[n][j]);
	int ans=0;
	For (i,1,k-1) Add(ans,dp2[n][i]);
	Add(Ans,-1ll*ans*quick(1ll*fac[k]*inv[k-m]%modd,modd-2)%modd);
	printf("%d",Ans);
}

inline void solve2() {
	int p=0,q=0;
	Set(lst,0);
	For (i,1,m)
		if (!lst[a[i]]) lst[a[i]]=i;
		else { p=i-1; break; }
	Set(lst,0);
	Forr (i,m,1) {
		if (!lst[a[i]]) lst[a[i]]=i;
		else { q=m-i; break; }
	}
	dp1[0][p]=1; dp2[0][q]=1;
	For (i,0,n-1) {
		int sum1=0,sum2=0;
		Forr (j,k-1,0) {
			Add(sum1,dp1[i][j]); Add(sum2,dp2[i][j]);
			if (j) Add(dp1[i+1][j],sum1),Add(dp2[i+1][j],sum2);
			if (j<k-1) Add(dp1[i+1][j+1],1ll*(k-j)*dp1[i][j]%modd);
			if (j<k-1) Add(dp2[i+1][j+1],1ll*(k-j)*dp2[i][j]%modd);
		}
	}
	For (i,0,n-m) {
		int sum1=0,sum2=0;
		For (j,1,k-1)
			Add(sum1,dp1[i][j]),Add(sum2,dp2[n-m-i][j]);
		Add(Ans,-1ll*sum1*sum2%modd);
	}
	printf("%d",Ans);
}

int main() {
//	file();
	init();
	n=read(); k=read(); m=read();
	For (i,1,m) a[i]=read();
	Ans=1ll*(n-m+1)*quick(k,n-m)%modd;
//	cout << Ans << endl;
	int len=0,Max=0;
	For (i,1,m)
		len=min(len+1,i-lst[a[i]]),lst[a[i]]=i,chkmax(Max,len);
	if (Max==k) {
		printf("%d",Ans); return 0;
	}
	if (Max==m) {
		solve1(); return 0;
	}
	solve2();
	return 0;
}

Measured memory_bytes: 100096
import sys
input = sys.stdin.readline
N = int(input())
a = list(map(int, input().split()))
if max(a) - min(a) <= 1:
  print("Yes")
  exit(0)
t = [0] * N
for i in range(N - 1):
  if a[i + 1] - a[i] < 0 and (t[i] == 0):
    a[i] -= 1
    t[i] = 1
  if a[i] - a[i + 1] < 0 and (t[i + 1] == 0):
    a[i + 1] -= 1
    t[i + 1] = 1

for i in range(N - 1):
  if a[i + 1] < a[i]:
    print("No")
    exit(0)
print("Yes")

Measured memory_bytes: 59632
#include <iostream>
using namespace std;
int main(){
  int N,Q,i,I,M,data,max,result;
  int box[100]={};
  while(1){
  cin>>N>>Q;
  if(N==0||Q==0) break;
  for(i=1;i<=N;i++){
    cin>>M;
    for(I=1;I<=M;I++){
      cin>>data;
      box[data]++;
    }
  }
  max=-1;
  for(i=0;i<100;i++){
    if(max<box[i]){
      max=box[i];
      result=i;
    }
  }
  if(box[result]<Q) cout<<"0"<<endl;
  else cout<<result<<endl;
  for(i=0;i<100;i++){
    box[i]=0;
  }
  }
  return 0;
}

Measured memory_bytes: 1160
#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
#include <climits>
#include <vector>
#include <numeric>
#include <complex>
#include <map>
#include <bitset>
#include <stack>
#include <queue>
#include <set>
using namespace std;

#define __int64 long long
#define long __int64
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
const int Vec = 4;
const int Vecy[Vec] = {0,-1,0,1};
const int Vecx[Vec] = {1,0,-1,0};
const int Modd = 1000000007;

int main(){
    int a, b;
    cin >> a >> b;
    
    if(a <= 5){
        cout << 0 << endl;
    }else if(a <= 12){
        cout << b / 2 << endl;
    }else{
        cout << b << endl;
    }
}

Measured memory_bytes: 256
import Control.Monad
import Data.Bool
import Data.List
import qualified Data.Vector as V

readInt = readLn :: IO Int
readInts = map read . words <$> getLine :: IO [Int]
readNInts = flip replicateM readInts

main :: IO ()
main = do
  [_, q] <- readInts
  s <- getLine
  lr <- readNInts q
  mapM_ print $ g lr $ f s

f :: String -> V.Vector Int
f = V.fromList . scanl (+) 0 . f'
  where
    f' :: String -> [Int]
    f' [] = []
    f' [_] = [0]
    f' ('A':'C':xs) = 0 : 1 : f' xs
    f' (x:xs) = 0 : f' xs

g :: [[Int]] -> V.Vector Int -> [Int]
g [] _ = []
g ([l, r]:lr) xs = (xs V.! r) - (xs V.! l) : g lr xs

Measured memory_bytes: 91004
#include<bits/stdc++.h>
using namespace std;
#pragma region atcoder
//using mint = modint998244353;
//These are for segment tree
/*int op(int a, int b){return max(a, b);}
int e(){return -1;}
bool f(int v){ return v < target;}
*/
#pragma endregion
#pragma region macros
using ll = long long;
using vi = vector<int>;
using vs = vector<string>;
using vl = vector<ll>;
using vb = vector<bool>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rrep(i, n) for(int i = n - 1; i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
template<class T>bool chmax(T &a, const T b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T b) { if (b<a) { a=b; return 1; } return 0; }
template<class T> T gcd(T a,T b){return b?gcd(b,a%b):a;}
template<class T> T lcm(T a,T b){return a / gcd(a, b) * b;}
#pragma endregion
#pragma region debug for var, v, vv
#define debug(var)  do{std::cout << #var << " : ";view(var);}while(0)
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){cout << endl;int cnt = 0;for(const auto& v : vv){cout << cnt << "th : "; view(v); cnt++;} cout << endl;}
#pragma endregion
const ll mod = 1000000007;
const int inf = 1001001001;
const ll INF = 1001001001001001001;
const int MAX = 2000005;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
 
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, m, R; cin >> n >> m >> R;
    vi r(R);
    rep(i,R) cin >> r[i];
    vvl dist(n, vl(n, inf));
    for(int i = 0; i < n; i++) dist[i][i] = 0;
    rep(i,m){
        int a, b, c; cin >> a >> b >> c;
        a--; b--;
        dist[a][b] = c;
        dist[b][a] = c;
    }
    rep(k,n){
        rep(i,n){
            rep(j,n){
                dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
            }
        }
    }
    ll ans = INF;
    //注意 : ソートしないといけません
    sort(all(r));
    do{
        //debug(r);
        ll tmp = 0;
        for(int i = 1; i < R; i++){
            tmp += dist[r[i] - 1][r[i - 1] - 1];
        }
        ans = min(ans, tmp);
    }while(next_permutation(all(r)));
    cout << ans << endl;
}

Measured memory_bytes: 3752
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<numeric>
#include<cmath>
#include<queue>
#include<stack>
#include<list>
#include<unordered_map>
#include<unordered_set>
#include<cctype>
#include<iomanip>
#include<limits>
#include<bitset>

using namespace std;
typedef long long int ll; typedef pair<int, int> P; typedef unsigned long long int ull;
const ll mod = 1000000007;
const int inf = 1e9 + 7;
const ll linf = 1LL << 60;
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define REP(i,m,n) for(int i=(m);i<(int)n;i++)
#define all(a) (a).begin(),(a).end()
#define allg(a) (a).begin(),(a).end(),greater<>()
#define SUM(a) accumulate((a).begin(),(a).end(),0)
#define d10 std::setprecision(10)
#define d20 std::setprecision(20)
#define vec vector<int>
#define vecb vector<bool>
#define vecd vector<double>
using str = string;
const double PI = 3.14159265359;
ll gcd(ll a, ll b) { ll t; while (b != 0) { t = a % b; a = b; b = t; }return a; }
int gcd(int a, int b) { int t; while (b != 0) { t = a % b; a = b; b = t; }return a; }
ll recfact(ll start, ll n) {
	ll i;
	if (n <= 16) {
		ll r = start;
		for (i = start + 1; i < start + n; i++) r = r * i % mod;
		return r % mod;
	}
	i = n / 2;
	return recfact(start, i) % mod * recfact(start + i, n - i) % mod;
}
ll lcm(ll a, ll b) {
	return a * b / gcd(a, b);
}
ll fct(ll n) { return recfact(1, n); }
ll ncm(ll n, ll m) {
	if (n < m)return 0;
	ll x = (fct(n) % mod / (fct(m) * fct(n - m)) % mod) % mod;
	return x;
}
std::string sreverse(string str, int firstItr, int secondItr) {
	if (firstItr < 0 || secondItr>int(str.size() - 1))return str;
	while (firstItr < secondItr) {
		swap(str[firstItr], str[secondItr]);
		firstItr++; secondItr--;
	}
	return str;
}
std::string RunLengthEncoding(std::string str) {
	int itr = 0; std::string res;
	while (itr < int(str.size())) {
		char tmp = str[itr++];
		int length = 1;
		while (itr <int(str.size()) && str[itr] == tmp) { ++itr; ++length; }
		res.push_back(tmp);
		res += to_string(length);
	}
	return res;
}
std::string split(std::string str, size_t first_itr, size_t second_itr) {
	std::string tmp;
	for (size_t i = first_itr; i < second_itr + 1; i++) {
		tmp.push_back(str.at(i));
	}
	return tmp;
}
ll max(ll a, ll b) {
	return a > b ? a : b;
}
ll min(ll a, ll b) {
	return a < b ? a : b;
}


int main() {
	ll a, b; cin >> a >> b;
	ll c = a + b;
	if (c % 2) {
		cout << "IMPOSSIBLE" << endl;
	}
	else {
		cout << c / 2 << endl;
	}
	

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
    #include<cstdlib>
    #include<math.h>
    #include<set>
    #include<string>
    using namespace std ;
    int main(){
          int N,A,B;
          cin>>N>>A>>B;
          if(A*N<B) cout<<A*N<<endl;
          else cout<<B<<endl;
        return 0 ;
    }

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
using namespace std;
using ll = long long;
int main() {
    int N; cin >> N;
    map<ll,int> mp;
    for(int i=0;i<N;i++){
        ll ai; cin >> ai;
        mp[ai]++;
    }
    int res = 0;
    auto begin = mp.begin(), end = mp.end();
    for (auto iter = begin; iter != end; iter++) {
        if (iter->second %2 == 1) res++;
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 6528
use std::io::*;
use std::str::FromStr;

#[allow(unused_macros)]
macro_rules! scan {
  ($e:expr; $t:ty) => {
    $e.get::<$t>()
  };
  ($e:expr; $($t:ty), *) => {
    ($($e.get::<$t>(),)*)
  };
  ($e:expr => $i:expr; $t:ty) => {
    (0..$i).map(|_| $e.get::<$t>()).collect::<Vec<$t>>()
  };
  ($e:expr => $row:expr, $col:expr; $t:ty) => {
    (0..$i).map(|_| scan!($e => $col; $t)).collect::<Vec<$t>>()
  }
}

struct Scanner<R: Read> {
  reader: R
}

#[allow(dead_code)]
impl<R: Read> Scanner<R> {
  fn new(reader: R) -> Scanner<R> {
    Scanner { reader: reader }
  }
  fn safe_get<T: FromStr>(&mut self) -> Option<T> {
    let token = self.reader.by_ref().bytes().map(|c| c.unwrap() as char)
      .skip_while(|c| c.is_whitespace())
      .take_while(|c| !c.is_whitespace())
      .collect::<String>();
    if token.is_empty() { None } else { token.parse().ok() }
  }
  fn get<T: FromStr>(&mut self) -> T {
    if let Some(v) = self.safe_get() { v } else {
      writeln!(stderr(), "Terminated with EOF").unwrap();
      std::process::exit(0);
    }
  }
}

trait Writable {
  fn write(&self, sep: &'static str) -> String;
}

impl<T: ToString> Writable for Vec<T> {
  fn write(&self, sep: &'static str) -> String {
    self.iter().map(|e| e.to_string()).collect::<Vec<String>>().join(sep)
  }
}

fn main() {
  let cin = stdin();
  let cin = cin.lock();
  let mut sc = Scanner::new(cin);
  let (a, b, k) = scan!(sc; usize, usize, usize);
  let mut vec = Vec::with_capacity(k * 2);
  if b - a + 1 < k {
    for i in a..(b + 1) {
      vec.push(i);
    }
  }
  else {
    for i in a..(a + k) {
      vec.push(i);
    }
    for i in (b - k + 1)..(b + 1) {
      vec.push(i);
    }
    vec.sort();
    vec.dedup();
  }
  println!("{}", vec.write("\n"));
}


Measured memory_bytes: 4352
#include <iostream>
#include <cmath>
#include <cstdio>
#include <string>

using namespace std;

int main()
{
	int N;
	char color[100];
	bool b[4] = { 0 };
	cin >> N;

	for (int i = 0; i < N; i++) {
		cin >> color[i];	
	}
	for (int i = 0; i < N; i++) {
		if (color[i] == 'P') b[0] = 1;
		else if (color[i] == 'W') b[1] = 1;
		else if (color[i] == 'G') b[2] = 1;
		else {
			b[3] = 1;
			break;
		}

	}
	if (b[3] == 1) cout << "Four" << endl;
	else cout << "Three" << endl;

	return 0;
}


Measured memory_bytes: 256
/*
Author:loceaner
*/
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#define int long long
using namespace std;

const int A = 1e6 + 11;
const int B = 1e6 + 11;
const int mod = 1e9 + 7;
const int inf = 0x3f3f3f3f;

inline int read() {
  char c = getchar();
  int x = 0, f = 1;
  for ( ; !isdigit(c); c = getchar()) if (c == '-') f = -1;
  for ( ; isdigit(c); c = getchar()) x = x * 10 + (c ^ 48);
  return x * f;
}

int k, a[A];

signed main() {
	k = read();
	for (int i = 1; i <= k; i++) {
		a[i] = a[i - 1] * 10 + 7;
		a[i] %= k;
		if (a[i] == 0) {
      cout << i << '\n';
			return 0;
		}
	}
	cout << -1 << '\n';
}

Measured memory_bytes: 11420
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define MAX 100000
#define  MOD  998244353
const int mod=1e9+7;
#define tezz std::ios::sync_with_stdio(false);std::cin.tie(NULL);std::cout.tie(NULL);
#define ull unsigned long long
#define pb push_back
#define vll vector<ll>
int main(){
     ll numbers;
     cin>>numbers;
        string ARRAYS[numbers];
    set<string>SETSs;
    for(int i=0;i<numbers;i++){
        cin>>ARRAYS[i];
        SETSs.insert(ARRAYS[i]);
    }
    cout<<SETSs.size();
        return 0;
}

Measured memory_bytes: 25400
#include <iostream>
#include <stdio.h>
using namespace std;

int main(void){
  int n;
  cin >> n;
  int i = 1;
  while(++i <= n){
    int x = i;
    if ( x % 3 == 0 ){
        cout << " " << i;
        continue;
    }
    while(x){
        if ( x % 10 == 3 ){
            cout << " " << i;
            break;
        }
        x /= 10;
    }
  }
  cout << endl;
}


Measured memory_bytes: 3120