akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
//#define int long long

using namespace std;
using LL = long long;
using P = pair<int, int>;

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

#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()

const int INF = (int)1e9;
const LL INFL = (LL)1e18;
const int MOD = (int)1e9 + 7;

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

    int n, m;
    cin >> n >> m;
    vector<int> a(n);
    REP(i, n) cin >> a[i];

    map<LL, int> mp;
    vector<LL> ruiseki(n+1);
    REP(i, n) ruiseki[i+1] += ruiseki[i] + a[i];
    REP(i, n+1) mp[ruiseki[i] % m]++;
    LL ans = 0;
    REP(i, n+1){
        mp[ruiseki[i] % m]--;
        ans += mp[ruiseki[i] % m];
    }
    cout << ans << endl;
}


Measured memory_bytes: 5376
#include <algorithm>
#include <array>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <sstream>
#include <unordered_map>
#include <vector>


#define INF 4000000000000000000LL
#define MOD 1000000007
#define ALL(x) std::begin(x), std::end(x)


int main(int argc, char** argv)
{
  std::cin.tie(0);
  std::ios_base::sync_with_stdio(0);

  std::cout << std::fixed << std::setprecision(6);

  int N, K;

  std::cin >> N >> K;

  long long xm = INF;

  for (int i = 0; i <= N; i ++) {
    std::string s(std::string(i, 'A') + std::string(N - i, 'B'));

    do {
      long long x = 1;
      
      for (int i = 0; i < N; i ++)
        if (s[i] == 'A') {
          x *= 2;
        }
        else {
          x += K;
        }

      xm = std::min(x, xm);
          
    } while (std::next_permutation(ALL(s)));
  }

  std::cout << xm << std::endl;

  return 0;
}


Measured memory_bytes: 508
import Control.Applicative
import Control.Monad
import Data.List
import Data.Array
import Data.Char

main = do
  arr <- map digitToInt <$> getLine
  putStrLn $ calc (tail arr) (7 - arr !! 0) (show (arr !! 0))

calc::[Int] -> Int -> String -> String
calc [] n s = if n == 0 then s ++ "=7" else ""
calc (x:rest) n s = let plus = calc rest (n - x) (s ++ "+" ++ show x)
                        minus = calc rest (n + x) (s ++ "-" ++ show x)
                    in if plus /= "" then plus else minus 

Measured memory_bytes: 380
#include <iostream>
using namespace std;
int main(){
  int x[4], y[4];
  cin >> x[0] >> y[0] >> x[1] >> y[1];
  x[2] = x[1] + y[0] - y[1];
  y[2] = y[1] + x[1] - x[0];
  x[3] = x[2] + y[1] - y[2];
  y[3] = y[2] + x[2] - x[1];
  cout << x[2] <<  " " << y[2] << " " << x[3] << " " <<  y[3] << endl;
}


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

int main() {
  int H, N;
  cin >> H >> N;
  vector<int> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A.at(i);
  }
  
  int sum = 0;
  for (int i = 0; i < N; i++) {
    sum += A.at(i);
  }
  if (sum >= H) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>
#include <functional>
#include <utility>
using namespace std;

int main(){
  int n;
  cin >> n;
  vector<int> v(n, 0);
  for(int i = 0; i < n; i++){
    cin >> v[i];
  }
  sort(v.begin(), v.end());
  int cnt = 1;
  int res = 1;
  for(int i = 0; i < n - 1; i++){
    if(v[i] == v[i + 1]){
      cnt++;
    }
    else{
      res++;
      if(cnt % 2 == 0){ res--; }
      cnt = 1;
    }
  }
  if(cnt % 2 == 0){ res--; }
  cout << res << endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cctype>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <functional>
using namespace std; 
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define FORD(i,a,b) for(int i=(a);i>=(b);i--)
inline bool EQ(double a, double b) { return fabs(a-b) < 1e-9; }
const int INF = 1<<29;
typedef long long int ll;
inline int two(int n) { return 1 << n; }
inline int test(int n, int b) { return (n>>b)&1; }
inline void set_bit(int & n, int b) { n |= two(b); }
inline void unset_bit(int & n, int b) { n &= ~two(b); }
inline int last_bit(int n) { return n & (-n); }
inline int ones(int n) { int res = 0; while(n && ++res) n-=n&(-n); return res; }
template<class T> void chmax(T & a, const T & b) { a = max(a, b); }
template<class T> void chmin(T & a, const T & b) { a = min(a, b); }
const int MOD=1000000007;

bool isPowerOfTwo (ll x)  
{  
    return x && (!(x&(x-1)));  
}
bool isPrime(int n) 
{ 
    if (n <= 1)  return false; 
    if (n <= 3)  return true; 
    if (n%2 == 0 || n%3 == 0) return false; 
  
    for (int i=5; i*i<=n; i=i+6) 
        if (n%i == 0 || n%(i+2) == 0) 
           return false; 
  
    return true; 
}
int highestPowerof2(unsigned int n) 
{ 
    // Invalid input 
    if (n < 1) 
        return 0; 
  
    int res = 1;
    for (int i=0; i<8*sizeof(unsigned int); i++) 
    { 
        int curr = 1 << i; 
        if (curr > n) 
           break; 
  
        res = curr; 
    } 
  
    return res; 
} 
long long binpow(long long a, long long b) {
    long long res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a;
        a = a * a;
        b >>= 1;
    }
    return res;
}
const int dx[] = {1,0,-1,0,1,1,-1,-1};
const int dy[] = {0,-1,0,1,1,-1,-1,1};
/*lcm(gcd(N1, M), gcd(N2, M), ..., gcd(Nk, M)) = gcd(lcm(N1, ..., Nk), M)
gcd(lcm(N1, M), lcm(N2, M), ..., lcm(Nk, M)) = lcm(gcd(N1, ..., Nk), M).

If gcd(N1, N2) = 1, then
gcd(N1·N2, M) = gcd(N1, M)·gcd(N2, M)
lcm(N1·N2, M) = lcm(N1, M)·lcm(N2, M)/M.

lcm(M, N, P) · gcd(M, N) · gcd(N, P) · gcd(P, M) = NMP · gcd(N, M, P).
*/
////////////////////////////////////////////////////////////////////

int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);  
  cout.tie(NULL);
  ll t=1;
  while(t--)
  {
    ll n;
    cin>>n;
    ll moves=0;
    ll dist=0;
    ll cnt=1;
    while(dist<n)
    {
        dist+=cnt;
        cnt++;
        moves++;
    }
    cout<<moves;
  }  
  return 0;
}
/* Look for:
* the exact constraints (multiple sets are too slow for n=10^6 :( )
* special cases (n=1?)
* 1LL<<i and not 1<<i
* overflow (int vs ll?)
* array bounds
* if you have no idea just guess the appropriate well-known algo instead of doing nothing :/
*/

Measured memory_bytes: 3616
#include<bits/stdc++.h>
using namespace std;
/* run this program using the console pauser or add your own getch, system("pause") or input loop */

stack<char> p;
char c1,c2;

int main()
{
	while(scanf("%c",&c1)!=EOF && c1!='\n')
	{
		if(p.empty())
		{
			p.push(c1);
			continue;
		}
		c2 = p.top();
		p.push(c1);
		if(c1=='T' && c2=='S')
		{
			p.pop();
			p.pop();
		}
	}
	printf("%d",p.size());
	
	return 0;
 }

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod=1e9+7;

string S;

int main(){ 

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

cin>>S;

string s1=S.substr(0,2);
string s2=S.substr(2,2);

int i1=atoi(s1.c_str());
int i2=atoi(s2.c_str());

if((i1>=1)&&(i1<=12)){
	if((i2>=1)&&(i2<=12)){
		cout<<"AMBIGUOUS"<<endl;
	}
	else{
		cout<<"MMYY"<<endl;
	}
	return 0;
}
if((i2>=1)&&(i2<=12)){
	if((i1>=1)&&(i1<=12)){
		cout<<"AMBIGUOUS"<<endl;
	}
	else{
		cout<<"YYMM"<<endl;
	}
	return 0;
}

cout<<"NA"<<endl;
return 0;

}


Measured memory_bytes: 384
#include<iostream>
#include <algorithm>
#include<string>
#include <bitset>
#include <vector>
#include <functional>
#include <climits>
#include <iomanip>
#include <utility>
using namespace std;
typedef pair <int, int> pii;
int main()
{

	//int a = 0, b = 0, c = 0, d = 0, e = 0, f = 0, g = 0, h = 0, ans = 0;
	int a = 0, b = 0, c = 0, d = 0, e = 0, f = 0, g = 0, h = 0, i = 0, j = 0, k = 0, l = 0, ans = 0;
	//cout << LONG_MAX << endl;
	//string s, t;
	//long long n, A[1000000000];
	long long n, m;
	//int   y[100001], z[100001], x[10001] = {};
	//pii y[100001];
	//pair<int, float> pii[100001];
	
	string s[2001];
	cin >> a;
	cin >> b;
	if (a%b==0)
	{
		cout << 0 << endl;
	}
	else
	{
		cout << 1 << endl;
	}
	////std::cout << std::fixed;
	//cout << std::setprecision(20) << << endl;
	//cout << d+1 << endl;

	//cout << "No" << endl;

	return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("O3")
#include<bits/stdc++.h>
using namespace std;
#define rc(x) return cout<<x<<endl,0
#define pb push_back
#define dbg(x) cout << #x << '=' << x << '\n';
#define ll long long
#define sz size()
#define x first
#define y second
#define pi pair <int, int>
#define pii pair <pi, pi>
#define vi vector <int>
const ll mod = 1e9 + 7;
ll x, y;

int32_t main(){
    ios_base :: sync_with_stdio(0); cin.tie(); cout.tie();
    cin>>x>>y;
    if(x%y==0) rc(-1);
    for(ll i=x; i<=1000000000000000000; i+=x){
        if(i%y) rc(i);
    }
}


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

int main()
{
	int N, K;
	cin >> N >> K;
	vector<char> a(K);
	for (int i = 0; i < K; i++) {
		cin >> a[i];
	}
	for (int i = 0;;i++){
		string s = to_string(N);
		int t = 0;
		for (int j = 0; j < s.size();j++){
			for (int k = 0; k < K;k++)
				if (s[j] == a[k]) {
					t++;
				}

		}
		if(t==0){
			cout << N <<endl;
			break;
		}
		else {
			N++;
		}
	}
}


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


int main(void)
{
    int n, k ,q;
    scanf("%d %d %d", &n, &k, &q);
    int a[q];
    for (int i=0; i < q; i++) scanf("%d", &a[i]);
    
    int p[n+1];
    for (int i=1; i <= n; i++){
        p[i] = k - q;
    }

    for (int i=0; i < q; i++){
        p[a[i]]++;
    }

    for (int i=1; i <= n; i++){
        if (0 < p[i]) printf("Yes\n");
        else printf("No\n");
    }




    return 0;
} 



Measured memory_bytes: 1280
#include <iostream>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>
#include <cmath>
#include<climits>
#include <string>
#include <map>
#include <set>
#include <list>

#define ll long long
#define fornum(A,B,C) for(A=B;A<C;A++)

using namespace std;

/////////////////////////////////////////////////////
#define pll pair<ll,ll>

ll N,M,P[101010],Y[101010];
vector<pll> ys[101010];
ll anum[101010];
ll i, j;
int main(){
    scanf("%lld%lld",&N,&M);
    fornum(i,0,M){
        scanf("%lld%lld",&P[i],&Y[i]);
        ys[P[i]-1].push_back(make_pair(Y[i], i));
    }
    fornum(i,0,N){
        sort(ys[i].begin(),ys[i].end());
    }
    fornum(i,0,N){
        fornum(j,0,ys[i].size()){
            anum[ys[i][j].second] = j+1;
        }
    }

    fornum(i,0,M){
        printf("%06lld%06d\n",P[i],anum[i]);
    }
    return 0;
}

Measured memory_bytes: 9344
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double lb;
#define REP(i,j,n) for (int i=j;i<(n);i++)
#define RREP(i,n) for (int i = n; 0<i;i--)
#define print(out) cout<< out  << "\n";
#define mod 1000000007
const int INF = 1e9;
typedef pair<ll,ll> P;
using Edge=pair<ll,ll>;

void dfs(ll n,ll p, ll c);

ll N;
vector<ll> visited;
vector<vector<Edge>> G;
int main(){
    cin >> N;
    G.assign(N, vector<Edge>());
    for (int i = 0; i < N-1; ++i) {
        int u, v, w; cin >> u >> v >> w;
        u--, v--;
        G[u].push_back(Edge(v, w));
        G[v].push_back(Edge(u, w));
    }
    visited.assign(N, 0);
    dfs(0, -1, 1);

  REP(i,0,N){
    print(visited[i])
  }

}

void dfs(ll n,ll p, ll c){
  visited[n]=c;
  for(auto e:G[n]){
    if(e.first==p)continue;
    if(e.second&1)dfs(e.first,n,1-c);
    else dfs(e.first,n,c);
  }

}

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

int main() {
  string a;
  cin >> a;
  
  if (a >= "A" && a <= "Z") {
    cout << "A" << endl;
  }
  
  else {
    cout << "a" << endl;
  }
  
  return 0;
}

Measured memory_bytes: 3620
<?php
  list($a, $b) = explode(" ", trim(fgets(STDIN)));

  // 最大公約数
  $m = gcd($a, $b);

  $f = factorize($m);

  echo count($f)+1;

//  var_dump($x);

// 最大公約数（２つ）（ユークリッドの互除法）
function gcd($a, $b){
  if($b===0){
    return $a;
  }
  return gcd($b, $a%$b);
  
}

function factorize($n){
  $res = [];
  for($i=2; $i*$i<$n; $i++){
    if($n % $i != 0) continue;
    $res[$i]=0;
    while($n % $i == 0){      
      $res[$i]++;
      $n /= $i;
    }
  }
  if($n != 1){
    $res[$n]=0;
  }
  return $res;
}


Measured memory_bytes: 4728
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef map<int, int> mii;
typedef map<char,int> mci;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<pair<int,int>> vii;
typedef vector<char> vc;
typedef vector<vc> vcc;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pb push_back
#define F first
#define S second
#define in insert
#define mina(a,b) (a)=min((a),(b));
#define maxa(a,b) (a)=max((a),(b));
const int INF = 1e9 + 7;
const int MAX_SIZE=1000;

void solve(){
    string s; cin>>s;
    int cnt1=0,cnt2=0;  //cnt1 == 010101  
    for(int i = 0; i < s.size(); i++){
        if(i%2==0 && s[i]=='1' || i%2==1 && s[i]=='0') cnt1++;
        if(i%2==0 && s[i]=='0' || i%2==1 && s[i]=='1') cnt2++;
    }
    cout<<min(cnt1,cnt2);
}
int main(){
    int T=1;
    //cin>>T;
    for(int i = 0; i < T; i++) solve(); 
}

Measured memory_bytes: 512
# Aizu Problem ITP_1_9_D: Transformation
#
import sys, math, os

# read input:
PYDEV = os.environ.get('PYDEV')
if PYDEV=="True":
    sys.stdin = open("sample-input2.txt", "rt")


string = [_ for _ in input().strip()]
n = int(input())
for _ in range(n):
    s = input().split()
    a, b = int(s[1]), int(s[2])
    cmd = s[0]
    if cmd == "print":
        print(''.join(string[a:b+1]))
    elif cmd == "reverse":
        tmp = string[a:b+1]
        string[a:b+1] = [_ for _ in tmp[::-1]]
    elif cmd == "replace":
        for p in range(a, b + 1):
            string[p] = s[3][p-a]

Measured memory_bytes: 7820
from collections import deque
H,W = map(int,input().split())
A = [input().strip() for _ in range(H)]
d = 0
if A[0][0]=="#":
    d += 1
que = deque([(0,0,d)])
hist = [[H*W for _ in range(W)] for _ in range(H)]
hist[0][0] = d
while que:
    i,j,d = que.popleft()
    if j+1<W and A[i][j+1]==A[i][j]:
        if hist[i][j+1]>d:
            hist[i][j+1] = d
            que.append((i,j+1,d))
    elif j+1<W and A[i][j+1]!=A[i][j]:
        if hist[i][j+1]>d+1:
            hist[i][j+1] = d+1
            que.append((i,j+1,d+1))
    if i+1<H and A[i+1][j]==A[i][j]:
        if hist[i+1][j]>d:
            hist[i+1][j] = d
            que.append((i+1,j,d))
    elif i+1<H and A[i+1][j]!=A[i][j]:
        if hist[i+1][j]>d+1:
            hist[i+1][j] = d+1
            que.append((i+1,j,d+1))
m = hist[H-1][W-1]
print((m+1)//2)

Measured memory_bytes: 78100
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
a = a[::-1]
b = b[::-1]


nmon = 0
c = 0
for i in range(n):
	#b[i] = b[i] + c
	if c > a[i]:
		nmon += a[i]
		c = b[i]
		continue
	elif b[i] + c > a[i]:
		nmon += a[i]
		c = b[i] + c - a[i]
	else:
		nmon += b[i]+c
		c = 0
if a[n] >= c:
	nmon += c
else:
	nmon += a[n]
print(nmon)

Measured memory_bytes: 19004
#include <iostream>
#include <tuple>
#include <sstream>
#include <vector>
#include <cmath>
#include <ctime>
#include <bitset>
#include <cassert>
#include <cstdio>
#include <queue>
#include <set>
#include <map>
#include <fstream>
#include <cstdlib>
#include <string>
#include <cstring>
#include <algorithm>
#include <numeric>

#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)

using namespace std;

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef double ld;

template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }

const i64 P = 1000000000 + 7;
const int maxn = 3100;

i64 p[maxn][maxn];
int a[maxn];

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.precision(10);
    cout << fixed;
#ifdef LOCAL_DEFINE
    freopen("input.txt", "rt", stdin);
#endif

    int n, q;
    cin >> n >> q;
    forn(i, n) cin >> a[i];
    forn(i, n) forn(j, n) if (a[i] < a[j]) p[i][j] = 1;
    const i64 d2 = (P + 1) / 2;

    forn(i, q) {
        int x, y;
        cin >> x >> y;
        --x; --y;
        forn(j, n) {
            if (j == x || j == y) continue;
            i64 s = (p[x][j] + p[y][j]) * d2 % P;
            p[x][j] = p[y][j] = s;
            s = (p[j][x] + p[j][y]) * d2 % P;
            p[j][x] = p[j][y] = s;
        }
        i64 s = (p[x][y] + p[y][x]) * d2 % P;
        p[x][y] = p[y][x] = s;
    }

    i64 ans = 0;
    forn(i, n) forn(j, n) if (i > j) (ans += p[i][j]) %= P;
    forn(i, q) (ans *= 2) %= P;
    cout << ans << '\n';

#ifdef LOCAL_DEFINE
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
    return 0;
}


Measured memory_bytes: 73984
#include <stdio.h>

int main() {
  int a, b, c;
  scanf("%d %d %d", &a, &b, &c);

  int ans = 0;

  for (int x = 1; x*x <= c; x++) {
    // 平方数のときの処理
    if (x * x == c) {
      if ( a <= x && x <= b ) { ans++; }
    } else if (c % x == 0) {
      if ( a <= x && x <= b ) { ans++; }
      if ( a <= c/x && c/x <= b ) { ans++; }
    }
  }
  printf("%d\n", ans);

  return 0;
}


Measured memory_bytes: 2048
#include<iostream>
#include<map>
#include<queue>

using namespace std;

typedef pair<int,int> pi;
#define MAX 32
#define fr first
#define sc second

const int di[] = {-1,0,1,0};
const int dj[] = {0,1,0,-1};
static const int di_sz = sizeof(di)/sizeof(*di);

inline pi comp(pi p, int H, int W){
  if(p.fr>=H)p.fr=H-1;
  if(p.fr<0)p.fr=0;
  if(p.sc>=W)p.sc=W-1;
  if(p.sc<0)p.sc=0;
  return p;
}

struct ghost{
  pi p;
  ghost():p(0,0){}
  ghost(pi p):p(p){}
  void move(int ind, const string &pat, int H, int W){
    pi next=p;
    switch(pat[ind]){
    case '5':return;break;
    case '8':next.fr--;break;
    case '6':next.sc++;break;
    case '4':next.sc--;break;
    case '2':next.fr++;break;
    }
    if(next.fr>=H)next.fr=H-1;
    if(next.fr<0)next.fr=0;
    if(next.sc>=W)next.sc=W-1;
    if(next.sc<0)next.sc=0;
    p = next;
  }
};

struct state{
  int now;
  pi girl;
  vector<ghost> g;
  bool operator<(const state &t)const{
    if(now!=t.now)return now<t.now;
    if(girl.fr!=t.girl.fr)return girl.fr<t.girl.fr;
    if(girl.sc!=t.girl.sc)return girl.sc<t.girl.sc;
    for(int i=0;i<g.size();++i){
      if(g[i].p.fr!=t.g[i].p.fr)return g[i].p.fr<t.g[i].p.fr;
      if(g[i].p.sc!=t.g[i].p.sc)return g[i].p.sc<t.g[i].p.sc;
    }
    return false;
  }
};

int bfs(state init, int H, int W, char M[][MAX], const string &pat, pi &ans_pos){
  map<state,int> vis;
  queue<state> qs;
  vis[init]=0;
  qs.push(init);

  while(!qs.empty()){
    state nst = qs.front(); qs.pop();
    int ns = vis[nst];

    for(int i = 0; i < nst.g.size(); ++i){
      if( nst.girl.fr == nst.g[i].p.fr && nst.girl.sc == nst.g[i].p.sc ){
	ans_pos = nst.girl;
	return ns;
      }
    }

    for(int k = 0; k < di_sz; ++k){
      state Next=nst;
      pi next(nst.girl.fr+di[k], nst.girl.sc+dj[k]);
      next =comp(next,H,W);
      if(M[next.fr][next.sc]=='#')next=nst.girl;
      Next.girl = next;
    
      // move ghosts;
      for(int i = 0; i < nst.g.size(); ++i){
	Next.g[i].move( nst.now, pat, H, W );
      }
      Next.now++;
      if(Next.now>=pat.length()){
	Next.now=0;
      }
      
      if( vis.find(Next) == vis.end() ){
	vis[Next]=ns+1;
	qs.push(Next);
      }else if( vis[Next] > ns+1 ){
	vis[Next]=ns+1;
	qs.push(Next);
      }
    }

  }
  return -1;
}


int main()
{
  while(true){
    int H,W;
    string pat;
    state init;
    char M[MAX][MAX] = {{0,},};
    cin >> H >> W;
    if( H == 0 && W == 0 )break;
    
    for(int i = 0; i < H; ++i){
      for(int j = 0; j < W; ++j){
	char c; cin >> c;
	if( c == 'A'){
	  init.girl = make_pair(i,j);
	  M[i][j]='.';
	}else if( c == 'B'){
	  init.g.push_back( ghost(make_pair(i,j) ) );
	  M[i][j]='.';
	}else{
	  M[i][j]=c;
	}
      }
    }
    init.now=0;
    cin >> pat;
    pi ans_pos;
    int ans_step = bfs(init,H,W,M,pat,ans_pos);
    if( ans_step >= 0 ){
      cout << ans_step << ' ' << ans_pos.fr << ' ' << ans_pos.sc << endl;
    }else{
      cout << "impossible" << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 3048
ant = [int(input()) for i in range(5)]
k = int(input())

count = 0
for i in range(5):
    for j in range(0, i):
        if abs(ant[i] - ant[j]) > k:
            count += 1

if count > 0:
    print(":(")
else:
    print("Yay!")



Measured memory_bytes: 2940
#include <cstdio>
#include <vector>
#include <cstring>
#include <algorithm>
#include <numeric>

using namespace std;

const int N = 59;

bool g[2][N][N];
bool ng[2][N][N];
int leaf[N];
int pa[2][N];
int d[2][N];
int q[N];
int o[N];
int deg[N];
int color[N];

int main() {
  int tt;
  scanf("%d", &tt);
  while (tt--) {
    int n;
    scanf("%d", &n);
    memset(g, false, sizeof g);
    for (int i = 0; i < 2; ++i) {
      for (int j = 0; j < n - 1; ++j) {
        int x, y;
        scanf("%d %d", &x, &y);
        --x;
        --y;
        g[i][x][y] = true;
        g[i][y][x] = true;
      }
    }
    for (int x = 0; x < n; ++x) {
      int cnt = 0;
      for (int y = 0; y < n; ++y) {
        if (g[0][x][y]) {
          ++cnt;
        }
      }
      leaf[x] = cnt == 1;
    }
    memcpy(ng[1], g[1], sizeof ng[1]);
    int ans = n + 1;
    for (int root = 0; root < n; ++root) {
      for (int ver = 0; ver < n; ++ver) {
        if (ver != root && !leaf[root]) {
          continue;
        }
        memcpy(ng[0], g[0], sizeof ng[0]);
        if (ver != root) {
          for (int i = 0; i < n; ++i) {
            if (ng[0][root][i]) {
              ng[0][root][i] = false;
              ng[0][i][root] = false;
            }
          }
          ng[0][root][ver] = true;
          ng[0][ver][root] = true;
        }
        for (int i = 0; i < 2; ++i) {
          pa[i][root] = root;
          d[i][root] = 0;
          q[0] = root;
          for (int qh = 0, qt = 1; qh < qt; ++qh) {
            int x = q[qh];
            for (int y = 0; y < n; ++y) {
              if (!ng[i][x][y]) {
                continue;
              }
              if (y != pa[i][x]) {
                pa[i][y] = x;
                d[i][y] = d[i][x] + 1;
                q[qt++] = y;
              }
            }
          }
        }
        iota(o, o + n, 0);
        sort(o, o + n, [](int i, int j) {
          return d[0][i] < d[0][j];
        });
        memset(color, 0, sizeof color);
        memset(deg, 0, sizeof deg);
        for (int i = 1; i < n; ++i) {
          int x = o[i];
          if (color[pa[0][x]] == 1 || pa[0][x] != pa[1][x]) {
            color[x] = 1;
          }
          ++deg[pa[0][x]];
        }
        int cur = (ver != root) + accumulate(color, color + n, 0);
        while (true) {
          bool any = false;
          for (int i = 0; i < n; ++i) {
            if (deg[i] == 0 && color[i] == 1 && color[pa[1][i]] == 0) {
              --deg[pa[0][i]];
              color[i] = 0;
              any = true;
            }
          }
          if (!any) {
            break;
          }
        }
        if (accumulate(color, color + n, 0) == 0) {
          ans = min(ans, cur);
        }
      }
    }
    if (ans == n + 1) {
      ans = -1;
    }
    printf("%d\n", ans);
  }
}


Measured memory_bytes: 128
#include <algorithm>
#include <iostream>
#include <list>
#include <math.h>
#include <stack>
#include <stdio.h>
#include <string>
#include <queue>
#include <vector>
using namespace std;

int main()
{
	int n;
	int s[10000];
	cin >> n;
	for (int i = 0; i < n; i++) cin >> s[i];

	int q, x;
	cin >> q;

	int cnt = 0;
	for (int i = 0; i < q; i++) {
		cin >> x;
		for (int j = 0; j < n; j++) {
			if (s[j] == x) {
				cnt++;
				break;
			}
		}
	}

	cout << cnt << endl;
}


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

const ll INF = 1ll << 60;
ll MOD = 998244353;

int main()
{

    int a, b;
    cin >> a;
    cin >> b;

    if ((a + b) % 2 == 1)
        cout << "IMPOSSIBLE";
    else
    {
        cout << (a + b) / 2;
    }

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
template <class T> int size(const T &x) { return x.size(); }
#define rep(i,a,b) for (__typeof(a) i=(a); i<(b); ++i)
#define iter(it,c) for (__typeof((c).begin()) \
  it = (c).begin(); it != (c).end(); ++it)
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef long long ll;
const int INF = ~(1<<31);

const double EPS = 1e-9;
const double pi = acos(-1);
typedef unsigned long long ull;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
template <class T> T smod(T a, T b) {
  return (a % b + b) % b; }

int main()
{
    ios_base::sync_with_stdio(false);
    int n;
    cin >> n;
    set<string> seen;
    string s;
    cin >> s;
    char last = s[s.size()-1];
    seen.insert(s);
    rep(i,1,n)
    {
        cin >> s;
        if(s[0] != last || seen.find(s) != seen.end())
        {
            cout << "No" << endl;
            return 0;
        }
        seen.insert(s);
        last = s[s.size()-1];
    }
    cout << "Yes" << endl;
    
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std; 
int main(){
    int x,y;
    int small,big;
    do{
        cin >> x >>y;
        if(x !=0 || y!=0){
            if(x > y){
                small = y;
                big = x;
            }else{
                small = x;
                big = y;
            }
            cout << small << " " << big << endl;
        }
    }while(x !=0 || y!=0);
    return 0;
}


Measured memory_bytes: 3084
#include <bits/stdc++.h>
#include <stdio.h>
 
using namespace std;
 
#define int long long
#define rep(i, a, b) for (int i = (a); i < (b); ++i)
#define trav(i, a) for (auto &i: (a))
#define sz(x) (int)(x).size()
#define all(v) (v).begin(), (v).end()
#define fr(i, a, b) for (int i = (a); i <= (b); ++i)

void solve();

signed main () {
    clock_t beg = clock();
    cout << fixed << setprecision(15);
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    #ifdef LOCAL
    freopen("input.txt", "r", stdin);
    #endif 
    int t = 1; 
    // cin >> t;    
    int tt = t;
    while (t--) {
        // cout << "Case #" << tt - t << ": "; 
        solve();
    }
    cerr << "\nExecution time: " << (clock() - beg) / 1000 << '\n';
    return 0;
}
const int N = 1e4 + 5;
int cnt[N] = {0};
void solve() {  
    int n;
    cin >> n;
    for (int x = 1; x <= 100; ++x) {
        for (int y = 1; y <= 100; ++y) {
            for (int z = 1; z <= 100; ++z) {
                int lol = x * x + y * y + z * z + x * y + y * z + x * z;
                if (lol <= n)
                    cnt[lol]++;
            }
        }
    }
    fr(i, 1, n)
        cout << cnt[i] << '\n';
}       

Measured memory_bytes: 3588
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<cstdio>
#include<cmath>
#include<numeric>
#include<queue>
#include<stack>
#include<cstring>
#include<limits>
#include<functional>
#include<unordered_set>
#include<iomanip>
#define rep(i,a) for(int i=(int)0;i<(int)a;++i)
#define pb push_back
#define eb emplace_back
using ll=long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 50;
constexpr double pi=3.14159265358979;
 
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
using namespace std;

void solve(){
 string s;
 cin>>s;
 if(s.size()==2)cout<<s<<"\n";
 else {
   string t="";
   rep(i,3)t+=string{s[2-i]};
   cout<<t<<"\n";
 }
 return;
}
 
signed main(){
	ios::sync_with_stdio(false);
  cin.tie(0);
  cout<<fixed<<setprecision(20);
	solve();
	return 0;
}


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

int main() {
	int n,k; cin>>n>>k;
	int a[n+1];
	for (int i=1; i<=n; ++i) cin >> a[i];
	
	for (int i=k+1; i<=n; ++i) {
		if (a[i] > a[i-k]) cout << "Yes" << endl;
		else cout << "No" << endl;
	}
}

Measured memory_bytes: 4284
unittest
{
	assert( [ "1234", "150", "100" ].parse.expand.solve == 84 );
	assert( [ "1000", "108", "108" ].parse.expand.solve == 28 );
	assert( [ "579", "123", "456" ].parse.expand.solve == 0 );
	assert( [ "7477", "549", "593" ].parse.expand.solve == 405 );
}



import std.conv;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto x = input.front.strip.to!( long );
	input.popFront;
	auto a = input.front.strip.to!( long );
	input.popFront;
	auto b = input.front.strip.to!( long );
	return tuple( x, a, b );
}

auto solve( long x, long a, long b )
{
	return ( x - a ) % b;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fastio() ios_base::sync_with_stdio(false);
using namespace std;
typedef long long ll;
typedef long double ld;


int main(){
	int n, m;
	cin >> n >> m;
	string a = "";
	for(int i = 0; i < n; i++) a.push_back(m+'0');
	string b = "";
	for(int i = 0; i<m; i++) b.push_back(n+'0');
	string ans = min(a, b);
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static boolean inList(int number, int[] list) {
		for(int n = 0; n < list.length; n += 1) {
			if (list[n] == number) {
				return true;
			}
		}
		return false;	
	}
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String arraySizeS = sc.nextLine();
		int arraySize = Integer.parseInt(arraySizeS);
		String[] inputArrayS = sc.nextLine().split(" ");
		int[] inputArray = new int[arraySize];
		for( int i = 0; i < arraySize; i += 1) {
			inputArray[i] = Integer.parseInt(inputArrayS[i]);}
		String arraySizeS2 = sc.nextLine();
		int arraySize2 = Integer.parseInt(arraySizeS2);
		String[] inputArrayS2 = sc.nextLine().split(" ");
		int[] inputArray2 = new int[arraySize2];
		for( int j = 0; j < arraySize2; j += 1) {
			inputArray2[j] = Integer.parseInt(inputArrayS2[j]);	
		}
		int counter = 0;
		for(int m = 0; m < inputArray2.length; m += 1) {
			if(inList(inputArray2[m],inputArray)) {
				counter += 1;
			}
		}
		System.out.println(counter);
			
	}

}



Measured memory_bytes: 30200
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
const ll maxn=2e5+1;
const ll INF=4e18;
ll gcd(ll a,ll b)
{
	if(b==0) return a;
	else return gcd(b,a%b);
}
void solve()
{
	ll A,B;
	cin>>A>>B;
	ll g=gcd(A,B);
	ll ans=(A*B)/g;
	cout<<ans<<"\n";
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll T=1,p=0;
	//cin>>T;
	do
	{
		solve();
		p++;
	}while(p<T);
	return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <atomic>
#include <thread>
#include <mutex>
#include <string>
#include <string.h>
#include <functional>
#include <vector>
#include <list>
#include <queue>
#include <map>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#define rep(i,n) for(int i=0;i<n;i++)
#define eps LDBL_EPSILON
#define moder 1000000007
#define int long long
#define ll long long
#define INF LLONG_MAX/3
#define P std::pair<int,int>
#define prique priority_queue<int,vector<int>,greater<int>>
using namespace std;
int n, a, b;
vector<P> v;
map<P, int> mp;
bool func(P p, P q) {
	if (p.first + p.second > q.first + q.second)return true;
	return false;
}
signed main() {
	cin >> n;
	rep(i, n) {
		cin >> a >> b;
		v.push_back({ a, b });
		mp[{ a, b }]++;
	}
	sort(v.begin(), v.end(), func);
	int t = 0, o = 0;
	a = 0, b = 0;
	rep(i, n) {
		if (i % 2 == 0) {
			t += v[i].first;
		}
		else {
			o += v[i].second;
		}
	}
	cout << t - o << endl;
	return 0;
}

Measured memory_bytes: 10096
import java.util.Scanner;
public class Main {
@SuppressWarnings("resource")
public static void main(String[] args) {
	Scanner sc =new Scanner(System.in);
	int N=sc.nextInt();
	for(int i=1;i<10;i++) {
		if(N%i==0) {
			N/=i;
			if(N<10) {
				System.out.println("Yes");
				System.exit(0);
				}
			N*=i;
		}
	}
	System.out.println("No");
}
}


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

#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 reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repc(i, n) for (int i = 0; i <= int(n); i++)
#define rrepc(i, n) for (int i = int(n); i >= 0; i--)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define repic(i, a, b) for (int i = int(a); i <= int(b); i++)
#define each(x, y) for (auto &x : y)
#define all(a) (a).begin(), (a).end()
#define bit(b) (1ll << (b))
#define uniq(v) (v).erase(unique(all(v)), (v).end())

using namespace std;

using i32 = int;
using i64 = long long;
using f80 = long double;
using vi32 = vector<i32>;
using vi64 = vector<i64>;
using vf80 = vector<f80>;
using vstr = vector<string>;

inline void yes() { cout << "Yes" << '\n'; exit(0); }
inline void no() { cout << "No" << '\n'; exit(0); }
inline i64 gcd(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); if (a % b == 0) return b; return gcd(b, a % b); }
inline i64 lcm(i64 a, i64 b) { return a / gcd(a, b) * b; }
void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); solve(); return 0; }
template <typename T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {};
template <typename T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {};
template <typename T> inline void amax(T &x, T y) { if (x < y) x = y; }
template <typename T> inline void amin(T &x, T y) { if (x > y) x = y; }
template <typename T> inline T power(T x, i64 n, T e = 1) { T r = e; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }
template <typename T> istream& operator>>(istream &is, vector<T> &v) { each(x, v) is >> x; return is; }
template <typename T> ostream& operator<<(ostream &os, vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } return os; }
template <typename T, typename S> istream& operator>>(istream &is, pair<T, S> &p) { is >> p.first >> p.second; return is; }
template <typename T, typename S> ostream& operator<<(ostream &os, pair<T, S> &p) { cout << p.first << ' ' << p.second; return os; }

void solve() {
  int N, M; cin >> N >> M;
  vector<vi32> b(N, vi32(N, 1e9));
  rep(i, N) b[i][i] = 0;
  
  vector<tuple<int, int, int>> edges;
  rep(i, M) {
    int v, u, c; cin >> v >> u >> c;
    v--, u--;
    edges.emplace_back(v, u, c);
    b[v][u] = b[u][v] = c;
  }

  rep(k, N) rep(i, N) rep(j, N) amin(b[i][j], b[i][k] + b[k][j]);

  int ans = 0;
  each(e, edges) {
    int v, u, c;
    tie(v, u, c) = e;
    if (c != b[v][u]) ans++;
  }
  cout << ans << '\n';
}


Measured memory_bytes: 384
//Use valgrind once if the submission doesn't go through. It can detect uninitialized variables and see where they could be an issue.
#include <bits/stdc++.h>
using namespace std;

int main(){

	ios_base::sync_with_stdio(false);
    	cin.tie(NULL);

	long long n,clen=0,cycle=0,dest;
	unsigned long long k;
	cin>>n>>k;
	vector<int> a(n);
	for(int i=0;i<a.size();i++)
	{
		cin>>a[i];
		a[i]--;
	}
	vector<bool> visited(n,false);
	while(!visited[cycle])
	{
		visited[cycle]=true;
		cycle=a[cycle];
	}
	for(dest=0;dest!=cycle&&clen<k;dest=a[dest],clen++);
	if(clen!=k)
	{
		k-=clen;
		for(clen=1,dest=a[dest];dest!=cycle;dest=a[dest],clen++);
		k%=clen;
		for(;k>0;k--,dest=a[dest]);
	}
	cout<<dest+1<<endl;
	return 0;
}


Measured memory_bytes: 3992
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const long long MOD=998244353;

int main(void){
    int n;
    cin>>n;
    vector<int> A(n);
    rep(i,n) cin>>A[i];
    sort(A.begin(),A.end());
    int ans=0;
    vector<int> done(1000009,0);
    rep(i,n){
        if(done[A[i]]==0){
            if(i!=n-1){
                if(A[i]!=A[i+1]) ans++;
            }
            else ans++;
            rep(j,1000000){
            if(A[i]*j>1000000) break;
            done[A[i]*j]=1;
            }
        }
    }
    //rep(i,1000000) cout<<i<<" "<<done[i]<<endl;
    cout<<ans<<endl;
    return 0;
}

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


int main()
{
	//freopen("input16.txt","r",stdin);freopen("output16.txt","w",stdout);
	ios_base::sync_with_stdio(false); cin.tie(0);
	string a;
	int i,p=0,g=0,t=0;
	cin>>a;
	for (i=0;i<a.size();i++){
		if (a[i]=='g'){
			if (g>p){
				t++;
				p++;
			}
			else {
				g++;
			}
		}
		else {
			if (g>p){
				p++;
			}
			else {
				g++;
				t--;
			}
		}
	}
	cout<<t;
	return 0;
}

Measured memory_bytes: 512
#include<iostream>
#include<algorithm>
#include<cmath>
#include<map>
#include<string>
#include<set>
#include<vector>
using namespace std;

int solve(){
  char c; cin >> c;
  cout << (char)(c+1) << endl;
  return 0;
}

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ll long long int
const int INF = 2147483647;
const ll MOD = 1000000007;

using namespace std;

int main() {
  string s;
  cin >> s;
  if (s == "Sunny") {
    cout << "Cloudy" << endl;
  } else if (s == "Rainy") {
    cout << "Sunny" << endl;
  } else {
    cout << "Rainy" << endl;
  }
}


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

typedef pair<int, int> P;
typedef long long ll;

#define rep(i, n) for(int i = 0; i < (n); i++)
#define repto(i, n) for(int i = 0; i <= (n); i++)
#define all(c) (c).begin, (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end())
#define _1 first
#define _2 second
#define pb push_back
#define INF 1145141919
#define MOD 1000000007
#define DEBUG(x) cout << #x << ": " << x << endl;

int main() {
  int H, A;
  cin >> H >> A;
  if (H % A)
    cout << H / A + 1 << endl;
  else
    cout << H/A << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#include <complex>
#include <time.h>
#define int long long
#define endl '\n'
#define INF 1000000000000000000
#define EPS 1e-10
#define PI 3.141592653589793238
#define all(a) a.begin(),a.end()
#define rep(i, n) for (int i = 0; i < (n); i++)
#define fi first
#define se second
#define pb push_back
#define double long double
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<ll, P> PP;
typedef complex<double> com;
template<class T, class S> bool chmax(T &a, const S &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T, class S> bool chmin(T &a, const S &b) { if (a > b) { a = b; return 1; } return 0; }
ll gcd(ll n, ll m) { return (m ? gcd(m, n%m) : n); }
ll lcm(ll n, ll m) { return n / gcd(n, m)*m; }


signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(20);
	//modcalc();

	int h, w;
	cin >> h >> w;
	vector<vector<char>> c(h, vector<char>(w));
	rep(i, h) rep(j, w) cin >> c[i][j];
	rep(i, h) {
		rep(_, 2) {
			rep(j, w) cout << c[i][j];
			cout << endl;
		}
	}
}

Measured memory_bytes: 256
import Control.Arrow
import Data.List

main :: IO ()
main = interact $ unlines . map (show' . uncurry era_name) . read' . lines
 where
  read' ("0 0":_) = []
  read' (nq:xs) = (db, map read qs') : read' xs'
   where
    [n,q] = map read (words nq)
    ((db',qs'),xs') = first (splitAt n) (splitAt (n+q) xs)
    db = map ((\[e,ey,wy] -> ((e, read ey), read wy)) . words) db'
  show' = init . unlines . map (maybe "Unknown" (\(e,ey) -> e ++ " " ++ show ey))

era_name :: [((String,Int),Int)] -> [Int] -> [Maybe (String,Int)]
era_name db qs = map (query (map period db)) qs

period :: ((String,Int),Int) -> (String, (Int,Int))
period ((e,ey),wy) = (e, (wy-ey+1,wy))

query :: [(String, (Int,Int))] -> Int -> Maybe (String,Int)
query db q = do
 (e,(wy1,_)) <- find (\(_,(wy1,wy2)) -> wy1 <= q && q <= wy2) db
 return (e, q-wy1+1) 

Measured memory_bytes: 7540
#include <algorithm>
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <string>
#include <sstream>
#include <vector>
#include <set>
#include <stack>
#include <map>
#include <cmath>
#include <queue>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
using namespace std;
typedef unsigned long long ll;


int main()
{
	int x,y,z;
	cin>>x>>y>>z;
	int i = 0;
	for(i = 0; (i*(y + z) + z) <= x; i++){
		
	}
	cout<<i-1<<endl;
	return 0;
}



Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())

const ll mod = 1000000007;
ll modpow(ll x,ll n){
	ll res=1;
	while(n>0){
		if(n&1) res=res*x%mod;
		x=x*x%mod;
		n>>=1;
	}
	return res;
}
ll F[1005],R[1005];
void make(){
	F[0] = 1;
	for(int i=1;i<1005;i++) F[i] = F[i-1]*i%mod;
	for(int i=0;i<1005;i++) R[i] = modpow(F[i],mod-2);
}
ll C(int a,int b){
	return F[a]*R[b]%mod*R[a-b]%mod;
}
int n;
int L[105],x;
int cnt[505];
ll dp[2][505][505];
ll m[505][505];
int main(){
	rep(i,505){
		m[i][0] = 1;
		repn(j,503) m[i][j] = m[i][j-1]*1LL*i%mod;
	}
	make();
	cin >> n >> x;
	rep(i,n){
		cin >> L[i]; cnt[L[i]]++;
	}
	int cur = 0, nxt = 1;
	dp[cur][0][0] = 1;
	for(int d=x;d>=1;d--){
		rep(a,505)rep(c,505)dp[nxt][a][c]=0;
		rep(a,x+1) rep(b,x+1){
			if(dp[cur][a][b] == 0) continue;
			int aa = a, bb = b;
			while(aa <= x){
				dp[nxt][aa][bb] += dp[cur][a][b] * R[bb-b] % mod;
				if(dp[nxt][aa][bb] >= mod) dp[nxt][aa][bb]-=mod;
				aa += d;
				bb += 1;
			}
		}
		swap(cur,nxt);
		if(cnt[d]){
			rep(a,505)rep(c,505)dp[nxt][a][c]=0;
			rep(a,x+1)rep(b,x+1){
				if(dp[cur][a][b] == 0) continue;
				dp[nxt][a][b] += dp[cur][a][b] * m[a-(d-1)*b][cnt[d]] % mod;
				if(dp[nxt][a][b] >= mod) dp[nxt][a][b] -= mod;
			}
			swap(cur,nxt);
		}
	}
	ll ans = 0;
	rep(a,x+1) rep(b,x+1){
		if(dp[cur][a][b] == 0) continue;
		if(b-1 > x-a) continue;
		int zan = x-a-(b-1);
		ll add = dp[cur][a][b] * F[b] % mod * C(b+zan,b) % mod;
		if((x-a)%2 == 0) ans += add;
		else ans -= add;
	}
	cout << (ans%mod+mod)%mod << endl;
}

Measured memory_bytes: 6272
#include <cstring>
#include <cstdio>
#include <algorithm>
using namespace std;
#include <cmath>
char s[105];
int main()
{
while(~scanf ("%s", s))
{
        if(s[0]==s[1] && s[0]==s[2] && s[0]==s[3] || s[1]==s[2] && s[1]==s[3] || s[0]==s[1] && s[0]==s[2] )
				printf("Yes\n");
			else
			{
				printf("No\n");
			}
}
		return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <cmath>
#include <typeinfo>
#include <set>
#include <bitset>
#include <string>
#include <map>
#include <algorithm>
using namespace std;
typedef long long ll;



int main(){
  string s;
  cin >> s;
  if(s == "SUN"){
    cout << 7 << endl;
  }else if(s == "MON"){
    cout << 6 << endl;
  }else if(s == "TUE"){
    cout << 5 << endl;
  }else if(s == "WED"){
    cout << 4 << endl;
  }else if(s == "THU"){
    cout << 3 << endl;
  }else if(s == "FRI"){
    cout << 2 << endl;
  }else if(s == "SAT"){
    cout << 1 << endl;
  }
}

Measured memory_bytes: 256
h,w=map(int,input().split())
A=[]
for i in range(h):
  A.append([int(i) for i in input().split()])
Ans=[]
for i in range(h):
  for j in range(w-1):
    if A[i][j]%2==1:
      Ans.append([i+1,j+1,i+1,j+2])
      A[i][j+1]+=1
for i in range(h-1):
  if A[i][w-1]%2==1:
    Ans.append([i+1,w,i+2,w])
    A[i+1][w-1]+=1
print(len(Ans))
for ans in Ans:
  print(*ans)

Measured memory_bytes: 30148
#include <stdio.h>
#include <algorithm>

int A, B, d[11][11], f[101][101];

int main() {
    scanf("%d %d", &A, &B);
    for (int i = 1; i <= A; ++i) {
        for (int j = 1; j <= B; ++j) {
            scanf("%d", &d[i][j]);
        }
    }

    for (int a = 0; a <= 100; ++a) {
        for (int b = 0; b <= 100; ++b) {
            f[a][b] = 0;
            for (int x = 1; x <= A; ++x) {
                for (int y = 1; y <= B; ++y) {
                    f[a][b] = std::max(f[a][b], d[x][y] - x * a - y * b);
                }
            }
        }
    }
    for (int x = 1; x <= A; ++x) {
        for (int y = 1; y <= B; ++y) {
            int D = 1e9;
            for (int a = 0; a <= 100; ++a) {
                for (int b = 0; b <= 100; ++b) {
                    D = std::min(D, a * x + b * y + f[a][b]);
                }
            }
            if (D != d[x][y]) {
                printf("Impossible\n");
                return 0;
            }

        }
    }

    puts("Possible");
    printf("%d %d\n", 202, 101 * 101 + 200);
    for(int i = 1; i <= 100; ++i) {
        printf("%d %d X\n", i, i + 1);
    }
    for(int i = 102; i <= 201; ++i) {
        printf("%d %d Y\n", i, i + 1);
    }
    for(int a = 0; a <= 100; ++a) {
        for(int b = 0; b <= 100; ++b) {
            printf("%d %d %d\n", a + 1, 202 - b, f[a][b]);
        }
    }
    printf("1 202\n");

    return 0;
}

Measured memory_bytes: 256