akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define ll                  long long
#define dl                 double
#define pb                push_back
#define F                  first
#define S                  second
#define endl              "\n"
#define rep(i,a,b)       for(i=a;i<b;i++)
#define all(v)             v.begin(),v.end()
#define allr(v)            v.rbegin(),v.rend()
#define mod              1000000007
#define CIN(V,s,n)      for(int i=s;i<n;i++){cin >> V[i];}
#define COUT(V,s,n)   {for(int i=s;i<n;i++){cout <<  V[i] << " "  ;} cout << endl;}
#define fast               ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define CLEAR(V);      for(ll i=0;i<V.size();i++) V[i] = 0;
#define N                  1000LL
#define tmod            998244353
using namespace std;

bool sBs(const pair<int,int> &a,const pair<int,int> &b)
{   return (a.second < b.second);   }

ll SUMD(ll n);
ll BS(vector<ll> &PS,ll s,ll e,ll ser);
ll MI(ll a, ll m);
bool P[N+1];
void Sieve(int n=N);
ll Powb(ll b,ll n);

int main()
{
fast;
ll q=1,t;
//cin >> q;
t = q;
while(q--)
{

    ll h,n,m,k,i,j,l,r,c=0,b,a,g,counter=0,u,v,d,e,w,p,x,y,z,fl=1;
    //n=m=i=j=l=r=a=t=b=c=u=v=w=p=x=y=0;
    cin >> n  ;
    vector<ll> V(n);
    CIN(V,0,n);
    ll ans = 0;
    for(i=0;i<n;i++)
    {
        for(j=0;j<n;j++)
        {
            if(i!=j) ans += V[i]*V[j];
        }
    }
    cout << (ans/2);
    //cout << max(0LL,n-2*m);
}
    return 0;
}

//*****************************************************************************************************************************************

ll Powb(ll b,ll n)
{
    if(n==0) return 1LL;
    if(n==1) return b;
    ll temp = Powb(b,n/2);
    if(n%2==0){return (temp*temp)%mod;}
    else{return (b*((temp*temp)%mod))%mod;}
}

ll SUMD(ll n)
{   ll sum=0;
    while(n>0){sum += n%10;n = n/10;}
    return sum;

}
ll BS(vector<ll> &PS,ll s,ll e,ll ser)
{
    if(s>e)
        return s;
    ll mid = (s+e)/2;
    if(PS[mid]==ser)
    {
        return mid;
    }
    else if(PS[mid] > ser)
    {
        return BS(PS,s,mid-1,ser);
    }
    else
        return BS(PS,mid+1,e,ser);
}
ll MI(ll a, ll m)
{
    ll m0 = m;
    ll y = 0, x = 1;
    if (m == 1)
      return 0;
    while (a > 1)
    {
        ll q = a / m;
        ll t = m;
        m = a % m, a = t;
        t = y;
        y = x - q * y;
        x = t;
    }
    if (x < 0)
       x += m0;
    return x;
}

void Sieve(int n)
{
    memset(P,true,sizeof(P));
    P[0] = false;
    P[1]= false;
    for(ll i=2;i*i<=n;i++)
    {
        if(P[i])
        {
            for(ll j=i*i;j<=n;j+=i)
            {
                P[j]=false;
            }
        }
    }

}


Measured memory_bytes: 256
import java.util.Scanner;

class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		int[] s = new int[n];

		for(int i=0; i<s.length; i++){
			s[i] = sc.nextInt();
		}

		int sum = 0;
		for(int i : s){
			sum += i;
		}

		if(sum%10!=0){
			System.out.println(sum);
			return;
		}

		if(n==1){
			System.out.println("0");
			return;
		}

		int min = s[0];
		for(int i=1; i<s.length; i++){
			if(min%10==0){
				min = s[i];
			}
			if(min>s[i] && s[i]%10!=0){
				min = s[i];
			}
		}

		if(min%10==0){
			System.out.println("0");
		}else{
			System.out.println(sum-min);
		}

	}

}


Measured memory_bytes: 23636
N, A, B, C = map(int, input().split())
ls = []
for _ in range(N):
    ls.append(int(input()))
INF = 10 ** 10


def dfs(i, a, b, c):
    if i == N:
        if min(a, b, c) > 0:
            return abs(a - A) + abs(b - B) + abs(c - C) - 30
        else:
            return INF
    ret0 = dfs(i + 1, a, b, c)
    ret1 = dfs(i + 1, a + ls[i], b, c) + 10
    ret2 = dfs(i + 1, a, b + ls[i], c) + 10
    ret3 = dfs(i + 1, a, b, c + ls[i]) + 10
    return min(ret0, ret1, ret2, ret3)


print(dfs(0, 0, 0, 0))

Measured memory_bytes: 3192
#include <stdio.h>
#include <math.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <numeric>
#include <string>
#include <map>
#include <stack>
using namespace std;
typedef long long int lli;
#define urept(soeji, start, n) for (int soeji = start; soeji < n; soeji++)
#define drept(soeji, start, n) for (int soeji = start; soeji > n; soeji--)
int main(void)
{
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    int ans = 0;
    if (min(b, d) - max(a, c)>=0)
    {
        ans = min(b, d) - max(a, c);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

int main(void) {
	int a, b;
	char op;
	char buf[128], *ch;

	fgets(buf, sizeof(buf), stdin);
	ch = strtok(buf, " ");
	a = atoi(ch);
	op = *strtok(NULL , " ");
	ch = strtok(NULL , " ");
	b = atoi(ch);

	if(op == '+') {
		printf("%d\n", a + b);
	} else if (op == '-') {
		printf("%d\n", a - b);
	}

	return 0;
}


Measured memory_bytes: 2088
#include <iostream>
#include <cstdio>
#include <cctype>

using namespace std;

int main() {
	char ch;
	int count[26] = {};
	while (scanf("%c", &ch) != EOF) {
		ch = tolower(ch);
		int num = ch - 'a';
		count[num]++;
	}
	for (int i = 0; i < 26; i++) {
		printf("%c : %d\n", 'a' + i, count[i]);
	}
	return 0;
}

Measured memory_bytes: 1136
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<queue>
#include<stack>
#include <cassert>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
typedef long long ll;
typedef pair<int,int> P;

vector<P> to[100005];
vector<ll> dist(100005,-1);

void dfs(int v,int p = -1){
  if(p==-1)dist[v]=0;
  for(auto P:to[v]){
    int u = P.first;
    if(u==p)continue;
    dist[u]=dist[v]+P.second;
    dfs(u,v);
  }
}

int main(){
  int n;
  cin >> n;
  rep(i,n-1){
    int a,b,c;
    cin >> a >> b >> c;
    a--,b--;
    to[a].emplace_back(b,c);
    to[b].emplace_back(a,c);
  }
  int q,k;
  cin >> q >> k;
  dfs(k-1);
  rep(i,q){
    int x,y;
    cin >> x >> y;
    cout << dist[x-1]+dist[y-1] << endl;
  }
}

Measured memory_bytes: 12800
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;cin>>n;
  string s[n];
  for(int i=0;i<n;i++)cin>>s[i];
  int cnt[n];fill(cnt,cnt+n,n);
  for(int i=0;i<n;i++){
    for(int j=0;j<n;j++){
      int ni=j;
      int nj=i;
      for(int k=0;k<n;k++){
        if(s[i][j]==s[ni][nj])cnt[k]*=1;
        else cnt[k]*=0;
        ni=(ni+1)%n;
        nj=(nj-1+n)%n;
      }
    }
  }
  int ans=0;
  for(int i=0;i<n;i++)ans+=cnt[i];
  cout<<ans<<endl;
}

Measured memory_bytes: 512
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <limits>
#include <random>
#include <complex>
#include <cmath>
#include <cstdio>
#include <cstdlib>
using namespace std;

#define REP(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define RREP(i,n) for(int (i)=(int)(n)-1;i>=0;i--)
#define REMOVE(Itr,n) (Itr).erase(remove((Itr).begin(),(Itr).end(),n),(Itr).end())
typedef long long ll;

int main() {

    int N; cin >> N;
    vector < int > X(N);
    REP(i,N) cin >> X[i];

    vector < int > B = X;
    sort(B.begin(), B.end());

    int a = B[B.size() / 2];
    int b = B[B.size() / 2 - 1];

    REP(i,X.size()) {
        if (X[i] <= b) {
            cout << a << endl;
        } else {
            cout << b << endl;
        }
    }

    return 0;
}

Measured memory_bytes: 3712
S=int(input())
a=S
ans=[a]
for i in range(2,1000001):
    if a%2==1:
        a = a*3+1
    else:
        a = a//2

    if a in ans:
        print(i)
        exit()
    else:

        ans.append(a)
        
    


    
        


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

#include <boost/range/adaptors.hpp>
#include <boost/range/irange.hpp>

using namespace std;
using namespace boost;
using namespace boost::adaptors;

int main() {
    int64_t n, k;
    bitset<18> s, t;
    cin >> n >> k;
    {
        uint64_t ss, tt;
        cin >> ss >> tt;

        s = ss;
        t = tt;
    }

    vector<bitset<18>> a;
    for (auto _ : irange(0L, n)) {
        uint64_t tmp;
        cin >> tmp;

        bitset<18> aa = tmp;

        if ((aa & s) != s) {
            continue;
        }

        if ((aa | t) != t) {
            continue;
        }

        a.push_back(aa);
    }

    n = a.size();

    vector<vector<int64_t>> combi(n + 1, vector<int64_t>(k + 1, 0));
    vector<vector<int64_t>> scombi(n + 1, vector<int64_t>(k + 1, 0));
    combi[0][0] = 1L;
    for (auto i : irange(0L, k + 1)) {
        scombi[0][i] = 1l;
    }
    for (auto i : irange(1L, n + 1)) {
        combi[i][0] = 1;
        for (auto j : irange(1L, min(i, k + 1))) {
            combi[i][j] = combi[i - 1][j - 1] + combi[i - 1][j];
        }
        if (i < k + 1) {
            combi[i][i] = 1;
        }

        scombi[i][0] = combi[i][0];
        for (auto j : irange(1L, k + 1)) {
            scombi[i][j] = scombi[i][j - 1] + combi[i][j];
        }
    }

    vector<int64_t> pos;
    for (auto i : irange(0L, 18L)) {
        if (!s[i] && t[i]) {
            pos.push_back(i);
        }
    }

    int64_t m = pos.size();

    int64_t ans = 0;
    for (auto b : irange(0uL, 1uL << m)) {
        bitset<18> bs(b);

        bitset<18> mask;
        int64_t c = 0;
        for (auto i : irange(0L, m)) {
            if (!bs[i]) {
                continue;
            }

            mask[pos[i]] = true;
            ++c;
        }

        unordered_map<uint64_t, int64_t> nums;
        for (const auto& aa : a) {
            ++nums[(aa & mask).to_ullong()];
        }

        int64_t tmp = 0;
        for (const auto& kv : nums) {
            tmp += scombi[kv.second][k] - scombi[kv.second][0];
        }

        if (c % 2 == 0) {
            ans += tmp;
        } else {
            ans -= tmp;
        }
    }

    cout << ans << endl;
}

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

int main() {
  int a, b, c, i, ans = 0;
  cin >> a >> b >> c;
  for (i = 1; i <= b; i++) {
    if ((a * i - c) % b == 0) {
      ans = 1;
      break;
    }
  }
  if (ans) {
    cout << "YES"
         << "\n";
  } else {
    cout << "NO"
         << "\n";
  }
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#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++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;	

int main() {
    int n; cin >> n;
    vector<int> a(n);
    REP(i, n) cin >> a[i];
    sort(ALL(a));
    REP(i, n - 1) {
        if (a[i] == a[i + 1]) {
            cout << "NO" << endl;
            break;
        }
        if (i == n - 2) {
            cout << "YES" << endl;
        }
    }
}


Measured memory_bytes: 4012
N, K =(int(i) for i in input().split())
table = [False for _ in range(N)]
for _ in range(K):
  di = int(input())
  a = list(map(int,input().split()))
  for i in a:
    table[i-1] = True

count = 0
for i in range(N):
  if table[i] == False:
    count+=1
   
print(count)
  

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

int main()
{
	int n;
	scanf("%d",&n);

	vector<int> dp(3 , 0);
	// dp[i] is the total cost for the activity i at the last considered day

	for(int day =0;day<n; ++day)
	{
		vector<int> c(3) , new_dp(3 , 0);		
		// a , b , c => a lot of implementations

		for(int i=0;i<3;i++)
		{
			scanf("%d",&c[i]);
		}

		for(int i=0;i<3;i++) // iterate over previous day values
		{
			for(int j=0;j<3;j++) // iterate over today's values
			{
				if(i!=j)
				{
					new_dp[j] = max(new_dp[j] , c[j] + dp[i]);
				}
			}
		}
		dp = new_dp;
	}
	
	printf("%d\n",max({dp[0] , dp[1] , dp[2]}));
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <cctype>
#include <cmath>
#include <iomanip>
#include <climits>
#include <cfloat>
#define ll long long
#define uint unsigned
#define MOD 1000000007
using namespace std;

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

    // #ifndef _DEBUG
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    // #endif

    // --------------------------------
    string s;
    cin >> s;

    string ans (s.size(), 'x');
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
inline void scan(int &num){
int c=getchar();
num=0;
while(c<'0'||c>'9')c=getchar();
while(c>='0'&&c<='9'){num=num*10+c-'0';c=getchar();}
}
int main(){
int x,y;
long long  i=2;
long long result;
long long max=1000000000000000000;
long long imax;
scan(x);
scan(y);
imax=max/x;
if(x%y==0){printf("-1\n");return 0;}
for(i=1;i<y&&(y+i)<imax;i++){
result=x*(y-i);
if((result%y)){printf("%lld\n",result);return 0;}
result=x*(y+i);
if((result%y)){printf("%lld\n",result);return 0;}
}
for (i=y;i<imax;i++){
result=i*x;
if((result%y)){printf("%lld\n",result);return 0;}
}
printf("-1");
return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;
 
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound

const int MOD = 1000000007;

int K, dist[100000];
deque<int> todo;

int main() {
	ios_base::sync_with_stdio(0);cin.tie(0);
	cin >> K;
	F0R(i,K) dist[i] = MOD;
	dist[1] = 1; todo.pb(1);
	while (todo.size()) {
	    int x = todo.front(); todo.pop_front();
	    if (dist[(10*x)%K] > dist[x]) {
	        dist[(10*x)%K] = dist[x];
	        todo.push_front((10*x)%K);
	    }
	    if (dist[(x+1)%K] > dist[x]+1) {
	        dist[(x+1)%K] = dist[x]+1;
	        todo.push_back((x+1)%K);
	    }
	}
	cout << dist[0];
}

// read!
// ll vs. int!

Measured memory_bytes: 896
import java.io.IOException;
import java.io.InputStream;
import java.util.*;
import java.lang.*;


public class Main{
	public static void main(String[] args) {
		FastScanner sc = new FastScanner();
		int n = sc.nextInt();
		long sum = 0;
		TreeMap<Integer, Integer> map = new TreeMap<>();
		for (int i = 1; i <= 9; i++) {
			for (int j = 1; j <= 9; j++) {
				map.put(i * 10 + j, 0);
			}
		}
		for (int i = 1; i <= n; i++) {
			int tmp = i;
			int shita = tmp % 10;
			int ue = tmp % 10;
			while (tmp > 0) {
				ue = tmp % 10;
				tmp /= 10;
			}
			if (ue == 0 || shita == 0) {
				continue;
			}
			map.put(shita * 10 + ue, map.get(shita * 10 + ue) + 1);
		}
		for (int i = 1; i <= 9; i++) {
			for (int j = 1; j <= 9; j++) {
				if (i == j) {
					continue;
				}
				sum += map.get(i * 10 + j) * map.get(j * 10 + i);
			}
		}
		for (int i = 1; i <= 9; i++) {
			sum += map.get(i * 10 + i) * map.get(i * 10 + i);
		}
		System.out.println(sum);
	}
	
}

class FastScanner {
	private final InputStream in = System.in;
	private final byte[] buffer = new byte[1024];
	private int ptr = 0;
	private int buflen = 0;
	private boolean hasNextByte() {
		if (ptr < buflen) {
			return true;
		} else {
			ptr = 0;
			try {
				buflen = in.read(buffer);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (buflen <= 0) {
				return false;
			}
		}
		return true;
	}
	private int readByte() {
		if (hasNextByte()) {
			return buffer[ptr++];
		} else {
			return -1;
		}
	}
	private static boolean isPrintableChar(int c) {
		return 33 <= c && c <= 126;
	}
	public boolean hasNext() {
		while (hasNextByte() && !isPrintableChar(buffer[ptr])) {
			ptr++;
		}
		return hasNextByte();
	}
	public String next() {
		if (!hasNext()) {
			throw new NoSuchElementException();
		}
		StringBuilder sb = new StringBuilder();
		int b = readByte();
		while (isPrintableChar(b)) {
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}
	public long nextLong() {
		if (!hasNext()) {
			throw new NoSuchElementException();
		}
		long n = 0;
		boolean minus = false;
		int b = readByte();
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		if (b < '0' || '9' < b) {
			throw new NumberFormatException();
		}
		while (true) {
			if ('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			} else if (b == -1 || !isPrintableChar(b)) {
				return minus ? -n : n;
			} else {
				throw new NumberFormatException();
			}
			b = readByte();
		}
	}
	public int nextInt() {
		long nl = nextLong();
		if (nl < Integer.MIN_VALUE || Integer.MAX_VALUE < nl) {
			throw new NumberFormatException();
		}
		return (int) nl;
	}
	public double nextDouble() {
		return Double.parseDouble(next());
	}
}


Measured memory_bytes: 24692
import java.io.BufferedReader
import java.io.InputStream
import java.io.InputStreamReader
import java.io.PrintWriter
import java.lang.StringBuilder
import java.util.*

fun PrintWriter.solve(sc: FastScanner) {
    val n = sc.nextInt()
    val a = Array(n) { sc.nextLong().toBigInteger() }
    var ans = 1.toBigInteger()
    a.sort()
    if (a[0] == 0.toBigInteger()) {
        println(0)
        return
    }
    for (i in 0 until n) {
        ans *= a[i]
        if (ans > 1000000000000000000.toBigInteger()) {
            println(-1)
            return
        }
    }
    println(ans)
}

fun main(args: Array<String>) {
    val writer = PrintWriter(System.out, false)
    writer.solve(FastScanner(System.`in`))
    writer.flush()
}

class FastScanner(s: InputStream) {
    private var st = StringTokenizer("")
    private val br = BufferedReader(InputStreamReader(s))

    fun next(): String {
        while (!st.hasMoreTokens()) st = StringTokenizer(br.readLine())

        return st.nextToken()
    }

    fun nextInt() = next().toInt()
    fun nextLong() = next().toLong()
    fun nextLine() = br.readLine()
    fun nextDouble() = next().toDouble()
    fun ready() = br.ready()
}


Measured memory_bytes: 61820
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <limits.h>
#include <queue>
#include <cmath>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
#define REP(i, n) for(int i=0; i<n; i++)

ll N;
int L;

int dfs(int n, int m, bool close, bool seven, bool five, bool three){
    if(n == L) return (seven == true && five == true && three == true);

    int x = (N / (ll)pow(10, (L-1-n))) % 10;
    int ret = 0;
    if(close){
        if(x > 7) ret += dfs(n+1, m, false, true, five, three);
        else if(x == 7) ret += dfs(n+1, m, true, true, five, three);

        if(x > 5) ret += dfs(n+1, m, false, seven, true, three);
        else if(x == 5) ret += dfs(n+1, m, true, seven, true, three);

        if(x > 3) ret += dfs(n+1, m, false, seven, five, true);
        else if(x == 3) ret += dfs(n+1, m, true, seven, five, true);

    }else{
        ret += dfs(n+1, m, false, true, five, three);
        ret += dfs(n+1, m, false, seven, true, three);
        ret += dfs(n+1, m, false, seven, five, true);
    }
    if(n == m) ret += dfs(n+1, m+1, false, seven, five, three);
    return ret;
}

int main(){
    cin >> N;
    ll n = N;
    while(n != 0){
        n /= 10;
        L++;
    }

    int ans = dfs(0, 0, true, false, false, false);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.StringTokenizer;

public class Main {
	public static void main(String[] args) {
		FastScanner sc = new FastScanner(System.in);
		char[] s = sc.next().toCharArray();
		ArrayList<String> front = new ArrayList<>();
		ArrayList<String> back = new ArrayList<>();
		front.add(String.valueOf(s[0]));
		for(int i = 1; i < s.length; i++) {
			back.add(String.valueOf(s[i]));
		}
		int q = sc.nextInt();
		int c = 0;
		for(int i = 0; i < q; i++) {
			int t = sc.nextInt();
			if(t == 1) {
				c++;
			}else {
				int f = sc.nextInt();
				String x = sc.next();
				if((f == 1 && c % 2 == 0)||(f == 2 && c % 2 != 0)) {
					front.add(x);
				}else {
					back.add(x);
				}
			}
		}
		
		if(c % 2 == 0) {
			for(int i = front.size()-1; i >= 0; i--) {
				System.out.print(front.get(i));
			}
			for(String str : back) {
				System.out.print(str);
			}
		}else {
			for(int i = back.size()-1; i >= 0; i--) {
				System.out.print(back.get(i));
			}
			for(String str : front) {
				System.out.print(str);
			}
		}
	}
	
	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;
	    }
	}
}


Measured memory_bytes: 79148
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
using namespace std;
using ll = long long;

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

void dfs(vector<vector<pair<int, int> > >& adja, int node, vector<int>& ans){
  REP(i, adja[node].size()){
    int next = adja[node][i].first;
    if(ans[next]!=-1) continue;
    ans[next] = (ans[node] + adja[node][i].second)%2;
    dfs(adja, next, ans);
  }
}

int main(){
  int n;
  
  cin>>n;
  vector<vector<pair<int, int> > > adja(n);
  REP(i, n-1){
    int u, v, w;
    cin>>u>>v>>w;
    u--;
    v--;
    adja[u].push_back(make_pair(v, w%2));
    adja[v].push_back(make_pair(u, w%2));
  }
  vector<int> ans(n, -1);
  ans[0]=0;
  dfs(adja, 0, ans);

  REP(i, n){
    cout<<ans[i]<<'\n';
  }
}


Measured memory_bytes: 8192
#include <stdio.h>
#include <algorithm>
const long long Mod=1e9+7;
using namespace std;

long long jieA[100010],_jieB;

inline long long extend_gcd(long long a, long long b, long long &x, long long &y)
{
    if (a == 0 && b == 0)
        return -1ll;
    if (b == 0)
    {
        x = 1ll;
        y = 0ll;
        return a;
    }
    long long d = extend_gcd(b, a % b, y, x);
    y -= a / b * x;
    return d;
}
inline long long mod_reverse(long long a, long long n)
{
    long long x, y, d = extend_gcd(a, n, x, y);
    if (d == 1)
    {
        if (x % n <= 0)
            return x % n + n;
        else
            return x % n;
    }
    else
        return -1ll;
}

long long cal(int a,int b){
    //C(a,b)%Mod   a!/b!/(a-b)!
    if (b>a) return 0;
    if (a==b) return 1;
    return jieA[a]*_jieB %Mod *mod_reverse(jieA[a-b],Mod) % Mod;
}

int main(){
    int n,k;
    scanf("%d%d",&n,&k);
    int a[n];
    for (int i=0;i<n;++i) scanf("%d",&a[i]);
    sort(a,a+n);

    jieA[0]=1;
    for (int i=1;i<=n;++i)
        jieA[i]=1LL*jieA[i-1]*i%Mod;
    _jieB = mod_reverse(jieA[k-1],Mod);
    long long ans=0;
    for (int i=0;i<n;++i){
        ans-=1LL*a[i]*cal(n-i-1,k-1)%Mod;
        ans+=1LL*a[i]*cal(i,k-1)%Mod;
        ans%=Mod;
    }
    ans%=Mod;ans+=Mod;ans%=Mod;
    printf("%lld\n",ans);

}


Measured memory_bytes: 1280
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
const long long LINF = 1e18;
#define dump(x)  cout << 'x' << ' = ' << (x) << ` `;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
typedef long long ll;
using namespace std;
typedef pair<ll, ll> P;

int main(int argc, char const *argv[]) {
    int n;
    cin>>n;
    vector<int> x(n);
    int o=0; int t = 0;
    rep(i,n) cin>>x[i];
    vector<int> a(x);
    sort(a.begin(), a.end(), greater<>());
    o=a[0]; t=a[1];
    
    rep(i,n) {
        if (x[i]==o) cout << t << endl;
        else cout << o << endl;
    }
    return 0;
}

Measured memory_bytes: 3200
/*
 * DATE : 2017-07-29
 * Algo :
*/
#include<bits/stdc++.h>
using namespace std;
/*------- Constants---- */

#define LL                      long long
#define Ulong                   unsigned long long
#define FOR(I,A,B)              for(long long i=0; i < n ; i++ )
#define REP(i,n)                for(long long i=0; i < n ; i++ )
#define mp                      make_pair
#define pb                      push_back
#define all(x)                  (x).begin(),(x).end()
#define PI                      acos(-1.0)
#define EPS                     1e-14
#define F                       first
#define S                       second
#define di(x)                   int x; input(x)
#define in(x)                   input(x)
#define in2(x,y)                in(x),in(y)
#define in3(x,y,z)              in(x),in2(y,z)
#define lc                      ((n)<<1)
#define rc                      ((n)<<1|1)
#define db(x)                   cout << #x << " -> " << x << endl
#define nl                      cout<<endl
#define ms(ara_name,value)      memset(ara_name,value,sizeof(ara_name))
#define IO                      ios_base::sync_with_stdio(0);cin.tie(0)
#define READ                    freopen("in.txt","r",stdin)
#define WRITE                   freopen("out.txt","w",stdout)
template<class T> inline void input(T &x) {
    register char c = getchar();x = 0;
    int neg = 0;
    for(; ((c<48 || c>57) && c != '-'); c = getchar());
    if(c=='-'){neg = 1;c = getchar();}
    for(; c>47 && c<58 ; c = getchar()){x = (x<<1) + (x<<3) + c - 48;}
    if(neg) x = -x;
}
inline long long bigmod(long long p,long long e,long long M){
    long long ret = 1;
    for(; e > 0; e >>= 1){
        if(e & 1) ret = (ret * p) % M;
        p = (p * p) % M;
    } return ret;
}
template <class T> inline T gcd(T a,T b){if(b==0)return a;return gcd(b,a%b);}
template <class T> inline T modinverse(T a,T M){return bigmod(a,M-2,M);}

/***************************** END OF TEMPLATE *******************************/

const int N = 1001;
long long k;

LL Lim = 1e16+1000;
bool Try(int n)
{
    LL c = k / n;
    if(k % n ) c ++;
    LL del = c * n - k;

    vector<LL> vec;

    for(int i = 0; i < n;i ++ ) vec.push_back(c + n - 1);
    for(int i = 0; i < del; i ++ ){
        sort(all(vec));
        for(int i = 0; i < vec.size()- 1; i ++ ) vec[i] ++;
        vec[vec.size() - 1] -= n;

    }
    for(auto x: vec) {
        if(x > Lim ) return 0;
    }
    printf("%d\n",n);
    for(auto x: vec ) {
        printf("%lld ",x);
    }
    return 1;
}
int main()
{
     cin >> k;
     Try(50);
//    for(int i = 2; i <= 50; i ++){
//        if(Try(i)) return 0;
//    }
//    return 0;
}


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

int main() {
    long a, b, c, d;
    cin >> a >> b >> c >> d;
    int turn = 0;
    while (a > 0 && c > 0) {
        if (turn % 2 == 0) {
            c -= b;
            if (c <= 0)
                cout << "Yes" << endl;
        } else {
            a -= d;
            if (a <= 0)
                cout << "No" << endl;
        }
        turn++;
    }
}


Measured memory_bytes: 3636
#include<iostream>
#include<vector>
using namespace std;
int main(){
	int n,p=1;cin>>n;
	vector<int>a(n);
	for(int i=0;i<n;i++)cin>>a[i];
	for(int i=0;i<n;i++){
		if(a[i]==p){
			p++;
		}
	}
	if(p==1)cout<<-1<<endl;
	else cout<<n-p+1<<endl;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#include<string.h>
 
typedef long long int ll;
#define all(x) (x).begin(), (x).end()
 
using namespace std;

int nxt() {
    int x;
    cin >> x;
    return x;
}

ll nxtl(){
    ll x;
    cin>>x;
    return x;
}
 
void SieveOfEratosthenes(int n,vector <int> &primes) 
{ 
    // Create a boolean array "prime[0..n]" and initialize 
    // all entries it as true. A value in prime[i] will 
    // finally be false if i is Not a prime, else true. 
    bool prime[n+1]; 
    memset(prime, true, sizeof(prime)); 
  
    for (int p=2; p*p<=n; p++) 
    { 
        // If prime[p] is not changed, then it is a prime 
        if (prime[p] == true) 
        { 
            // Update all multiples of p greater than or  
            // equal to the square of it 
            // numbers which are multiple of p and are 
            // less than p^2 are already been marked.  
            for (int i=p*p; i<=n; i += p) 
                prime[i] = false; 
        } 
    } 
  
    // Print all prime numbers 
    for (int p=2; p<=n; p++) 
       if (prime[p]) 
          primes.push_back(p);
} 
 
ll max(ll a,ll b)
{
    if(a>b)
        return a;
    return b;
}
 
ll power(ll x, ll y,ll mod) 
{ 
    ll temp; 
    if( y == 0) 
        return 1; 
    temp = power(x, y/2,mod); 
    if (y%2 == 0) 
        return (temp*temp)%mod; 
    else
        return (((x*temp)%mod)*temp)%mod; 
}

ll binomialCoeff(ll n, ll k) 
{ 
    ll C[k+1]; 
    memset(C, 0, sizeof(C)); 
  
    C[0] = 1;  // nC0 is 1 
  
    for (ll i = 1; i <= n; i++) 
    { 
        // Compute next row of pascal triangle using 
        // the previous row 
        for (ll j = min(i, k); j > 0; j--) 
            C[j] = C[j] + C[j-1]; 
    } 
    return C[k]; 
} 

ll f[200001];
 
ll pow(ll a, ll b, ll MOD)
{
 ll x=1,y=a; 
 while(b > 0)
    {
        if(b%2 == 1)
    {
        x=(x*y);
        if(x>MOD) x%=MOD;
    }
    y = (y*y);
    if(y>MOD) y%=MOD; 
    b /= 2;
    }
 return x;
}
 
/* Modular Multiplicative Inverse
 Using Euler's Theorem
 a^(phi(m)) = 1 (mod m)
 a^(-1) = a^(m-2) (mod m) */
ll InverseEuler(ll n, ll MOD)
{
 return pow(n,MOD-2,MOD);
}
 
ll C(ll n, ll r, ll MOD)
{
 
 return (f[n]*((InverseEuler(f[r], MOD) * InverseEuler(f[n-r], MOD)) % MOD)) % MOD;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll mod=1e9+7;
     f[0] = 1;
    for(ll i = 1 ; i <= 200000 ; i++)
        f[i] = (f[i-1]*i)%mod;
    int n=nxt();
    vector <ll> v(n+1);
    generate(all(v),nxt);
    map <int,int>  m2;
    int x,y;
    for(int i=0;i<=n;i++)
    {
        if(m2.find(v[i])!=m2.end())
        {
            x=m2[v[i]];
            y=i;
            break;
        }
        else
            m2[v[i]]=i;
    }
    //cout<<x<<" "<<y<<endl;
    for(int k=1;k<=n+1;k++)
    {
        ll test=0;
        test=C(n+1,k,mod);
        if(x+n-y>=k-1&&k-1>0)
        {
            test=(test+mod-C(x+n-y,k-1,mod))%mod;
        }
        
        if(k==1)
            test--;
        cout<<test<<endl;
    }
    
    
    return 0;   
}




 
 


Measured memory_bytes: 8320
//set many funcs template
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#define inf 1072114514
#define llinf 4154118101919364364
#define mod 1000000007
#define pi 3.1415926535897932384
 
int max(int a,int b){if(a>b){return a;}return b;}
int min(int a,int b){if(a<b){return a;}return b;}
int zt(int a,int b){return max(a,b)-min(a,b);}
int round(int a,int b){if((a%b)*2 >= b){return (a/b)+1;}return a/b;}
int ceil(int a,int b){if(a%b==0){return a/b;}return (a/b)+1;}
int gcd(int a,int b){int c;while(b!=0){c=a%b;a=b;b=c;}return a;}
int lcm(int a,int b){int c=gcd(a,b);a/=c;return a*b;}
int nCr(int a,int b){int i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
int fact(int a){int i,r=1;for(i=1;i<=a;i++){r*=i;}return r;}
int pow(int a,int b){int i,r=1;for(i=1;i<=b;i++){r*=a;}return r;}
long long llmax(long long a,long long b){if(a>b){return a;}return b;}
long long llmin(long long a,long long b){if(a<b){return a;}return b;}
long long llzt(long long a,long long b){return llmax(a,b)-llmin(a,b);}
long long llround(long long a,long long b){if((a%b)*2 >= b){return (a/b)+1;}return a/b;}
long long llceil(long long a,long long b){if(a%b==0){return a/b;}return (a/b)+1;}
long long llgcd(long long a,long long b){long long c;while(b!=0){c=a%b;a=b;b=c;}return a;}
long long lllcm(long long a,long long b){long long c=llgcd(a,b);a/=c;return a*b;}
long long llnCr(long long a,long long b){long long i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
long long llfact(long long a){long long i,r=1;for(i=1;i<=a;i++){r*=i;}return r;}
long long llpow(long long a,long long b){long long i,r=1;for(i=1;i<=b;i++){r*=a;}return r;}
double dbmax(double a,double b){if(a>b){return a;}return b;}
double dbmin(double a,double b){if(a<b){return a;}return b;}
double dbzt(double a,double b){return dbmax(a,b)-dbmin(a,b);}
int sortfncsj(const void *a,const void *b){if(*(int *)a>*(int *)b){return 1;}if(*(int *)a==*(int *)b){return 0;}return -1;}
int sortfnckj(const void *a,const void *b){if(*(int *)a<*(int *)b){return 1;}if(*(int *)a==*(int *)b){return 0;}return -1;}
int llsortfncsj(const void *a,const void *b){if(*(long long *)a>*(long long *)b){return 1;}if(*(long long *)a==*(long long *)b){return 0;}return -1;}
int llsortfnckj(const void *a,const void *b){if(*(long long *)a<*(long long *)b){return 1;}if(*(long long *)a==*(long long *)b){return 0;}return -1;}
int dbsortfncsj(const void *a,const void *b){if(*(double *)a>*(double *)b){return 1;}if(*(double *)a==*(double *)b){return 0;}return -1;}
int dbsortfnckj(const void *a,const void *b){if(*(double *)a<*(double *)b){return 1;}if(*(double *)a==*(double *)b){return 0;}return -1;}
 
int main(void){
    long long n,m;
    scanf("%lld%lld",&n,&m);
    printf("%lld\n",(100*(n-m)+1900*m)*llpow(2,m));
    return 0;
}

Measured memory_bytes: 128
#include <iostream>
using namespace std;
int Euclid (int,int);
int main(){
    int A,B,C;
    cin >>A>>B>>C;
    
    int gcd=Euclid(A, B);
    if(C%gcd==0){
        cout<<"YES"<<endl;
    }else{
        cout<<"NO"<<endl;
    }
    return 0;
}
int Euclid(int x,int y){
    int a,b,c;
    a=max(x,y);
    b=min(x,y);
    while (a%b!=0) {
        c=a%b;
        a=b;
        b=c;
    }
    return b;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

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

            int count = 0;
            for (int i = 1; i <= N; i++)
            {
                if (i % 2 == 1 && DivisorsNum(i) == 8)
                {
                    count++;
                }
            }

            Console.WriteLine(count);
        }

        public static int DivisorsNum(int N)
        {
            int count = 0;
            for (int i = 1; i <= N; i++)
            {
                if(N%i == 0)
                {
                    count++;
                }
            }
            return count;
        }
    }
}


Measured memory_bytes: 27504
#include <bits/stdc++.h>
#define fi first
#define se second
#define ii pair<int, int>
#define int long long
using namespace std;

const int mod = 1e9 + 7;
int n;
map<ii, int> cnt;
vector<ii> v;

int qickpuw(int u, int p)
{
    if (p == 0)
        return 0;
    if (p == 1)
        return u;
    int tmp = qickpuw(u, p/2);
    if (p % 2 != 0)
        return (tmp * tmp * u)%mod;
    return (tmp * tmp) % mod;
}

int32_t main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

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

    cin >> n;

    int cnt0 = 0;
    for (int i = 1; i <= n; i++)
    {
        int x, y;
        cin >> x >> y;
        if (x == y && x == 0)
        {
            cnt0++;
            continue;
        }
        if (x == 0)
            y = 1;
        if (y == 0)
            x = -1;
        if (x != 0 && y != 0){
            int g = __gcd(x, y);
            x /= g;
            y /= g;
        }

        if ((x < 0 && y < 0) || (x > 0 && y < 0))
        {
            x = -x;
            y = -y;
        }
        if (cnt[ii(x, y)] == 0)
            v.push_back(ii(x, y));
        cnt[ii(x, y)]++;
    }
//
// cout << "----------------------------------\n";
//    for (int i = 0; i < v.size(); i++)
//        cout << v[i].fi << " " << v[i].se << "\n";
// cout << "----------------------------------\n";

    int ans = 1;

    for (int i = 0; i < v.size(); i++)
    {
        int x2 = -v[i].se, y2 = v[i].fi;

        if ((x2 < 0 && y2 < 0) || (x2 >= 0 && y2 <= 0))
        {
            x2 = -x2;
            y2 = -y2;
        }

        if (cnt[v[i]] == 0)
            continue;

        int a = cnt[v[i]], b = cnt[ii(x2, y2)];

        int m = (qickpuw(2, a) + qickpuw(2, b))%mod;

        if (b != 0) {
//            cout << "vuong goc\n";
            m = ((m - 1) %mod + mod)%mod;
        }

        ans = (ans * m)%mod;

        cnt[v[i]] = 0;
        cnt[ii(x2, y2)] = 0;
    }
    ans = ((ans - 1)%mod + mod)%mod;
    ans = (ans + cnt0) % mod;
    cout << ans;
}


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

int main (){
  int N;
  cin >> N;
  vector<int> X (N);
  for (int i=0; i<N ; i++){
    cin >> X.at(i);
  }
  int a=1;
  int b=0;
  for (int i=0; i<N ; i++){
    a = X.at(a-1);
    if ( a == 2 ){
      cout << i + 1 << endl;
      b=1;
      break;
    }
  }
  if (b==0)
    cout <<  -1 <<endl;
}
  

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize ("-ffloat-store") // to restrict undesirable precision
#pragma GCC optimize ("-fno-defer-pop")// to pop argument of function as soon as it returns
#define all(a) a.begin(),a.end()
#define ll long long int
#define ld long double
ll power(ll a,ll b,ll m){ if(b==0) return 1; if(b==1) return a%m; ll t=power(a,b/2,m)%m; t=(t*t)%m; if(b&1) t=((t%m)*(a%m))%m; return t;}
ll modInverse(ll a, ll m) { return power(a, m-2, m); }
#define ps push_back
#define fs first
#define takeline cin.ignore();
#define sc second
#define N 3000005
#define endl "\n"
#define mod 1000000007
//((1.0l)*BIG MULTIPLY MAGIC?)
// string to integer stoi()
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();
//-----------------------------------------------
int main(){

	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	
	ll i,j,k,l,n;
	cin>>n>>k;
	ll ar[n+1];
	for(i=1;i<=n;i++){
		cin>>ar[i];
	}
	
	ll ans=0,v=((k*(k+1))/2)%mod,x=(((k-1)*k)/2)%mod;
	for(i=1;i<=n;i++){
		ll c=0;
		for(j=1;j<i;j++){
			if(ar[j]>ar[i]) c++;
		}
		ans=(ans%mod+v*c)%mod;
		c=0;
		for(j=i+1;j<=n;j++){
			if(ar[j]>ar[i]) c++;
		}
		ans=(ans%mod+(x*c)%mod)%mod;
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 256
w = int(input())
n = int(input())
lines = []
for i in range(n):
    a, b = map(int, input().split(","))
    lines.append([a, b])
lines = list(reversed(lines))
for j in range(1, w + 1):
    for line in lines:
        if line[0] == j:
            j = line[1]
        elif line[1] == j:
            j = line[0]
    print(j)

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


int main(void) {
	vector<int> c;
	vector<int> t;
	int time,n,i,k,a,b;
	vector<int> ans;
	
	scanf("%d%d",&n,&time);
	for (i = 0; i<n; ++i) {
		cin >> a; cin >> b;
		if (b <= time) {
			c.push_back(a);
			t.push_back(b);
		}
	}
	k = c.size();
	if (k == 0) {
		printf("TLE\n");
	}

	else {
		sort(c.begin(), c.end());
		printf("%d\n", c[0]);
	}
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <queue>
#include <string>
#include <cmath>
#include <algorithm>

using namespace std;

#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define BIT(X, i) ((X>>i)&1)

typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef pair<ll, ll> pii;
typedef vector<pii> vii;
typedef priority_queue<ll> pq;

const int MOD = 1e9+7;
const int INF = (1<<30);
const ll INFL = (1L<<62);

int main() {
  int N; cin >> N;
  string s; cin >> s;
  int cnt = 0;
  for (int i = 0; i < N; i++) {
    if (s[i] == 'R') cnt++;
    else cnt--;
  }
  if (cnt > 0) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 256
n = int(input())
slist = [input().strip() for _ in range(n)]

ea, sb = 0, 0
ans = 0
sd = {(0, 1): 0, (1, 0): 0, (1, 1): 0}
for s in slist:
  for prevs, _s in zip(s, s[1:]):
    if prevs + _s == 'AB':
      ans += 1
  if s[0] == 'B' and s[-1] == 'A':
    sd[(1, 1)] += 1
  elif s[0] == 'B':
    sd[(0, 1)] += 1
  elif s[-1] == 'A':
    sd[(1, 0)] += 1

if sd[(0, 1)] > 0 and sd[(1, 1)] > 0 and sd[(1, 0)] > 0:
  sd[(0, 1)] -= 1
  sd[(1, 0)] -= 1
  ans += sd[(1, 1)] + 1
elif sd[(0, 1)] > 0 and sd[(1, 1)] > 0 and sd[(1, 0)] == 0:
  sd[(0, 1)] -= 1
  ans += sd[(1, 1)]
elif sd[(0, 1)] == 0 and sd[(1, 1)] > 0 and sd[(1, 0)] > 0:
  sd[(1, 0)] -= 1
  ans += sd[(1, 1)]
elif sd[(0, 1)] == 0 and sd[(1, 0)] == 0:
  if sd[(1, 1)] > 0:
    ans += sd[(1, 1)] - 1

print(ans + min(sd[(1, 0)], sd[(0, 1)]))


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

#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < n; i++)
typedef long long ll;

int main() {
    string s; cin >> s;
    ll k; cin >> k;
    char ans = '1';
    for(int i = 0; i < min(k, (ll)s.size()); i++){
        if(s[i] != '1'){
            ans = s[i];
            break;
        }
    }
    cout << ans << endl;
}



Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<set>
using namespace std;
int w,h;

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

void solve(){
	set<string> S;
	vector<string> V;
	for(int i=0;i<h;i++){
		string s;
		cin>>s;
		V.push_back(s);
	}
	string res="";

	for(int y=0;y<h;y++){
		for(int x=0;x<w;x++){
			for(int r=0;r<8;r++){
				int nx=x,ny=y;
				string read="";
				while(!(nx==x && ny==y) || read.size()==0){
					read+=V[ny][nx];
					if(S.count(read)){
						if(res.size()<read.size()) res=read;
						if(res.size()==read.size() && res>read) res=read;
					}
					S.insert(read);
					ny+=dy[r];
					nx+=dx[r];
					if(ny<0) ny=h-1;
					if(ny>=h) ny=0;
					if(nx<0) nx=w-1;
					if(nx>=w) nx=0;
				}
			}
		}
	}
	if(res.size()>1)
		cout<<res<<endl;
	else cout<<0<<endl;
}



int main()
{
	while(cin>>h>>w){
		if(h==0) break;
		solve();
	}
	return 0;
}

Measured memory_bytes: 26000
a,b,c,x,y = map(int, input().split())

if(x < y):
    x,y = y,x
    a,b = b,a

result = 5000*5000*200000
ab = 0
while(x >= 0):
    tmp = x * a + y * b + ab*c
    if(result > tmp):
        result = tmp
    x -= 1
    if(y > 0):
        y -= 1
    ab += 2

print(result)

Measured memory_bytes: 3064
h,w,k=map(int,input().split())
x1=[[0 for i in range(w)] for i in range(h)]
x2=[]
x3=[[0 for i in range(w)] for i in range(h)]

for i in range(h):
    s=input()
    l=0
    for j in range(w):
        if s[j]=="#":
            l+=1
            x1[i][j]=1
    x2.append(l)

lx=1
for i in range(h):
    if x2[i]!=0:
        f=0
        for j in range(w):
            if x1[i][j]==1:
                f+=1
                if f==1:
                    x3[i][j]=lx
                else:
                    lx+=1
                    x3[i][j]=lx
                if j==w-1:
                    lx+=1
            else:
                x3[i][j]=lx
                if j==w-1:
                    lx+=1
    else:
        for j in range(w):
            x3[i][j]=-1




for i in range(h):
    if x3[i][0]!=-1:
        print(" ".join(map(str,x3[i])))
    else:
        j=i
        while j<h-1:
            j+=1
            if x3[j][0]!=-1:
                print(" ".join(map(str,x3[j])))
                break
        else:
            j=i
            while True:
                j-=1
                if x3[j][0]!=-1:
                    print(" ".join(map(str,x3[j])))
                    break


Measured memory_bytes: 7880
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);

    long N = scanner.nextLong();

    long min = 10_000_000_000_000L;
    for (long i = 1; i * i <= N; i++) {
      if (N % i == 0) {
        long j = N / i;
        min = Math.min(min, i + j - 2);
      }
    }
    System.out.println(min);
  }
}


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

using namespace std;

int main() {
	
	
	long long int X,K,D;       
    cin>>X>>K>>D;
    X=abs(X);
    if(X/D>=K) cout<<X-K*D<<endl;
    else{
        K-=X/D;
        X-=(X/D)*D;
        if(K%2==0) 
            cout<<X<<endl;
        else 
           cout<<abs(X-D)<<endl;
    }
	   
	
	return 0;
}

Measured memory_bytes: 3620
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
def resolve():
    n,k=map(int,input().split())
    D=set(map(int,input().split()))
    for i in range(n,100000):
        flag=True
        for s in str(i):
            if(int(s) in D):
                flag=False
        if(flag):
            print(i)
            return
resolve()

Measured memory_bytes: 40684
#include <iostream>
#include <iomanip>
#include <vector>
#include <numeric>
using namespace std;

int main()
{

    int N;
    cin >> N;
    vector<double> x(N,0);
    vector<string> u(N);

    for (int i = 0; i < N; ++i){
        cin >> x[i] >> u[i];
    }

    double sum = 0;
    for (int i = 0; i < N; ++i){
        if(u[i] =="JPY")
            sum += x[i];
        else{
            sum += x[i] * 380000;
        }
    }
    cout << std::fixed << setprecision(5) << sum  << endl;
    return 0;
}

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

int main(){
	int r,d,i;
	long long x;
	cin>>r>>d>>x;
	for(i=1;i<=10;i++){
		x=r*x-d;
		cout<<x<<endl;
	}
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include <stdio.h>
#include <string>
#include <string.h>
#include <algorithm>
#include <functional>
#include <vector>
#include <math.h>

using namespace std;
int main()
{
	long long N;
	cin >> N;

	string s = "";

	int r;

	if (N == 0) s = "0";

	while (N != 0) {
		r = N % (-2);
		if (r < 0) r = 1;
		char a = '0' + r;
		s = s + a;
		N = (N - r) / (-2);
	}

	reverse(s.begin(), s.end());

	cout << s;

	return 0;
}


Measured memory_bytes: 256
#define __USE_MINGW_ANSI_STDIO 0
#include <iostream>
#include <string>
#include <vector>
#include <stdio.h>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <set>
#include <numeric>
#include <bitset>
#include <map>
#include <limits.h>

using namespace std;

/// 各桁の和
int sumdigit(int x){
   int sum = 0;
    while(x != 0){
        sum += x % 10;
        x /= 10;    
    }
    return sum;
}
/// 最大公約数 
int gcd(int x, int y){
      if(x<y){
          int temp = x;
          x = y;
          y = temp;
      }
      int r = x % y;
       while(r!=0){
           x = y;
           y = r;
           r = x % y;
       }
      return y;
   }



int main(){
int N,M;
int n,m;
cin >> N >> M >> n >> m;
cout << N*M - n*M - m*(N-n) << endl;


}

Measured memory_bytes: 256