akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> l_l;
typedef pair<int , int> i_i;
typedef vector<ll> vel;
typedef vector<int> vei;
typedef vector<char> vec;
typedef vector<bool> veb;
typedef vector<string> ves;
typedef vector<vector<ll>> ve_vel;
typedef vector<vector<int>> ve_vei;
typedef vector<vector<char>> ve_vec;
typedef vector<vector<bool>> ve_veb;
typedef vector<vector<string>> ve_ves;
#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 rep2(i,n) for(int i=2;i<(int)(n);i++)
#define repk(i,k,n) for(int i=k;i<(int)(n);i++)
#define fs first
#define sc second
#define pub push_back
#define puf push_front
#define pob pop_back
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define maxel(a) *max_element(all(a))
#define minel(a) *min_element(all(a))
#define acc accumulate
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define mod (1000000007)
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

int main() {
  string s;
  cin >> s;
  set<string> st;
  for(int i = 0; i < s.size(); i++) {
    for(int j = 1; j <= 10; j++) {
      st.insert(s.substr(i, j));
    }
  }
  auto cur = st.begin();
  int K;
  cin >> K;
  K--;
  while(K--) cur++;
  cout << *cur << endl;
}

Measured memory_bytes: 3968
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    if(n%10==2 || n%10==4 || n%10==5 || n%10==7 || n%10==9){
        cout<<"hon";
    }
    else if(n%10==0 || n%10==1 || n%10==6 || n%10==8){
        cout<<"pon";
    }
    else
        cout<<"bon";
}


Measured memory_bytes: 3596
#include <bits/stdc++.h>
 
using namespace std;
 
int main()
{
	int n,k;
  	cin >> n >> k;
  	int a[n];
  	int sum = 0;
  	for(int i=0;i<n;i++)
    {
      	cin >> a[i];
      	sum += a[i];
    }
  	int count = 0;
  	float s = (float)((float)sum/(k*4));
  	//cout << s << "\n";
  	sort(a, a+n);
  	bool c = true;
  	for(int i=n-1;i>=0;i--)
    {
      	if((float)a[i] >= s)
        {
          count = count + 1;
        }
      if(k == count)
      {
        	c = false;
        	break;
      }
    }
  if(!c)
  {
    cout << "Yes\n";
  }
  else
  {
    cout << "No\n";
  }
}

Measured memory_bytes: 256
# abc109b

N = int(input())
W = []

for i in range(N):
    W.append(input())

h = []
for i in range(1,N):
    h.append(W[i][0])
t = []
for i in range(N-1):
    t.append(W[i][-1])    

flg = 1
for i in range(N-1):
    if h[i] != t[i]: flg = 0
W.sort()
for i in range(N-1):
    if W[i] == W[i+1]: flg = 0

if flg==1: print("Yes")
else: print("No")

Measured memory_bytes: 3064
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<string>
#include<cmath>
#include<map>
#include<queue>
#include<set>
#include<vector>
#include<cstdio>

using namespace std;
/*
int find(int x, vector<int> &p) {
if (p[x] == x)return x;
return p[x] = find(p[x], p);
}

void uni(int x, int y, vector<int> &p) {
x = find(x, p);
y = find(y, p);
p[x] = y;
}

int same(int x, int y, vector<int> p) {
if (find(x, p) == find(y, p))return 1;
return 0;
}
*/

//long long a[1002];


int main()
{
	long long N, cnt = 0, tmp, ans = 0;
	long long K;
	cin >> N >> K;

	vector<long long> xm, xp;
	for (int i = 0; i < N; i++) {
		cin >> tmp;
		if (tmp >= 0) {
			xp.push_back(tmp);
		}
		else {
			xm.push_back(-tmp);
		}
	}
	if(xm.size() != 0)sort(xm.begin(), xm.end());
	/*
	vector<long long> sm, sp;
	for (auto x : xm) {
		sm.push_back(cnt);
		cnt += x;
	}
	sm.push_back(cnt);
	cnt = 0;
	for (auto x : xp) {
		sp.push_back(cnt);
		cnt += x;
	}
	sm.push_back(cnt);
	*/
	if (xm.size() >= K && xp.size() >= K) ans = min(xm[K - 1], xp[K - 1]);
	else if(xm.size() >= K && xp.size() < K) ans = xm[K - 1];
	else if(xm.size() < K && xp.size() >= K) ans = xp[K - 1];
	else ans = 1000000000;
	for (int i = 0; i < K; i++) {
		if (xm.size() >= i + 1 && xp.size() >= K - 1 - i && xp.size() != 0) {
			ans = min(ans, 2 * min(xm[i], xp[K - 2 - i]) + max(xm[i], xp[K - 2 - i]));
			tmp = 2 * min(xm[i], xp[K - 1 - i]) + max(xm[i], xp[K - 2 - i]);
		}
	}

	cout << ans;

	char qq;
	cin >> qq;
	return 0;
}

Measured memory_bytes: 1656
n = int(input())
p_list = list(map(int,input().split()))

count = 0

for i in range(len(p_list)-2):
    target = p_list[i:i+3]
    if (target[0] < target[1] < target[2]) or (target[2] < target[1] < target[0]):
        count += 1


print(count)

Measured memory_bytes: 3064
#include <iostream>
#include <vector>

// aの配列の文字を使ってxを作れるか？
bool find(int x, const std::vector<int> &a, int sum = 0, std::size_t i = 0) {
  if (sum == x)
    return true;
  if (i >= a.size())
    return false;
  return find(x, a, sum, i + 1) || find(x, a, sum + a[i], i + 1);
}

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

  std::cin >> n;
  int x;
  for (int i = 0; i < n; i++) {
    std::cin >> x;
    std::cout << (find(x, a) ? "yes" : "no") << std::endl;
  }
}



Measured memory_bytes: 3120
#include <iostream>
#include <vector>

using namespace std;

int main(){
  int N;
  cin >> N;
  vector <long> A(N);
  for (int i = 0; i < N; ++i) {
    cin >> A[i];
  }
  
  long ans = 0;
  for (int i = 1; i < N; ++i) {
    if (A[i - 1] > A[i]) {
      ans += A[i - 1] - A[i];
      A[i] = A[i - 1];
    }
  }
  
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 4840
def l(n)
    l0, l1, l2 = 2, 1 ,3
    return l1 if n == 1
    return l2 if n == 2
    
    (n-2).times {
        l0 = l1
        l1 = l2
        l2 = l0 + l1
    }
    
    l2
end

n = gets.to_i
p l(n)

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

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] ar = new int[n];
		int count =0;
		// create second array 
		for (int i=0;i<n;i++){
			ar[i] = sc.nextInt();
		}
		//count
		for (int i=0;i<n;i++){
			int self = i;
			int self_love = ar[i]-1;
			int love_one = self_love;
			int love_ones_love = ar[self_love]-1;
			if (self == love_ones_love && self_love == love_one){
				count ++;
			}
		}
		//System.out.print("pairs" + count/2);
		System.out.print(count/2);
		//sc.close();
	}

}

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


Measured memory_bytes: 5596
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
int gcd(int a,int b)
{
	if(b==0)
	return a;
	
	return gcd(b,a%b);
}
int power(int x,int y,int p)
{
	int res=1;
	x=x%p;
	while(y>0)
	{
		if(y&1)
		res=(res*x)%p;
		
		y=y>>1;
		x=(x*x)%p;
	}
	return res;
}
struct Matrix{ 
	int a[2][2] = {{0,0},{0,0}};
	Matrix operator *(const Matrix& other){
		Matrix product;
		for(int i=0;i<2;i++){
			for(int j=0;j<2;j++){
				for(int k=0;k<2;k++){
						product.a[i][k] =product.a[i][k] + (ll)a[i][j]*other.a[j][k];
				}
			}
		}
		return product;
	}
};
int modInverse(int n,int p)
{
	return power(n,p-2,p);
}
int main() {
	
	// your code goes here
	 ios_base::sync_with_stdio(0);
	 cin.tie(0);
	 string s;
	 cin>>s;
	 ll sum = 0;
	 for(int i=0;i<(int)s.length();i++)
	 {
		 int x = s[i] - '0';
		 sum+=x;
	 }
	 if(sum%9 == 0)
	 cout<<"Yes"<<'\n';
	 else
	 cout<<"No"<<'\n';
}


Measured memory_bytes: 3720
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <numeric>
#include <utility>
#include <string>

using namespace std;

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

	int ans = max({a+b, a-b, a*b});
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#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;
bool ask(int a,int b){
	cout<<"? "<<a<<" "<<b<<endl;
	char c;
	cin>>c;
	return c=='Y';
}
int main(){
	int A,B;
	cin>>A>>B;
	if(A<=B){
		cout<<"Impossible"<<endl;
		return 0;
	}
	int N=A+B;
	vector<int> vc;
	int need = B+1;
	rep(i,N){
		if(vc.empty()){
			vc.pb(i);
			if(vc.size()>=need) break;
			continue;
		}
		bool b = ask(i,vc.back());
		if(b){
			vc.pb(i);
			if(vc.size()>=need) break;
		}
		else{
			vc.pop_back();
			need--;
		}
	}
	int honest = vc.front();
	string ans(N,'0');
	rep(i,N) if(ask(honest,i)) ans[i]='1';
	cout<<"! "<<ans<<endl;
}

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

namespace test
{
    class Program
    {
        static void Main(string[] args)
        {
            var cnt = new int[4];
            var set = new int[3, 2];
            var suc = true;
            for (int i = 0; i < 3; i++)
            {
                var input = ReadArrayInt();
                var a = input[0] - 1;
                var b = input[1] - 1;
                cnt[a]++;
                cnt[b]++;
                set[i, 0] = a;
                set[i, 1] = b;
            }
            if (cnt.Any(c => c >= 3)) suc = false;
            if (cnt.Any(c => c == 0)) suc = false;

            Console.WriteLine(suc ? "YES" : "NO");
            Console.ReadLine();
        }

        static string Read() { return Console.ReadLine(); }
        static int ReadInt() { return int.Parse(Read()); }
        static long ReadLong() { return long.Parse(Read()); }
        static int[] ReadArrayInt() { return Read().Split(' ').Select(s => int.Parse(s)).ToArray(); }
        static long[] ReadArrayLong() { return Read().Split(' ').Select(s => long.Parse(s)).ToArray(); }
    }
}

Measured memory_bytes: 13396
var input = '';
process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stdin.on('data', function(chunk) {
    input += chunk;
});
process.stdin.on('end', function() {
    main(input)
});

function main(input){
    var args = input.trim().split('\n');
    args.forEach(function(pair){
        pair = pair.split(' ').map(Number);
        var res = '' + (pair[0] + pair[1]);
        console.log(res.length);
    })
}

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

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
int main(){
  int n;
  cin >> n;
  vector<int> a(n);
  vector<int> b(n);
  int ans = 0;
  for (int i = 0; i < n; i++) {
    cin >>  a[i];
  }
  for (int i = n-2; i >= 0; i--) {
    if (a[i+1] <= a[i]) {
      b[i] = b[i+1] + 1;
      if (b[i] > ans) ans = b[i];
    } else {
      b[i] = 0;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1024
#!/usr/bin/env python3
import sys
INF = float("inf")


def solve(N: int, A: int, B: int):
    if (B-A) % 2 == 0:
        print(min((B-A)//2, min(max(A, B)-1, N-min(A, B))))
    else:
        # 偶奇をすらすパターン
        m = A + (B-A-1)//2
        m = min(m, N-B+1+(B-A-1)//2)
        print(m)
    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    solve(N, A, B)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include <cmath>
#include <iostream>
#include <string>
#include <time.h>
#include <stdio.h>
using namespace std;

int main()
{
    int a, b, c;
    cin >> a >> b >> c;
    if (a < b && b < c)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
}



Measured memory_bytes: 3080
#include<bits/stdc++.h>
using namespace std;
int main(){
    ios::sync_with_stdio(false);
    cin.tie();
    int n, m;
    cin>>n>>m;
    int a[n];
    int total = 0;
    for(int i = 0; i < n; i++){
        cin>>a[i];
        total +=a[i];
    }
    int div = 4*m;
    int k = 0;
    int temp;
    if(total%div == 0)
    temp = total/div;
    else
    {
        temp = total/div + 1;
    }
    for(int i = 0; i < n ;i++){
        
        if(a[i] >= temp)
        k++;
    }
    if(k >= m) cout<<"Yes";
    else cout<<"No";
    return 0;
}

Measured memory_bytes: 3636
import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main {

	int mod = 1000000007;

	static public int diff(int[] a, int i, int j) {
		return Math.abs(a[i] - a[j]);
	}

	public static void main(String[] args) {
		MyScanner sc = new MyScanner();
		out = new PrintWriter(new BufferedOutputStream(System.out));

		int n = sc.nextInt();
		int k = sc.nextInt();

		int[] a = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = sc.nextInt();
		}

		int[] dp = new int[n];
		for (int i = 0; i < k && i < n; i++) {
			dp[i] = diff(a, 0, i);
		}

		for (int i = k; i < n; i++) {
			dp[i] = Integer.MAX_VALUE;
			for (int j = 1; j <= k; j++) {
				dp[i] = Math.min(dp[i], diff(a, i, i - j) + dp[i - j]);
			}
		}

		out.print(dp[n - 1]);
		/*
		 * int n = sc.nextInt(); // read input as integer long k = sc.nextLong(); //
		 * read input as long double d = sc.nextDouble(); // read input as double String
		 * str = sc.next(); // read input as String String s = sc.nextLine(); // read
		 * whole line as String
		 * 
		 * int result = 3*n; out.println(result); // print via PrintWriter
		 */

		// Stop writing your solution here. -------------------------------------
		out.close();
	}

	// -----------PrintWriter for faster output---------------------------------
	public static PrintWriter out;

	// -----------MyScanner class for faster input----------
	public static class MyScanner {
		BufferedReader br;
		StringTokenizer st;

		public MyScanner() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		String next() {
			while (st == null || !st.hasMoreElements()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}

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

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

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

		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (IOException e) {
				e.printStackTrace();
			}
			return str;
		}

	}
	// --------------------------------------------------------
}


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

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;

ll cnt[200010];

int main(){
    int n;
    cin >> n;
    for (int i = 1; i <= n; ++i) {
        string s;
        s = to_string(i);
        cnt[i] += cnt[i-1];
        if(i % 10 == 0){
            continue;
        }
        if(s.size() == 1){
            cnt[i] += 1;
            continue;
        }
        if(s[0] - '0' > i % 10){
            ll c = 0;
            for (int j = 2; j <= s.size(); ++j) {
                if(j == 2) c += 1;
                else c += pow(10, (j - 2));
            }
            cnt[i] += c * 2;
            continue;
        }
        if(s[0] - '0' < i % 10){
            ll c = 0;
            for (int j = 2; j < s.size(); ++j) {
                if(j == 2) c += 1;
                else c += pow(10, (j - 2));
            }
            cnt[i] += c * 2;
            continue;
        }
        if(s[0] - '0' == i % 10){
            ll c = 0;
            for (int j = 1; j <= s.size(); ++j) {
               if(j <= 2){
                   c += 1;
                   continue;
               }
               if(j == s.size()){
                   c += (i / 10) - (i % 10) * pow(10, s.size() - 2) + 1;
               }
               else{
                   c += pow(10, (j - 2));
               }
            }
            cnt[i] += c * 2 - 1;
            continue;
        }
    }
    cout << cnt[n] << endl;
}

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

int main(){
    unordered_set<int> s1, s2;
    int N, M;
    cin >> N >> M;
    int a, b;
    for(int i=0; i<M; i++){
        cin >> a >> b;
        if(a == 1){
            s1.insert(b);
        }else if(b == N){
            s2.insert(a);
        }
    }
    for(auto x: s1){
        if(s2.find(x) != s2.end()){
            cout <<  "POSSIBLE";
            return EXIT_SUCCESS;
        }
    }
    cout <<  "IMPOSSIBLE";
    return EXIT_SUCCESS;
}

Measured memory_bytes: 8520
/*----------------by syr----------------*/
/*
  -----  -----  -----
  |   |  |---|    _/
  |   |  | \_    /
  -----  |   \  -----

  |---\  \   /  |\  /|
  |   |   \_/   | \/ |
  |   |   / \   |    |
  |---/  /   \  |    |
*/
#include<bits/stdc++.h>

using namespace std;

#define PH push
#define MP make_pair
#define PB push_back
#define fst first
#define snd second
#define FOR(i,x,y) for(int i=(x);i<(y);++i)
#define REP(i,x,y) for(int i=(x);i<=(y);++i)
#define x0 x0123456789
#define y0 y0123456789
#define x1 x1234567890
#define y1 y1234567890
#define x2 x2345678901
#define y2 y2345678901
typedef double db;
typedef long long ll;
typedef long double ldb;
typedef pair<int,int> pii;

const ll INF=1e18+7;
const int maxn=18;

int n;
int a[maxn][maxn];
ll b[1<<maxn],dp[1<<maxn];

int main(){
	scanf("%d",&n);
	FOR(i,0,n) FOR(j,0,n) scanf("%d",&a[i][j]);
	FOR(i,1,1<<n){
		FOR(j,0,n){
			if(!(i&(1<<j))) continue;
			FOR(k,j+1,n){
				if(!(i&(1<<k))) continue;
				b[i]+=a[j][k];
			}
		}
	}
	FOR(i,1,1<<n){
		dp[i]=b[i];
		for(int j=i;j;j=(j-1)&i) dp[i]=max(dp[i],dp[j]+b[i^j]);
	}
	printf("%lld ",dp[(1<<n)-1]);
	return 0;
}


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

using namespace std;

namespace {

    typedef double real;
    typedef long long ll;

    template<class T> ostream& operator<<(ostream& os, const vector<T>& vs) {
        for (int i = 0; i < vs.size(); i++) os << vs[i] << endl;
        return os;
    }
    template<class T> istream& operator>>(istream& is, vector<T>& vs) {
        for (auto&& v : vs) is >> v;
        return is;
    }

    int N; ll L;
    vector<ll> A;
    void input() {
        cin >> N >> L;
        A.clear(); A.resize(N);
        cin >> A;
    }

    void solve() {
        int pos = 0;
        for (int i = 0; i < N - 1; i++) {
            if (A[i] + A[i + 1] >= L) {
                pos = i + 1;
                break;
            }
        }

        if (!pos) {
            cout << "Impossible" << endl;
            return;
        }

        cout << "Possible" << endl;
        for (int i = 1; i < pos; i++) {
            cout << i << endl;
        }
        for (int i = N - 1; i > pos; i--) {
            cout << i << endl;
        }
        cout << pos << endl;


    }

}

int main() {
    input(); solve();
    return 0;
}



Measured memory_bytes: 1536
import collections
n,q = map(int,input().split())
class deque():
  def __init__(self):
    self.a = [None]*100000
    self.head = 0
    self.tail = 0
  def append(self,e):
    self.a[self.tail] = e
    self.tail += 1
    if self.tail == 100000: self.tail = 1
  def __bool__(self):
    return self.head != self.tail
  def popleft(self):
    if self.head == self.tail:
      return None
    ret = self.a[self.head]
    self.head += 1
    if self.head == 100000: self.head = 1
    return ret
#a = collections.deque()
a = deque()
for i in range(n):
  name,time = input().split()
  a.append([name,int(time)])
rest = q
t = 0
while a:
  name,time = a.popleft()
  if q < time:
    t += q
    a.append([name,time-q])
  else:
    t += time
    print(name,t)


Measured memory_bytes: 20508
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<climits>
#include<iostream>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<list>
#include<map>
#include<set>
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
#define pb push_back
int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};
  
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
char room[100][100];
bool fin[100][100];
int w,h;

int dfs(int i,int j){
    int sum = 1;
 
    fin[i][j] = false;
 
    for(int k = 0;k < 4;k++){
        int ii = i + dy[k];int jj = j + dx[k];
        if(ii >= 0 && ii < h && jj >= 0 && jj < w && fin[ii][jj] && room[ii][jj] == '.')
            sum += dfs(ii,jj);
    }
    return sum;
}
 
int main(){
    while(1){
        scanf("%d%d",&w,&h);
 
        if(w == 0 && h == 0)
            break;
 
        for(int i = 0;i < h;i++)
            scanf("%s",&room[i][0]);
 
        for(int i = 0;i < h;i++)
            for(int j = 0;j < w;j++)
                fin[i][j] = true;
 
        for(int i = 0;i < h;i++){
            for(int j = 0;j < w;j++){
                if(room[i][j] == '@')
                    printf("%d\n",dfs(i,j));
            }
        }
    }
    return 0;
}

Measured memory_bytes: 3140
#include <iostream>

using namespace std;

int n, s, cnt;

void dfs(int next, int sum, int depth) {
    if (depth == n && sum == s) {
        cnt++;
        return;
    }

    if (next == 10 || depth == n || sum > s) return;

    dfs(next + 1, sum + next, depth + 1);
    dfs(next + 1, sum, depth);
}

int main() {
    while (cin >> n >> s) {
        if (n == 0 && s == 0) break;
        cnt = 0;
        dfs(0, 0, 0);
        cout << cnt << endl;
    }
    return 0;
}

Measured memory_bytes: 3080
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

func s(A, B, i int) int {
	a := make([]int, 3)
	a[0] = i * B
	a[1] = (A - i) * (B / 2)
	a[2] = (A - i) * ((B + 1) / 2)
	sort.Ints(a)

	return abs(a[2] - a[0])
}

func search(N, M int) int {

	mn := abs(s(N, M, 1))
	for i := 2; i < N-1; i++ {

		l := abs(s(N, M, i))
		if mn > l {
			mn = l
		}
	}
	return mn

}
func split3(N, M int) int {
	a := (N + 2) / 3

	return a*M - (N-a*2)*M
}

func main() {
	sc := NewScanner()
	N, M := sc.NextInt(), sc.NextInt()

	if N%3 == 0 || M%3 == 0 {
		fmt.Println(0)
		return
	}
	ans := make([]int, 4)
	ans[0] = search(N, M)
	ans[1] = search(M, N)
	ans[2] = split3(N, M)
	ans[3] = split3(M, N)

	sort.Ints(ans)
	fmt.Println(ans[0])
}
func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

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

type Scanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func NewScanner() *Scanner {
	rdr := bufio.NewReaderSize(os.Stdin, 1000)
	return &Scanner{r: rdr}
}
func (s *Scanner) Next() string {
	s.pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	result := string(s.buf[start:s.p])
	s.p++
	return result
}
func (s *Scanner) NextLine() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}
func (s *Scanner) NextInt() int {
	v, _ := strconv.Atoi(s.Next())
	return v
}
func (s *Scanner) NextInt64() int64 {
	v, _ := strconv.ParseInt(s.Next(), 10, 64)
	return v
}

func (s *Scanner) NextIntArray() []int {
	s.pre()
	start := s.p
	result := []int{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 0)
			result = append(result, int(v))
			start = s.p + 1
		}
	}

	return result
}
func (s *Scanner) NextInt64Array() []int64 {
	s.pre()
	start := s.p
	result := []int64{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 64)
			result = append(result, v)
			start = s.p + 1
		}
	}
	return result
}

func (s *Scanner) NextMap() map[int]bool {
	s.pre()
	start := s.p
	mp := map[int]bool{}
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			v, _ := strconv.Atoi(string(s.buf[start:s.p]))
			mp[v] = true
			start = s.p + 1
		}
	}
	v, _ := strconv.Atoi(string(s.buf[start:s.p]))
	mp[v] = true

	return mp
}

func (s *Scanner) pre() {
	if s.p >= len(s.buf) {
		s.readLine()
		s.p = 0
	}
}
func (s *Scanner) readLine() {
	s.buf = make([]byte, 0)
	for {
		l, p, e := s.r.ReadLine()
		if e != nil {
			panic(e)
		}
		s.buf = append(s.buf, l...)
		if !p {
			break
		}
	}
}


Measured memory_bytes: 5504
#include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define MOD 1000000007
#define MOD2 998244353
#define PRIM 3
#define INF (1 << 29)
#define LINF (1LL << 60)
#define EPS (1e-10)
#define PI 3.1415926535897932384626433832795028
typedef long long Int;
typedef pair<Int, Int> P;
typedef long double Real;
typedef complex<Real> CP;

Int rem(vector<Int> &bs, Int num) {
    for (int i = 0; i < bs.size(); i++) {
        if ((bs[i] ^ num) < num)
            num ^= bs[i];
    }
    return num;
}

void solve() {
    int n;
    cin >> n;
    string s;
    vector<Int> a(n);
    for (auto &elem : a)
        cin >> elem;
    cin >> s;

    vector<Int> bs;

    for (int i = n - 1; i >= 0; i--) {
        if (s[i] == '1') {
            if (rem(bs, a[i]) == 0)
                continue;
            {
                cout << 1 << endl;
                return;
            }
        } else {
            Int r = rem(bs, a[i]);
            if (r == 0)
                continue;
            bs.push_back(r);
            for (int i = bs.size() - 1; i > 0; i--) {
                if (bs[i] > bs[i - 1])
                    swap(bs[i], bs[i - 1]);
            }
        }
    }
    cout << 0 << endl;
}

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

Measured memory_bytes: 3096
#include <iostream>
#include <string>
#include <cmath>
#include <vector>
#include <map>
#include <numeric>
#include <algorithm>
#include <iomanip>
#include <stdio.h>

int main(void){
  int ans;
  std::string s;
  std::cin >> s;

  if(s[0]=='R'&&s[1]=='R'&&s[2]=='R')
    ans=3;
  else if(s[0]=='R'&&s[1]=='R')
    ans=2;
  else if(s[1]=='R'&&s[2]=='R')
    ans=2;
  else if(s[0]=='R'||s[1]=='R'||s[2]=='R')
    ans=1;

  std::cout << ans;
  return 0;
}

Measured memory_bytes: 3612
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.*;

public class Main {
  private static class FastScanner {
    private BufferedReader reader = null;
    private StringTokenizer tokenizer = null;

    public FastScanner(InputStream in) {
      reader = new BufferedReader(new InputStreamReader(in));
      tokenizer = null;
    }

    public String next() {
      if (tokenizer == null || !tokenizer.hasMoreTokens()) {
        try {
          tokenizer = new StringTokenizer(reader.readLine());
        } catch (IOException e) {
          throw new RuntimeException(e);
        }
      }
      return tokenizer.nextToken();
    }

    public String nextLine() {
      if (tokenizer == null || !tokenizer.hasMoreTokens()) {
        try {
          return reader.readLine();
        } catch (IOException e) {
          throw new RuntimeException(e);
        }
      }

      return tokenizer.nextToken("\n");
    }

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

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

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

    public int[] nextIntArray(int n) {
      int[] a = new int[n];
      for (int i = 0; i < n; i++)
        a[i] = nextInt();
      return a;
    }

    public long[] nextLongArray(int n) {
      long[] a = new long[n];
      for (int i = 0; i < n; i++)
        a[i] = nextLong();
      return a;
    }
  }

  private static boolean check(long xi) {
    boolean three = false;
    boolean five = false;
    boolean seven = false;
    while (xi > 0L) {
      long d = xi % 10L;
      if (d == 3L) three = true;
      if (d == 5L) five = true;
      if (d == 7L) seven = true;
      xi /= 10L;
    }
    return three && five && seven;
  }
  public static void main(String[] args) {
    FastScanner sc = new FastScanner(System.in);
    long n = sc.nextLong();
    if (n < 357L) {
      System.out.println(0);
      return;
    }
    int c = 0;
    long[] d = new long[] {3L, 5L, 7L};
    Deque<Long> queue = new ArrayDeque<>();
    queue.add(3L);
    queue.add(5L);
    queue.add(7L);
    while (!queue.isEmpty()) {
      long x = queue.poll();
      if (check(x)) c++;
      for (long di : d) {
        if (x * 10L + di > n) break;
        queue.add(x * 10L + di);
      }
    }
    System.out.println(c);
  }
}

Measured memory_bytes: 22996
n = int(input())

n_li = [i for i in range(1,n+1)]

count = 0
while n_li:
    if len(n_li)==1:
        ans = int(n_li[0]*(2**count))
        break
    n_li = [i/2 for i in n_li if i%2==0]
    count+=1
    
print(ans)

Measured memory_bytes: 3060
import java.util.Arrays
import java.util.ArrayList
import java.util.ArrayDeque

const val MOD: Long = (1e9+7).toLong()
fun Double.format(digits: Int) = String.format("%.${digits}f", this)
fun <T : Comparable<T>> Iterable<T>.argmax(): Int? = withIndex().maxBy{it.value}?.index
fun <T : Comparable<T>> Iterable<T>.argmin(): Int? = withIndex().minBy{it.value}?.index

fun main(args: Array<String>) {
    val reader = System.`in`.bufferedReader()
    val (a, b) = reader.readLine()!!.split(" ").map{it.toInt()}

    if (a <= 5) {
        println(0)
    } else if (a <= 12) {
        println(b/2)
    } else {
        println(b)
    }
}


Measured memory_bytes: 35784
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-9;
const ll mod=1e9+7;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};

int n,m,r;
vvi g;
vi a,b;

void dfs(int v){
	int S=0;
	vi c;
	for(auto u:g[v]){
		if(a[u]>1) a[u]--;
		else c.push_back(u);
	}
	for(auto u:c){
		b[u]=v+1;
		dfs(u);
	}
}

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin>>n>>m;
	g=vvi(n);
	a=b=vi(n);
	for(int i=0;i<n+m-1;i++){
		int u,v;
		cin>>u>>v;
		u--;v--;
		g[u].push_back(v);
		a[v]++;
	}
	for(int i=0;i<n;i++) if(a[i]==0) r=i;
	dfs(r);
	for(int i=0;i<n;i++) cout<<b[i]<<endl;
}

Measured memory_bytes: 19584
N,M=map(int,input().split())
A=list(map(int,input().split()))
ALL=sum(A)
ave=ALL/(4*M)
count=0
for i in range(N):
    if(A[i]>=ave):
        count+=1
    else:
        pass
if(count>=M):
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3064
/*
    Author:zeke
    
    pass System Test!
    GET AC!!
*/
#include <iostream>
#include <queue>
#include <vector>
#include <iostream>
#include <vector>
#include <string>
#include <cassert>
#include <algorithm>
#include <functional>
#include <cmath>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <map>
#include <iomanip>
#include <utility>
#include <stack>
#include <bitset>
using ll = long long;
using ld = long double;
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define rep3(var, min, max) for (ll(var) = (min); (var) < (max); ++(var))
#define repi3(var, min, max) for (ll(var) = (max)-1; (var) + 1 > (min); --(var))
#define Mp(a, b) make_pair((a), (b))
#define F first
#define S second
#define Icin(s) \
    ll(s);      \
    cin >> (s);
#define Scin(s) \
    ll(s);      \
    cin >> (s);
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 pair<ll, ll> P;
typedef vector<ll> V;
typedef vector<V> VV;
typedef vector<P> VP;
ll mod = 1e9 + 7;
ll MOD = 1e9 + 7;
ll INF = 1e18;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,a,b;
    cin>>n>>a>>b;
    ll d=n%(a+b);
    ll k=n/(a+b);
    if(d<a){
        cout<<k*a+d<<endl;
    }else{
        cout<<k*a+a<<endl;
    }
}


Measured memory_bytes: 256
#if __has_include("debug.h")
    #include "debug.h"
#else  
#include <bits/stdc++.h>
using namespace std;
#define d(...) 2;
#endif

#define int long long int
#define ld long double

#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define endl "\n"      

#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
#define ff first
#define ss second
#define eps 1e-10
#define PI acos(-1LL)

#define gcd(a,b)            __gcd((a),(b))
#define lcm(a,b)            ((a*b)/gcd(a,b))

void solve();

int32_t main()
{
    #ifdef DEBUG
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
    #endif 

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

void solve()
{
	int i,j;
	int n;
	cin>>n;

	bool flag=0;

	vector<pair<int, int>>a(n+2);

	int cnt=0;

	for(i=1;i<=n;i++)
	{
		cin>>a[i].ff>>a[i].ss;

		if(a[i].ff==a[i].ss)
		{
			cnt++;
		}
		else
		{
			if(cnt>=3)
			{
				flag=1;
			}
			cnt=0;
		}
	}
	if(cnt>=3)
	{
		flag=1;
	}


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

}

Measured memory_bytes: 3656
#include <bits/stdc++.h>
#define int long long
#define uint unsigned int
#define rep(i, a, b) for (int i = a; i < b; i++)
#define repr(i, a, b) for (int i = a; i >= b; i--)
#define all(a) (a).begin(), (a).end()
#define sz(a) (a).size()
#define pb(a) push_back(a)
#define eb(...) emplace_back(__VA_ARGS__)
#define mp(a, b) make_pair(a, b)
#define mt(...) make_tuple(__VA_ARGS__)
using namespace std;
using pii = pair<int, int>;
constexpr int MOD = 1000000007;
constexpr int INF = 1LL << 30;
constexpr double EPS = 1e-10;

struct edge {
  int t, c;
  edge() {}
  edge(int t, int c) : t(t), c(c) {}
};

int N, M;
vector<edge> g[100010];
int dis[100010];

bool dfs(int v, int x) {
  dis[v] = x;
  for (edge e : g[v]) {
    int nv = e.t;
    if (dis[nv] == INF) {
      if (dfs(nv, x+e.c)) continue;
      else return false;
    } else {
      if (dis[nv] == x+e.c) continue;
      return false;
    }
  }
  return true;
}

signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  cin >> N >> M;
  rep(i, 0, M) {
    int L, R, D;
    cin >> L >> R >> D;
    L--; R--;
    g[L].eb(R, D);
    g[R].eb(L, -D);
  }

  fill(dis, dis+N, INF);
  rep(i, 0, N) {
    if (dis[i] == INF) {
      if (!dfs(i, 0)) {
        cout << "No" << endl;
        return 0;
      }
    }
  }
  cout << "Yes" << endl;

  return 0;
}

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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int L;
string S,T;

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>L>>S>>T;
	if(S+T>T+S) swap(S,T);
	for(i=L;i>=0;i--) {
		if(S.size()*i>L) continue;
		if((L-S.size()*i)%T.size()==0) {
			string R;
			FOR(j,i) R+=S;
			while(R.size()<L) R+=T;
			cout<<R<<endl;
			return;
		}
	}
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


Measured memory_bytes: 1684
import collections
N = int(input())
S = [input() for i in range(N)]
ans = collections.defaultdict(int)
for i in S:
  ans[i] += 1
  
max_num = max(ans.values())
max_list = [kv[0] for kv in ans.items() if kv[1] == max_num] 
max_list.sort()
for i in max_list:
  print(i)

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

#define REP(i,n) for(int i=0; i < (n); ++i)
#define REPR(i,n) for(int i=(n); i >= 0; --i)
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)

using ll = long long;
#define INF 1e9

int main(){
  int N, K, X, Y;
  cin >> N >> K >> X >> Y;
  int ans = 0;
  if(K < N){
    ans += K*X;
    ans +=(N-K)*Y;
  }
  else{
    ans += N*X;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define fastio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define range(i,l,h) for(int i=l;i<h;i++)
#define endl '\n'
#define I INT_MAX
#define L INT_MIN
#define pb push_back
#define ll long long
#define ull unsigned long long
#define vi vector<int>
using namespace std;
using std::ios;
constexpr int MOD=1e9+7;
constexpr int mod=998244353;

ll cost[100005];

int main() 
{
    fastio;
    memset(cost,0,sizeof cost);
    int n,k;
    cin>>n>>k;
    vi a(n+1);
    range(i,1,n+1)cin>>a[i];
   
    cost[1]=0;
    range(i,1,k+1)
    {
      cost[i]=abs(a[i]-a[1]);
      range(j,1,i)
      {
        cost[i]=min(cost[i],cost[i-j]+abs(a[i-j]-a[i]));
      }
      //cost[t]
    }
    range(i,k+1,n+1)
    {
      cost[i]=I;
      range(j,1,k+1)
      {
        if(i-j>0)
        cost[i]=min(cost[i],cost[i-j]+abs(a[i-j]-a[i]));
      }
    }
    
    cout<<cost[n];
}

Measured memory_bytes: 1408
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll,ll> pll;
const ll mod=1e9+7;
const ll inf=1e18;

typedef pair<ll,pll> ppll;

int main() {
  ll n;
  string s;
  cin >> n >> s;
  ll ans=0;
  for(ll i=1;i<n-1;i++) {
    string s1=s.substr(0,i);
    string s2=s.substr(i);
    set<char> count;
    for(ll j=0;j<s1.size();j++) {
      count.insert(s1[j]);
    }
    set<char> count2;
    ll tans=0;
    for(ll j=0;j<s2.size();j++) {
      if(count.count(s2[j])&&!count2.count(s2[j])) {
        tans++;
        count2.insert(s2[j]);
      }
    }
    ans=max(ans,tans);
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
	"sort"
)

func main()  {
	var A1,A2,A3 int
	_, _ = fmt.Scan(&A1,&A2,&A3)
	A :=[]int{A1,A2,A3}
	sort.Ints(A)
	ans := (A[2] - A[1]) + (A[1] - A[0])
	fmt.Println(ans)
}


Measured memory_bytes: 512
#include <cstdio>
#include <iostream>
#include <cassert>
#include <algorithm>    
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <cstring>
#include <cmath>
#include <bitset>
#define mk make_pair
#define eb emplace_back
#define eps 1e-8
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
// #define int long long
using namespace std;

typedef long double ld;
typedef unsigned int ui;
typedef pair<int,int> pii;
typedef unsigned long long ull; 
typedef vector<int> vii;
typedef vector<long double> vd;
const int inf = 1e9;
const int M = 1e9 + 7;
//__int128


signed main()
{
  ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
  int n;
  cin >> n;
  printf("%.8f\n", ((n + 1) / 2) / (double) n);
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int MAXN = 1e5+10;
char str[MAXN];
int n,tot,h[MAXN],nx[MAXN<<1],to[MAXN<<1],cnt;
void add_edge(int x,int y){
	to[++tot]=y;nx[tot]=h[x];h[x]=tot;
}
void link(int x,int y){
	add_edge(x,y);
	add_edge(y,x);
}
bool check(){
	if(str[1]=='0')return false;
	if(str[n]=='1')return false;
	for(int i=2;i<n;i++){
		if(str[i]=='1'&&str[n-i]!='1')
			return false;
		if(str[i]=='0'&&str[n-i]!='0')
			return false;
	}
	return true;
}
void dfs(int cur,int sz){
	int rsz=sz-1;
	for(int i=rsz;i>=1;i--){
		if(str[i]=='1'){
			while(rsz>=i){
				rsz-=i;
				link(cur,++cnt);
				dfs(cnt,i);
			}
			break;
		}
	}
	while(rsz){
		rsz-=1;
		link(cur,++cnt);
		dfs(cnt,1);
	}
}
void print(int x,int y){
	for(int i=h[x];i;i=nx[i]){
		if(to[i]==y)continue;
		printf("%d %d\n",x,to[i]);
		print(to[i],x);
	}
}
int main(){
	scanf("%s",str+1);
	n=strlen(str+1);
	if(!check()){
		puts("-1");
		return 0;
	}
	cnt=1;
	dfs(cnt,n);
	print(1,0);
	return 0;
}


Measured memory_bytes: 8192
#include <bits/stdc++.h>
#define DEBUG if(0)
#define lli long long int
#define ldouble long double
using namespace std;

const int maxN = 8; int n;
struct Point
{
  ldouble x, y;
  void read() { scanf("%Lf %Lf", &x, &y); }
  ldouble dist(Point &other)
  {
    return sqrt((x - other.x)*(x - other.x) + (y - other.y)*(y - other.y));
  }
  bool operator<(const Point &other) const
  {
    return x < other.x || (x == other.x && y < other.y);
  }
};
Point points[maxN];

ldouble fat(ldouble x)
{
  if (x <= 1) return 1;
  return x * fat(x - 1);
}

int main()
{
  while (scanf("%d", &n) != EOF)
  {
    for (int i = 0; i < n; i ++)
      points[i].read();
    sort(points, points+n);

    ldouble ans = 0;
    do
    {
      for (int i = 1; i < n; i ++)
        ans += points[i - 1].dist(points[i]);
    } while (next_permutation(points, points+n));
    ans /= fat(n);
    printf("%.15Lf\n", ans);
  }
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
 
using namespace std;
 
int main(void) {
  int k, length;
  cin >> k;
  char s[101];
  scanf("%s", s);
  length = strlen(s);

  if(length > k){
    for(int i = 0; i<k; i++){
      printf("%c", s[i]);
    }
    cout << "..." << endl;
  } else {
    cout << s << endl;
  }

  return 0;
}

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

int main(){
    int n;
    cin>>n;
    int yen=0;
    double btc=0;
    rep(i,n){
        double x;
        string u;
        cin>>x>>u;
        if(u=="JPY")yen+=x;
        else btc+=x;
    }
    cout<<yen+380000*btc;
    return 0;
}

Measured memory_bytes: 256
from fractions import gcd
from functools import reduce

def read_int_n():
    return list(map(int, input().split()))

def read_float_n():
    return list(map(float, input().split()))

NM=read_int_n()
A=read_float_n()
A=list(set(A)) ##重複した要素を削除し、新たなリストを生成

##2で何回割れるかをcountする
def power2(n): ##参考：https://note.nkmk.me/python-prime-factorization/
  m=0
  while n % 2 == 0:
    m+=1
    n //= 2
  return m

#####2で奇数回割り切れる場合のみのflag
flag=0

a=[]
a_2=power2(A[0])

for i in range(len(A)): ###len(A) ###### A[0]をa=[]にappendする
  if power2(A[i])==a_2:
    a.append(int(A[i]*0.5)) ########## floatをintに直す
  else:
    flag=1

def lcm_base(x, y):
    return (x * y) // gcd(x, y)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)  
  
from decimal import Decimal, ROUND_HALF_UP, ROUND_HALF_EVEN

if flag==0:
  lcm=lcm_list(a)
  amari=NM[1]/lcm #50までは15,30,45の3つ
  amari=(amari+1)//2 #3つのうち奇数を切り上げ
  ########roundは偶数への丸め(0.5は1になる):https://note.nkmk.me/python-round-decimal-quantize/
  ########四捨五入するならdecimalモジュールのquantize('.01')
  #Decimal(i).quantize(Decimal('0.01'), rounding=ROUND_HALF_UP)
  print(int(amari)) 
else:
  print(0)
#print(flag,amari,NM[1],lcm,a,A)

Measured memory_bytes: 15540
#include <iostream>
#include <vector>
#include <cstdio>
#include <string>
#include <algorithm>
#include <map>
#include <numeric>
using namespace std;


int main()
{
    long long int n, m;
    cin >> n >> m;

    vector<long long int> a;
    vector< vector <long long int> > v(m+1, vector<long long int>(2));

    for (int i = 0; i < n; i++) {
        long long int tmp;
        cin >> tmp;
        a.push_back(tmp);
    }

    for (int i = 0; i < m; i++) {
        long long int tmp[2];
        cin >> tmp[0] >> tmp[1];
        v[i][0] = tmp[0];
        v[i][1] = tmp[1];
    }

    sort(a.begin(), a.end());
    sort(v.rbegin(), v.rend(), [](auto& x, auto& y) { return x[1] < y[1]; });
    
    int pos = 0;
    for (int i = 0; i < m; i++) {
        long long int param = v[i][1];
        int num = v[i][0];
        for (int j = 0; j < num; j++) {
            if (pos >= n) {
                goto CALC;
            }
            if (a[pos] > param) {
                goto CALC;
            }
            a[pos] = param;
            pos++;
        }
    }
  
CALC:
  cout << accumulate(a.begin(), a.end(), 0ll) << endl;
    
}


Measured memory_bytes: 6904
#include<stdio.h>

int num1,first[2000];
  
int solve(int a,int b){
  int result;
  if(b==0){
    return 1;
  }
  if(a>=num1){
    return 0;
  }
  result=solve(a+1,b) || solve(a+1,b-first[a]);
  return result;
}



int main(){
 int i,num2,second[2000];
   scanf("%d",&num1);
  for(i=0;i<num1;i++){
    scanf("%d",&first[i]);
  }
  scanf("%d",&num2);
  for(i=0;i<num2;i++){
    scanf("%d",&second[i]);
  }

  for(i=0;i<num2;i++){
    if(solve(0,second[i])){
	printf("yes\n");
      }else{
	printf("no\n");
      }
  }
  return 0;
}







Measured memory_bytes: 2048
#include <bits/stdc++.h>
#pragma GCC optimize("O3")

#define fi first
#define se second
#define em emplace
#define eb emplace_back
#define mp make_pair
#define pi pair<int,int>
#define vi vector<int>
#define vpi vector<pair<int,int>>
#define vll vector<ll>
#define vpll vector<pair<ll,ll>>
#define endl '\n'

#define si(v) int(v.size())
#define all(v) v.begin(), v.end()
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define rep2(i, n, m) for (ll i = n; i <= (m); ++i)
#define rep3(i, n, m) for (ll i = n; i >= (m); --i)

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

using ll = long long;
using ld = long double;
using namespace std;

constexpr ll MOD = 1000000007;

signed main()
{
  cout << fixed << setprecision(20);
  ios::sync_with_stdio(false);
  cin.tie(0);
  
  string s, t; cin >> s;
  t = "CF";

  int now = 0;
  rep(i, si(s)) {
    if (s[i] == t[now]) ++now;
    if (now == 2) {
      cout << "Yes\n";
      return (0);
    }
  }

  cout << "No\n";
  
  return (0);
}

Measured memory_bytes: 3604
from sys import exit
import copy
#import numpy as np
#from collections import deque


d, = map(int, input().split())
c= list(map(int, input().split()))
s=[list(map(int, input().split())) for _ in range(d)]
#  t=[int(input()) for _ in range(d)]

sche=[0 for _ in range(d)]
last=[0 for _ in range(26)]

score=0
for day in range(1,d+1):
    idx=day-1
    d_tmp=0
    i_tmp=0
    for t in range(26):    
        delta=0
        l_tmp=copy.copy(last)
        delta+=s[idx][t]
        l_tmp[t]=day
        for l in range(26):
            delta-=c[l]*(day-l_tmp[l])
        if delta>=d_tmp:
            d_tmp=delta
            i_tmp=t
    sche[idx]=i_tmp
    score+=d_tmp
    last[i_tmp]=day
    # print(score)
    print(i_tmp+1)





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

int w, h;

vector<vector<int>> field(55, vector<int>(55));
vector<vector<int>> island(55, vector<int>(55, -1));

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

void dfs(int y, int x, int id) {
    island[y][x] = id;
    rep(i, 8) {
        int ny = y + dy[i]; int nx = x + dx[i];
        if (ny < 0 || ny >= h || nx < 0 || nx >= w || field[ny][nx] == 0) continue;
        if (island[ny][nx] != -1) continue;
        dfs(ny, nx, id);
    }
}

int main() {
    
    while (cin >> w >> h && w) {
        rep(i, h) {
            rep(j, w) { 
                cin >> field[i][j];
            }
        }

        rep(i, h) {
            rep(j, w) {
                island[i][j] = -1;
            }
        }

        int ans = 0;
        rep(y, h) {
            rep(x, w) {
                if (field[y][x] == 1 && island[y][x] == -1) {
                    dfs(y, x, ans);
                    ans++;
                } 
            }
        }
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 3148