akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <cstring>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <list>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <unordered_set>
#include <unordered_map>
#include <array>
#include <cassert>
#include <bitset>
using namespace std;
using LL = long long;

int main(void)
{
	string S, T;
	cin >> S >> T;
	string ans = "";
	if (S.size() < T.size())
	{
		cout << "UNRESTORABLE\n" << endl;
		return 0;
	}
	string SS = S;
	for (int i = 0; i <= S.size() - T.size(); ++i) {
		bool flag = true;
		for (int j = 0; j < T.size(); ++j) {
			if (S[i + j] == '?' || S[i + j] == T[j]) {

			}
			else {
				flag = false;
				break;
			}
		}
		if (flag) {
			for (int j = 0; j < T.size(); ++j) {
				S[i + j] = T[j];
			}
			for (int j = 0; j < S.size(); ++j) {
				if (S[j] == '?')S[j] = 'a';
			}
			if (ans.empty()) {
				ans = S;
			}
			else {
				ans = min(ans, S);
			}
		}
		S = SS;
	}
	if(ans.empty())
		cout << "UNRESTORABLE\n";
	else {
		cout << ans << endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int n; cin >> n;
    int ab = 0;
    int a = 0;
    int b = 0;
    int ba = 0;
    for(int i = 0; i < n; i ++) {
        string s; cin >> s;
        if(s[s.length()-1]=='A') a++;
        if(s[0]=='B') b++;
        if(s[0]=='B' && s[s.length()-1]=='A') ba ++;
        for(int j = 0; j < s.length(); j ++) {
            if(j<s.length()-1 && s[j]=='A' && s[j+1]=='B') ab ++;
        }
    }
    if(a==ba && b==ba) cout << ab + max(0,ba-1) << endl;
    else cout << ab + min(a,b) << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<queue>
using namespace std;
const int N = 1000;
const int inf = (1<<28);
enum{NORTH=0,EAST=1,SOUTH=2,WEST=3};
int dx[]={0,1,0,-1};
int dy[]={-1,0,1,0};

int cost[N][N][4];
int dir[N*N+1];
int next[N*N+1][4];
char m[N][N+1];

void precalc(string in){
  in=" "+in;
  int td = NORTH;
  for(int i=1;i<in.size();i++){
    if (in[i] == 'R')td++;
    else if (in[i] == 'L')td+=3;
    td%=4;
    dir[i]=td;
  }
  int last[4]={inf,inf,inf,inf};
  for(int i=in.size()-1;i>=0;i--){
    last[dir[i]]=i;
    for(int j=0;j<4;j++){
      next[i][j]=last[j];
    }
  }
  /*
  for(int i=0;i<in.size();i++){
    cout <<"dir of " << i <<" is " << dir[i] << " : next is ";
    for(int j=0;j<4;j++)cout << next[i][j] <<" " ;cout << endl;
  }cout << endl;
  */
}

class st{
public:
  int y,x,d;
  int cost;
  bool operator<(const st & a)const{
    return cost > a.cost;
  }
};

void solve(int r,int c,int sy,int sx){
  for(int i=0;i<r;i++)
    for(int j=0;j<c;j++)
      for(int k=0;k<4;k++)cost[i][j][k]=inf;
  cost[sy][sx][NORTH]=0;
  priority_queue<st> Q;
  Q.push((st){sy,sx,NORTH,0});
  while(!Q.empty()){
    st now = Q.top();Q.pop();
    if (cost[now.y][now.x][now.d] != now.cost)continue;
    if (m[now.y][now.x] == 'G'){
      cout <<"Yes" << endl;
      return;
    }

    {
      int nex=now.x+dx[now.d],ney=now.y+dy[now.d];
      int nec=now.cost;
      if (nex != -1 && ney != -1 && nex != c && ney != r &&
	  m[ney][nex] != '#' && cost[ney][nex][now.d] > nec){
	cost[ney][nex][now.d] = nec;
	Q.push((st){ney,nex,now.d,nec});
      }
    }

    for(int i=0;i<4;i++){
      int ned=i;
      int nec=next[now.cost][i];
      if (cost[now.y][now.x][ned] > nec){
	cost[now.y][now.x][ned] = nec;
	Q.push((st){now.y,now.x,ned,nec});
      }
    }
  }
  cout <<"No"<<endl;
}

main(){
  int r,c,n;
  while(cin>>r>>c>>n && r){
    string in;cin>>in;
    for(int i=0;i<r;i++)cin>>m[i];
    int sy,sx;
    for(int i=0;i<r;i++){
      for(int j=0;j<c;j++){
	if (m[i][j] == 'S'){sy=i,sx=j;break;}
      }
    }
    precalc(in);
    solve(r,c,sy,sx);
  }
  return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
#pragma region atcoder
//#include <atcoder/all>
//using namespace atcoder;
#pragma endregion
#pragma region macros
using ll = long long;
using vi = vector<int>;
using vs = vector<string>;
using vl = vector<ll>;
using vb = vector<bool>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rrep(i, n) for(int i = n - 1; i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#pragma endregion
#pragma region debug for var, v, vv
#define debug(var)  do{std::cout << #var << " : ";view(var);}while(0)
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){cout << endl;int cnt = 0;for(const auto& v : vv){cout << cnt << "th : "; view(v); cnt++;} cout << endl;}
#pragma endregion

const ll mod = 1000000007;
const int inf = 1001001001;
const ll INF = 1001001001001001001;
const int MAX = 2000005;

//using mint = modint998244353;
//These are for segment tree
/*int op(int a, int b){return max(a, b);}
int e(){return -1;}
bool f(int v){ return v < target;}
*/

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

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; }
ll modpow(ll a, ll p){ll ret = 1; while(p){if(p & 1){ret = ret * a % mod;} a = a * a % mod; p >>= 1;} return ret;}

/*--------------------------------------------------------------------------------------------------------------------------------*/

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n; cin >> n;
	int cnt = 0;
	int tmp = 0;
	for(ll i = 1; i < n; i++){
		for(ll j = 1; j < n; j++){
			if(i * j < n) cnt++;
			else break;
		}
	}
	cout << cnt << endl;
	
} 


Measured memory_bytes: 3688
#pragma region RegionDefs
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0,i##_len=(n);i<i##_len;++i)
#define reps(i,l,r) for(int i=(l),i##_len=(r);i<i##_len;++i)
#define repr(i,l,r) for(int i=(r)-1,i##_left=(l);i>=i##_left;--i)
#define all(x) begin(x),end(x)
using namespace std;
typedef long long ll;
const ll INF = 1e9;
template<class T=ll> using V = vector<T>;
template<class T=ll> using PQ = priority_queue<T>;
template<class T=ll> using PQG = priority_queue<T, V<T>, greater<T>>;
const ll MOD = 1000000007LL;
void in() {}
template<class Head, class... Tail>
void in(Head&& head, Tail&&... tail) { cin >> head; in(move(tail)...); }
#define IN(...) ll __VA_ARGS__; in(__VA_ARGS__)
#define TIN(T, ...) T __VA_ARGS__; in(__VA_ARGS__)
#define VIN(T, v, n) V<T> v(n); for(auto& _elem:v)cin>>_elem
#define VIND(T, v, n) V<T> v(n); for(auto& _elem:v)cin>>_elem,--_elem
#define OUT(x) cout << x;
#define OUTL(x) cout << x << endl;
template<class T>bool chmax(T &a, const T &b) {if (a<b) {a=b; return 1;} return 0;}
template<class T>bool chmin(T &a, const T &b) {if (a>b) {a=b; return 1;} return 0;}
template<class T>
string join(vector<T>& v, string delim="") { ostringstream os; rep(i,v.size())i?os<<delim<<v[i]:os<<v[0]; return os.str(); }
#pragma endregion RegionDefs

void solve()
{
    IN(a, b, c, d);
    ll ans = a*c;
    chmax(ans, a*d);
    chmax(ans, b*c);
    chmax(ans, b*d);
    cout << ans << endl;
}

int main()
{
    cin.tie(0); cout.tie(0);
    ios::sync_with_stdio(false);
    cout << setprecision(numeric_limits<double>::max_digits10);

    solve();

    return 0;
}

Measured memory_bytes: 3664
#include <bits/stdc++.h>
#define R real()
#define I imag()
#define EPS (1e-8)
using namespace std;
typedef complex <double> point;
struct S{
  double x,y,z,r;
  S(){x=y=z=r=0;}
  S(double x,double y,double z,double r):x(x),y(y),z(z),r(r){};
};

S s[2001],b[20],E;
vector <int> B[20];

double get_dis(S a,S b){
  a.x-=b.x,a.y-=b.y,a.z-=b.z;
  return sqrt(a.x*a.x+a.y*a.y+a.z*a.z);
}

//right baloon
bool check(S s,S p){
  S res;
  point A=point(s.x,s.y),B=point(p.x,p.y);
  if(abs(A))B*=(conj(A)/abs(A));
  res.y=B.I;
  A=point(abs(A),s.z),B=point(B.R,p.z);
  if(abs(A))B*=(conj(A)/abs(A));
  res.x=B.R,res.z=B.I;

  double X=get_dis(s,S(0,0,0,0)),r=0;
  if(res.x<0) r=get_dis(res,S(0,0,0,0));
  else if(X<res.x) r=get_dis(res,S(X,0,0,0));
  else r=sqrt(res.z*res.z+res.y*res.y);
  if(max(get_dis(res,S(0,0,0,0)),get_dis(res,S(X,0,0,0)))<=p.r)return 0;
  return p.r>=r;
  
}

double cal(S a){return a.r/((a.x*a.x)+(a.y*a.y)+(a.z*a.z));}

int main(){
  int n,m,r;
  while(1){
    cin>>n>>m>>r;
    if(!n&&!m&&!r)break;

    for(int i=0;i<n;i++)cin>>s[i].x>>s[i].y>>s[i].z>>s[i].r;
    for(int i=0;i<m;i++)cin>>b[i].x>>b[i].y>>b[i].z>>b[i].r;
    cin>>E.x>>E.y>>E.z;
    for(int i=0;i<n;i++)s[i].x-=E.x,s[i].y-=E.y,s[i].z-=E.z;
    for(int i=0;i<m;i++)b[i].x-=E.x,b[i].y-=E.y,b[i].z-=E.z;

    for(int i=0;i<m;i++){
      B[i].clear();
      for(int j=0;j<n;j++)
	if(check(b[i],s[j]))B[i].push_back(j);
    }


    double ans=0;
    for(int i=0;i<(1<<m);i++){
      int used[2001]={},cnt=0;
      double sum=0;
      for(int j=0;j<m;j++){
	if(!((i>>j)&1))continue;
	for(int k=0;k<B[j].size();k++)cnt+=!used[B[j][k]],used[B[j][k]]=1;
	if(cnt>r)break;
	sum+=cal(b[j]);
      }
      ans=max(ans,sum);
    }
    cout <<ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 1488
s = list(map(int, list(input())))
m = 1000
for i in range(len(s)-2):
  if abs(753 - (s[i]*100+s[i+1]*10+s[i+2])) < m:
    m = abs(753 - (s[i]*100+s[i+1]*10+s[i+2]))
print(m)

Measured memory_bytes: 2940
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int n=scanner.nextInt();
		int k=scanner.nextInt();
		int x=scanner.nextInt();
		int y=scanner.nextInt();
		int ans =0;

		if(n <= k) {
			System.out.println(n*x);
		}
		else {
			System.out.println(k*x + (n-k)*y);
		}
	    scanner.close();
		}
}


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

#define REP(i,n) for(ll i=0;i<ll(n);++i)
#define RREP(i,n) for(ll i=ll(n)-1;i>=0;--i)
#define FOR(i,m,n) for(ll i=m;i<ll(n);++i)
#define RFOR(i,m,n) for(ll i=ll(n)-1;i>=ll(m);--i)
#define ALL(v) (v).begin(),(v).end()
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9

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


using namespace std;

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vvl = vector<vl>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

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

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	string s; cin >> s;
	int ans = 0;
	int n = s.size();
	REP(i, n) {
		int cnt = 0;
		FOR(j, i, n) {
			if (s[j] == 'A' || s[j] == 'T' || s[j] == 'C' || s[j] == 'G') {
				cnt++;
				chmax(ans, cnt);
			}
			else {

				break;
			}
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
int main() {
	int width , height;
	int x , y , r;
	scanf("%d %d %d %d %d" , &width , &height , &x , &y , &r);

	if (x - r < 0) {
		printf("No\n");
	} 
	else if (width < x + r) {
		printf("No\n");
	}
	else if (height < y + r ) {
		printf("No\n");
	}
	else if (y - r < 0) {
		printf("No\n");
	}
	else {
		printf("Yes\n");
	}
	return 0;
}

Measured memory_bytes: 584
import java.io.*;
import java.util.*;

public class Main {
    private void solve() {
        long A = sc.nextLong();
        long B = sc.nextLong();
        long N = sc.nextLong();

        if (N > B - 1) {
            N = B - 1;
        }

        long ans = (long)Math.floor(1.0 * A * N / B) - (long)Math.floor(1.0 * N / B) * A;
        out.println(ans);
    }

    private static PrintWriter out;
    private static MyScanner sc;

    private static class MyScanner {
        BufferedReader br;
        StringTokenizer st;

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

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

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

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

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

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


Measured memory_bytes: 32888
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <string>
#include <iostream>
#include <algorithm>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <vector>

using namespace std;

typedef long long ll;
const int Maxn = 1e9 + 10;
const int N = 1e5 + 10;
const int INF=(0x7fffffff)/2;
const int MOD = 1000000007;
const int MaxN = 1e5;
int a[110];
int main(){
	int n;
	scanf("%d", &n);
	int d, x;
	scanf("%d %d", &d, &x);
	int sum = x + n;
	for(int i = 1; i <= n; i++){
		scanf("%d", &a[i]);
		int y = a[i] + 1;
		int k = 0;
		/*while(y <= d){
			if(y <= n)
				k = k + 1;
			printf(i"%d\n", k);
			y += a[i];
		}*/
		 k = (d - 1)/a[i];
		sum += k;
	}
	printf("%d\n",sum);
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
using ll = long long;
const ll MOD = 1e9 + 7;

const int K = 1e5;
bool dp[K + 1];

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

	int n, k;
	cin >> n >> k;

	vector<int> as(n);
	for (int i = 0; i < n; ++i) cin >> as[i];

	for (int j = 1; j <= k; ++j) {
		for (auto v : as) {
			if (j >= v && !dp[j-v]) {
				dp[j] = true;
			}
		}
	}
	if (dp[k]) {
		cout << "First\n";
	} else {
		cout << "Second\n";
	}
}


Measured memory_bytes: 384
#include <stdio.h>
int main()
{
  int i,n,s,p,moraeruhito,sum,ns;
  while(1){
    scanf("%d %d %d",&n,&s,&p);
    //printf("%d ",n);///
    if(n==0&&s==0&&p==0)break;
    sum=0;
    for(i=1;i<=n;i++){
      scanf("%d",&ns);
      if(i==s)moraeruhito=ns;
      sum+=ns;
    }
    if(moraeruhito==0){
      printf("0\n");
      continue;
    }
    //printf("%d ",sum);///
    sum*=100;
    sum=(double)sum/100*(100-p);
    //printf("%d ",sum);///
    //printf("%d ",moraeruhito);///
    sum/=moraeruhito;
    printf("%d\n",sum);
  }
  return 0;
}

Measured memory_bytes: 1040
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
void xin(){
	#ifndef ONLINE_JUDGE 
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	#endif
}
int main()
{
  	xin();
	ios_base::sync_with_stdio(false); 
    cin.tie(NULL);
    cout.tie(NULL);
    
    int n;
    cin>>n;
    cin.ignore();
    map<string,int> a;
    while(n--)
    {
    	string s;
    	getline(cin,s);
    	a[s]++;
	}
	cout<<"AC x "<<a["AC"]<<endl;
	cout<<"WA x "<<a["WA"]<<endl;
	cout<<"TLE x "<<a["TLE"]<<endl;
	cout<<"RE x "<<a["RE"]<<endl;
}

Measured memory_bytes: 3664
#include <stdio.h>
int main(int argc, char const *argv[])
{
	int a,b,c;
	scanf("%d %d %d",&a,&b,&c);
	if (a>=c)
	{
		if (c>b)
		{
			printf("Yes\n");
		}else{
			printf("No\n");
		}
	}else{
		if (c<b)
		{
			printf("Yes\n");
		}else{
			printf("No\n");
		}
	}
	return 0;
}

Measured memory_bytes: 128
/*
	Copyright: razouq (c)
	Author: Anass BENDARSI
	Date: 06/08/2017 13:03:33
	flamers will **** you
*/
#include<bits/stdc++.h>
//#include<flamers.h>
#define ll long long
#define ull unsigned long long
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define POB pop_back
#define dist(a, b) sqrt(a*a + b*b)
using namespace std;
typedef vector<int> vi;
typedef pair<int, int> pi;
typedef vector<pair<int, int>> vipi;
bool compare(pi p1, pi p2){
	 if(1) return true;
	 return false;
}

int main(){
//	freopen("input.in", "r", stdin);
//	freopen("output.out", "w", stdout);
	ios::sync_with_stdio(0);
	cin.tie();
	int n, m;
	cin>>n>>m;
	cout<<(n-1)*(m-1)<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <set>
#include <map>
#include <sstream>
//#include <fstream>

using namespace std;

int main()
{
//	cut here before submit 
//	freopen ("testcase.trading", "r", stdin );
	string str = "";

	map<int, int> d;
	set<int> D;

	while (getline (cin, str ) ){
		if (str.empty() ){
			break;
		} // end if
		str = str.replace (str.find (','), 1, " " );
		int c, dummy;
		stringstream ss(str);
		ss >> c >> dummy;
//		prev.insert (c );
		d[c]++;
	} // end loop


	while (getline (cin, str ) ){
		str = str.replace(str.find(','), 1, " " );
		int c, dummy;
		stringstream ss(str);
		ss >> c >> dummy;
		if (d[c] ){
			d[c]++;
			D.insert (c);
		} // end if
	} // end loop

	for (set<int>::iterator it = D.begin(); it != D.end(); ++it ){
		cout << *it << " " << d[*it] << endl;
	} // end for

	return 0;
}

Measured memory_bytes: 0
#include <iostream>

int main(){
  long long a, b, c, d;
  std::cin >> a >> b >> c >> d;
  
  long long prod1, prod2;
  prod1 = a * c;
  prod2 = b * d;
  
  if (prod1 < 0 && prod2 < 0) std::cout << std::max(a * d, b * c);
  else std::cout << std::max(prod1, prod2);
  
  return 0;
}


Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  int j=0;
  cin >> N;
  vector<int> mochi(N);
  for(int i=0;i<N;i++){
      cin >> mochi.at(i);
  }
  sort(mochi.begin(), mochi.end());
  for(int i=0;i<N-1;i++){
      if(mochi.at(i) < mochi.at(i+1)){
          j++;
      }
      else continue;
  }
 cout << j+1 << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include<algorithm>
using namespace std;
#define ll long long 
const int MAX = 510000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

void COMinit() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < MAX; i++){
    fac[i] = fac[i - 1] * i % MOD;
    inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
    finv[i] = finv[i - 1] * inv[i] % MOD;
  }
}
// 二項係数計算
long long COM(int n, int k){
  if (n < k) return 0;
  if (n < 0 || k < 0) return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
int main() {
  int n,k;
  cin >> n >> k;
  vector<int> a(n);
  
  for(int i = 0;i< n;i++){
    cin >> a[i];
  }
  sort(a.begin(),a.end());
  // 前処理
  COMinit();
  
  ll mi = 0;
  ll mx = 0;
  ll tmp;
  for(int i = 0;i < n-k+1;i++){
    tmp = COM(n-i-1,k-1);
    //cout << i << " " << tmp << endl;
    mi += tmp*a[i]%MOD;
  }
  
  for(int i = k-1;i < n;i++){
    tmp = COM(i,k-1);
    //cout << i << " " << tmp << endl;
    mx += tmp*a[i]%MOD;
  }
  
  ll res = mx-mi;
  res %= MOD;
  cout << res;
  //cout << 100;
}


Measured memory_bytes: 15660
inlist=input("").split(" ")
n=int(inlist[0])
m=int(inlist[1])
lista=[]
listb=[]
for i in range(n):
    lista+=[[]]
    listb+=[-1]
listb[0]=-2

listnum=[0]
for i in range(m):
    inlist=input("").split(" ")
    s=int(inlist[0])
    t=int(inlist[1])
    lista[s-1]+=[t-1]
    lista[t-1]+=[s-1]
k=0
while(k<len(listnum)):
    for i in lista[listnum[k]]:
        
        if(listb[i]==-1):
            listb[i]=listnum[k]
            listnum+=[i]
    k+=1

if (-1 in listb):
    print("No")
else:
    print("Yes")
    for i in listb[1:]:
        print(i+1)
        
    






    
    
    

    
    


Measured memory_bytes: 35308
sqlist = []
x = 1
while x*x <= 100100:
	sqlist.append(x*x)
	x += 1
a, b = input().split()
c = int(a+b)
ans = 'No'
for i in range(0, len(sqlist)):
	if c == sqlist[i]:
		ans = 'Yes'
		break
print(ans)

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

#define all(x)        (x).begin(),(x).end()
#define eb            emplace_back
#define mp            make_pair
#define pb            push_back
#define fi            first
#define se            second
#define sz(x)         ((int)(x).size())
#define rep(x,y,z)    for(int x=y;x<z;x++)
#define per(x,z,y)    for(int x=z-1;x>=y;x--)
#define trav(y,x)     for(auto& y:x)
#define pii           pair<int, int>
#define pll           pair<ll, ll>
#define vi            vector<int>
#define vpi           vector<pii>

int dbg = 0;
#define cri           if(0)
#define shame         cri cerr<<(++dbg)<<"\n\n";

// aaaaaaaaaaaaaaaa
void solve() {
  string s; cin >> s;
  cout << (s == "ABC" ? "ARC" : "ABC") << '\n';
  return;
}

int main() {
  // int _; scanf("%d", &_); while (_--)
  // ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  // int _; cin >> _; while(_--)
  solve();
	return 0;
}



Measured memory_bytes: 3604
#include <stdio.h>
#include <algorithm>
#include <vector>
using namespace std;
using ll = long long;

constexpr ll mod = 998244353;
ll f[310000], fi[310000];
ll mpow(ll n, ll e) {
	ll r = 1;
	while (e) {
		if (e & 1)
			r = r * n % mod;
		n = n * n % mod;
		e /= 2;
	}
	return r;
}
ll comb(ll n, ll r) {
	return f[n] * fi[n - r] % mod * fi[r] % mod;
}
void init() {
	f[0] = 1;
	for (int i = 1; i <= 300000; i++)
		f[i] = f[i - 1] * i % mod;
	fi[300000] = mpow(f[300000], mod - 2);
	for (int i = 300000; 0 < i; i--)
		fi[i - 1] = fi[i] * i % mod;
}

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

	init();
	ll c = 0;
	for (int i = 0; i <= k; i++) {
		c += comb(n - 1, i) * mpow(m - 1, n - i - 1) % mod * m % mod;
		c %= mod;
	}
	printf("%lld\n", c);
}

Measured memory_bytes: 6420
#include <bits/stdc++.h>
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 all(x) (x).begin(), (x).end()
#define sz(x) int(x.size())
#define get_unique(x) x.erase(unique(all(x)), x.end());
typedef long long ll;
typedef complex<double> Complex;
const int INF = 1e9;
const ll MOD = 1e9 + 7;
const ll LINF = 1e18;
template <class T>
bool chmax(T& a, const T& b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T& a, const T& b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
double dist(pair<double, double> a, pair<double, double> b) {
    double ax, ay, bx, by;
    tie(ax, ay) = a;
    tie(bx, by) = b;
    return sqrt((ax - bx) * (ax - bx) + (ay - by) * (ay - by));
}
int main() {
    int n;
    cin >> n;
    vector<int> a(n), b(n);
    rep(i, n) cin >> a[i];
    rep(i, n) cin >> b[i];

    vector<int> p(n);
    rep(i, n) p[i] = i + 1;
    int x, y;
    int cnt = 0;
    do {
        if (p == a) x = cnt;
        if (p == b) y = cnt;
        cnt++;
    } while (next_permutation(all(p)));
    cout << abs(x - y) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
#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)-1;i>=0; --i)
#define FORq(i, m, n) for(int i = (m);i <= (n);++i)
#define FORqr(i, m, n) for(int i = (n);i >=(m);--i)
#define PB push_back
#define MP make_pair
#define DEBUG printf("%s\n","debug")
#define fst first
#define snd second
#define SIN(x, S) (S.count(x) != 0)
#define M0(x) memset(x,0,sizeof(x))
#define FILL(x, y) memset(x,y,sizeof(x))
#define MM(x) memset(x,-1,sizeof(x))
#define ALL(x) (x).begin(),(x).end()
using namespace std;
typedef pair<int, int> PII;
typedef pair<long long, long long> PLL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<long long> VL;
typedef long long ll;
typedef long long integer;
///////////////////////////////////////////////
/* (๑╹◡╹) */
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
ll MOD = 1000000007;
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;
}
/* (๑╹◡╹)(๑╹◡╹)(๑╹◡╹)(๑╹◡╹)(๑╹◡╹)(๑╹◡╹) */
///////////////////////////////////////////////
const int MAX = 510000;
 
long long fac[MAX], finv[MAX], inv[MAX];
 



int main() {
int ans = 0;
	ll N; cin >> N;
	ll A[N+1];
	ll sum = 0;
	rep(i,N){cin >> A[i];sum += A[i];}
	sum = sum /2;
	rep(i,N)
	{
		if(i==0)
		{
			ans = sum;
			for (int j = 1; j < N; j+=2)
			{
				ans -= A[j];
			}
		}
		else
		{
			ans = A[i-1] - ans;
		}
			cout << ans*2 << endl;
	}
	


}



Measured memory_bytes: 2048
package main

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

func main() {
	sc = initScanner(os.Stdin)
	a, b, k := scanInt(sc), scanInt(sc), scanInt(sc)
	solve(a, b, k)
}

func solve(a, b, k int) {
	n := intAbs(a - b) + 1
	if n <= k*2 {
		for i:=a;i<=b;i++ {
			fmt.Println(i)
		}
		return
	}

	cnt := 0
	for i:=a;i<=b;i++ {
		fmt.Println(i)
		cnt++
		if cnt == k {
			break
		}
	}
	for i:=b-k+1;i<=b;i++ {
		fmt.Println(i)
	}
}

func intAbs(num int) int {
	if num < 0 {
		return -num
	}
	return num
}

// --------------- BASE DEFINITIONS ---------------

const (
	initialBufSize = 100000
	maxBufSize     = 1000000
)

var sc *bufio.Scanner

func initScanner(r io.Reader) *bufio.Scanner {
	buf := make([]byte, initialBufSize)

	sc := bufio.NewScanner(r)
	sc.Buffer(buf, maxBufSize)
	sc.Split(bufio.ScanWords)
	return sc
}

func scanInt(sc *bufio.Scanner) int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return i
}

func scanIntSlice(sc *bufio.Scanner, n int) []int {
	is := make([]int, n)
	for i := 0; i < n; i++ {
		is[i] = scanInt(sc)
	}

	return is
}

func scanFloat64(sc *bufio.Scanner) float64 {
	sc.Scan()
	f, _ := strconv.ParseFloat(sc.Text(), 64)
	return f
}

func scanFloat64Slice(sc *bufio.Scanner, n int) []float64 {
	fs := make([]float64, n)
	for i := 0; i < n; i++ {
		fs[i] = scanFloat64(sc)
	}

	return fs
}

func scanString(sc *bufio.Scanner) string {
	sc.Scan()
	return sc.Text()
}

func scanStringSlice(sc *bufio.Scanner, n int) []string {
	ss := make([]string, n)
	for i := 0; i < n; i++ {
		sc.Scan()
		ss[i] = sc.Text()
	}

	return ss
}


Measured memory_bytes: 1780
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,n-1,0)
#define all(v) v.begin(), v.end()
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n; cin >> n;
  map<ll, int> cnt1;
  vector<ll> D(n); rep(i, n) cin >> D[i], cnt1[D[i]]++;
  int m; cin >> m;
  map<ll, int> cnt2;
  vector<ll> T(m); rep(i, m) cin >> T[i], cnt2[T[i]]++;
  for(auto ele: cnt2) {
    if(cnt1[ele.first] < ele.second) {
      cout << "NO" << "\n";
      return 0;
    }
  }
  cout << "YES" << "\n";
  return 0;
}


Measured memory_bytes: 31348
#include <iostream>
// #include <algorithm>
// #include <set>
// #include <map>
#include <vector>
using namespace std;

int main()
{
  int N, K;
  cin >> N >> K;
  string S;
  cin >> S;

  // ex)
  // 000111000 => [0, 3, 3, 3]
  // 111000111000 => [3, 3, 3, 3]
  vector<int> nums;
  char now = '1';
  int count = 0;
  for (int i = 0; i < N; i++)
  {
    if (S[i] == now)
    {
      count++;
    }
    else
    {
      nums.push_back(count);
      now = S[i];
      count = 1;
    }
  }
  nums.push_back(count);

  int left = 0;
  int right = 0;
  int max = 0;
  while (left < (nums.size() + 1))
  {
    int cnt = 0;

    for (right = left; right < nums.size(); right++)
    {
      // K == 2
      // right == 0 => 0
      // right == 1 => 1
      // right == 2 => 1
      // right == 3 => 2
      // right == 4 => 2
      // right == 5 => 3 => break
      if (K < ((right - left + 1) / 2))
      {
        break;
      }
      cnt = cnt + nums[right];
    }

    if (max < cnt)
    {
      max = cnt;
    }

    left += 2;
  }
  cout << max << endl;

  return 0;
}

Measured memory_bytes: 1020
n, k = map(int, input().split())
s, p, r = map(int, input().split())
t = input()

cnt = 0
for i in range(k):
    f = 0
    pre = ""
    for j in range(i, n, k):
        if pre != t[j] or f == 1:
            cnt += eval(t[j])
            f = 0
        else:
            f = 1
        pre = t[j]
print(cnt)

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

using namespace std;

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

int main(){
  
  int n;
cin>> n;
  
  vector<int> h(n);
vector<int> now(n,0);
  
  rep(i,0,n) cin >> h[i];
  
  int res=0;
  
  rep(i,0,n){
    int d=h[i]-now[i];
    res+=d;
    rep(j,i,n){
      d=min(d,h[j]-now[j]);
      now[j]+=d;
    }
  } 
 
  cout << res << endl;

}

Measured memory_bytes: 256
import java.util.*;
public class Main{
  public static void main(String args[]){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int l = sc.nextInt();
    int[] aji = new int[n];
    int ajisum = 0;
    for(int count = 0;count<n;count++){
      aji[count] = l+(count+1)-1;
      ajisum += aji[count];
    }
    int eat = 0;
    if(l<0){
      if(l+n<=0){
        eat = aji[n-1];
      }
    }else if(l>0){
      eat = aji[0];
    }
    System.out.println(ajisum-eat);
  } 
}

Measured memory_bytes: 21716
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <cmath>
#include <climits>
#include <iomanip>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
int main(){
  int n = 0;
  string s;
  cin >> n >> s;
  int res = 0;
  for(int i = 0;i < 1000;i++){
    string num;
    if(i < 10)num = "00" + to_string(i);
    else if(i < 100)num = "0" + to_string(i);
    else num = to_string(i);
    //cout << num << endl;
    int now = 0;
    for(int j = 0;j < n;j++){
      if(s[j] == num[now])now++;
    }
    if(now >= 3)res++/*,cout << num << endl*/;
  }
  cout << res << endl;
}

Measured memory_bytes: 256
N = int(input())
C = list(input())

i = 0
j = N-1
count = 0 
frag = True
Frag_f = True
Frag_b = True
while (frag):
    if i >= j:
        break
    if Frag_f == True:
        if C[i] == "R":
            i = i + 1
        else:
            Frag_f = False
    if Frag_b == True:
        if C[j] == "W":
            j = j - 1
        else:
            Frag_b = False
    
    if Frag_b == False and Frag_f == False:
        count += 1
        Frag_f = True
        Frag_b = True
        i = i+1
        j = j-1
print(count)

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

using namespace std;

int main() {
	ios::sync_with_stdio(false);
	string s;
	int x;
	cin >> s >> x;
	int i;
	for (i = 0; i < s.length(); i++) {
		if (i % x == 0)cout << s[i];
	}

}

Measured memory_bytes: 256
//includes
#include<iostream>
#include<vector>
#include<set>
#include<tuple>
#include<algorithm>
#include<cmath>
#include<string>
#include<stack>
#include<map>
#include<queue>
#include<iomanip>
#include<numeric>
#include<assert.h>
#include<cstring>
#include<unordered_map>
#include<bitset>

//macros and consts
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define all(a) (a).begin(),(a).end()
#define FOR(i,a,b) for(int i = (a); i < (b); i++)
#define FORE(i,a) for(auto &i : a)
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define accm accumulate
#define Fi first
#define Se second
#define INF 1e9
#define llINF (1LL<<60)
#define mINF -1e9
#define mllINF -(1LL<<60)
#define endl "\n"
#define CONT continue
#define BRK break
#define modulo(n, m) (((n)%(m)+(m))%m)

//shorter types
using namespace std;
using ll = long long;
using vi = std::vector<int>;
using vc = std::vector<char>;
using vll = std::vector<long long>;
using vs = std::vector<string>;
using Mi = map<int,int>;
using Mll = map<ll,ll>;
using UMi = unordered_map<int,int>;
using UMll = unordered_map<ll,ll>;
using Pi = pair<int,int>;
using Pll = pair<ll,ll>;
using vPi = vector<Pi>;
using vPll = vector<Pll>;
using vvi = vector<vector<int>>;
using vvll = vector<vector<ll>>;
using vvc = vector<vector<char>>;
using vvs = vector<vector<string>>;
using pqgi = priority_queue<int,vector<int>,greater<int>>;
using pqsi = priority_queue<int,vector<int>,less<int>>;
using pqgll = priority_queue<int,vector<int>,greater<int>>;
using pssll = priority_queue<int,vector<int>,less<int>>;
template<class T>
using vec = vector<T>;
#define int long long


//here begins your code
signed main(){
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);

  int N,M;
  cin >> N >> M;
  vec<int> problems;
  vec<int> aced;
  problems.assign(N,0);
  aced.assign(N,0);
  for(int i = 0 ; i < M ; i++){
  	int p;
  	string S;
  	cin >> p >> S;
  	p--;
  	if(aced[p] == 1){
  		continue;
  	}
  	else{
  		if(S == "WA"){
  			problems[p]++;
  		}
  		else{
  			aced[p] = 1;
  		}
  	}

  }
  int ac = 0;
  int wa = 0;
  for(int i = 0 ; i < N; i++){
  	if(aced[i] == 1){
  		ac++;
   		wa += problems[i];
  	}
  }

  cout << ac << " " << wa << endl;
  //check types
  //do not eb if you resize
  //resize before you access by idx
  return 0;
} 

Measured memory_bytes: 1792
#include <math.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define PI acos(-1)
typedef unsigned long long int ull;
typedef long long int ll;
typedef long double ld;

int main(void) {
  /* 標準入力フラグ */
  int   scan;

  /* 数入力 */
  ll    answer;
  ll    n;
  answer = 0;
  scan = scanf("%lld", &n);

 
  /* プログラムを書く */
	ll count = 0;
	if (n % 1000 == 0)
		count = n / 1000;
	else
		count = n / 1000 + 1;

	answer = 1000 *  count - n;



  /* 数回答 */
  printf("%lld", answer);


  return (0);
}



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

using namespace std;
long long x[10000010], y[10000010];
#define rep(i, n) for (int i = 0; i < (n); i++)
#define lep(j, n) for (int j = 0; j < (n); j++)
#define reps(i, n) for (int i = 1; i < (n); i++)
#define leps(i, n) for (int j = 1; j < (n); j++)
#define all(x) (x).begin(), (x).end()
#define pii pair<int, int>
#define int long long
#define gsort(x, n) sort((x), (x) + (n), greater<int>());
#define setout(n, x) setw(n) << setfill(x)
#define Fixed fixed << setprecision(10);
const long long mod = 1e9 + 7;

signed main()
{

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

   int a, b, c, d;
   cin >> a >> b >> c >> d;

   a = min(a, b);
   c = min(c, d);
   cout << a + c << '\n';
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
/*
g++ -std=c++11 -Wall -g -fsanitize=undefined -D_GLIBCXX_DEBUG abc/abc061/c.cpp
*/
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define SZ(x) ((int)(x).size())
#define INF (1e16)
typedef long long ll;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);//おまじないでcin, cout早くする
    ll N, K;
    cin >> N >> K;
    map<int, ll> m;
    rep(i, N){
        int a;
        ll b;
        cin >> a >> b;
        if(m.count(a)){
            m[a] += b;
        }else{
            m.insert(make_pair(a, b));
        }
    }
    ll cnt = 0;
    for(auto i = m.begin(); i != m.end(); ++i){
        cnt += i->second;
        if(cnt >= K){
            cout << i->first << "\n";
            return 0;
        }
    }
    return 0;
}

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

class Program{

  static int ans = 0;

  static int Main() {

    string[] nyu = Console.ReadLine().Split(' ');
    int x  = int.Parse(nyu[0]);
    int y = int.Parse(nyu[1]);

    ans = x + y / 2;

    Console.WriteLine("{0}", ans);

    return 0;
  }

}


Measured memory_bytes: 13268
// AFTER CONTEST, WIP

#include <bits/stdc++.h>
using namespace std;

// Utility
#define ALL(X) (X).begin(), (X).end()
#define FOR(I, X, Y) for (int I = (X); I < (Y); I++)
using ll = int64_t;
using ull = uint64_t;
template<typename T> struct is_container {
template<typename C> static char test(typename C::const_iterator*); template<typename> static int test(...);
static bool const value = sizeof(test<T>(nullptr)) == sizeof(char) && !std::is_same<std::string, T>::value;
};
namespace std {
template<class ...Ts>        istream& operator>>(istream& i, tuple<Ts...>& x) { apply([&](auto&&... ys){ ((i >> ys), ...); }, x); return i; }
template<class T1, class T2> istream& operator>>(istream& i, pair<T1, T2>& x) { i >> x.first >> x.second; return i; }
template<class T, enable_if_t<is_container<T>::value, int> = 0>
istream& operator>>(istream& i, T& x) { for (auto& y : x) { i >> y; } return i; }
}

// Debugging
#define DD(X) std::cout << #X ": " << (X) << std::endl << std::flush
#define DD2(X) std::cout << #X ":" << std::endl; for (auto x : (X)) { std::cout << x << std::endl << std::flush; }
namespace std {
template<class ...Ts>        ostream& operator<<(ostream& o, const tuple<Ts...>& x) { o << "("; apply([&](auto&& y, auto&&... ys){ o << y; ((o << ", " << ys), ...); }, x); o << ")"; return o; }
template<class T1, class T2> ostream& operator<<(ostream& o, const pair<T1, T2>& x) { o << tie(x.first, x.second); return o; }
template<class T, enable_if_t<is_container<T>::value, int> = 0>
ostream& operator<<(ostream& o, const T& x) { o << "{"; for (auto it = x.begin(); it != x.end(); it++) { if (it != x.begin()) { o << ", "; } o << *it; } o << "}"; return o; }
}

// Main
void mainCase() {
  ll n; // <= 10^9
  cin >> n;

  auto p5 = [](ll x) -> ll { return x * x * x * x * x; };
  vector<ll> p5s;
  for (ll x = 0; ; x++) {
    p5s.push_back(p5(x));
    if (p5(x + 1) - p5(x) > n) { break; }
  }
  // DD(p5s);

  int k = p5s.size(); // O(n^1/4)
  FOR(x, 0, k) {
    FOR(y, x, k) {
      if (p5s[y] + p5s[x] == n) {
        cout << y << " " << (-x) << endl;
        return;
      }
      if (p5s[y] - p5s[x] == n) {
        cout << y << " " << x << endl;
        return;
      }
    }
  }
  assert(0);
}

int main() {
  ios_base::sync_with_stdio(0); cin.tie(0);
  // [ Single case ]
  mainCase();
  return 0;
  // [ Multiple cases ]
  // int t;
  // cin >> t;
  // FOR(i, 0, t) { mainCase(); }
  // return 0;
}

/*
python misc/run.py atcoder/abc166/d/main.cpp --check

%%%% begin
33
%%%%
2 -1
%%%% end
*/


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

using namespace std;

int a[105][105];

int main() {
    int n, m, k;
    scanf("%d%d%d", &n, &m, &k);
    int x = 0, y = 0, d = 1;
    for (int c, i = 1; i <= k; ++i) {
        scanf("%d", &c);
        while (c --) {
            if (y < 0) {
                ++ x;
                y = 0;
                d = 1;
            }
            if (y >= m) {
                ++ x;
                y = m - 1;
                d = -1;
            }
            a[x][y] = i;
            y += d;
        }
    }
    for (int i = 0; i < n; ++i)
        for (int j = 0; j < m; ++ j)
            printf("%d%c", a[i][j], j == m - 1 ? '\n' : ' ');
    return 0;
}


Measured memory_bytes: 384
s = gets
x, y = gets.split.map(&:to_i)

ind = 0
while s[ind] == "F"
  x -= 1
  ind += 1
end

xys = [[0],[0]]
xory = 1
allXY = [0,0]
s[(ind+1)..-1].each_char do |c|
  if c == "F"
    xys[xory][-1] += 1
    allXY[xory] += 1
  else
    xory += 1
    xory %= 2
    if xys[xory][-1] != 0
      xys[xory] << 0
    end
  end
end
xys = xys.map{ |z| z.sort.reverse }
xys.each_with_index do |xy, i|
  z = i == 0 ? x : y
  xy.each do |pos|
    if z >= 0
      z -= pos
    else
      z += pos
    end
  end
  if i == 0
    x = z
  else
    y = z
  end
end

if x == 0 && y == 0
  puts "Yes"
else
  puts "No"
end


Measured memory_bytes: 3836
def slove():
    import sys
    import collections
    import bisect
    input = sys.stdin.readline
    n = int(input().rstrip('\n'))
    l = list(map(int, input().rstrip('\n').split()))
    l.sort()
    cnt = 0
    d = collections.defaultdict(int)
    for i in range(n-2):
        for j in range(i+1, n-1):
            ma = l[i] + l[j]
            p = bisect.bisect_left(l, ma)
            if j < p:
                cnt += p - j - 1
    print(cnt)


if __name__ == '__main__':
    slove()


Measured memory_bytes: 42204
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <queue>
#include <deque>
#include <list>
#include <map>
#include <set>
#include <cmath>
#include <cstring>
#include <string>
#include <bitset>
#include <fstream>
#include <iomanip>

using namespace std;

typedef long long ll;
typedef double db;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<double,double> pdd;
typedef vector<pii> vii;

#define INF 1000000007ll
#define PB push_back
#define MP make_pair
#define X first
#define Y second
#define cil(a,b) ( ((a)%(b) == 0)?((a)/(b)):((a)/(b)+1) )
#define err(x) cerr << #x << " = " << x << endl;
#define SIZE 55

const ll mod = INF;
ll dp[SIZE][2];
char s[2][SIZE];
bool same[SIZE];

int main() {
   int n;
   scanf("%d %s %s", &n, s[0], s[1]);
   s[0][n] = s[1][n] = '#';
   vi pos;
   pos.PB(0);
   for (int i = 1 ; i < n ; ++i) {
      //cout << s[0][i] << " " << s[0][i - 1] << "  ";
      if (s[0][i] != s[0][i - 1]) {
         pos.PB(i);
         //cout << i << endl;
      }
      same[i] = (s[0][i] == s[1][i]);
      //cout << endl;
   }
   
   same[0] = (s[0][0] == s[1][0]);
   if (s[0][0] == s[1][0]) {
      dp[0][0] = 3;
      dp[0][1] = 0;
   }
   else {
      dp[0][1] = 6;
      dp[0][0] = 0;
   }

   for (int i = 1 ; i < pos.size() ; ++i) {
      int j = pos[i];
      if (same[j]) {
         dp[i][0] = (dp[i - 1][0] * 2) % mod;
         dp[i][0] += dp[i - 1][1];
         dp[i][1] = 0;
      }
      else {
         dp[i][1] = (dp[i - 1][0] * 2) % mod;
         dp[i][1] += (dp[i - 1][1] * 3) % mod;
         dp[i][0] = 0;
      }
   }

   //cout << same[pos.back()] << endl;
   printf("%lld\n", dp[pos.size() - 1][!same[pos.back()]]);
   return 0;
}

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

const int N = 500005;
const int MOD = 1000000007;

int power(int x, int y) {
  int ret = 1;
  for (; y; y >>= 1) {
    if (y & 1) ret = 1LL * ret * x % MOD;
    x = 1LL * x * x % MOD;
  }
  return ret;
}

int n, m;
int fact[N], ifact[N];

int C(int n, int k) {
  return 1LL * fact[n] * ifact[k] % MOD * ifact[n-k] % MOD;
}

int solve() {
  fact[0] = 1;
  for (int i = 1; i < N; ++i) fact[i] = 1LL * fact[i-1] * i % MOD;
  ifact[N-1] = power(fact[N-1], MOD-2);
  for (int i = N-2; i >= 0; --i) ifact[i] = 1LL * ifact[i+1] * (i+1) % MOD;

  scanf("%d %d", &n, &m);

  int ans = 0;
  for (int i = 0; i <= n; ++i) {
    int term = (1LL * fact[m] * ifact[m-n] % MOD) * C(n, i) % MOD * (1LL * fact[m-i] * ifact[m-n] % MOD) % MOD;
    if (i & 1) ans = (ans - term) % MOD;
    else ans = (ans + term) % MOD;
  }
  if (ans < 0) ans += MOD;
  printf("%d\n", ans);
  return 0;
}

int main() {
  int t = 1;
  // scanf("%d", &t);
  while (t--) solve();
  return 0;
}


Measured memory_bytes: 7720
import java.awt.Point;
import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int H = sc.nextInt();
		int W = sc.nextInt();
		int D = sc.nextInt();
		Point[] A = new Point[H*W];
		for(int i = 0; i < H; i++)
			for(int j = 0; j < W; j++)
				A[sc.nextInt()-1] = new Point(j, i);
		int[] c = new int[H*W+D];
		for(int i = 0; i < D; i++) {
			int j = i;
			while(j + D < H*W) {
				c[j+D] = c[j] + Math.abs(A[j].x-A[j+D].x) + Math.abs(A[j].y-A[j+D].y);
				j += D;
			}
		}
		int Q = sc.nextInt();
		for(int i = 0; i < Q; i++) {
			int L = sc.nextInt()-1;
			int R = sc.nextInt()-1;
			System.out.println(c[R] - c[L]);
		}
	}

}

Measured memory_bytes: 100848
#include <iostream>
using namespace std;
typedef long long ll;
const ll MOD = 1e9+7;
int main(){
  ll N,M;
  cin >> N >> M;

  if(N == M + 1 || M == N + 1){
    ll ans = 1;

    for(ll i = 1;i <= M;i++){
      ans *= i;
      ans %= MOD;
    }

    for(ll i = 1;i <= N;i++){
      ans *= i;
      ans %= MOD;
    }

    cout << ans << endl;
  }
  else if(N == M){
    ll ans = 1;

    for(ll i = 1;i <= N;i++){
      ans *= i;
      ans %= MOD;
    }

    for(ll i = 1;i <= M;i++){
      ans *= i;
      ans %= MOD;
    }

    ans *= 2;
    ans %= MOD;
    
    cout << ans << endl;
  }
  else cout << 0 << endl;
}


Measured memory_bytes: 256
n = int(input())
maps = []
maps.append([0,0,0])
for i in range(n):
  t,x,y = map(int,input().split())
  maps.append([t,x,y])
count = 0
for j in range(n):
  tgap = maps[j+1][0] - maps[j][0]
  total = maps[j+1][1] - maps[j][1] + maps[j+1][2] - maps[j][2]
  gap = tgap - total
  if gap >= 0 and gap % 2 == 0:
    count += 1
if count == n:
  print("Yes")
else:
  print("No")

Measured memory_bytes: 19572
N,A,B=map(int,input().split())
ab=A+B
if N <= ab and N>=A:
    print(A)
elif N <= ab:
    print(N)
else:
    t = N//ab
    t2 = N%ab
    if t2>=A:
        print(A*t + A)
    else:
        print(A*t + t2)

Measured memory_bytes: 3060
a,b=map(int,input().split())
c=list(map(int,input().split()))
t=b
ans=b
for i in range(1,a):
  if t>=c[i]:
    t=c[i]+b
    ans+=c[i]-c[i-1]
  else:
    t=c[i]+b
    ans+=b
    
print(ans)

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

#define rep(i, a, b) for (int i = (a); i < (int)(b); i++)
#define rrep(i, a, b) for (int i = (a); i >= (int)(b); i--)
#define all(x) (x).begin(), (x).end()
using i32 = int32_t;
using i64 = int64_t;
using f32 = float;
using f64 = double;
using P = pair<int, int>;

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

template <class T>
void dump_vec(const vector<T>& v) {
    auto len = v.size();
    rep(i, 0, len) {
        cout << v[i] << (i == (int)len - 1 ? "\n" : " ");
    }
}

struct FastIO {
    FastIO() {
        cin.tie(0);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(20);
    }
} FASTIO;

//---------------------------------------------------------------------------------------------------

//---------------------------------------------------------------------------------------------------

signed main() {
    int N;
    cin >> N;
    vector<int> A(N);
    rep(i, 0, N) cin >> A[i];
    int Q;
    cin >> Q;
    rep(i, 0, Q) {
        int s, t, k;
        cin >> s >> t >> k;
        int cnt = 0;
        rep(j, s, t) {
            if (A[j] == k) cnt++;
        }
        cout << cnt << "\n";
    }
}



Measured memory_bytes: 3224
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <algorithm>
#include <unordered_map>
#include <numeric>

#define rep(i, a, b) for (ll i = a; i < b; i++)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> pll;
typedef unordered_map<string, ll> u_map;

// input
void input() {}
template <class Head, class... Tail>
void input(Head &&a, Tail &&... b)
{
    cin >> a;
    input(forward<Tail>(b)...);
}

template <class V>
void input(vector<V> &v)
{
    for_each(v.begin(), v.end(), [](auto &i) { input(i); });
}

// output
template <class V>
void output(vector<V> &v)
{
    for_each(v.begin(), v.end(), [](auto &x) { cout << x << " "; });
    cout << endl;
}

// math functions
ll mpow(ll a, ll n, ll p)
{
    ll x = 1;
    while (n > 0)
    {
        if (n & 1)
        {
            x = a * x % p;
        }
        a = a * a % p;
        n >>= 1;
    }

    return x;
}

ll mfact(ll n, ll p)
{
    ll res = 1;
    for (ll i = 2; i <= n; i++)
    {
        res = res * i % p;
    }
    return res;
}

ll mcomb(ll n, ll r, ll p)
{
    if (n == 0 && r == 0)
    {
        return 1;
    }
    if (n < r || n < 0 || r < 0)
    {
        return 0;
    }

    ll a = mfact(n, p);
    ll b = mfact(n - r, p);
    ll c = mfact(r, p);
    return (((a * mpow(b, p - 2, p)) % p) * mpow(c, p - 2, p)) % p;
}

ll gcd(ll a, ll b)
{
    if (a < b)
    {
        a ^= b;
        b ^= a;
        a ^= b;
    }
    return b ? gcd(b, a % b) : a;
}

ll lcm(ll a, ll b)
{
    return a * b / gcd(a, b);
}

int main()
{
    ll N, K;
    input(N, K);

    vector<ll> H(N, 0);
    input(H);

    sort(H.begin(), H.end());

    cout << (K >= N ? 0 : accumulate(H.begin(), H.end() - K, 0LL)) << endl;

    return 0;
}

Measured memory_bytes: 1792