akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<queue>
using namespace std;

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

int search(vector<string> v) {

  pair<int,int> init;
  for(int i=0; i<v.size(); i++) {
    for(int j=0; j<v[i].length(); j++) {
      if( v[i][j] == '@' )
	init.second = i,init.first = j;
    }
  }

  int res = 0;

  queue< pair<int,int> > que;
  que.push(init);
  while(!que.empty()) {
    pair<int,int> q = que.front();
    que.pop();

    for(int i=0; i<4; i++) {
      int x=q.first+dx[i];
      int y=q.second+dy[i];
      if( x >= 0 && x < v[q.second].length() ) {
	if( y >= 0 && y < v.size() ) {
	  if( v[y][x] == '.') {
	    v[y][x] = '@';
	    pair<int,int> p;
	    p.first = x;
	    p.second = y;
	    que.push(p);
	  }
	}
      }
    }

  }

  for(int i=0; i<v.size(); i++) {
    for(int j=0; j<v[i].length(); j++) {
      //cout<<v[i][j];
      if(v[i][j] == '@') res++;
    }
    //cout<<endl;
  }
  return res;

}

int main() {

  int w,h;
  while(true) {

    cin>>w>>h;
    if(!w&&!h) break;
    vector<string> v;
    string s;

    for(int i=0; i<h; i++) {
      cin>>s;
      v.push_back(s);
    }

    cout<<search(v)<<endl;
  }
}

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

using namespace std;

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

  string s, t;
  cin >> s >> t;
  int n = s.size();
  map<char, int> ms, mt;
  string ss, tt;
  int ps = 0, pt = 0;
  for (int i = 0; i < n; ++i) {
    if (ms.find(s[i]) == ms.end()) {
      ms[s[i]] = ps++;
    }
    ss += '0'+ms[s[i]];
    if (mt.find(t[i]) == mt.end()) {
      mt[t[i]] = pt++;
    }
    tt += '0'+mt[t[i]];
  }

  cout << (ss == tt ? "Yes" : "No") << endl;

  return 0;
}



Measured memory_bytes: 1428
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
using namespace std;
using ll = long long;

vector<string> grid(1000);
ll dp[1000][1000];

int main() {
    int h, w;
    cin >> h >> w;

    for (int i=0; i<h; i++) {
        cin >> grid[i];
    }

    for (int i=h-2; i>=0; i--) {
        if (grid[i][w-1] == '#') break;
        dp[i][w-1] = 1;
    }
    for (int i=w-2; i>=0; i--) {
        if (grid[h-1][i] == '#')
            break;
        dp[h-1][i] = 1;
    }

    for (int i=h-2; i>=0; i--) {
        for (int j=w-2; j>=0; j--) {
            if (grid[i][j] != '#') {
                dp[i][j] = (dp[i+1][j] + dp[i][j+1]) % 1000000007;
            }
        }
    }

    cout << dp[0][0] << endl;

    return 0;
}

Measured memory_bytes: 9088
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a; i<=b; i++)
#define per(i,b,a) for(int i=b; i>=a; i--)
#define pb push_back
#define fi first
#define se second
using namespace std;
typedef pair<int, int> pi ;
typedef vector<pair<int,int> > vpi ;
typedef vector<int> vi ;
typedef long long ll ;
const int mod = 998244353 ;
const int inf = 1e9 + 5;
ll powmod(ll a, ll b) { ll ret = 1 ; while(b) { if(b&1) ret = (ret*a)%mod ;  a = (a*a)%mod ; b >>= 1 ; }  return ret ; }
const int maxn = 1e5 + 5 ;
int n, k ;
int h[maxn] ;
int dp[maxn] ;
int main()
{
    ios::sync_with_stdio(false) ;
    cin.tie(NULL) ;
    cin >> n >> k ;
    rep(i,0,n-1)
    cin >> h[i] ;
    rep(i,0,n-1) dp[i] = inf ;
    dp[0] = 0 ;
    rep(i,1,n-1)
    {
        rep(j,i-k,i-1)
         if(j >= 0)
          dp[i] = min(dp[i], dp[j] + abs(h[i]-h[j])) ;
    }
    cout << dp[n-1] << "\n" ;
    return 0 ;
}


Measured memory_bytes: 1024
#include <iostream>
#include <utility>
#include <vector>
#include <algorithm>
using namespace std;

using pii = pair<int, int>;

int main()
{
  int n, m;
  vector<pii> bridges;
  cin >> n >> m;
  int a, b;
  for (int i = 0; i < m; ++i)
  {
    cin >> a >> b;
    bridges.push_back(pii(b - 1, a - 1));
  }
  // end でソート
  sort(bridges.begin(), bridges.end());

  vector<int> bps; // break points
  for (int i = 0; i < m; ++i)
  {
    bool needBreak = true;
    for (auto p : bps)
    {
      if (bridges[i].second < p && p <= bridges[i].first)
      {
        needBreak = false;
        break;
      }
    }
    // 破壊ポイントにかぶっていない場合は壊す
    if (needBreak)
    {
      bps.push_back(bridges[i].first);
    }
  }
  cout << bps.size() << endl;
  return 0;
}

Measured memory_bytes: 1400
#include <algorithm>
#include <climits>
#include <iostream>
#include <string>
#include <utility>
#include<vector>
using namespace std;

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

    int a = 0;

    for(int i=n-1;i>=0;i--){
        
        if(h[i]<h[i-1]){
            int sub = h[i-1]-h[i];
            if(sub>1){
                cout<<"No"<<endl;
                a = -2;
                break;
            }else{
                h[i-1] = h[i-1]-1;
            }
        }
        // for(int j=0;j<n;j++){
        //     cout<<h[j]<<" ";
        // }
        // cout<<endl;

    }
        if(a != -2) cout<<"Yes"<<endl;

    
    return 0;

}

Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;


bool destroyed(vector<int> &hs, long long A, long long B, long long k) {
	long long n = 0;
	long long d = A - B;
	for (auto h : hs) {
		if (h > B * k)
			n += (h - B * k + d - 1) / d;
	}
	return n <= k;
}

int main(int argc, char *argv[]) {
	int N, A, B;
	cin >> N >> A >> B;

	vector<int> h(N);
	for (int i = 0; i < N; i++) cin >> h[i];

	sort(begin(h), end(h));

	long long l = 0, r = 10000000001;
	while (l + 1 < r) {
		long long m = l + (r - l) / 2;
		if (destroyed(h, A, B, m)) {
			r = m;
		} else {
			l = m;
		}
	}

	cout << r << endl;

	return 0;
}

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

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

  int count = 0;
  for (int i = 0; i < n; i+=2) {
    if (a[i]%2 == 1) count++;
  }

  cout << count << endl;

  return 0;
}



Measured memory_bytes: 3596
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <cstdio>
#include <ctime>
#include <assert.h>
#include <chrono>
#include <random>
#include <numeric>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
using namespace std;
typedef long long int ll;
typedef unsigned long long ull;

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll myRand(ll B) {
    return (ull)rng() % B;
}

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int x; cin >> x;
    if(x>=30){
        printf("Yes\n");
    }
    else{
        printf("No\n");
    }
}


Measured memory_bytes: 3652
#include<iostream>
#include<algorithm>
using namespace std;
signed main()
{
  int a,b,c,d,s;
  cin>>s;
  a=s/3600;
  d=s-a*3600;
  b=(s-a*3600)/60;
  c=(d-b*60);
  cout<<a<<":"<<b<<":"<<c<<"\n";
  return(0);
}



Measured memory_bytes: 3108
#include <bits/stdc++.h>
#define ll long long
#define rep(i, n) for(ll i=0; i<n; i++)
#define repr(i, s, e) for(ll i=s; i>=e; i--)
#define reps(i, s, e) for(ll i=s; i<=e; i++)
#define inf 1e18
#define all(v) v.begin(),v.end()
#define vsort(v) sort(v.begin(), v.end())
#define vsortr(v) sort(v.begin(), v.end(), greater<ll>())
#define sz(x) x.size()
#define ceil(a, b) (a+b-1)/b
#define ok cout << "ok" << endl;
#define sp << " " <<
using namespace std;
template<typename T> inline bool chmax(T &a, T b){ if(a<b){ a=b; return true; } return false; }
template<typename T> inline bool chmin(T &a, T b){ if(b<a){ a=b; return true; } return false; }
template<typename T> T gcd(T a, T b){ if(b==0) return a; return gcd(b, a%b); }
template<typename T> T lcm(T a, T b){ return a*(b/gcd(a, b)); }
template<typename T> T keta(T num){ T k=0; while(num>0){ num/=10; k++; } return k; }
template<typename T> void vdebug(vector<T> v){ for(auto vv : v){ cout << vv << " "; } cout << endl; }
template<typename T> void adebug(T arr[], ll n){ reps(i, 0, n){ cout << arr[i] << " "; } cout << endl; }
void ans(bool b){ if(b) cout << "Yes" << endl; else cout << "No" << endl; }
void ans2(bool b){ if(b) cout << "YES" << endl; else cout << "NO" << endl; }
int dx[] = {1, -1, 0, 0, 1, -1, 1, -1};
int dy[] = {0, 0, 1, -1, 1, -1, -1, 1};


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

    string ss;
    int n=0, w=0, s=0, e=0;
    cin >> ss;

    rep(i, ss.length()){
        if(ss[i] == 'S') s++;
        if(ss[i] == 'W') w++;
        if(ss[i] == 'N') n++;
        if(ss[i] == 'E') e++;
    }

    if((s*n==0 && !(s==0 && n==0))) ans(false);
    else if((w*e==0 && !(w==0 && e==0))) ans(false);
    else ans(true);

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,cc,n) for(int i=cc;i<=n;++i)
#define drep(i,cc,n) for(int i=cc;i>=n;--i)
#define sz(s) (int)(s.size())
#define vecprint(v) rep(i,0,v.size()-1)cout << v[i] << " ";cout << endl;
#define mod 1000000007
using namespace std;

int main(){
    int r;
    cin >> r;

    cout << 3*r*r << endl;
//  printf("%.10f\n",ans);

    return 0;
}

Measured memory_bytes: 256
N , K = map(int,input().split())
A = list(map(int,input().split()))
P = [0]*(N - K)
P0 = 1
for i in range(N-K):
  if A[i+K] > A[i] : 
    P[i] = 1
for i in range(N-K):
  if P[i] == 1:
    print('Yes')
  else:
    print('No')


Measured memory_bytes: 31752
/*
    In the name of Allah

    MohammadErfan Gooneh

*/
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;

#define endl                        '\n'
#define all(a, n)                   for (int i = 0; i < n; i++) cout << a[i] << " "; cout << endl;
#define IOS                         ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);


const ll MAXN = 1e6 + 10;
const ll INF = 8e18;
const ll MOD = 1e9 + 7;
int main() {
    IOS ;
    ll cnt = 0;
    string s ;
    cin >> s ;
    for(int i = 0 ; i < 3 ; i++){
        if(s[i] == '1')cnt++ ; 
    }
    cout << cnt ;





















return 0 ;
}


Measured memory_bytes: 3632
#include <cstdio>
#include <cctype>
#include <utility>
#include <vector>
#include <complex>
#include <algorithm>
using namespace std;

#define gcu getchar_unlocked
#define pcu putchar_unlocked
#define _T template <typename T>
#define _HT template <typename H, typename... T>
#define _il inline
#define _in _il int in
#define _sc _il bool scan
_T T in(int c){T n=0;bool m=false;while(isspace(c)){c=gcu();}if(c=='-')m=true,c=gcu();
	do{n=10*n+(c-'0'),c=gcu();}while(c>='0'&&c<='9');return m?-n:n;}
_in() {return in<int>(gcu());}
_T T scan(T &n){int c=gcu();return c==EOF?false:(n=in<T>(c),true);}
_sc(char &c){c=gcu();gcu();return c!=EOF;}
#ifdef _GLIBCXX_STRING
_sc(string &s){int c;s="";
	for(;;){c=gcu();if(c=='\n'||c==' ')return true;else if(c==EOF)return false;s+=c;}}
#endif
_HT _sc(H &h, T&&... t){return scan(h)&&scan(t...);}
#define _vo _il void out
#define _vl _il void outl
_vo(bool b) {pcu('0'+b);}
_vo(const char *s){while(*s)pcu(*s++);}
_vo(char c){pcu(c);}
#ifdef _GLIBCXX_STRING
_vo(string s){for(char c:s)pcu(c);}
#endif
_T _vo(T n){static char buf[20];char *p=buf;
	if(n<0)pcu('-'),n*=-1;if(!n)*p++='0';else while(n)*p++=n%10+'0',n/=10;
	while (p!=buf)pcu(*--p);}
_vl(){out('\n');}
#ifdef _GLIBCXX_VECTOR
_T _vo(vector<T> &v){for(T &x:v)out(&x == &v[0]?"":" "),out(x);outl();}
#endif
_HT _vo(H&& h, T&&... t){out(h);out(move(t)...);}
template <typename... T> _vl(T&&... t){out(move(t)...);outl();}

using C = complex<int>;
using V = vector<C>;
#define all(a) a.begin(), a.end()

void shift(V &v) {
	C c = v[0], &d = v[1];
	for_each(all(v), [&c](auto &x) {x -= c;});
	C r = d.imag() < 0 ? C{0, 1} : d.imag() > 0 ? C{0, -1} :
		  d.real() < 0 ? C{-1, 0} : C{1, 0};
	for_each(1 + all(v), [&r](auto &x) {x *= r;});
}

V read () {
	V v(in());
	for (auto &x: v)
		x = {in(), in()};
	shift(v);
	return move(v);
}

int main() {
	for (int n; (n = in());) {
		V a = read();
		vector<V> v = {a, (reverse(all(a)), shift(a), a)};
		for (int i = 1; i <= n; i++) {
			V b = read();
			if(find(all(v), b) != v.end())
				outl(i);
		}
		outl("+++++");
	}
}


Measured memory_bytes: 2464
def calcs(x,y,ax,ay,bx,by) ((ax-x)*(by-y)-(bx-x)*(ay-y))/2.0 end
def inpf() a=gets.chomp.split(" ").map(&:to_f)end
def inps() a=gets.chomp.split(" ")end  
def copy(a) Marshal.load(Marshal.dump(a)) end
def factorial(n)(n < 2)? 1 : (2..n).inject(:*) end
def scount(a) b=na(a.max+1);a.each{|n|b[n]+=1};return b end
def na(n,d=0) Array.new(n,d)end
def na2(n,m,d=0) Array.new(n){Array.new(m,d)}end
def na3(n,m,l,d=0) Array.new(n){Array.new(m){Array.new(l,d)}}end
def yn(f) return (f)? "Yes": "No" end
def ynb(f) return (f)? "YES": "NO" end
def ap(a) a.each{|u| p u} end
def bit(n) n.to_s(2).split("").map(&:to_i) end
def inp() a=gets.chomp.split(" ").map(&:to_i)end
y,m,d = gets.split("/").map(&:to_i)
if(y<=2018 or (y ==2019 and m <= 4))
  puts 'Heisei'
else
  puts 'TBD'
end

Measured memory_bytes: 1788
#include <iostream>
#include <iomanip>
using namespace std;
double ans = 0;
int main()
{
    int n;
    cin >> n;
    double a[n + 1];
    double dp[n + 1][n + 1];
    for (int i = 1; i <= n; i++)
        cin >> a[i];
    for (int i = 0; i <= n; i++)
    {
        for (int j = 0; j <= n; j++)
        {
            if (j > i || (i == 0 && j == i))
                dp[i][j] = 0;
            else if (i == 1 && j == 0)
                dp[i][j] = 1 - a[i];
            else if (i == 1 && j == 1)
                dp[i][j] = a[i];
            else if (j == 0)
                dp[i][j] = dp[i - 1][j] * (1 - a[i]);
            else if (i == j)
                dp[i][j] = dp[i - 1][j - 1] * a[i];
            else
                dp[i][j] = dp[i - 1][j] * (1 - a[i]) + dp[i - 1][j - 1] * a[i];
        }
    }
    for (int i = n; i >= (n / 2 + 1); i--)
        ans += dp[n][i];
    cout << setprecision(10) << ans << endl;
}

Measured memory_bytes: 70528
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<climits>
#include<numeric>
#include<cmath>
#include<cstring>
#include<deque>
#include<fstream>
#include<queue>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define VSORT(v) sort(v.begin(), v.end());
#define VE vector<int>
#define VEP vector<pair<int,int>>
#define llong long long
#define pb(a) push_back(a)
using namespace std;
long long GCD(long long a, long long b) {
	if (b == 0) return a;
	else return GCD(b, a % b);
}
class union_find{
public:
	vector<int> parent;
	vector<int> depth;
	vector<int> size;
	union_find(int num) {
		parent.resize(num);
		for (int i = 0; i < num; ++i) {
			parent[i] = i;
		}
		// depth = vector<int>(num, 0);
		size = vector<int>(num, 1);
	}
	int root(int idx) {
		if (parent[idx] == idx) {
			return idx;
		}
		return parent[idx] = root(parent[idx]);
	}
	bool same(int lhs, int rhs) {
		return root(lhs) == root(rhs);
	}
	void unite(int lhs, int rhs) {
		lhs = root(lhs);
		rhs = root(rhs);
		if (lhs == rhs) {
			return;
		}
		parent[rhs] = lhs;
		size[lhs] += size[rhs];
		// depth[rhs] += depth[lhs] + 1;
	}
};
int main() {
	int n, fri, blo;
	cin >> n >> fri >> blo;
	union_find uf(n);
	vector<VE> fd(n);
	vector<VE> bk(n);
	int a, b;
	REP(_, fri) {
		cin >> a >> b;
		fd[a - 1].push_back(b - 1);
		fd[b - 1].push_back(a - 1);
		uf.unite(a - 1, b - 1);
	}
	REP(_, blo) {
		cin >> a >> b;
		bk[a - 1].push_back(b - 1);
		bk[b - 1].push_back(a - 1);
	}
	REP(i, n) {
		int ans = uf.size[uf.root(i)] - 1;
		REP(f, fd[i].size()) {
			if (uf.same(fd[i][f], i)) {
				ans--;
			}
		}
		REP(b, bk[i].size()) {
			if (uf.same(bk[i][b], i)) {
				ans--;
			}
		}
		cout << ans << " ";
	}
	cout << endl;
	return 0;
}


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

int main() {
  int N; cin >> N;
  vector<int> ans;
  if (N == 0) ans.push_back(0);
  while (N != 0) {
    if (N > 0) {
      ans.push_back(N % (-2));
      N /= (-2);
    }
    else {
      ans.push_back((N % (-2))*(-1));
      N = ((-1)*N+1) / 2;
    }
  }
  reverse(ans.begin(), ans.end());
  for (auto c : ans) cout << c;
  cout << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
#define chmin(a, b) ((a)=min((a), (b)))
#define chmax(a, b) ((a)=max((a), (b)))
#define fs first
#define sc second
#define eb emplace_back
using namespace std;

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

const ll MOD=1e9+7;
const ll INF=1e18;
const double pi=acos(-1);
const double eps=1e-10;

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

const int MAX_V = 41000;

vector<vector<P>> G(MAX_V);
vector<int> dist(MAX_V, 1e9);
void dijkstra(int s){
    priority_queue<P, vector<P>, greater<P>> que;
    dist[s] = 0;
    que.push(P(0, s));

    while(!que.empty()){
        int ccost, cv;
        tie(ccost, cv) = que.top();
        que.pop();

        if(dist[cv] < ccost) continue;

        for(auto x : G[cv]){
            int nv = x.first;
            int ncost = x.second;
            if(dist[cv] + ncost < dist[nv]){
                dist[nv] = dist[cv] + ncost;
                que.push(P(dist[nv], nv));
            }
        }
    }
}

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

    vector<int> v(n);
    iota(v.begin(), v.end(), 0);

    map<vector<int>, int> node;
    int cnt = 0;
    do{
        node[v] = cnt++; 
    }while(next_permutation(v.begin(), v.end()));

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

    do{
        int cv = node[v];
        for(int i=0; i<n; i++){
            for(int j=i+1; j<n; j++){
                swap(v[i], v[j]);
                int nv = node[v];
                G[cv].push_back(P(nv, c[v[i]][v[j]]));
                G[nv].push_back(P(cv, c[v[i]][v[j]]));
                swap(v[i], v[j]);
            }
        }
    }while(next_permutation(v.begin(), v.end()));

    dijkstra(0);

    int ans = 0;
    for(int i=0; i<cnt; i++){
        ans = max(ans, dist[i]);
    }

    cout << ans << endl;
}


Measured memory_bytes: 31748
a,b,h,m=map(int,input().split())
# Pythonで三角関数は単位をradiansにしてから
from math import cos,radians
# 時針Aの角度は1時間で30°、分数を加味してh*30°+30°*m/60
# 分針Bの角度は1分で6°、m*6°
theta = abs(m*6 - (h*30 + m / 2))
# 余弦定理 c**2 = a**2 + b**2 - 2abcosθ
print((a**2 + b**2 - 2*a*b*cos(radians(theta)))**0.5)

Measured memory_bytes: 9504
#include <iostream>
using namespace std;
typedef long long ll;
#define INF 2147483647

int w,h;
char a[102][102];
int dir[4][2] = {-1,0,1,0,0,-1,0,1};
int ans = 0;

void dfs(int x,int y,char s){
    if(x < 0 || x >= h || y < 0 || y >= w || a[x][y] != s) return;
    char t = a[x][y];
    a[x][y] = 'o';
    for(int i = 0;i < 4; i++){
        dfs(x+dir[i][0], y+dir[i][1], t);
    }
}

int main(){
    while(cin >> h >> w){
        if(w == 0 && h == 0) break;
        ans = 0;
        int sx,sy;
        for(int i = 0;i < h; i++){
            for(int j = 0;j < w; j++){
                cin >> a[i][j];
            }
        }
        for(int i = 0;i < h; i++){
            for(int j = 0;j < w; j++){
                if(a[i][j] != 'o'){
                    ans++;
                    dfs(i,j,a[i][j]);
                }
            }
        }
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 3540
function main(lines) {
  const [N, M] = na();
  
  // 頂点情報構築
  for (let i = 0; i < M; i++) {
    const [a, b] = na();
    nodes[a-1][b-1] = nodes[b-1][a-1] = true;
  }
  // 訪問済みフラグ
  const visited = Array(N).fill(false);

  // ルート探索
  visited[0] = true;
  const ans = countRoute(0, N, visited);
  
  return ans;
}

// 最大頂点数
const maxN = 8;
// 頂点情報
const nodes = Array(maxN).fill(0).map(_ => Array(maxN).fill(false));
// 探索再帰関数
function countRoute(node, N, visited) {
  if (　visited.every(b => b)　) return 1;
  let ret = 0;
  for (let i = 0; i < N; i++) {
    if (!nodes[node][i] || visited[i]) continue;
    visited[i] = true;
    ret += countRoute(i, N, visited);
    visited[i] = false;
  }
  return ret;
}


const lines = require("fs").readFileSync("/dev/stdin", "utf8").trim().split("\n");

let lineCount = 0;
const s = () => lines[lineCount++];
const n = () => Number(s());
const b = () => BigInt(s());
const sa = () => s().split(' ');
const na = () => sa().map(Number);
const ba = () => sa().map(BigInt);

const ans = main(lines);
console.log( ans );

Measured memory_bytes: 32624
#include<stdio.h>
#include<string.h>
int min(int a,int b){
  if(a>b) return b;
  return a;
}
int main(void){
  char s[100010],t[100010],u[100010];
  int cnt1=0,cnt2=0;
  scanf("%s",s);
  int l,i,ans;
  l=strlen(s);
  for(i=0;i<l;i++){
    if(i%2==0){
      t[i]='0';
      u[i]='1';
    }else{
      t[i]='1';
      u[i]='0';
    }
  }
  //printf("%s\n%s\n%s\n",s,t,u);
  for(i=0;i<l;i++){
    if(s[i]!=t[i]) cnt1++;
    if(s[i]!=u[i]) cnt2++;
  }
  ans=min(cnt1,cnt2);
  printf("%d\n",ans);
  return 0;
}

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

int main() {
  int A, B;
  cin >> A >> B;
  if(A % 3 == 0 || B % 3 == 0 || (A + B) % 3 == 0)
    cout << "Possible" << endl;
  else
    cout << "Impossible" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

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

  int N;
  cin >> N;
  vector<int> a;
  for (int i = 0; i < N; i++) {
    int buf;
    cin >> buf;
    a.push_back(buf);
  }

  sort(a.begin(), a.end());
  reverse(a.begin(), a.end());
  int alice = 0, bob = 0;
  for (int i = 0; i < N; i++) {
    if (i % 2 == 0) alice += a[i];
    else bob += a[i];
  }

  int ans = alice - bob;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
from typing import List

def step(n: int, a: List[int])-> int:
  result = 0
  dai = 0
  for i in range(1,n):
    sub = a[i-1] + dai - a[i]
    if sub > 0:
      dai = sub      
      result += sub
      continue
    dai = 0
  return result

if __name__ == "__main__":
  n = int(input())
  a = list(map(int, input().split()))
  print(step(n, a))

Measured memory_bytes: 33496
n = int(input())
s = input()
li = [chr(i) for i in range(65,65+26)]

def shift(l, k):
  return l[k:] + l[:k]

lish = shift(li,n)
ans = ""
for i in range(len(s)):
  ans += lish[li.index(s[i])]
print(ans)

Measured memory_bytes: 3060
arr =[int(x) for x in raw_input().split()]
n = int(raw_input())
ans = 0
for i in xrange(4):
	arr[i] = 2**(3-i)*arr[i]
while(True):
	if(n>=2):
		ans += (n/2)*min(arr)
		n -= (n/2)*2
	elif(n==1):
		for i in xrange(4):
			arr[i] = arr[i]/2
		ans += min(arr[0:3])
		n-=1
	else:
		break
print ans


Measured memory_bytes: 2568
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int a,b;
  cin>>a>>b;
  if(a<b){
    for(int i=1; i<=b; i++){
      cout<<a;
    }
    cout<<"\n";
  }
  else{
    for(int i=1; i<=a; i++){
      cout<<b;
    }
    cout<<"\n";
  }

  return 0;
}


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

int main() {
  int n = 0;
  string s;
  cin >> s;
  for(int i=0 ;i<s.size() ;i++){
    if(s[i] == '+'){
      n++;
    }else{
      n--;
    }
  }
  cout << n << endl;
}

Measured memory_bytes: 256
n = int(input())
a = [list(map(int,input().split())) for i in range(n)]
mod = 10**9+7

dp = [0]*(1<<n)
bit = [0]*(1<<n)
dp[0] = 1

for i in range(1,1<<n):
    bit[i] = bit[i//2]+i%2
    for j in range(n):
        if i >> j & 1:
            dp[i] += dp[i-(1<<j)]*a[bit[i]-1][j]
            dp[i] %= mod
print(dp[-1]%mod)


Measured memory_bytes: 75228
#include<iostream>
#include<vector>
#include<string>
#include<tuple>
#include<algorithm>

using namespace std;

int main(){

    int N;
    cin >> N;

    vector< tuple< string, int, int>> vec;

    for(int i=1; i<=N; i++)
    {
        string s;
        int p;
        cin >> s >> p; 
        p = -p;
        vec.emplace_back(s,p,i);
    }

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

    for(int i=0; i<N ; i++)
    {
        cout << get<2>(vec[i]) << endl;
    }


}

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

	/*
	 * 122A
	 * 
	 * To read a character we can read it as a string and do .charAt(0) for it to be a character
	 * A <--> T
	 * C <--> G
	 * When you get one character output the other one
	 * Can be done with if statements like below
	 * 
	 */
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		if(s.charAt(0) == 'A') {
			System.out.println('T');
		}
		else if(s.charAt(0) == 'T') {
			System.out.println('A');
		}
		else if(s.charAt(0) == 'G') {
			System.out.println('C');
		}
		else {
			System.out.println('G');
		}
	}

}


Measured memory_bytes: 35476
#include<iostream>
#include<stdio.h>
#include<vector>//s1.erase(n)=文字列s1の、n文字目以降削除
#include<algorithm>//辞書順=next_permutation
#include<set>
#include<string>//char 小文字のほうが32大きい
#include<sstream>
#include<string.h>
#include<complex>
#include<time.h>
#include<random>
#include<cmath>
#include<math.h>
#include<queue>
#include<time.h>
#include<iomanip>
#include<locale>
#include<utility>//swap=数値交換
#define rt "\n"
#define rep(i,n) for(int i=0;i<n;i++)
#define rop(i,n) for(int i=1;i<=n;i++)
#define drep(i,n) for(int i=n-1;0<=i;i--)
#define drop(i,n) for(int i=n;0<i;i--)
#define yes(ans) if(ans)cout<<"yes"<<rt;else cout<<"no"<<rt;
#define Yes(ans) if(ans)cout<<"Yes"<<rt;else cout<<"No"<<rt;
#define YES(ans) if(ans)cout<<"YES"<<rt;else cout<<"NO"<<rt;
#define sec(a,b,ans) if(ans)cout<<a<<rt;else cout<<b<<rt;
#define vcin(s,n) rep(i,n)cin>>s[i];//vcin(配列名),(繰り返し回数)
#define sort(s) sort(s.begin(),s.end())//標準=昇順
#define reve(s) reverse(s.begin(),s.end())
#define asas int ans=0
#define llcncn llint cnt=0
#define llasas llint ans=0
#define str string
#define please return
#define AC 0
#define ic_a int a;cin>>a;
#define ic_b int b;cin>>b;
#define ic_s string s;cin>>s;
#define Rapid_pleaseAC_fast cin.tie(0);ios::sync_with_stdio(false)
#define Pi 3.1415926535897932384626
#define nine 1000000000

using namespace std;
typedef vector<int> vint;
typedef vector<string> vstr;
typedef vector<char> vchar;
typedef vector<double> vdou;
typedef long long int llint;
typedef pair<int, int> pint;
typedef pair<llint, llint> pllint;
typedef vector<llint> vllint;
typedef vector<pint> vpint;
typedef vector<pair<llint, llint>> vpllint;
typedef vector<vector<int>> vvint;
typedef vector<vector<char>> vvchar;
typedef vector<vector<llint>> vvllint;
typedef vector<vector<string>> vvstr;
typedef vector<vector<bool>> vvbool;
typedef vector<vector<pint>> vvpint;
typedef vector<bool> vbool;

long long GCD(long long a, long long b) {
	if (b == 0) return a;
	else return GCD(b, a % b);
}

long long LCM(long long a, long long b) {
	return a * b / GCD(a, b);
}

unsigned GetDigit(unsigned num) {
	return std::to_string(num).length();
}

int tow(int n) {//2のn乗
	if (n == 0)return 1;
	int x = tow(n / 2);
	x *= x;
	if (n % 2 == 1)x *= 2;
	return x;//@domino
}

/*

 (char)toupper(a[n])=文字列のn文字目を大文字で出力

  pow(a,b)=aのb乗

  */


int main(void) {
	Rapid_pleaseAC_fast;

	string s;
	cin >> s;
	bool a=false, b=false;
	rep(i, 3) {
		if (s[i] == 'A')a=true;
		if (s[i] == 'B')b=true;
	}
	Yes(a == true && b == true);

	please AC;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(){
  int N, M, C;
  scanf("%d %d %d", &N, &M, &C);

  int B[M], A[M], sum = 0;
  int c = 0;

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

  for(i = 0; i < N; i++){
    c = 0;
    for(j = 0; j < M; j++){
      scanf("%d", &A[j]);
      c += A[j] * B[j];
    }

    c += C;
    if(c > 0) sum++;
  }

  printf("%d\n", sum);

  return 0;
}



Measured memory_bytes: 128
import java.util.*;

class Main {
    // ABC152D
    static final long MOD = 1_000_000_007;
    // 10^9+7
    //static final int MAX = 2_147_483_646;
    static final int MAX = 10_000_000;
    // intの最大値
    static final int INF = 1_000_000_000;
    // 10^9

  
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();
        double ary[] = new double[n];
        int tmp = 0;
        for(int i = 0;i < n;i++){
            tmp = sc.nextInt();
            ary[i] = (double)(tmp+1)/2;
        }
        double ans = 0;
        double poyo = 0;
        for(int j = 0;j < k;j++){
            poyo += ary[j];
        }
        ans = poyo;
        for(int i = k;i < n;i++){
            poyo +=ary[i] - ary[i-k];
            if(ans < poyo)ans = poyo; 
        }
        System.out.println(ans);
    }
    
}




Measured memory_bytes: 83236
#include <iostream>
#include <algorithm>
#define flush fflush(stdout)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pl;
const int mod = (int)1e9 + 7, INF = (int)1e9;
const int di[4] = { 1,0,-1,0 }, dj[4] = { 0,1,0,-1 };


int main(void) {
    int n, m, k, i, l, r, mid;
    ll a[200003] = {}, b[200003] = {};
    bool pos;

    scanf("%d%d%d", &n, &m, &k);
    for (i = 1; i <= n; i++) {
        scanf("%lld", &a[i]);
    }
    for (i = 1; i <= m; i++) {
        scanf("%lld", &b[i]);
    }

    for (i = 1; i <= n; i++) {
        a[i] += a[i - 1];
    }
    for (i = 1; i <= m; i++) {
        b[i] += b[i - 1];
    }

    l = 0;
    r = n + m + 1;
    while (r - l > 1) {
        mid = (l + r) / 2;
        pos = false;
        for (i = max(0, mid - m); i <= min(mid, n); i++) {
            pos |= (a[i] + b[mid - i] <= k);
        }
        if (pos) {
            l = mid;
        }
        else {
            r = mid;
        }
    }

    printf("%d\n", l);
    
    return 0;
}

Measured memory_bytes: 6888
#include<bits/stdc++.h>                                                         
using namespace std;
int main()
{
  int X,Y,Z;
  cin >> X >> Y >> Z;
  X=X-(Y+2*Z);
  int count=1;
  while(1){
    if(X>=Y+Z){
      count++;
      X-=(Y+Z);
    }
    else
      break;
  }
  cout << count << endl;
}

Measured memory_bytes: 256
def main():
    s = input()
    cnt = True
     
    l_num = s.count('L')
    r_num = s.count('R')
    u_num = s.count('U')
    D_num = s.count('D')
    
    for i in range( len(s) ):
      if s[i] == 'L' and i % 2 == 0:
        cnt = False
      if s[i] == 'R' and i % 2 == 1:
        cnt = False
    
    if cnt == True:
      print("Yes")
    else:
      print("No")
      
if __name__ == '__main__': main()

Measured memory_bytes: 3064
#include <stdio.h>

int main(void){
    int n,k,p,i;
    scanf("%d",&n);
    int w[n];
    for(i=0;i<n;i++){
        scanf("%d %d",&k,&p);
        if(k%p==0)
            w[i]=p;
        else
            w[i]=k%p;
    }
    for(i=0;i<n;i++)
        printf("%d\n",w[i]);
    return 0;
}

Measured memory_bytes: 596
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); i++) 
#define all(v) begin(v),end(v)
using ll = long long;

int main() {
  string s;cin>>s;
  int n=s.size();
  ll ans=0;
  for(int bit=0;bit<(1<<n-1);bit++){
    ll cnt=0;
    rep(i,n-1){
      cnt*=10;
      cnt+=s[i]-'0';
      if(bit&(1<<i)){
        ans+=cnt;
        cnt=0;
      }
    }
    cnt*=10;
    cnt+=s[n-1]-'0';
    ans+=cnt;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 3608
import sys
def input(): return sys.stdin.readline().strip()

def resolve():
    n=int(input())
    l=list(map(int,input().split()))
    from collections import Counter
    c=Counter(l)# ()にカウンターの対象のリストの変数名
    cl=list(c.items())
    cl.sort(key=lambda x:x[0],reverse=True)
    ans=[]
    for key,value in cl:
        if value>=4:
            if len(ans)==0:
                ans.append(key)
                ans.append(key)
                break
            elif len(ans)==1:
                ans.append(key)
                break
        elif value>=2:
            ans.append(key)
            if len(ans)==2:
                break
    if ans:
        print(ans[0]*ans[1])
    else:
        print(0)
resolve()

Measured memory_bytes: 68352
s=input()

def func(ass):
    for i in range(len(ass)//2):
        if ass[i] != ass[-(i+1)]:
            print('No')
            exit()

func(s)
func(s[:len(s)//2])
func(s[len(s)//2+len(s)%2:])

print('Yes')

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define MOD 1000000007

vector<vector<pair<int,ll>>> tree;
vector<ll> depth;

void solve(int v){
  for(auto nv :tree.at(v)){
    if(depth.at(nv.first)==-1){
      depth.at(nv.first)=depth.at(v)+nv.second;
      solve(nv.first);
    }
  }
}

int main(){
  int N;
  cin>>N;
  tree.resize(N);
  depth.resize(N,-1);
  for(int i=0;i<N-1;i++){
    int a,b;
    ll c;
    cin>>a>>b>>c;
    a--;
    b--;
    tree.at(a).push_back(make_pair(b,c));
    tree.at(b).push_back(make_pair(a,c));
  }
  int Q,K;
  cin>>Q>>K;
  K--;
  vector<int> x(Q),y(Q);
  for(int i=0;i<Q;i++){
    cin>>x.at(i)>>y.at(i);
    x.at(i)--;
    y.at(i)--;
  }

  depth.at(K)=0;
  solve(K);

  for(int i=0;i<Q;i++){
    cout<<depth.at(x.at(i))+depth.at(y.at(i))<<endl;
  }

}


Measured memory_bytes: 15104
from itertools import chain

n, m = int(input()), int(input())
cards = list(range(1, 2 * n + 1))
for _ in range(m):
    k = int(input())
    if k:
        cards = cards[k:] + cards[:k]
    else:
        cards = list(chain.from_iterable(zip(cards[:n], cards[n:])))
for c in cards:
    print(c)

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

int main(){
int a,d;
cin >> a >>d;
int b=1,c=3;
int i=2;
while(1){
    b+=i;
    c+=i+1;
    if(a-b==d-c){
        cout << b-a << endl;
        break;
    }
    i++;
}
}

Measured memory_bytes: 256
n = gets.to_i
a = gets.split.map(&:to_i)
money = 1000
stock = 0
(n-1).times do |i|
  if a[i] < a[i+1]
    s = money / a[i]
    money -= s * a[i]
    stock += s
  elsif a[i] > a[i+1]
    money += stock * a[i]
    stock = 0
  end
end
money += stock * a[n-1]
puts money


Measured memory_bytes: 14392
#include <stdio.h>
#include <string.h>
int main()
{
  int a,b,c;
  scanf("%d%d%d", &a, &b, &c);
  if(a+b+c >= 22)
    printf("bust\n");
  else if(a+b+c <= 21)
    printf("win\n");
}

Measured memory_bytes: 128
#135
N=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
s=0
for i in range(N):
    if A[i]>=B[i]:
        s+=B[i]
    elif A[i]+A[i+1]<B[i]:
        s+=A[i]+A[i+1]
        A[i+1]=0
    else:
        s+=B[i]
        A[i+1]-=B[i]-A[i]
print(s)
        

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

int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= 9; i++) {
    for (int j = 1; j <= 9; j++) {
      if (i * j == n) {
        cout << "Yes" << endl;
        return 0;
      }
    }
  }

  cout << "No" << endl;
  return 0;
}

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

int main() {
    /* Input */
    int k, a, b;
    cin >> k;
    cin >> a >> b;

    /* Main Logic */
    int largest_k = (b / k) * k;
    if (a <= largest_k) cout << "OK" << endl;
    else cout << "NG" << endl;

    return 0;
}

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

int main() {

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




Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <cstring>
#include <climits>
#include <iomanip>
#include <bitset>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <list>
#include <map>

using namespace std;

int main() {
  string a, b;
  cin >> a >> b;
  cout << b + a << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include <cstdlib>  
#include <math.h>
#include <cmath>
#include<complex>
#include<cctype>
#include<string>
#include<set>
#include<iomanip>
#include <map>
#include<algorithm>
#include <functional>
#include<vector>
#include<climits>
#include<stack>
#include<queue>
#include<bitset>
#include <deque>
#include <climits>
#include <typeinfo>
#include <utility> 
using namespace std;
using Complex = complex<double>;
using ll = long long;
template<typename T>using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
const ll inf = 1145141919810364364LL;
double PI = acos(-1.0);
#define all(x) (x).begin(),(x).end()
#define puts(x) cout << x << endl
#define rep(i,m,n) for(ll i = m;i < n;++i)
#define pb push_back
#define fore(i,a) for(auto &i:a)
#define rrep(i,m,n) for(ll i = m;i >= n;--i)


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

	int N;
	cin >> N;
	for (int i = 0; i < N; i++) {
		int A;
		cin >> A;
		if (A % 2 == 0) {
			if (A % 3 == 0 || A % 5 == 0)continue;
			else {
				puts("DENIED");
				return 0;
			}
		}
	}
	puts("APPROVED");

	return 0;
}

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

using namespace std;

int main() {
	int N,Q;
	cin >> N>>Q;
	string S;
	cin >> S;
	int *l = new int[Q];
	int *r = new int[Q];
	for (int i = 0; i < Q; i++) {
		cin >> l[i] >> r[i];
	}

	vector<int> count(N,0);
	for (int i = 0; i < N - 1; i++) {
		if (S.substr(i, 2) == "AC") {
			count[i]++;
			i++;
		}
	}


	vector<int> sum(N + 1,0);//累積和

	for (int i = 1; i <= N; i++) {
		sum[i] = sum[i - 1] + count[i - 1];
	}
	for (int i = 0; i < Q; i++) {
		cout << sum[r[i]-1]-sum[l[i]-1] << endl;
	}
	return 0;
}

Measured memory_bytes: 2688
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import array
from bisect import *
from collections import *
import fractions
import heapq
from itertools import *
import math
import random
import re
import string
import sys

ans = 0
N = int(input())
for n in range(N):
    x, u = input().split()
    if u == 'JPY':
        ans += int(x)
    else:
        ans += float(x) * 380000.0
print("{:.9f}".format(ans))




Measured memory_bytes: 8008
#include <bits/stdc++.h>
#define rep(a,n) for (ll a = 0; a < (n); ++a)
using namespace std;
using ll = long long;
typedef pair<ll,ll> P;
typedef pair<ll,P> PP;
typedef vector<vector<ll> > Graph;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const ll INF = 1e18;


int main(){
    ll n,x,m;
    cin >> n >> x >> m;
    vector<ll>seen(m,-1);
    seen[x]=0;
    ll last = x;
    ll f=-1,s=-1;
    ll S = x;
    ll now;
    for(ll i=1;i<n;i++){
        now = (last*last)%m;
        if(seen[now]==-1){
            seen[now]=i;
            S += now;
            last = now;
        }
        else{
            f = seen[now];
            s = i;
            break;
        }
    }
    if(s==-1){
        cout << S << endl;
        return 0;
    }
    last = -1;
    ll ans = 0;

    rep(i,f){
        if(i==0){
            ans += x;
            last = x;
            continue;
        }
        now = (last*last)%m;
        ans += now;
        last = now;
    }
    ll rem = (n-f)%(s-f);
    ll p = 0;
    rep(i,s-f){
        if(last==-1){
            p += x;
            last = x;
            continue;
        }
        now = (last*last)%m;
        p += now;
        last = now;
    }

    rep(i,rem){
        if(last==-1){
            ans += x;
            last = x;
            continue;
        }
        now = (last*last)%m;
        ans += now;
        last = now;
    }
    ans += (n-f)/(s-f)*p;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 4056
sx , sy , tx, ty = map(int , input().split())
lx = abs(tx - sx)
ly = abs(ty - sy)
print('U'*ly,end = "")
print('R'*lx,end = "")
print('D'*ly,end = "")
print('L'*(lx+1),end = "")
print('U'*(ly+1),end = "")
print('R'*(lx+1),end = "")
print('D',end = "")
print('R',end = "")
print('D'*(ly+1),end = "")
print('L'*(lx+1),end = "")
print('U')



Measured memory_bytes: 3064
#include <iomanip>
#include <iostream>
#include <cmath>

using namespace std;

typedef long long ll;

int main(void) {
  ll N, K;
  cin >> N >> K;
  double pWin = 0.0;
  for (ll dice = 1; dice <= N; dice++) {
    ll points = dice;
    ll tosTimes = 0;
    while (points < K) {
      tosTimes++;
      points *= 2;
    }
    pWin += pow(0.5, tosTimes) / N;
  }
  cout << setprecision(10);
  cout << pWin << endl;
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<queue>
using namespace std;
int head2[64],last2[128],to2[128],cnt2=0;
void add2(int u,int v)
{
	cnt2++;
	last2[cnt2]=head2[u];
	head2[u]=cnt2;
	to2[cnt2]=v;
}
int fa2[64];
void dfs2(int u,int f)
{
	fa2[u]=f;
	for(int i=head2[u];i;i=last2[i])
	{
		int v=to2[i];
		if(v==f)
		{
			continue;
		}
		dfs2(v,u);
	}
}
int head1[64],last1[128],to1[128],cnt1=0;
void add1(int u,int v)
{
	cnt1++;
	last1[cnt1]=head1[u];
	head1[u]=cnt1;
	to1[cnt1]=v;
}
int fa1[64];
void dfs1(int u,int f)
{
	fa1[u]=f;
	for(int i=head1[u];i;i=last1[i])
	{
		int v=to1[i];
		if(v==f)
		{
			continue;
		}
		dfs1(v,u);
	}
}
int a[64],b[64];
int deg[64];
int head[64],last[128],to[128],d[128],cnt=0;
void add(int u,int v)
{
	cnt++;
	last[cnt]=head[u];
	head[u]=cnt;
	to[cnt]=v;
	d[v]++;
}
queue<int> q;
int main()
{
	int t;
	scanf("%d",&t);
	while(t--)
	{
		int n;
		scanf("%d",&n);
		for(int i=1;i<=n;i++)
		{
			head1[i]=0;
			head2[i]=0;
			deg[i]=0;
		}
		cnt1=0;
		cnt2=0;
		for(int i=1;i<n;i++)
		{
			scanf("%d%d",&a[i],&b[i]);
			deg[a[i]]++;
			deg[b[i]]++;
			add1(a[i],b[i]);
			add1(b[i],a[i]);
		}
		for(int i=1;i<n;i++)
		{
			int u,v;
			scanf("%d%d",&u,&v);
			add2(u,v);
			add2(v,u);
		}
		dfs1(1,0);
		dfs2(1,0);
		bool ok=true;
		for(int i=1;i<=n;i++)
		{
			if(fa1[i]!=fa2[i])
			{
				ok=false;
				break;
			}
		}
		if(ok)
		{
			printf("0\n");
			continue;
		}
		int ans=n+1;
		for(int i=1;i<n;i++)
		{
			if(deg[b[i]]==1)
			{
				int t=a[i];
				a[i]=b[i];
				b[i]=t;
			}
			if(deg[a[i]]>1)
			{
				continue;
			}
			for(int j=1;j<=n;j++)
			{
				if(j==a[i])
				{
					continue;
				}
				cnt1=0;
				for(int k=1;k<=n;k++)
				{
					head1[k]=0;
				}
				for(int k=1;k<n;k++)
				{
					if(k==i)
					{
						continue;
					}
					add1(a[k],b[k]);
					add1(b[k],a[k]);
				}
				add1(a[i],j);
				dfs1(a[i],0);
				dfs2(a[i],0);
				int ans2=1;
				for(int k=1;k<=n;k++)
				{
					d[k]=0;
					head[k]=0;
				}
				cnt=0;
				for(int k=1;k<=n;k++)
				{
					if(k==a[i])
					{
						continue;
					}
					if(fa1[k]==fa2[k])
					{
						if(fa1[fa1[k]]!=fa2[fa2[k]])
						{
							ans2=n+1;
							break;
						}
					}
					else
					{
						ans2++;
						if(fa1[fa1[k]]!=fa2[fa1[k]])
						{
							add(k,fa1[k]);
						}
						if(fa1[fa2[k]]!=fa2[fa2[k]])
						{
							add(fa2[k],k);
						}
					}
				}
				if(ans2>=ans)
				{
					continue;
				}
				int rm=ans2-1;
				for(int i=1;i<=n;i++)
				{
					if(fa1[i]==fa2[i])
					{
						continue;
					}
					if(d[i]==0)
					{
						q.push(i);
					}
				}
				while(!q.empty())
				{
					int u=q.front();
					q.pop();
					rm--;
					for(int i=head[u];i;i=last[i])
					{
						int v=to[i];
						d[v]--;
						if(d[v]==0)
						{
							q.push(v);
						}
					}
				}
				if(!rm)
				{
					ans=ans2;
				}
			}
		}
		if(ans>n)
		{
			ans=-1;
		}
		printf("%d\n",ans);
	}
	return 0;
}

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

using namespace std;

#ifdef SG
	#include <debug.h>
#else
	#define show(...)
	#define debug(...)
	#define deepen(...)
	#define timer(...)
#endif

#define ARG4(_1,_2,_3,_4,...) _4

#define forn3(i,l,r) for (int i = int(l); i < int(r); ++i)
#define forn2(i,n) forn3 (i, 0, n)
#define forn(...) ARG4(__VA_ARGS__, forn3, forn2) (__VA_ARGS__)

#define ford3(i,l,r) for (int i = int(r) - 1; i >= int(l); --i)
#define ford2(i,n) ford3 (i, 0, n)
#define ford(...) ARG4(__VA_ARGS__, ford3, ford2) (__VA_ARGS__)

#define ve vector
#define pa pair
#define tu tuple
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define fs first
#define sc second
#define all(a) (a).begin(), (a).end()
#define sz(a) ((int)(a).size())

typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef unsigned char uc;
typedef pa<int, int> pii;
typedef pa<int, ll> pil;
typedef pa<ll, int> pli;
typedef pa<ll, ll> pll;
typedef ve<int> vi;

const ld pi = 3.1415926535897932384626433832795l;

template<typename T> inline auto sqr (T x) -> decltype(x * x) {return x * x;}
template<typename T1, typename T2> inline bool umx (T1& a, T2 b) {if (a < b) {a = b; return 1;} return 0;}
template<typename T1, typename T2> inline bool umn (T1& a, T2 b) {if (b < a) {a = b; return 1;} return 0;}

const int N = 110;

bool use[26];
int p[N];

int main () {
	//std::ios::sync_with_stdio(false);
	cout.setf(ios::showpoint | ios::fixed);
	cout.precision(20);
#ifdef SG
	freopen((problemname + ".in").c_str(), "r", stdin);
	//freopen((problemname + ".out").c_str(), "w", stdout);
#endif
	string s;
	getline(cin, s);
	if (sz(s) < 26) {
		memset(use, 0, sizeof(use));
		forn(i, sz(s)) {
			use[s[i] - 'a'] = 1;			
		}
		int pos = -1;
		forn(i, 26) {
			if (!use[i]) {
				pos = i;
				break;	
			}
		}
		cout << s << char('a' + pos) << endl;
		return 0;
	}
	forn(i, sz(s)) {
		p[i] = s[i] - 'a';
	}
	if (!next_permutation(p, p + 26)) {
		puts("-1");
		return 0;
	}
	string t;
	forn(len, 1, 27) {
		forn(i, len) {
			t += char('a' + p[i]);
		}
		if (t > s) {
			break;
		}
		t.clear();
	}
	cout << t << endl;
	cout << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(), (c).end());
const long long MOD = 10e9 + 7;
typedef long long ll;

int main(){
	string S;
	cin >> S;
	string ans = "TBD";
	if(S[6] == '3' || S[6] == '4')ans = "Heisei";
	else if(S[6] == '1' || S[6] == '2'){
		if(S[5] == '0')ans = "Heisei";
	}
	cout << ans << endl;
}

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

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

			if (x == 3 || x == 5 || x == 7)
				Console.WriteLine("YES");
			else
				Console.WriteLine("NO");

			Console.ReadKey();
        }
    }
}

Measured memory_bytes: 11092
#include<stdio.h>
int gcd(int p,int q){
    while(q!=0){
        int r=p%q;
        p=q;
        q=r;
    }
    return p;
}
int a,b,c,k,r=0;
int main(){
    scanf("%d",&k);
    for(a=1;a<=k;a++){
        for(b=1;b<=k;b++){
            int t=gcd(a,b);
            for(c=1;c<=k;c++){
                r+=gcd(t,c);
            }
        }
    }
    printf("%d",r);
    return 0;
}

Measured memory_bytes: 1732
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pli = pair<ll, int>;
using Graph = vector<vector<int>>;
const int MOD = 1e9 + 7;


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

    int N;
    cin >> N;
    vector<int> p(N);
    for (int i = 0; i < N; ++i) {
        cin >> p[i];
        p[i]--;
    }

    int ans = 0;
    for (int i = 0; i < N - 1; ++i) {
        if (i == p[i]) {
            ans++;
            swap(p[i], p[i + 1]);
        }
    }
    ans += (p[N - 1] == N - 1);

    cout << ans << endl;
    return 0;
}


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

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"
#define PI 3.14159265358979
#define MOD 1000000007 // = 10^9 + 7

using namespace std;
using ll = long long;


void solve()
{
	string s;
	cin >> s;
	int ans = 0;
	int s_size = s.length();
	for(int i = 0; i < s_size / 2; ++i)
	{
		if (s[i] != s[s_size - i - 1])
		{
			ans++;
		}
	}
	cout << ans;
}

int main()
{
	fastio;
	solve();

	return 0;
}

Measured memory_bytes: 256