akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections.Generic;
using System.Linq;
using static Input;

public class Prog
{
    private const int INF = 1000000007;
    public static void Main()
    {
        int n = NextInt();
        Dictionary<char, int> dic = new Dictionary<char, int>();
        for (char c = 'a'; c <= 'z'; c++) dic[c] = 0;
        string s = NextString();
        foreach (char c in s.ToCharArray()) dic[c]++;
        for (int i = 1; i < n; i++)
        {
            Dictionary<char, int> nxdic = new Dictionary<char, int>();
            for (char c = 'a'; c <= 'z'; c++) nxdic[c] = 0;
            s = NextString();
            foreach (char c in s.ToCharArray()) nxdic[c]++;

            for (char c = 'a'; c <= 'z'; c++)
            {
                dic[c] = Math.Min(dic[c], nxdic[c]);
            }
        }
        for (char c = 'a'; c <= 'z'; c++) {
            for (int i = 0; i < dic[c]; i++) Console.Write(c);
        }
        Console.WriteLine();
    }
}

public class Input
{
    private static Queue<string> q = new Queue<string>();
    private static void Confirm() { if (q.Count == 0) foreach (var s in Console.ReadLine().Split(' ')) q.Enqueue(s); }
    public static int NextInt() { Confirm(); return int.Parse(q.Dequeue()); }
    public static long NextLong() { Confirm(); return long.Parse(q.Dequeue()); }
    public static string NextString() { Confirm(); return q.Dequeue(); }
    public static double NextDouble() { Confirm(); return double.Parse(q.Dequeue()); }
    public static int[] LineInt() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); }
    public static long[] LineLong() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); }
    public static string[] LineString() { return Console.ReadLine().Split(' ').ToArray(); }
    public static double[] LineDouble() { return Console.ReadLine().Split(' ').Select(double.Parse).ToArray(); }
}

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

int main(){
  int n;
  cin >> n;
  int a[n], minV=1000, maxV=-1000;
  for ( int i = 0; i < n; i++){
    cin >> a[i];
    minV = min(minV, a[i]);
    maxV = max(maxV, a[i]);
  }
  long long minS = 10000000000000;
  for ( int i = minV; i <= maxV; i++){
    long long sum = 0;
    for ( int j = 0; j < n; j++){
      sum += (i-a[j])*(i-a[j]);
    }
    if (sum < minS ){
      minS = sum;
    }
  }

  cout << minS << endl;

  return 0;
}

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

#define N 55
#define INF 1<<30

int H, W, h, w;
char s[N][N];
int d[N][N];

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

void bfs()
{
    queue<pair<int, int> > que;

    for (int i = 0; i < N; i++) for (int j = 0; j < N; j++) d[i][j] = INF;

    que.push(pair<int, int> (0, 0));
    d[0][0] = 0;

    while (que.size()) {
        pair<int, int> p = que.front(); que.pop();
        if (p.first == w && p.second == h) break;
        for (int i = 0; i < 4; i++) {
            int nx = p.first + dx[i], ny = p.second + dy[i];

            if (0 <= nx && nx < W && 0 <= ny && ny < H && s[ny][nx] != '#' && d[ny][nx] == INF) {
                que.push(pair<int, int>(nx, ny));
                d[ny][nx] = d[p.second][p.first] + 1;
            }
        }
    }
}

int main()
{
    cin >> H >> W;
    for (int i = 0; i < H; i++) for (int j = 0; j < W; j++) cin >> s[i][j];

    h = H - 1;
    w = W - 1;

    bfs();

    if (d[h][w] == INF) return cout << -1 << endl, 0;

    int cnt = 0;
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            if (s[i][j] == '.') cnt++;
        }
    }
    cout << cnt - d[h][w] - 1 << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <bitset>
#include <iomanip>
#include <deque>
#include <tuple>
#include <algorithm>

using namespace std;

int main()
{
    double n;
    cin >> n;

    cout << n / 2 * (n + 1) << endl;
}


Measured memory_bytes: 256
using System;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] input = Console.ReadLine().Split(' ');
            int a = int.Parse(input[0]);
            int b = int.Parse(input[1]);

            if ((a * b) % 2 != 0)
            {
                Console.WriteLine("Odd");
            }
            else
            {
                Console.WriteLine("Even");
            }
        }
    }
}



Measured memory_bytes: 13140
h, w = map(int, input().split())
while h != 0 or w != 0:
    for i in range(h):
        if i%2 == 0:
            print("#" if w == 1 else "#."*(w//2)+"#"*(w%2))
        else:
            print("." if w == 1 else ".#"*(w//2)+"."*(w%2))

    print()
    h, w = map(int, input().split())


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

signed main() {
	int n, w ; cin >> n >> w ; 
	std::vector<int> dp(100001,INT_MAX) ;
	dp[0] = 0 ; 
	for (int i = 0; i < n; ++i ) {
		int val, weight ; cin >> weight >> val ; 
		for (int j = 100000; j >= val; --j) {
			dp[j] = min(dp[j], dp[j-val]+weight) ; 
		}
	}
	int ans = 0 ; 
	for (int i = 1; i <= 100000; ++i) {
		if ( dp[i] <= w ) {
			ans = i ;
		}
	}
	cout << ans << endl ; 
	return 0 ; 
}

Measured memory_bytes: 1024
base = 10^9 + 7

data BST = Null
         | Node Integer Int BST BST -- ここ以下の要素数、要素、より小さい要素の部分木、より大きい要素の部分木

getN Null = 0
getN (Node n _ _ _) = n

cntAndIns x Null = (0, Node 1 x Null Null)
cntAndIns x (Node n y l r) = case compare x y of
  LT -> let (c,l1) = cntAndIns x l in (c, Node (succ n) y l1 r)
  EQ -> (getN l, Node (succ n) y l r)
  GT -> let (c,r1) = cntAndIns x r in (n - getN r + c, Node (succ n) y l r1)

doCount :: [Int] -> [Integer]
doCount as = tail $ map fst $ scanl (\(_,t) x -> cntAndIns x t) (undefined, Null) as

compute :: Integer -> Integer -> [Int] -> Integer
compute n k as = foldl1 add $ zipWith f xs ys
  where
    xs = doCount as
    ys = reverse (doCount (reverse as))
    f x y = k * y + k * (k-1) * (x+y) `div` 2
    add x y = (x+y) `mod` base

main = do
  li <- getLine
  let [n,k] = map read $ words li
  li <- getLine
  let as = map read $ words li
  let ans = compute n k as
  print ans


Measured memory_bytes: 5628
package main

import (
	"fmt"
)

func main() {

	var S string
	fmt.Scanf("%s", &S)

	var flag int = 0
	for i, j := range S {

		if (i+1)%2 == 0 {
			if j == 'R' {
				flag = 1
			}
		} else {
			if j == 'L' {
				flag = 1
			}
		}
	}

	if flag == 1 {
		fmt.Println("No")
	} else {
		fmt.Println("Yes")
	}
}


Measured memory_bytes: 1840
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int (i)=(0);(i)<(int)(n);++(i))
#define p(x) cout<<(x)<<endl;
#define pv(v) for(auto a: v){ cout << a << endl; }

int main() {
  int n; cin >> n;
  vector <int> ls(n);
  rep(i, n){
    cin >> ls[i];
  }

  // sort(ls.begin(), ls.end());  

  int ans = 100000000;
  rep(i, n-1) {
    int a = 0;
    for(int j = 0; j<=i; j++) {
      a += ls[j];
    }

    int b = 0;
    for(int k = i+1; k < n; k++) {
      b+=ls[k];
    }


    ans = min(ans, abs(a-b));
  }
  p(ans);

}


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

const int mod = 1e9 + 7;

struct BinaryIndexedTree {
  BinaryIndexedTree(size_t n) : n(n), v(n + 1, 0) {}

  size_t n;
  vector<int64_t> v;

  int64_t sum(int k) {
    int ret = 0;
    for (; k; k -= k & -k) (ret += v[k]) %= mod;
    return ret;
  }

  void add(int k, int64_t x) {
    for (; k <= n; k += k & -k) (v[k] += x) %= mod;
  }
};

int main() {
  int n;
  int64_t a, b;
  cin >> n >> a >> b;

  const int64_t infll = 1001001001001001001ll;
  vector<int64_t> s(n + 1);

  s[0] = -infll;
  for (int i = 1; i <= n; ++i) {
    cin >> s[i];
  }

  if (a > b) swap(a, b);

  BinaryIndexedTree bit(n + 1);
  bit.add(1, 1);

  int idx = 1;
  for (int i = 1; i <= n; ++i) {
    int r = upper_bound(s.begin(), s.end(), s[i] - b) - s.begin();

    int64_t t = 0;
    if (r >= idx) t = (bit.sum(r) - bit.sum(idx - 1) + mod) % mod;
    if (s[i] - s[i - 1] < a) idx = i;
    if (2 <= i && s[i] - s[i - 2] < a) idx = i + 1;

    bit.add(i + 1, t);
  }

  cout << (n >= idx ? (bit.sum(n + 1) - bit.sum(idx - 1) + mod) % mod : 0) << endl;
}


Measured memory_bytes: 1792
#include<iostream>
#include<string>
#include<cstring>
#include<cctype>
#include<queue>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
using namespace std;

bool check(string s){
	rep(i,s.size()){
		if(!isalpha(s[i]))return true;
	}
	return false;
}

int main(){
	string s;
	getline(cin,s);
	int size=s.size();
	vector<int> bre;
	bre.push_back(0);
	rep(i,size){
		if(!isalpha(s[i]) && s[i]!='\'')bre.push_back(i);
	}
	vector<string> spot;
	rep(i,bre.size()-1){
		spot.push_back(s.substr(bre[i],bre[i+1]-bre[i]));
	}
	//cout<<"debug"<<endl;
	vector<string> ans;
	rep(i,spot.size()){
		rep(j,spot[i].size()){
			if(!isalpha(spot[i][j]) && spot[i][j]!='\'')spot[i].erase(j,1);
		}
		if(spot[i].size()>2 && spot[i].size()<7 /*&& /*!check(spot[i])*/)ans.push_back(spot[i]);
	}
	//cout<<"debug2 "<<ans.size()<<endl;
	cout<<ans[0];
	for(int i=1;i<ans.size();i++){
		cout<<" "<<ans[i];
	}
	cout<<endl;
	return 0;
}

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

using namespace std;

template<class INT>
INT mod_pow(INT n, INT k, INT p){
    if (k == 0)
        return 1;
    if (k % 2 == 0){
        INT res = mod_pow(n, k / 2, p);
        return res * res % p;
    }
    return mod_pow(n, k - 1, p) * n % p;
}

template<class INT>
vector<INT> fact(INT n, INT p=INT(1e9 + 7)){
    vector<INT> f(n + 1);
    f[0] = 1;
    for (INT i = 0; i < n; i++)
        f[i + 1] = (i + 1) * f[i] % p;
    return f;
}

template<class INT>
vector<INT> invfact(INT n, const vector<INT> &f, INT p=INT(1e9 + 7)){
    vector<INT> inv(n + 1);
    inv[n] = mod_pow<INT>(f[n], p - 2, p);
    for (INT i = n; i > 0; i--)
        inv[i - 1] = inv[i] * i % p;
    return inv;
}

template<class INT>
INT comb(INT a, INT b, const vector<INT> &f, const vector<INT> &invf, INT p=INT(1e9 + 7)){
    if (a < b)
        return 0;
    if (a < 0 or b < 0)
        return 0;
    return f[a] * invf[b] % p * invf[a - b] % p;
}

template<class INT>
std::map<INT, int> factorize(INT n){
    map<INT, int> res;
    for (int i = 2; i * i <= n; i++){
        while (n % i == 0){
            res[i]++;
            n /= i;
        }
    }

    if (n > 1)
        res[n]++;

    return res;
}

int main(){
    int n, m;
    cin >> n >> m;
    const int64_t p = 1e9 + 7;

    int64_t ans = 1;
    auto factors = factorize<int64_t>(m);
    auto f = fact<int64_t>(1e6);
    auto inv_f = invfact<int64_t>(1e6, f);
    for (const auto &m: factors){
        ans *= comb<int64_t>(n + m.second - 1, n - 1, f, inv_f);
        ans %= p;
    }

    cout << ans << endl;
}

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

int main() {
  int n, m, ans = -1;
  cin >> n;

  map<string, int> p;
  vector<string> s(n);
  for (int i = 0; i < n; i++) {
    cin >> s[i];
    p[s[i]]++;
  }

  cin >> m;
  string t;
  for (int i = 0; i < m; i++) {
    cin >> t;
    p[t]--;
  }

  for (int i = 0; i < n; i++) {
    if (ans < p[s[i]]) ans = p[s[i]];
  }

  cout << max(ans, 0) << endl;
}

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

using namespace std;


//repetition
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define euc_dis(x, y) sqrt(x*x + y*y)

#define MOD 1e9+7
#define sp ' '


using ll = long long;


ll mod(ll a, ll b){return (a%b+b)%b;}
ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b){return a*b/gcd(a,b);}
void Yes(){cout << "Yes" << endl;}
void No(){cout << "No" << endl;}
void Judge(bool b){b?Yes():No();}
void YES(){cout << "YES" << endl;}
void NO(){cout << "NO" << endl;}
void JUDGE(bool b){b?YES():NO();}
ll powMod(ll b, ll e, ll m){ll r=1;while(e>0){if(e&1)r=(r%m)*(b%m)%m;b=(b%m)*(b%m)%m;e>>=1;}return r;}
double distance(ll x1, ll y1, ll x2, ll y2){return sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2));}

template<typename T>
void ppp(T n){cout << n << endl;}


int main(){

    cin.tie(0);
    ios::sync_with_stdio(false);

    int n;
    cin >> n;
    ll k;
    cin >> k;

    vector<ll> a(n);
    ll G, M;
    rep(i, n) {
        cin >> a[i];
        if(i == 0) G = M = a[0];
        else {
            G = gcd(G, a[i]);
            M = max(M, a[i]);
        }
    }

    if(k%G == 0 and k <= M){
        ppp("POSSIBLE");
    }
    else{
        ppp("IMPOSSIBLE");
    }

    return 0;
}


Measured memory_bytes: 1024
#define _USE_MATH_DEFINES

#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cmath>
#include <bitset>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef tuple<ll, ll, ll> tl3;



const int BIG_NUM = 1e9;
const ll INF = 1000000000000000000;
const ll MOD = 1e9 + 7;
//const ll MOD = 998244353;



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

	map<char, int> m;
	for (int i = 0; i < 4; i++) {
		m[s[i]]++;


	}

	bool isConsist = true;
	for (auto it = m.begin(); it != m.end(); it++) {
		if (it->second != 2) {
			isConsist = false;
			break;
		}
	}

	if (isConsist) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}

}


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

int gcd(int a, int b){
  if(b == 0){
    return a;
  } else if(a >= b){
    int tmp = a % b;
    return gcd(b, tmp);
  } else {
    return gcd(b, a);
  }
}

int main(){
  long long int a, b;

  while(cin >> a && cin >> b){
    int g = gcd(a, b);
    cout << g << " " << (a * b) / g << endl;
  }
  
  return 0;
}

Measured memory_bytes: 3064
#include<cstdio>
#include<algorithm>
using namespace std;
int main(){
  int p[5],c[14],p2,p3,p4;
  while(scanf("%d,%d,%d,%d,%d",p,p+1,p+2,p+3,p+4)!=EOF){
    for(int i=1;i<14;i++) c[i] = 0;
    p2 = 0;
    p3 = 0;
    p4 = 0;
    for(int i=0;i<5;i++) c[ p[i] ]++;
    for(int i=1;i<14;i++){
      if(c[i]==2) p2++;
      if(c[i]==3) p3++;
      if(c[i]==4) p4++;
    }
    if(p4 == 1) puts("four card");
    else if(p3 == 1){
      if(p2 == 1) puts("full house");
      else puts("three card");
    } else if(p2 == 2) puts("two pair");
    else if(p2 == 1) puts("one pair");
    else {
      sort(p,p+5);
      if(p[4]-p[0]==4||p[0]==1&&p[1]==10) puts("straight");
      else puts("null");
    }
  }
  return(0);
}



Measured memory_bytes: 2592
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main{
	public static void main(String[] args) throws IOException {
		try (BufferedReader br = new BufferedReader(
				new InputStreamReader(System.in))) {

			int r = Integer.parseInt(br.readLine());
			int g = Integer.parseInt(br.readLine());
			System.out.println(2*g-r);

		}
	}
}

Measured memory_bytes: 25316
/*
  AUTHOR:SOURABH
  CREATED:10:01:20
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define ordered_set tree<ll , null_type, less< ll >, rb_tree_tag, tree_order_statistics_node_update>
#define ll long long int
#define ld long double
#define fi first
#define se second
#define pb push_back
#define pob pop_back
#define W while
#define fn(i,x) for(i=0;i<x;i++)
#define fs(i,s,x) for(i=s;i<x;i++)
#define fr(i,x) for(i=x;i>=0;i--)
#define fit(it,s) for(it=s.begin();it!=s.end();it++)
#define mp make_pair
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vii vector<int>
#define vll vector<ll>
#define mii map<int,int>
#define mll map<ll,ll>
#define mod 998244353
#define MAX 100005
#define M 32

using namespace std;
using namespace __gnu_pbds;

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

    //freopen("in.txt","r",stdin);
    //freopen(2 "out.txt","w",stdout);

    ll x,k;
    cin>>k>>x;
    if(500*k>=x)
        cout<<"Yes";
    else
        cout<<"No";
    return 0;
}





























Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e5+1;

ll a[N];
int d[N][2];
bool vis[N][2];
int dfs(int x,bool f){
	if(!x)return 0;
	if(vis[x][f])return d[x][f];
	vis[x][f]=1;
	int lim=f?a[x]:9;
	for(int i=0;i<=lim;++i){
		d[x][f]=max(d[x][f],i+dfs(x-1,f&&lim==i));
	}
	return d[x][f];
}

int main(){
	ll n,m=0;
	cin>>n;
	for(;n;n/=10)a[++m]=n%10;
	cout<<dfs(m,1);
	
}

Measured memory_bytes: 256
import sys


def input(): return sys.stdin.readline().strip()
def I(): return int(input())
def LI(): return list(map(int, input().split()))
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def S(): return input()
def LS(): return input().split()


INF = float('inf')

n = I()
a = LI()
ans = 1000
for i in range(n - 1):
    kabu = 0
    if a[i] < a[i+1]:
        # 出来るだけ買う
        kabu = ans // a[i]
    # 買った株があれば i + 1日目 に売る
    if kabu > 0:
        ans += (a[i + 1] - a[i]) * kabu
print(ans)


Measured memory_bytes: 9212
// ConsoleApplication1.cpp : このファイルには 'main' 関数が含まれています。プログラム実行の開始と終了がそこで行われます。
//
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;


int main()
{
	int A, B, C;
	cin >> A >> B >> C;
	if (A <= C&& B>=C) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
}
// プログラムの実行: Ctrl + F5 または [デバッグ] > [デバッグなしで開始] メニュー
// プログラムのデバッグ: F5 または [デバッグ] > [デバッグの開始] メニュー

// 作業を開始するためのヒント: 
//    1. ソリューション エクスプローラー ウィンドウを使用してファイルを追加/管理します 
//   2. チーム エクスプローラー ウィンドウを使用してソース管理に接続します
//   3. 出力ウィンドウを使用して、ビルド出力とその他のメッセージを表示します
//   4. エラー一覧ウィンドウを使用してエラーを表示します
//   5. [プロジェクト] > [新しい項目の追加] と移動して新しいコード ファイルを作成するか、[プロジェクト] > [既存の項目の追加] と移動して既存のコード ファイルをプロジェクトに追加します
//   6. 後ほどこの,プロジェクトを再び開く場合、[ファイル] > [開く] > [プロジェクト] と移動して .sln ファイルを選択します

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

#define INF 999999999
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; i++)
#define all(v) v.begin(), v.end()
#define pub push_back
#define pob pop_back
#ifdef LOCAL
  #define de(e) cout << "L" << __LINE__ << ": " << e << "\n" // debug echo
  #define dr(e) cout << "L" << __LINE__ << ": " << #e << " -> " << e << "\n" // debug repr
#else
  #define de(e)
  #define dr(e)
#endif
#define out(fmt, ...) printf(fmt, __VA_ARGS__); printf("\n")
int gcd(int m, int n) { if((0 == m) || (0 == n)){return 0;} while(m != n){ if(m > n){m -= n;}else{n -= m;} } return m; }
int lcm(int m, int n) { if((0 == m) || (0 == n)){return 0;} return (m / gcd(m, n)) * n; }

//
// Implementation
//

int main() {
  int N, A, B; cin >> N >> A >> B;
  int allsum = 0;
  for (int i = 1; i <= N; i++) {
    string s = to_string(i);
    int sum = 0;
    rep(si, (int)s.size()) {
      sum += s[si] - '0';
    }
    if (A <= sum && sum <= B) {
      dr(sum);
      allsum += i;
    }
  }
  cout << allsum << endl;
}


Measured memory_bytes: 256
module Main where

import Control.Applicative
import Control.Monad
import Data.List

f :: [Int] -> ([Int], [Int])
f []       = ([], [])
f (x:y:zs) = (x:xs, y:ys)
  where
    (xs, ys) = f zs

g :: [Int] -> [[Int]]
g xs = sortBy (\a b -> length b `compare` length a) . group . sort $ xs

main :: IO ()
main = do
    n <- readLn :: IO Int
    vs <- fmap read . words <$> getLine :: IO [Int]
    let (as, bs) = f vs
    let (cs:css) = g as
    let (ds:dss) = g bs
    let ans = case () of
            _ | head cs /= head ds -> length (concat css) + length (concat dss)
              | otherwise          ->
                    let (cs2, css2) = splitAt 1 css
                        (ds2, dss2) = splitAt 1 dss
                        ans1 = length (concat css) + length (concat (ds:dss2))
                        ans2 = length (concat dss) + length (concat (cs:css2))
                    in min ans1 ans2
    print ans


Measured memory_bytes: 42364
#include<bits/stdc++.h>
#define ll long long
#define all(a) a.begin(),a.end()
#define sz(a) a.size()
#define re return 
#define MP make_pair
#define pb push_back
#define pii pair<int,int>
#define se second
#define fi first
using namespace std;
const int MOD=1e9+7;
ll n,ans=1,x=1;
signed main(){
	ios_base::sync_with_stdio(0);
	cin>>n;
	while(n--){
		ans*=x;
		ans%=MOD;
		x++;
	}
	cout<<ans;
	re 0;
}

Measured memory_bytes: 3608
#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,ceil,sqrt,factorial,hypot,log #log2ないｙｐ
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
inf=float('inf')
mod = 10**9+7
def pprint(*A): 
    for a in A:     print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    print(ST().count("1"))
if __name__ == '__main__':
    main()

Measured memory_bytes: 38256
import java.util.LinkedList;
import java.util.Scanner;
import java.util.Iterator;

class Graph {
	private int totalVertex;
	private LinkedList<LinkedList<Integer>> adjList;
	//adjacency list of edges
	public Graph() { totalVertex = 0; }
	public void loadAdjList() {
		Scanner in = new Scanner(System.in);
		totalVertex = in.nextInt();
		adjList = new LinkedList<LinkedList<Integer>>();
		for(int i = 0; i < totalVertex; i ++) {
			LinkedList<Integer> tmp = new LinkedList<Integer>();
			int idx1 = in.nextInt() - 1; //we need 0123 not 1234
			int degree = in.nextInt(); //degree 2 number
			//System.out.println("mark idx1 = " + idx1 + " degree = " + degree);
			for(int j = 0; j < degree; j ++) { //degree: how many edges we have to the node
				int idx2 = in.nextInt() - 1; //coz every node -1
				tmp.add(idx2);
			}	
			adjList.add(tmp);
			//current adList:
			/*
			 	0 -> 1 -> 3
				1 -> 3
				2 -> null
				3 -> 2
			*/
		}
		in.close();
	}
	public void printAdjMatrix() {
		Integer[][] adjMatrix = new Integer[totalVertex][totalVertex];
		//complete the following
		Graph p = new Graph();
		LinkedList<LinkedList<Integer>> adjList2;
		adjList2 = new LinkedList<LinkedList<Integer>>();
		adjList2 = p.adjList;
		
		for(int x=0;x<totalVertex;x++) {
			for(int y=0;y<totalVertex;y++) {
				adjMatrix[x][y] = 0; //fill up with 0
			}
		}
		//O(n): iterator
		//O(n^2): total
		Iterator<LinkedList<Integer>> cur = adjList.iterator();
		int index = 0;//the first index
		while(cur.hasNext()) {
			LinkedList<Integer> mm = cur.next();
			Iterator<Integer> mynext = mm.iterator();
			while(mynext.hasNext()) {
				int v = mynext.next();
				adjMatrix[index][v] = 1;
			}
			index++;
		}
		
		/*for(int x=0;x<totalVertex;x++) {
			for (int y=0;y<totalVertex;y++) {
				System.out.print(adjMatrix[x][y] + " "); //use print so it does not move to next line
			}
			System.out.println();
		}*/
		
		for(int w = 0; w < totalVertex; w ++) {
			for(int z = 0; z < totalVertex; z ++) {
				if(z == totalVertex - 1)
					System.out.println(adjMatrix[w][z]);
				else
					System.out.print(adjMatrix[w][z] + " ");
			}
		}
	}
}
public class Main {

	public static void main(String[] args) {
		Graph g = new Graph();
		g.loadAdjList();
		g.printAdjMatrix();
	}

}



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

int main() {
    int n, x;
    cin >> n >> x;
    if(x==1 || x==2*n-1){
        cout << "No" << endl;
        return 0;
    }
    vector<int> ans(2*n-1);
    for(int i = 0; i < 2*n-1; i++){
        ans[(n-1+i)%(2*n-1)] = (x-1+i)%(2*n-1)+1;
    }

    cout << "Yes" << endl;
    for(int i = 0; i < 2*n-1; i++){
        cout << ans[i] << endl;
    }

    return 0;
}


Measured memory_bytes: 2304
int main()
{
    while (1) {
        int n, m, results [ 100 ], i, j ;
        memset(results, 0, sizeof(results)) ;
        scanf("%d%d", & n, & m) ;
        if ( n + m == 0 ) {
            return 0 ;
        }
        for (i = 0 ; i < n ; i ++) {
            for (j = 0 ; j < m ; j ++) {
                int k ;
                scanf("%d", & k) ;
                results [ j ] += k ;
            }
        }
        int first = 0 ;
        for (i = n ; i >= 0 ; i --) {
            for (j = 0 ; j < m ; j ++) {
                if ( results [ j ] == i ) {
                    if ( first ) {
                        putchar(' ') ;
                    }
                    printf("%d", j + 1 ) ;
                    first = 1 ;
                }
            }
        }
        puts("") ;
    }
}




Measured memory_bytes: 1912
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << x << endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
int H,W,S;
string s[50],mv[10][50],mp[1<<10][2][50];
bool fst[50][50];
int d[1<<10][2][50][50];
int inf=1e8,dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
int main(){
	cin>>W>>H;
	rep(i,H) cin>>s[i];
	cin>>S;
	rep(i,S) rep(j,H) cin>>mv[i][j];
	rep(i,H) rep(j,W){
		if(s[i][j]=='_'||islower(s[i][j])||s[i][j]=='%'||s[i][j]=='&') fst[i][j]=1;
	}
	rep(b,1<<S){
		rep(i,H) rep(j,W){
			if(s[i][j]=='#'||s[i][j]=='|'){
				mp[b][0][i]+=s[i][j];
				mp[b][1][i]+=s[i][j];
			}else{
				int f=1-fst[i][j];
				rep(k,S) if((b>>k)&1) if(mv[k][i][j]=='*') f=1-f;
				char c=s[i][j];
				if(isupper(c)) c=c-'A'+'a';
				if(c=='_'||c=='^') c='.';
				mp[b][f][i]+=c;
				mp[b][1-f][i]+="#";
			}
		}
	}
	queue<int> qb,qf,qx,qy;
	qb.push(0);
	qf.push(0);
	rep(i,1<<S) rep(j,2) rep(k,H) rep(l,W) d[i][j][k][l]=inf;
	rep(i,H) rep(j,W) if(s[i][j]=='%') qx.push(i),qy.push(j),d[0][0][i][j]=0;
	while(!qb.empty()){
		int b=qb.front(),f=qf.front(),x=qx.front(),y=qy.front();
		qb.pop(),qf.pop(),qx.pop(),qy.pop();
		if(mp[b][f][x][y]=='&'){
			cout<<d[b][f][x][y]<<endl;
			return 0;
		}
		rep(di,4){
			int nx=x+dx[di],ny=y+dy[di];
			if(mp[b][f][nx][ny]!='#'&&d[b][f][nx][ny]==inf){
				qb.push(b),qf.push(f),qx.push(nx),qy.push(ny);
				d[b][f][nx][ny]=d[b][f][x][y]+1;
			}
		}
		if(mp[b][f][x][y]=='|'&&d[b][1-f][x][y]==inf){
			qb.push(b),qf.push(1-f),qx.push(x),qy.push(y);
			d[b][1-f][x][y]=d[b][f][x][y]+1;
		}
		if(islower(mp[b][f][x][y])){
			int s=mp[b][f][x][y]-'a';
			int nb=b^(1<<s);
			int nf=f;
			if(mv[s][x][y]=='*') nf=1-nf;
			if(d[nb][nf][x][y]==inf){
				qb.push(nb),qf.push(nf),qx.push(x),qy.push(y);
				d[nb][nf][x][y]=d[b][f][x][y]+1;
			}
		}
	}
	puts("-1");
	return 0;
}

Measured memory_bytes: 33916
#include<iostream>
#include<vector>
#include<algorithm>
#include<math.h>
#include<queue>
using namespace std;
typedef long long ll;

const int INF = 1001001001;
const int MOD = 1e9+7;

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

    //dp[i][j]
    //i番目までの男性が集合jで示される女性と
    //ペアになるパターン
    vector<vector<int>> dp(n+1, vector<int>(1<<n));
    dp[0][0] = 1;

    for (int i = 0; i < n; i++)
    {
        for (int before = 0; before < (1<<n); before++)  //女性集合before
        {
            if(__builtin_popcount(before) != i) continue;
            for (int j = 0; j < n; j++) //男性iに対して女性jを確認
            {
                if(!(before & (1 << j))){ //女性jが集合beforeに属さないとき
                    if(a[i][j]){        //男性iと女性jの相性がいいとき
                        int after = before | (1<<j);
                        dp[i+1][after] += dp[i][before];
                        dp[i+1][after] %= MOD;
                    }
                }
            }
            
        }
    }
    
    cout << dp[n][(1<<n)-1] << endl;

    return 0;
}

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

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

int x[100005];

int main(){
    int n,m;
    scanf("%d %d",&n,&m);
    if(n>=m) return !printf("0\n");
    for(int i=0;i<m;i++)
        scanf("%d",&x[i]);
    sort(x,x+m);
    vector<int> V;
    for(int i=1;i<m;i++)
        V.push_back(x[i]-x[i-1]);
    sort(V.begin(),V.end(),greater<int>());
    int s=x[m-1]-x[0];
    for(int i=0;i<n-1;i++)
        s-=V[i];
    printf("%d\n",s);
    return 0;
}

Measured memory_bytes: 1276
using System;
using System.Collections.Generic;
using System.Linq;

namespace PaizaTest
{
    class Program
    {
        static void Main(string[] args)
        {
            var n = int.Parse(Console.ReadLine());

            var evenList = Console.ReadLine().Split(' ').Select(int.Parse).Where(x => x % 2 == 0).ToList();

            bool result = evenList.All(x => x % 3 == 0 || x % 5 == 0);

            Console.WriteLine(result ? "APPROVED" : "DENIED");
        }
    }
}


Measured memory_bytes: 13396
#include <stdio.h>
#include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>

using ll = long long int;
using P = std::pair<ll, int>;
const int INF = (1<<30);
const ll INFLL = (1ll<<60);
const ll MOD = (ll)(1e9+7);

#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	a = (a<MOD)?a:(a-MOD);
	b = (b<MOD)?b:(b-MOD);
	a += b;
	a = (a<MOD)?a:(a-MOD);
}

ll a[225816];
std::vector<P> u;

ll rwpw(ll a, ll p = MOD-2){
	ll ret = 1ll;
	while(p){
		if(p%2){
			mul_mod(ret,a);
		}
		mul_mod(a,a);
		p /= 2;
	}
	return ret;
}

int main(void){
	int n,k,i,z=0,p=0,m=0;
	ll ans = 0ll,tmp = 1ll,lp,lm,fp=0ll,fm=0ll;
	bool flag = false;
	std::cin >> n >> k;
	for(i=0; i<n; ++i){
		std::cin >> a[i];
		if(a[i]>0ll){
			u.push_back(P(a[i],1));
		}else if(a[i]<0ll){
			u.push_back(P(-a[i],-1));
		}else{
			++z;
		}
	}
	std::sort(u.begin(),u.end(),std::greater<P>());
	if(u.l_ength()<k){
		std::cout << 0 << std::endl;
		return 0;
	}
	for(i=0; i<k; ++i){
		if(u[i].second<0){
			++m;
			lm = u[i].first;
			mul_mod(tmp,lm);
		}else{
			++p;
			lp = u[i].first;
			mul_mod(tmp,lp);
		}
	}
	if(m%2){
		for(i=(u.l_ength()-1); i>=k; --i){
			if(u[i].second<0){
				fm = u[i].first;
			}else{
				fp = u[i].first;
			}
		}
		if(fm && fp && lm && lp){
			if(fp*lp>fm*lm){
				mul_mod(tmp,rwpw(lm));
				mul_mod(tmp,fp);
			}else{
				mul_mod(tmp,rwpw(lp));
				mul_mod(tmp,fm);
			}
			ans = tmp;
			flag = true;
		}else if(fm && lp){
			mul_mod(tmp,rwpw(lp));
			mul_mod(tmp,fm);
			ans = tmp;
			flag = true;
		}else if(fp && lm){
			mul_mod(tmp,rwpw(lm));
			mul_mod(tmp,fp);
			ans = tmp;
			flag = true;
		}
	}else{
		ans = tmp;
		flag = true;
	}
	if(flag){
		std::cout << ans << std::endl;
		return 0;
	}
	if(z){
		std::cout << 0 << std::endl;
		return 0;
	}
	std::reverse(u.begin(),u.end());
	ans = 1ll;
	for(i=0; i<k; ++i){
		mul_mod(ans,u[i].first);
	}
	std::cout << ((MOD-ans)%MOD) << std::endl;
	return 0;
}


Measured memory_bytes: 8608
#include <bits/stdc++.h>
using namespace std;
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
typedef long long ll;
typedef pair<ll,ll> pr;
typedef vector<ll> vc;
typedef unordered_map<ll,ll> umap;
#define pb emplace_back
#define rep(i,a,b) for(ll i=a;i<=b;i++)
#define repr(i,a,b) for(ll i=a;i>=b;i--)
#define reps(i,v) for(ll i=0;i<v.size();i++)
template<typename T> void chmin(T &a, const T &b) { a = min(a, b); }
template<typename T> void chmax(T &a, const T &b) { a = max(a, b); }

int main() {
    // your code goes here
    ll n, m, x, y, l[3005][3005] = {0};
    string s, t;
    pair<ll,ll> dp[3005][3005];
    cin >> s >> t;
    vector<char> ans;
    n = s.size();
    m = t.size();
    rep(i,1,n){
    	rep(j,1,m){
    		if(s[i-1] == t[j-1]){;
    			l[i][j] = l[i-1][j-1] + 1;
    			dp[i][j] = {i-1, j-1};
    		} else{
    			l[i][j] = max(l[i-1][j], l[i][j-1]);
    			if(l[i][j-1] >= l[i-1][j]) dp[i][j] = {i, j-1};
    			else dp[i][j] = {i-1, j};
    		}
    	}
    }
    while(n != 0 && m != 0){
    	x = dp[n][m].first;
    	y = dp[n][m].second;
    	if(x != n && y != m) ans.pb(s[x]);
    	n = x;
    	m = y;
    }
    reverse(ans.begin(), ans.end());
    for(auto a: ans) cout << a;
    cout << endl;
    return 0;
}

Measured memory_bytes: 211968
#include <stdio.h>

#define INFTY 1000000001

int A[500000];
int n;
int sum=0;


void merge(int A[],int left,int mid,int right) {

	int i,k,j,n1,n2;

	n1 = mid - left;
	n2 = right - mid;

	//L[0...n1], R[0...n2] を生成

	int L[n1+1], R[n2+1];

	for(i=0; i<n1; i++) {
		L[i]=A[left+i];
	}

	for(i=0; i<n2; i++) {
		R[i]=A[mid+i];
	}

	L[n1] = INFTY;
	R[n2] = INFTY;
	
	i = 0;
	j = 0;

	for (k = left; k < right; k++) {
		if (L[i] <= R[j]) {
			A[k] = L[i];
			i = i + 1;
			sum++;
		}
		else {
			A[k] = R[j];
			j = j + 1;
			sum++;
		}
		

	}
}

void mergeSort(int A[], int left, int right) {
	
	int mid;
	
	if(left+1 < right) {
		mid = (left + right)/2;
		mergeSort(A, left, mid);
		mergeSort(A, mid, right);
		merge(A, left, mid, right);
	}

}

int main(void) {

	int i;
	scanf("%d",&n);

	for(i=0; i<n; i++) scanf("%d",&A[i]);
	
	mergeSort(A,0,n);
	
	for(i=0;i<n;i++) {
		printf("%d",A[i]);
		if(i==n-1) printf("\n");
		else printf(" ");
	}
	printf("%d\n",sum);

	return 0;
}



Measured memory_bytes: 5612
#include "bits/stdc++.h"

using namespace std;

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

    int n;
    while(cin>>n,n){
        vector<int> imos(100000,0);
        for(int i=0;i<n;i++){
            string s,t;cin>>s>>t;
            int tmp=0;
            tmp+=(s[0]-'0')*36000;tmp+=(s[1]-'0')*3600;
            tmp+=(s[3]-'0')*600;tmp+=(s[4]-'0')*60;
            tmp+=(s[6]-'0')*10;tmp+=(s[7]-'0');
            imos[tmp]++;
            tmp=0;
            tmp+=(t[0]-'0')*36000;tmp+=(t[1]-'0')*3600;
            tmp+=(t[3]-'0')*600;tmp+=(t[4]-'0')*60;
            tmp+=(t[6]-'0')*10;tmp+=(t[7]-'0');
            imos[tmp]--;
        }
        for(int i=1;i<=99999;i++) imos[i]+=imos[i-1];
        int res=0;
        for(int i=0;i<100000;i++) res=max(res,imos[i]);
        cout<<res<<endl;
    }
}

Measured memory_bytes: 3528
#include<bits/stdc++.h>
using namespace std;
int main(){
int n,m[4],p[4]={10,50,100,500},x[4],y[4],k,i=0,q,j;
while(true){
cin>>n;if(!n){break;}
if(i){cout<<endl;}i++;k=0;
cin>>m[0]>>m[1]>>m[2]>>m[3];
for(j=3;j>=0;j--){k+=m[j]*p[j];}
q=k-n;
for(j=3;j>=0;j--){x[j]=q/p[j];q-=x[j]*p[j];y[j]=max(0,m[j]-x[j]);}
for(j=0;j<4;j++){if(y[j]){printf("%d %d\n",p[j],y[j]);}}
}}

Measured memory_bytes: 1176
from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations # (string,3) 3回
from collections import deque
from collections import defaultdict
import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#

import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7

def readInts():
  return list(map(int,input().split()))
def main():
    X = int(input())
    import math
    for i in range(-119,119):
        for j in range(-119,119):
            if i == j:
                continue
            if X % (i - j) == 0:
                if (i-j) * (pow(i,4) + pow(i,3)*j + pow(i,2)*pow(j,2) + i*pow(j,3) + pow(j,4)) == X:
                    print(i,j)
                    exit()
if __name__ == '__main__':
  main()


Measured memory_bytes: 72940
using System;
class aoj
{
    static void Main()
    {
        int n = int.Parse(Console.ReadLine());
        for(int z = 0; z < n; z++)
        {
            string a = Console.ReadLine();
            char[] t = new char[53];
            int b = 26;
            for(int i = 0; i < a.Length; i++)
            {
                if (a[i] == '-')
                {
                    i++;
                    b++;
                }
                else if (a[i] == '<')
                {
                    i++;
                    b--;
                }
                else
                {
                    t[b] = a[i];
                }
            }
            for (int i = 0; i < 53; i++)
            {
                if (t[i]!='\0')
                {
                    Console.Write(t[i]);
                }
            }
            Console.WriteLine();
        }
    }
}

Measured memory_bytes: 8872
# abc150_a.py
# https://atcoder.jp/contests/abc150/tasks/abc150_a

# A - 500 Yen Coins /
# 実行時間制限: 2 sec / メモリ制限: 1024 MB
# 配点 : 100点

# 問題文
# 高橋君は 500円玉を K 枚持っています。 これらの総額が X円以上である場合は Yes を、そうでない場合は No を出力してください。

# 制約
#     1≤K≤100
#     1≤X≤105

# 入力
# 入力は以下の形式で標準入力から与えられる。
# K X

# 出力
# 総額が X円以上である場合は Yes を、そうでない場合は No を出力せよ。

# 入力例 1
# 2 900

# 出力例 1
# Yes

# 500円玉が 2 枚なので総額は 1000 円であり、これは X=900円以上です。

# 入力例 2
# 1 501

# 出力例 2
# No

# 500円玉が 1 枚なので総額は 500 円であり、これは X=501円未満です。

# 入力例 3
# 4 2000

# 出力例 3
# Yes

# 500円玉が 4 枚なので総額は 2000 円であり、これは X=2000 円以上です。


global FLAG_LOG
FLAG_LOG = False


def log(value):
    # FLAG_LOG = True
    # FLAG_LOG = False
    if FLAG_LOG:
        print(str(value))


def calculation(lines):
    # S = lines[0]
    # N = int(lines[0])
    K, X = list(map(int, lines[0].split()))
    # values = list(map(int, lines[1].split()))
    # values = list(map(int, lines[2].split()))
    # values = list()
    # for i in range(N):
    #     values.append(int(lines[i]))
    # valueses = list()
    # for i in range(N):
    #     valueses.append(list(map(int, lines[i+1].split())))

    if K * 500 >= X:
        result = 'Yes'
    else:
        result = 'No'

    return [result]


# 引数を取得
def get_input_lines(lines_count):
    lines = list()
    for _ in range(lines_count):
        lines.append(input())
    return lines


# テストデータ
def get_testdata(pattern):
    if pattern == 1:
        lines_input = ['2 900']
        lines_export = ['Yes']
    if pattern == 2:
        lines_input = ['1 501']
        lines_export = ['No']
    if pattern == 3:
        lines_input = ['4 2000']
        lines_export = ['Yes']
    return lines_input, lines_export


# 動作モード判別
def get_mode():
    import sys
    args = sys.argv
    global FLAG_LOG
    if len(args) == 1:
        mode = 0
        FLAG_LOG = False
    else:
        mode = int(args[1])
        FLAG_LOG = True
    return mode


# 主処理
def main():
    import time
    started = time.time()
    mode = get_mode()
    if mode == 0:
        lines_input = get_input_lines(1)
    else:
        lines_input, lines_export = get_testdata(mode)

    lines_result = calculation(lines_input)

    for line_result in lines_result:
        print(line_result)

    # if mode > 0:
    #     print(f'lines_input=[{lines_input}]')
    #     print(f'lines_export=[{lines_export}]')
    #     print(f'lines_result=[{lines_result}]')
    #     if lines_result == lines_export:
    #         print('OK')
    #     else:
    #         print('NG')
    # finished = time.time()
    # duration = finished - started
    # print(f'duration=[{duration}]')


# 起動処理
if __name__ == '__main__':
    main()


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

int main() {
  int a,b,c,n,i,j,k,d[10][10];
  while(cin >> n && n!=0) {
	  for (i=0;i<10;i++) for (j=0;j<10;j++) d[i][j]=999999999;
	  for (i=0;i<n;i++) {
		   cin >> a >> b >> c;
		   d[a][b]=d[b][a]=c; d[a][a]=d[b][b]=0;
	   }
	   for (i=0;i<10;i++) for (j=0;j<10;j++) for (k=0;k<10;k++) d[j][k]=min(d[j][k],d[j][i]+d[i][k]);
	   c=999999999;
	   for (i=0;i<10;i++) {
		   if (d[i][i]>0) continue;
		   for (j=0,b=0;j<10;j++) if (d[i][j]<999999999) b+=d[i][j];
		   if (c>b) { a=i; c=b;}
	   }
	   cout << a << ' ' << c << endl;
	}
 return 0;
}	

Measured memory_bytes: 1156
#include<iostream>
#include<vector>
#include<algorithm>
#include <string>
#include<cmath>
#include<map>
#include<cstdio>
#include<stack>
#include<queue>
#include<math.h>

#define ok printf("ok\n");
#define MAX 1000000
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(g);(i)--)
#define all(a) (a).begin(),(a).end()
#define pb push_back

using namespace std;

typedef vector<int> vi;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vll;

int main()
{
	string s;
	cin >> s;
	bool x = true;
	repr(i,s.size()-1)
	{
		bool x = true;
		rep(j,i/2){
			if(i%2 == 1){
				x = false;
				//ok
				break;
			}
			if(s[0+j] != s[(i/2)+j]){
				//puts("x");
				x = false;
				break;
			}
			else
				continue;
		}
		if(x)
		{
			cout << i;
			return 0;
		}
	}
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int read()
{
	char ch=getchar();int f=0;
	while(ch<'0'||ch>'9') ch=getchar();
	while(ch>='0'&&ch<='9') {f=f*10+(ch^48);ch=getchar();}
	return f;
}
int a[100005],x,y;
int main()
{
	int n=read();
	for(int i=1;i<=n;i++)
	a[i]=read();
	for(int i=1;i<=n;i++)
	{
		if(a[i]%4==0)
		{
			x++;
		}
		else if(a[i]%2==0)
		{
			y++;
		}
		
	}
	if(2*x+1>=n||2*x+y>=n)
	printf("Yes");
	else printf("No");
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define rep(i,n,m) for(int i=n;i<(int)(m);i++)
#define rrep(i,n,m) for(int i=((int)(n)-1);i>=m;i--)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
const int MOD=1000000007;
using namespace std;
template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}
template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

int main(){
    int n,k;
    cin>>n>>k;
    vector<bool> ok(10,true);
    rep(i,0,k){
        int d;
        cin>>d;
        ok[d]=false;
    }
    
    while (true) {
        string s=to_string(n);
        bool check=true;
        rep(i,0,s.size()){
            if(!ok[s[i]-'0']) check=false;
        }
        if(check){
            cout<<n<<endl;
            return 0;
        }
        n++;
    }
}


Measured memory_bytes: 256
def f(l):
    r = sum(l)**2
    for x in l:
        r -= x**2
    r = r//2
    r += sum(l)+1
    return r

N, = map(int, input().split())
G = [set() for _ in range(N+1)]
G2 = [set() for _ in range(N+1)]
sz = [1 for _ in range(N+1)]
X = [-1] + list(map(int, input().split()))
for _ in range(N-1):
    a, b = map(int, input().split())
    G[a].add(b)
    G[b].add(a)

stack = [1]
vs = set([1])
vs_dfs = []
while stack:
    v = stack.pop()
    vs_dfs.append(v)
    for u in G[v]:
        if u in vs:
            continue
        vs.add(u)
        G2[v].add(u)
        stack += [u]
G = None

for x in vs_dfs[::-1]:
    for u in G2[x]:
        sz[x] += sz[u]

stack = [1]
path = []
R = [0] * (N+1)
kh = [[] for _ in range(N+1)]
tt = [N-1 for _ in range(N+1)]
while stack:
    v = stack.pop()
    if v > 0:
        if path:
            parent = path[-1]
            kh[X[parent]].append(sz[v])
        path.append(v)
        tmp = []
        for u in G2[v]:
            tmp.append(sz[u])
            stack += [-v, u]
        if kh[X[v]]:
            tmp.append(kh[X[v]][-1]-1-sum(tmp))
            kh[X[v]][-1] -= sz[v]
        else:
            tmp.append(tt[X[v]]-sum(tmp))
            tt[X[v]] -= sz[v]
        R[X[v]] += f(tmp)
#        kz[X[v]].append(v)
    else:
#        kz[X[path[-1]]].pop()
        c = path.pop()
        kh[X[-v]].pop()
for i in range(1, N+1):
    print(R[i])



Measured memory_bytes: 244520
#include<bits/stdc++.h>
#define fr(i,a,n) for(ll i=a;i<n;i++)
#define YES cout<<"YES"<<endl
#define all(v) v.begin(),v.end()
#define NO cout<<"NO"<<endl
#define pb(x) emplace_back(x)
#define fastio std::ios_base:: sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define vi vector<ll>
#define mi map<ll,ll>
#define pi pair<ll,ll>
#define what(x) cout<<#x<<" ="<<x<<endl;
#define scn(n) scanf("%d",&n)
#define print(a) printf("%d",a);
using namespace std;
using ll =int;
ll n;

ll dp[200005],a[200005]={1000000000};
ll invalid=1e9,k;
ll cnt=0;
int solve(ll i,ll p)
{ //cnt++;
    if(i==n-1)return dp[i]=0;
    if(i>=n)return 1e9;
    if(dp[i]!=-1)return dp[i];
    //what(p-a[i]);
    //cout<<i<<" GG "<<i+1<<endl;
    ll ans=1e9,x;
    fr(l,1,min(k,n)+1){
        //what(l);
    x=abs(a[i+l]-a[i])+solve( i+l,a[i]);

    ans=min(x,ans);

    }



    return dp[i]=ans;

}

int main()
{
    ll t;
    memset(dp,-1,sizeof dp);

    scn(n);
    scn(k);
    fr(i,0,n)cin>>a[i];

    solve(0,a[0]);

    printf("%d\n",dp[0]);
    //what(cnt);
    //fr(i,0,n)cout<<dp[i]<<" ";

}



























Measured memory_bytes: 11140
a = int(input())
b = int(input())
c = int(input())
x = int(input())

count = 0
for i in range(a+1):
    for j in range(b+1):
        for k in range(c+1):
            if 500*i + 100*j + 50*k == x:
                count+=1

print(count)

Measured memory_bytes: 3060
from collections import defaultdict

N, M = map(int, input().split())
A = list(map(int, input().split()))
A = sorted(A, reverse=True)  # 多分いる

C_counts = defaultdict(int)

for i in range(M):
    b, c = map(int, input().split())
    C_counts[c] += b

C_keys = sorted(C_counts.keys(), reverse=True)
indx_A = 0
indx_C = 0

ans = 0
for i in range(N):
    a = A[indx_A]
    if indx_C >= len(C_keys):
        ans += A[indx_A]
        indx_A += 1
        continue

    c = C_keys[indx_C]

    if a > c:
        ans += a
        indx_A += 1
    else:
        ans += c
        C_counts[C_keys[indx_C]] -= 1
        if C_counts[C_keys[indx_C]] == 0:
            indx_C += 1
print(ans)

Measured memory_bytes: 75672
/*
#pragma GCC optimize("Ofast,unroll-loops")
#pragma GCC target("avx,avx2,fma")
*/
#include <bits/stdc++.h>
#define LL              long long
#define ll              long long
#define SL(n)           scanf("%lld",&n)
#define LF              double
#define SF(n)           scanf("%lf",&n)
 
#define pb              push_back
#define mp              make_pair
 
#define ON(n,i)         (n|(1LL<<i))
#define OFF(n,i)        (n&(~(1LL<<i)))
#define CHK(n,i)        (n&(1LL<<i))
 
#define ff              first
#define ss              second
 
#define SET(arr)        memset( arr , -1 , sizeof arr)
#define RESET(arr)      memset( arr,0,sizeof arr)
 
#define srt(v)          sort(v.begin(),v.end())
#define uniq(v)			v.resize(distance(v.begin(),unique(v.begin(),v.end())))
#define found( s,d )    (s.find(d) != s.end())
 
#define FOR(i,s,e)      for( LL i = s ; i<=e ; i++ )
#define RFOR(i,e,s)     for( LL i = e ; i>=s ; i-- )
         
 
#define FILEIN          freopen("in.txt","r",stdin)
#define FILEOUT         freopen("WA.txt","w",stdout)
 
#define DEBUG(x)        cerr<<#x<<" = "<<x<<endl
#define PRINTALL(v)     {cerr<<endl<<"Printing: "<<#v<<endl;for(LL i = 0 ; i<v.size(); i++) DEBUG(v[i]); cerr<<endl;}
 
using namespace std;

LL f[110];

int main(){
    
    LL x,n;
    SL(x); SL(n);
    FOR(i,1,n){
        LL a;
        SL(a);
        f[a] = 1;
    }

    LL mn = 1e18, who = 1e18;
    FOR(i,0,101){
        if(f[i]) continue;
        LL diff = abs(i-x);
        if(diff<mn){
            mn = diff;
            who = i;
        }
    }
    cout<<who<<endl;
    
return 0;}

Measured memory_bytes: 3700
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N, count = 1;
  cin >> N;
  vector<string> S(N);
  for(int i=0;i<N;i++) cin >> S.at(i);
  sort(S.begin(), S.end());
  for(int i=0;i<N-1;i++){
    if(S.at(i) != S.at(i+1)) count++;
  }
  cout << count << endl;
  return 0;
}

Measured memory_bytes: 9600