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

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

    int N; cin >> N;
    string s; cin >> s; s += s[0];
    ves ans = {"SS", "SW", "WS", "WW"};

    bool flag = false; int index;
    rep(i,4) {
        rep1(j,N+1) {
            if(ans[i][j-1] == 'S' and ans[i][j] == 'S' and s[j] == 'o') ans[i] += 'S';
            else if(ans[i][j-1] == 'S' and ans[i][j] == 'W' and s[j] == 'o') ans[i] += 'W';
            else if(ans[i][j-1] == 'S' and ans[i][j] == 'S' and s[j] == 'x') ans[i] += 'W';
            else if(ans[i][j-1] == 'S' and ans[i][j] == 'W' and s[j] == 'x') ans[i] += 'S';
            else if(ans[i][j-1] == 'W' and ans[i][j] == 'S' and s[j] == 'o') ans[i] += 'W';
            else if(ans[i][j-1] == 'W' and ans[i][j] == 'W' and s[j] == 'o') ans[i] += 'S';
            else if(ans[i][j-1] == 'W' and ans[i][j] == 'S' and s[j] == 'x') ans[i] += 'S';
            else if(ans[i][j-1] == 'W' and ans[i][j] == 'W' and s[j] == 'x') ans[i] += 'W';
        }
        if(ans[i][0] == ans[i][N] and ans[i][1] == ans[i][N+1]) { index = i; flag = true; break; }
    }
    if(!flag) cout << -1 << endl;
    
    else {
        rep(i,N) cout << ans[index][i];
        cout << endl;
    }
    return 0;

}



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

public class ABC
{
    //          long[] sp = Console.ReadLine().Split().Select(long .Parse).ToArray();
    //          int[] sp = Console.ReadLine().Split().Select(int.Parse).ToArray();
    //          int N =  int.Parse(Console.ReadLine());
    //CompLib.Collections.PriorityQueue<?>
    public static void Main()
    {
        int N = int.Parse(Console.ReadLine());
        string S = Console.ReadLine();
        string looking = S[0].ToString();
        long output = 1;
        for (int i = 1; i < N; i++)
        {
            if (looking != S[i].ToString())
            {
                output++;
                looking = S[i].ToString();
            }
        }
        Console.WriteLine(output);
    }

}


Measured memory_bytes: 15160
#include <bits/stdc++.h>
using namespace std;
//解説を見た後
int main() {
  string s;
  cin>>s;
  long long sum=0;
  int n=s.size()+1;
  vector<int>a(n);
  for(int i=0;i<n-1;i++){
    if(s[i]=='<')a[i+1]=max(a[i+1],a[i]+1);
  }
  //for(int i=0;i<n;i++)cout<<a[i]<<s[i];
  //cout<<endl;
  for(int i=n-1;i>=0;--i){
    if(s[i]=='>')a[i]=max(a[i+1]+1,a[i]);
  }
  //for(int i=0;i<n;i++)cout<<a[i]<<s[i];
  //cout<<endl;
  for(int i=0;i<n;i++){
    sum+=a[i];
  }
  cout<<sum<<endl;
  return 0;
}

Measured memory_bytes: 2820
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
 
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;
 
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;
 
typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;
 
#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
 
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define ins insert
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
const int MOD = 1000000007;
const char nl = '\n';
const int MX = 100001; //check the limits, dummy
 
int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);    
	
    ll N; cin >> N;
    int ans = 0;
    FOR(i, 2, 1000010) {
        int cur = 0;
        while (N % i == 0) {
            cur++;
            N /= i;
        }
        FOR(j, 1, 10000) {
            if (cur < j) break;
            ans++; cur -= j;
        }
    }
    if (N > 1) ans++;
    cout << ans << nl;
	
	return 0;
}
 
// read the question correctly (ll vs int)
// template by bqi343

Measured memory_bytes: 3656
#include<iostream>
using namespace std;
 
int main(){
  int n;
  cin>>n;
  int a,b;
  int ans=0;
  for(int i=0;i<n;i++){
    cin>>a>>b;
    ans+=abs(a-b)+1;
  }
  cout<<ans<<endl;
  return 0;
}

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

using namespace std;

using ll = long long;

int main() {
    ll A,B,K; cin>>A>>B>>K;

    if (A > K) {
        cout << A-K << " " << B << endl;
    } else {
        cout << 0 << " " << ((B > K-A) ? B-(K-A) : 0) << endl; 
    }

    return 0;
}

Measured memory_bytes: 256
s = str(input())
abc = ["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"]
ans = "None"
sort_s = sorted(s)
for i in abc:
  if (i in sort_s)==False:
    ans = i
    break
print(ans)

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

using namespace std;

int main(){
 int N;
 cin >> N;
 vector<int> H(N);

 for(int i = 0; i < N; i++) cin >> H[i];
 
 int sum = 1;
 int hantei = 1;
 for(int i = 1; i < N; i++){
   hantei = 1;
   for(int j = 0; j <= i - 1; j++){
     if(H[i] < H[j]){ hantei = 0; break; }
   }
   if(hantei == 1){ sum += 1;}
 }

 cout << sum << endl;
  return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
string s;
int main()
{
	cin>>s;
	int p=0,b=1;int s1=0,s2=0;
	for(int i=0;i<s.size();++i){
		p^=1;b^=1;
		if(s[i]-'0'!=p)++s1;
		if(s[i]-'0'!=b)++s2;
	}
	printf("%d",min(s1,s2));
//	cout<<s;
	return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define rep(i, n) for(int i= 0; i < (n); i++)
using ll= long long int;
using namespace std;
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; }
ll mod= 1e9 + 7;


int main(){
  int a=0;
  string s;
  cin >> s;
  rep(i,4){
    if(s[i]=='+'){a++;}else{a--;}
  }
  cout << a << endl;
}

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

#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define st first
#define nd second
#define endl '\n'
#define what_is(x) cerr << #x << " is " << x << endl;
#define what_is_v(x) cerr << #x << " is "; for(auto&e: (x)) cerr << e << ' '; cerr << '\n'; //vector, set
#define what_is_a(x, n) cerr << #x << " is "; for(int i=0;i<n;i++) cerr << x[i] << ' '; cerr <<  '\n'; //n first element of array
#define cerr_pair(x) '{' << x.st << ", " << x.nd << '}'
#define pwhat_is(x) cerr << #x << " is " << cerr_pair(x) << endl;
#define pwhat_is_v(x) cerr << #x << " is "; for(auto&e: (x)) cerr << cerr_pair(e) << ' '; cerr << '\n'; //vector, set
#define pwhat_is_a(x, n) cerr << #x << " is "; for(int i=0;i<n;i++) cerr << cerr_pair(x[i]) << ' '; cerr <<  '\n'; //n first element of array
#define int long long
// #define pow mypow

typedef pair<int,int> pii;
const int N = 1e5+5;
const int INF = 1e9+5;
const int MOD = 1e9+7;

int32_t main()
{
	IOS
	// freopen("input.txt", "r", stdin);
	string s;
	cin >> s;
	for(int i=0; i<s.length(); i++) cout << 'x';
	cout << endl;
	
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<queue>
#include<string>
#include<stack>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<cassert>
#include<ctime>
#include<algorithm>
#include<utility>
#include<map>
#include<set>
#include<vector>
#include<functional>
#include<complex>

using namespace std;

typedef long long            ll;
typedef unsigned             ui;
typedef unsigned long long   ull;
typedef pair<int,int>        i_i;
typedef pair<ll,int>         ll_i;
typedef pair<ll,ll>          ll_ll;
typedef pair<double,int>     d_i;
typedef pair<double,double>  d_d;
typedef vector<int>          vi;
typedef vector<vector<int> > vii;

#ifdef DEBUG
#define dprintf      printf
#define dputs        puts
#define dout(x)      cout<<#x" = "<<(x)<<endl
#define darray(x,n)  {int i;rep(i,n)cout<<#x"["<<i<<"] = "<<*((x)+i)<<endl;}
#define dloop(i,s,g) for(int (i)=(s);(i)<(g);(i)++)
#define drep(i,n)    for(int (i)=0;(i)<(n);(i)++)
#define dstop()      scanf("%*c")
#else
#define dprintf      (1)?0:printf
#define dputs        (1)?0:puts
#define dout(x)
#define darray(x,n)
#define dloop(i,s,g) if(int i=0){}else
#define drep(i,n)    if(int i=0){}else
#define dstop()
#endif

#define F    first
#define S    second
#define pb   push_back
#define mp   make_pair

#define loop(i,s,g) for((i)=(s);(i)<(g);(i)++)
#define rep(i,n)    for((i)=0;(i)<(n);(i)++)
#define all(x)      (x.begin(),x.end())
#define in(T,...) T __VA_ARGS__; impl(__VA_ARGS__)
#define array(T,id,n) T id[(n)]; for(int i=0;i<(n);i++)cin>>id[i]
#define putv(n)     cout<<(n)<<endl

//#define int long long
#ifndef int
#define INF (100000000)
#else
#define INF __INT64_MAX__
#endif

#define EPS (1e-9)

void impl(){};
template <typename T,typename... TS >
void impl(T &head,TS &... tail)
{
  cin>>head;
  impl(tail ...);
}

int d[50][500][500];

signed main(void)
{
  int i,j,k;

  rep(k,50)rep(i,500)rep(j,500)
    d[k][i][j]=INF;

  in(int,n,ma,mb);

  double m=(double)ma/mb;
  dout(m);

  int a[50],b[50],c[50];

  rep(i,n)
    cin>>a[i]>>b[i]>>c[i];

  d[0][0][0]=0;
  d[0][a[0]][b[0]]=c[0];
  
  loop(k,1,n)rep(i,500)rep(j,500)
    if(d[k-1][i][j]!=INF)
      {
	d[k][i][j]=min(d[k-1][i][j],d[k][i][j]);
	d[k][i+a[k]][j+b[k]]=min(d[k][i+a[k]][j+b[k]],d[k-1][i][j]+c[k]);
      }
  
  drep(k,n)
    {
      dout(k);
      dprintf("    | ");
      drep(i,15)
	dprintf("%3d|",i);
      dputs("");
      drep(i,15)
	{
	  dprintf("%3d | ",i);
	  drep(j,15)
	    {
	      if(abs((double)i/j-m)<EPS)
		dprintf("\e[41m");
	      if(d[k][i][j]==INF)
		dprintf("___");
	      else
		dprintf("%3d",d[k][i][j]);
	      dprintf("\e[40m|");
	    }
	  dputs("");
	}
      dputs("");
    }
  
  int mini=INF;

  rep(i,500)rep(j,500)
    if(abs((double)i/j-m)<EPS)
      if(mini>d[n-1][i][j])
	mini=min(mini,d[n-1][i][j]);
  
  putv(mini==INF?-1:mini);
  return 0;
}


Measured memory_bytes: 49152
/**
 *    author:  otera    
**/
#include<iostream>
#include<string>
#include<cstdio>
#include<cstring>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<deque>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
using namespace std;

#define int long long
typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
typedef long double ld;
const int inf=1e9+7;
const ll INF=1LL<<60 ;
const ll mod=1e9+7 ;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<int, int> P;
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
#define pb push_back
#define debug(x)  cerr << #x << " = " << (x) << endl;
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; }

typedef pair<int, P> P2;

struct edge{
    int to, a, b;
};

int n, m, s;
vector<vector<edge>> g;
vector<int> c, d;

void solve() {
	cin >> n >> m >> s;
    g.assign(n, vector<edge>());
    rep(i, m) {
        int u, v, a, b; cin >> u >> v >> a >> b;
        --u, --v;
        g[u].pb({v, a, b});
        g[v].pb({u, a, b});
    }
    c.resize(n), d.resize(n);
    rep(i, n) {
        cin >> c[i] >> d[i];
    }
    priority_queue<P2, vector<P2>, greater<P2>> pque;
    static int dist[55][2700];
    rep(i, 55) {
        rep(j, 2700) {
            dist[i][j] = INF;
        }
    }
    if(s >= 2500) s = 2500;
    dist[0][s] = 0;
    rep(i, s) dist[0][s] = 0;
    pque.push({0, {0, s}}); 
    while(!pque.empty()) {
        P2 p = pque.top(); pque.pop();
        int v = p.sc.fr, sil = p.sc.sc, di = p.fr;
        if(di > dist[v][sil]) continue;
        if(sil < 2500) {
            int nsil = sil + c[v];
            if(nsil > 2500) nsil = 2500;
            if(chmin(dist[v][nsil], di + d[v])) {
                pque.push({di + d[v], {v, nsil}});
            }
        }
        for(auto e: g[v]) {
            int to = e.to, a = e.a, b = e.b;
            if(sil >= a) {
                if(chmin(dist[to][sil - a], di + b)) {
                    pque.push({di + b, {to, sil - a}});
                }
            }
        }
    } 
    for(int i = 1; i < n; ++ i) {
        int ans = INF;
        rep(j, 2501) {
            chmin(ans, dist[i][j]);
        }
        cout << ans << endl;
    }
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(10);
	//int t; cin >> t; rep(i, t)solve();
	solve();
    return 0;
}

Measured memory_bytes: 7556
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Main
{
	public static void main(String[] args)
	{
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		MyScanner in = new MyScanner(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		Solver solver = new B();
		solver.solve(1, in, out);
		out.close();
	}
	
	static class B implements Solver
	{
		public void solve(int testNumber, MyScanner in, PrintWriter out)
		{
			long a = in.nextInt();
			long b = in.nextInt();
			long c = in.nextInt();
			long d = in.nextInt();
			out.println(Math.max(Math.max(a*c, a*d), Math.max(b*c, b*d)));
		}
	}

	static class A implements Solver
	{
		public void solve(int testNumber, MyScanner in, PrintWriter out)
		{
			int x = in.nextInt();
			out.println(1 - x);
		}
	}

	static class UnionFind
	{
		int[] par;
		int[] n_nodes;
		int max = 1;
		
		public UnionFind(int n)
		{
			par = new int[n];
			n_nodes = new int[n];
			for( int i=0; i<n; i++ )
			{
				par[i] = i;
				n_nodes[i] = 1;
			}
		}
		
		int root(int x)
		{
			if( par[x] == x ) return x;
			return par[x] = root(par[x]);
		}
		
		void unite(int x, int y)
		{
			int rx = root(x);
			int ry = root(y);
			if( rx == ry ) return;
			par[rx] = ry;
			n_nodes[ry] += n_nodes[rx];
			max = Math.max(max, n_nodes[ry]);
		}
		
		boolean same(int x, int y)
		{
			int rx = root(x);
			int ry = root(y);
			return rx == ry;
		}
	}
	
	static class MyScanner
	{
		private BufferedReader in;
		private StringTokenizer st;
		
		public MyScanner(InputStream stream)
		{
			in = new BufferedReader(new InputStreamReader(stream));
		}
		
		public String next()
		{
			while( st == null || !st.hasMoreTokens() )
			{
				try
				{
					String rl = in.readLine();
					if( rl == null )
					{
						return null;
					}
					st = new StringTokenizer(rl);
				}
				catch( IOException e )
				{
					return null;
				}
			}
			return st.nextToken();
		}
		
		public int nextInt()
		{
			return Integer.parseInt(next());
		}
		
		public long nextLong()
		{
			return Long.parseLong(next());
		}
	}
	
	static interface Solver
	{
		public void solve(int testNumber, MyScanner in, PrintWriter out);
	}
}


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

int N, C;

struct Show {
  int s, t, c;

  bool operator < (const Show& that) {
    return s < that.s;
  }
};

int main () {
  cin >> N >> C;

  vector<vector<Show>> ss(C);
  rep(i,N) {
    Show x;
    cin >> x.s >> x.t >> x.c;
    x.c--;
    ss[x.c].push_back(x);
  }

  vector<Show> shows;
  rep(i,C) {
    sort(all(ss[i]));
    int l = ss[i].size();
    rep(j,l) {
      while(j + 1 < l && ss[i][j].t == ss[i][j+1].s) {
        ss[i][j+1].s = ss[i][j].s;
        j++;
      }
      shows.push_back(ss[i][j]);
    }
  }

  int ans = 1;
  priority_queue<int, vector<int>, greater<int>> pq;
  sort(all(shows));
  for(auto& s: shows) {
    while(!pq.empty() && pq.top() < s.s) pq.pop();
    ans = max(ans, static_cast<int>(pq.size()) + 1);
    pq.push(s.t);
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3768
#include <stdio.h>

int main(int argc, const char * argv[]) {
    int i=0;
    char ch[1200];
    while(1){
        scanf("%c", &ch[i]);
        if(ch[i] == '\n') break;
        if('a'<=ch[i] && ch[i]<='z'){
            ch[i] -= 32;
        } else if('A'<=ch[i] && ch[i]<='Z'){
            ch[i] += 32;
        }
        i++;
    }
    for(int j=0; j<=i; j++){
        printf("%c", ch[j]);
    }
    return 0;
}



Measured memory_bytes: 2044
#include<stdio.h>
#define MAX 100000

int Bis(int *,int,int);
int main() {

  int n,m,i;
  int num[MAX];
  int key,count=0;

  scanf("%d",&n);
  for(i=0;i<n;i++) scanf("%d",&num[i]);

  scanf("%d",&m);
  for(i=0;i<m;i++) {
    scanf("%d",&key);
    if( Bis(num,n,key) == 1 ) count++;
  }

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

  return 0;

}

int Bis(int *num,int n,int key) {

  int left=0;
  int right=n;
  int mid;
  
  while( left < right ) {
    
    mid = (left+right)/2;

    if(num[mid] == key) return 1;
    else if( key < num[mid]) right = mid;
    else left = mid+1;

  }

  return 0;

}


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

#define _ << " _ " <<
#define TRACE(x) cout << #x << " = " << x << endl

typedef long long ll;

const int MaxN = 2e5 + 10;
int n, c[MaxN];
ll dp[MaxN], x[MaxN], sol, mod = 1e9 + 7;

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

    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> c[i];
        if (i > 0 && c[i] == c[i - 1]) {
            x[i] = x[i - 1];
            continue;
        }
        x[i] = dp[c[i]];
        if (i > 0) x[i] += x[i - 1];
        else x[i]++;
        x[i] %= mod;
        dp[c[i]] = x[i];
    }

    cout << x[n - 1];


    return 0;
}



Measured memory_bytes: 4224
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<cstdlib>
using namespace std;
char a[4],b[4],c[4];
int main(){
	scanf("%s",a+1);
	scanf("%s",b+1);
	scanf("%s",c+1);
	printf("%c%c%c",a[1],b[2],c[3]);
	return 0;
	
}

Measured memory_bytes: 128
import itertools
def check(q):
    for r1, c1 in q:
        if any((r1 != r2 or c1 != c2) and (r1 == r2 or c1 == c2 or r1 + c1 == r2 + c2 or r1 - c1 == r2 - c2) for r2, c2 in q): return 0
    return 1
N = input()
Q, row, col = [], range(8), range(8)
for _ in range(N):
    r, c = map(int, raw_input().split())
    Q.append((r, c))
    row.remove(r)
    col.remove(c)
for l in itertools.permutations(col):
    queen = Q[:] + list(zip(row, l))
    if check(queen):
        print '\n'.join([''.join('Q' if (r, c) in queen else '.' for c in range(8)) for r in range(8)])
        break

Measured memory_bytes: 6556
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

H, W = map(int, input().split())
s = [list(input().strip()) for _ in [0]*H]

move = [[0,1],[1,0],[-1,0],[0,-1]]
distance = [[-1]*W for _ in range(H)]
distance[0][0] = 0
q = collections.deque()
q.append((0,0))

while q:
    h, w = q.popleft()
    cur = distance[h][w]
    for dh, dw in move:
        if not 0<=h+dh<=H-1 or not 0<=w+dw<=W-1:
            continue
        if distance[h+dh][w+dw] == -1 and s[h+dh][w+dw] == '.':
            distance[h+dh][w+dw] = cur + 1
            q.append((h+dh, w+dw))

num_white = 0
for x in s:
    num_white += x.count('.')

if distance[H-1][W-1] == -1:
    print(-1)
else:
    print(num_white - distance[H-1][W-1] - 1)

Measured memory_bytes: 5548
def q(a,k):
 d[a]=k
 for b in t[a]:
  if'-1'!=b:q(b,k+1)
def n(a,k):
 h[a]=max(h[a],k)if a in h else k
 if'-1'!=p[a]:n(p[a],k+1)
t,p,s,d,h={},{},{},{},{}
for _ in[0]*int(input()):
 x,y,z=input().split()
 t[x]=set([y,z])-{'-1'}
 p[y]=p[z]=x
 s[y],s[z]=z,y
r=(set(t)-set(p)).pop()
p[r]=s[r]='-1'
q(r,0)
for i in t:
 if not t[i]:n(i,0)
for i in map(str,sorted(map(int,t))):
 print(f"node {i}: parent = {p[i]}, sibling = {s[i]}, degree = {len(t[i])}, depth = {d[i]}, height = {h[i]}, {'root'if d[i]==0else'internal node'if t[i]else'leaf'}")


Measured memory_bytes: 5628
/*input
1
1

*/
 
/*
                                                    ______________
                                                          |       )
                                                          |   )   /
                                                          |______/
                                                    |     |      \
                                                    |     |   )   \
                                                    |_____|_______)
 
*/
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <iomanip>
#include <fstream>
#include <stack>

using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> PII;
typedef pair<ll , ll> PLL;
typedef long double ld;
 
#define pb push_back
#define all(c) c.begin(),c.end()
#define allr(c) c.rbegin(),c.rend()
int mod = 1000000007;
const int inf = 1034567891;
const ll LL_INF = 1234567890123456789ll;
#define PI 3.14159265
#define endl '\n'
#define F first
#define S second
#define debug(x) cout << #x << " = " << x << endl;
#define TRACE
 
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cout << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif
 
#define out(container) for (auto it : container) cout << it << " "; cout << endl;
 
 
template < typename T > T GCD(T a, T b)            { ll t; while(a) { t = a; a = b % a; b = t; } return b; }
template < typename T > string toString(T a)       { return to_string(a); }
template < typename T > void toInt(string s, T &x) { stringstream str(s); str >> x;}
inline int add(int x, int y){ x += y; if(x >= mod) x -= mod; return x;}
inline int sub(int x, int y){ x -= y; if(x < 0) x += mod; return x;}
inline int mul(int x, int y){ return (x * 1ll * y) % mod;}
inline int powr(int a, ll b){
  int x = 1 % mod;
  while(b){
    if(b & 1) x = mul(x, a);
    a = mul(a, a);
    b >>= 1;
  }
  return x;
}
inline int inv(int a){ return powr(a, mod - 2);}

int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  
  int r;
  cin >> r;
  cout << fixed << setprecision(15) << 2 * (22.0 / 7.0) * r << endl;

  return 0;
}

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

#define V             vector
#define PQ            priority_queue

#define pb            push_back
#define mp            make_pair
#define ins           insert
#define endl          '\n'
#define all(x)        x.begin(),x.end()
#define debug(X)      { cerr<<endl<<(#X)<<" = "<<(X)<<endl; }
//#define cerr if(0)cerr

typedef long long ll;
typedef unsigned long long ull;


int main() {
    ios_base::sync_with_stdio(0);cin.tie(0);
    string s,S;
    bool ok1=0, ok2=0;
    cin>>s;
    int n=s.length();
    S=s;
    reverse(all(s));
    
    ok1=(S==s);
    string p1, p11;
    p1=S.substr(0,n/2); reverse(all(p1));
    ok2=(S.substr(0,n/2)==p1);

    cout<<(ok1&&ok2?"Yes":"No")<<endl;

}



Measured memory_bytes: 256
#include<iostream>
using namespace std;
#define INF 1000000007
	int N;
	long long dp[100][4][4][4];
long long  dfs(int i,int a,int b,int c){
	if(i==N)//fin
		return 1;
	else if(dp[i][a][b][c]!=0)
		return dp[i][a][b][c];
	
	if(b==0 && c==1)
		return dp[i][a][b][c]=(long long)((dfs(i+1,b,c,0)%INF)+(dfs(i+1,b,c,1)%INF)+(dfs(i+1,b,c,3)%INF))%INF;
	else if(b==0 && c==2)
		return dp[i][a][b][c]=(long long)((dfs(i+1,b,c,0)%INF)+(dfs(i+1,b,c,2)%INF)+(dfs(i+1,b,c,3)%INF))%INF;
	else if(b==1 && c==0)
		return dp[i][a][b][c]=(long long)((dfs(i+1,b,c,0)%INF)+(dfs(i+1,b,c,1)%INF)+(dfs(i+1,b,c,3)%INF))%INF;
	else if(a==0 &&(b==1 || c==1) && i>2)
		return dp[i][a][b][c]=(long long)((dfs(i+1,b,c,0)%INF)+(dfs(i+1,b,c,1)%INF)+(dfs(i+1,b,c,3)%INF))%INF;
	else
		return dp[i][a][b][c]=(long long)((dfs(i+1,b,c,0)%INF)+(dfs(i+1,b,c,1)%INF)+(dfs(i+1,b,c,2)%INF)+(dfs(i+1,b,c,3)%INF))%INF;
}
int main(void){
		cin >> N ;
	long long ans=0;
	for(int j=0;j<4;j++){
		for(int k=0;k<4;k++){
			ans+=dfs(2,0,j,k);
			ans%=INF;
		}
	}
	
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#pragma once
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <deque>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
int t[101];
int pri[26];
int res = 0;
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}
int pr[100010];
void uini(int n) {
	for (size_t i = 0; i <= n; i++)
	{
		pr[i] = i;
	}
}

int parent(int x) {
	if (x == pr[x]) return x;
	return pr[x] = parent(pr[x]);
}

bool unit(int x, int y) {
	int px = parent(x);
	int py = parent(y);

	if (px == py) return false;
	if (px < py) {
		pr[y] = px;
	}
	else {
		pr[x] = py;
	}
	return true;
}
struct edge {
	int to;
	bool use = false;
	edge(int _to) : to(_to) {}
};

int bt[60];
void solv() {

	ll a, b;
	cin >> a >> b;
	ll rem = b - a;
	ll m = 4;

	for (ll i = 0; i < 60; i++)
	{

		ll sb = a % m;
		ll rm = b % m;
		if (i == 0) {
			if (sb == rm) {
				if (sb % 2 == 1) {
					bt[i] = 1;
					continue;
				}
			}
			int c = 0;
			for (int i = sb; i <= rm + 4; i++)
			{
				if (i % 2 == 1) c++;
			}

			bt[i] = c % 2;
			continue;
		}
		else {
			ll oc = m - max(m / 2LL,sb);
			ll rmc = max(0LL, (rm + 1) - m / 2LL);
			bt[i] = (oc + rmc) % 2;
		}
		m <<= 1;
	}
	ll res = 0;
	for (ll i = 0; i < 60; i++)
	{
		if (bt[i]) {
			res += 1LL << i;
		}
	}
	cout << res << endl;
}


int main() {
	solv();

	return 0;
}


Measured memory_bytes: 256
from collections import defaultdict
import sys
input = sys.stdin.readline

N, M = [int(x) for x in input().split()]
A = [0] + [int(x) % M for x in input().split()]

# 累積和(mod M)に変える
for i in range(1, N + 1):
    A[i] += A[i - 1]
    A[i] %= M

candy = defaultdict(int) # default value is 0
for i in range(N + 1):
    candy[A[i]] += 1

ans = 0
for n in candy.values():
    ans += n * (n - 1) // 2

print(ans)

Measured memory_bytes: 14596
#include <bits/stdc++.h>
#ifndef ONLINE_JUDGE
#define debug(x) cout << #x << ": " << x << endl
#else
#define debug(x)
#endif
using namespace std;
typedef long long ll;
const int MAXN=2e5+7;
const int INF=0x3f3f3f3f;
const int MOD=1e9+7;

ll fac[MAXN];
ll quick(ll x,ll n)
{
    ll res=1;
    while(n)
    {
        if(n&1) res=(res*x)%MOD;
        x=x*x%MOD;
        n>>=1;
    }
    return res;
}
ll inv(ll x) {return quick(x,MOD-2);}

void init()
{
    fac[0]=1;
    for(int i=1;i<MAXN;++i) fac[i]=(fac[i-1]*i)%MOD;
}
ll C(int n,int m)
{
    return fac[n]*inv(fac[m])%MOD*inv(fac[n-m])%MOD;
}

int a[MAXN];
int b[MAXN];
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    init();
    int n;
    cin>>n;
    int t=0;
    int pre=0,lst=0;
    for(int i=1;i<=n+1;++i)
    {
        cin>>a[i];
        if(b[a[i]]) t=a[i];
        b[a[i]]++;
    }
    for(int i=1;i<=n+1;++i)
    {
        if(t==a[i])
            break;
        pre++;
    }
    for(int i=n+1;i>=1;--i)
    {
        if(a[i]==t)
            break;
        lst++;
    }
    for(int i=1;i<=n+1;++i)
    {

        ll t=C(n+1,i);
        if(pre+lst>=i-1) t-=C(pre+lst,i-1);
        t+=MOD;
        t%=MOD;
        cout<<t<<endl;
    }
    return 0;
}


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

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define all(x) (x).begin(),(x).end()

ll GCD(ll a, ll b) {
    if (b == 0) return a;
    else return GCD(b, a % b);
}
ll LCM(ll a, ll b) { return a * b / GCD(a, b); }


int main(){
    int N, M;
    cin >> N >> M;
    cout << ((N == M) ? "Yes" : "No") << endl;
}

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

using namespace std;

constexpr int32_t posalpha(char ch)
{
	return ch - 'a';
}

constexpr char rotate_alpha(char ch, int32_t n)
{
	return posalpha(ch) + n < 26 ? ch + n : 'a' + (n < 26 ? n : n % 26);
}

int main(void)
{
	int32_t k, temp;
	string str;

	cin >> str;
	cin >> k;

	for (auto i{ 0 }; i < str.size(); ++i) {
		temp = posalpha(str[i]);
		if (k < 26 - temp || temp == 0)
			continue;
		k -= 26 - temp;
		str[i] = 'a';
	}

	if (k > 0)
		str.back() = rotate_alpha(str.back(), k);

	cout << str << endl;
}

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

ll N;
string S;

int main(void) {
  cin >> N >> S;

  ll ans = 1;
  REP(i, 1, N) {
    if(S[i - 1] == 'x' && S[i] == 'x') break;
    ans++;
  }
  cout << ans << endl;
}

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

#define sent 2000000000
#define MAX 500000

int cnt=0;
int L[MAX/2+2],R[MAX/2+2];

void merge(int A[],int left,int mid,int right){
    int n1=mid-left;
    int n2=right-mid;

    rep(i,n1) L[i]=A[left+i];
    rep(i,n2) R[i]=A[mid+i];

    L[n1]=R[n2]=sent;

    int i=0,j=0;
    for(int k=left;k<right;k++){
        if(L[i]<=R[j]){
            A[k]=L[i++];
        }else{
            A[k]=R[j++];
        }
        cnt++;
    }

}

void mergeSort(int A[],int left,int right){
    if (left+1<right){
        int mid=(left+right)/2;
        mergeSort(A,left,mid);
        mergeSort(A,mid,right);
        merge(A,left,mid,right);
    }

}

int main(){
    int n;
    int S[500000];
    cin>>n;
    rep(i,n) cin>>S[i];
    mergeSort(S,0,n);

    rep(i,n-1){
        cout<<S[i]<<" ";
    }
    cout<<S[n-1]<<endl;

    cout<<cnt<<endl;


    return 0;
}


Measured memory_bytes: 7000
import java.util.Scanner;
public class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		String[] name = new String[N];
		int[] counter = new int[4];

		for(int i = 0; i < N; i++) {
			name[i]  = sc.next();

			switch(name[i]) {
				case "AC":
					counter[0]++;
					break;
				case "WA":
					counter[1]++;
					break;
				case "TLE":
					counter[2]++;
					break;
				case "RE":
					counter[3]++;
					break;
				default:
					break;
			}
		}

		System.out.println("AC x " + counter[0]);
		System.out.println("WA x "+  counter[1]);
		System.out.println("TLE x "+counter[2]);
		System.out.println("RE x " + counter[3]);
	}
}

Measured memory_bytes: 65276
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(c) begin(c), end(c)
#define dump(x) cerr << __LINE__ << ":\t" #x " = " << (x) << endl

int main() {
    int n;
    while (cin >> n) {
        int a[2] = {};
        for (int i = 0; i < n; i++) {
            int x;
            cin >> x;
            ++a[x % 2];
        }
        if (a[1]%2 == 0) {
            puts("YES");
        } else {
            puts("NO");
        }
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <numeric>
typedef long long ll;
#define rep(i,a,b) for(int i=a;i<b;++i)
#define rrep(i,a,b) for(int i=a;i>=b;--i)
using namespace std;

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

    int H, W, N, sr, sc;
    string S, T;
    cin >> H >> W >> N >> sr >> sc >> S >> T;
    --sr; --sc; //0-indexed

    // bounds of the safety area
    int safetyL = 0;
    int safetyR = W-1;
    int safetyU = 0;
    int safetyD = H-1;

    rrep(i, N-1, 0) {
        // Aoki's turn
        switch (T[i]) {
            case 'L': safetyR = min(safetyR+1, W-1); break;
            case 'R': safetyL = max(safetyL-1, 0); break;
            case 'U': safetyD = min(safetyD+1, H-1); break;
            case 'D': safetyU = max(safetyU-1, 0); break;
        }

        // Takahashi's turn
        switch (S[i]) {
            case 'L': ++safetyL; break;
            case 'R': --safetyR; break;
            case 'U': ++safetyU; break;
            case 'D': --safetyD; break;
        }

        if (safetyL >= W or safetyR < 0 or safetyU >= H or safetyD < 0) {
            cout << "NO\n";
            return 0;
        }
    }

    if (sc < safetyL or safetyR < sc or sr < safetyU or safetyD < sr) {
        cout << "NO\n";
        return 0;
    }

    cout << "YES\n";
}

Measured memory_bytes: 920
#include <bits/stdc++.h>
// #include <atcoder/all>
#define ll long long int
#define ld long double
#define yorn(f) cout<<((f)?"Yes":"No")<<endl;
#define YORN(f) cout<<((f)?"YES":"NO")<<endl;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repi(i, n) for (ll i = 1; i < (ll)(n); i++)
#define all(x) (x).begin(), (x).end()
#define put(x) cout << x << endl;
#define println(x) cout << x << endl;
using namespace std;
// using namespace atcoder;

// dp[y][x]: (y,x)への生き方
ll dp[101][9];

bool valid(ll pat) {
    rep(i, 10) {
        if ((pat & (1LL << i)) && (pat & (1LL << (i+1)))){
            return false;
        }
    }

    return true;
}

void Main()
{
    ll mod = 1000000007;

    ll H, W, K;
    cin >> H >> W >> K;

    ll pow2[200];
    pow2[0] = 1;
    repi(i, 100) {
        pow2[i] = (pow2[i - 1] * 2) % mod;
    }

    dp[0][0] = 1;
    rep(y, H) {
        rep(x, W) {
            rep(pat, 1 << (W-1)) {
                if (!valid(pat)) {
                    continue;
                }
                if (pat & (1 << x)) {
                    dp[y+1][x+1] += dp[y][x];
                    dp[y+1][x+1] %= mod;
                }
                else if (pat & (1 << (x-1))) {
                    dp[y+1][x-1] += dp[y][x];
                    dp[y+1][x-1] %= mod;
                }
                else {
                    dp[y+1][x] += dp[y][x];
                    dp[y+1][x] %= mod;
                }
            }

        }
    }

    ll res = dp[H][K-1];
    put(res);
    
}
signed main(){ Main();return 0;}

Measured memory_bytes: 3648
n = int(input())
h = list(map(int,input().split()))
for i in range(1,n):
    if h[i] > h[i-1]:
        h[i] -= 1
    else:
        pass
l = list(h)
l.sort()
if h == l:
    print('Yes')
else:
    print('No')

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

int n, k;
vector<int> arr(100004, 0);
vector<int> dp(100004, -1);

int main() {

	cin >> n >> k;
	for(int i=0; i<n; ++i) cin >> arr[i];

	dp[n-1] = 0;
	dp[n-2] = abs(arr[n-1] - arr[n-2]);

	for(int i=n-3; i>=0; --i) 
	{
		for(int j=1; j<=k; ++j)
		{
			if(i+j>=n) break;
			int temp = abs(arr[i]-arr[i+j]) + dp[i+j];
			dp[i] = (dp[i]==-1) ? temp : min(dp[i], temp);
		}
	}

	cout << dp[0] << endl;

	return 0;
}

Measured memory_bytes: 1024
/*..........AAKASH GOYAL............*/
/*............DAIICT................*/
 
#pragma GCC optimize("O3", "unroll-loops")
#pragma GCC target("avx2")
#include <bits/stdc++.h>
using namespace std;
 

#define    int                   long long int 
#define    f(i,j,n)                 for(int i = j; i <= n; i++)
#define    r(i,n,j)                 for(int i = n; i >= j; i--)
#define    mod                      1110111110111
#define    speed                    ios_base::sync_with_stdio(false);
#define    upp                      cin.tie(NULL);
#define    pb                       push_back
#define    mp                       make_pair
#define    T                        int tt; cin >> tt; while(tt--)
#define    ff                       first
#define    ss                       second
#define    all(container)           container.begin() , container.end()
#define    sz(container)            (int)container.size()
#define    pii                      pair <int , int>
#define    pll                      pair <long long int , long long int>
#define    ppl                      pair <long long int , pll>              //pair of ll and pair ll 
#define    sp(x)                    setprecision(x)
 

int32_t main()
{
    speed upp
    int n,k;
    cin>>n>>k;
    int a[n+1],dp[n+1];
    dp[0]=dp[1]=0;
    f(i,1,n)
        cin>>a[i];

    dp[2]=abs(a[2]-a[1]);

    f(i,3,n)
    {
        dp[i]=9999999999;
        for(int j=max((int)1,i-k);j<i;j++)
            dp[i]=min(abs(a[i]-a[j])+dp[j],dp[i]);
        // cout<<dp[i]<<"  ";
    }
    cout<<dp[n];
}

Measured memory_bytes: 1792
object Main extends App {
  val Array(x, y) = io.StdIn.readLine.split(" ").map(_.toInt)
  def f(n:Int):Int = {
    if(n == 2) 3
    else if(n == 4 || n == 6 || n == 9 || n == 11) 2
    else 1
  }
  val ans = if(f(x) == f(y)) "Yes" else "No"
  println(ans)
}

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

using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define POW2(n) (1LL << (n))
#define FOR(i, begin, end) for (int i = (begin), i##_end_ = (end); i < i##_end_; i++)
#define IFOR(i, begin, end) for (int i = (end)-1, i##_begin_ = (begin); i >= i##_begin_; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)

int main()
{
    lint n,k;
    cin >> n >> k;
    lint ans=0;
    REP(i,n){
        lint x;
        cin >> x;
        ans += min(x, abs(x - k));

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

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) throws IOException{
		InputStreamReader is = new InputStreamReader(System.in);
		BufferedReader br = new BufferedReader(is);
		String str;
		while((str=br.readLine())!=null){
			String[] num=str.split(" ");
			int a=Integer.parseInt(num[0]),
				b=Integer.parseInt(num[1]);
			System.out.println(gcd(a,b)+" "+lcm(a,b));
			
		}
	}
	
	public static int gcd(int a,int b){
		return b==0 ? a : gcd(b,a%b);
	}
	
	public static int lcm(int a,int b){
		int max=Math.max(a, b);
		int min=Math.min(a, b);
		int back=max;
		int i=1;
		while(back%min!=0){
			back=max*i++;
			//System.out.println(back);
		}
		
		return back;
	}

}

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

ll fast(ll a,ll b)
{
    ll s = 1;
    while(b)
    {
        if(b%2)
            s = (s%mod*a%mod)%mod;
        a=(a%mod*a%mod)%mod;
        b = b/2;
    }
    return s;
}
ll solve(ll arr[], ll n) 
{ 
    ll  sum = 0; 
    for (int i = 0; i < 64; i++)  
    { 
        ll zc = 0, oc = 0;  
        ll idsum = 0;  
        for (int j = 0; j < n; j++) 
        { 
            if (arr[j] % 2 != 0) 
                oc++; 
            else
                zc++; 
            arr[j] /= 2; 
        } 
        
        ll x = (oc%mod * zc%mod)%mod;
        idsum = (x%mod * fast(2,i)%mod )%mod;      
        sum += idsum; 
        sum %= mod; 
    } 
    return sum%mod; 
} 

int main()
{
    ll n;
    cin >> n ;
    ll a[n];
    for(int i=0;i<n;i++)
        cin >> a[i];
    ll ans = solve(a,n);
    cout << ans << endl;
}

Measured memory_bytes: 2560
a, b, c, k = map(int, input().split())
sum = 0

if a <= k:
    sum += a
    k -= a
else:
    sum += k
    k = 0
    
if k > 0:
    k -= b
    if c <= k:
        sum -= c
        k -= c
    else:
        sum -= k

print(sum)

Measured memory_bytes: 9188
#0512
word = list(input())
l = []


for i in range(len(word)):
    if ord(word[i]) == 65:
        l.append('X')
    elif ord(word[i]) == 66:
        l.append('Y')
    elif ord(word[i]) == 67:
        l.append('Z')
    else:
        l.append(chr(ord(word[i])-3))
print(''.join(l))


Measured memory_bytes: 5580
N,K=map(int,input().split())
mod=10**9+7

ans=0
if K>=N+1:
    ans=1
else:
    for i in range(K,N+2):
        min=int(i*(i-1)/2)
        max=int(i*N-i*(i-1)/2)
        Z=max-min+1
        #print(Z)
        ans+=Z
print(ans%mod)


Measured memory_bytes: 9184
#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
int main(){
  double x = 0,y = 0,dis,ang = 90,a;
  for(;;){
    scanf("%lf,%lf",&dis,&a);
    if(dis == 0 && a == 0){break;}
    x+=dis*cos(M_PI*ang/180.0);
    y+=dis*sin(M_PI*ang/180.0);
    ang-=a;
  }
  cout <<(int)x<<endl<<(int)y<<endl;
  return 0;
}

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

int coordToVertex[20][20] = {};
int vertexToCoord[401][2] = {}; // Zeroth coordinate is not used
int adjacencyMatrix[401][401] = {};
int warshall[401][401];

#define MAXDIST 100000000

int main()
{
    int h,w;
    scanf("%d %d", &h, &w);
    int coordCount = 1;

    // Get an input and give name to coordinates

    for(int i = 0; i < h; i++)
    {
        char s[25];
        scanf("%s", s);
        for (int j = 0; j < w; j++)
        {
            if(s[j] == '.')
            {
                coordToVertex[i][j] = coordCount;

                vertexToCoord[coordCount][0] = i;
                vertexToCoord[coordCount][1] = j;
                
                coordCount++;
            }
        }
    }

    // Connect the coordinates as required

    for(int i = 0; i < h; i++)
    {
        for(int j = 0; j < w; j++)
        {
            if(coordToVertex[i][j] == 0)
            {
                continue;
            }

            if(i > 0 && coordToVertex[i-1][j] != 0)
            {
                adjacencyMatrix[coordToVertex[i][j]][coordToVertex[i-1][j]] = 1;
            }
            if(j > 0 && coordToVertex[i][j-1] != 0)
            {
                adjacencyMatrix[coordToVertex[i][j]][coordToVertex[i][j-1]] = 1;
            }
            if(i < h-1 && coordToVertex[i+1][j] != 0)
            {
                adjacencyMatrix[coordToVertex[i][j]][coordToVertex[i+1][j]] = 1;
            }
            if(j < w-1 && coordToVertex[i][j+1] != 0)
            {
                adjacencyMatrix[coordToVertex[i][j]][coordToVertex[i][j+1]] = 1;
            }
        }
    }

    // Execute Warshall

    for(int i = 1; i < coordCount; i ++)
    {
        for(int j = 1; j < coordCount; j ++)
        {
            warshall[i][j] = MAXDIST;
            if(i == j)
            {
                warshall[i][j] = 0;
            }
            if(adjacencyMatrix[i][j])
            {
                warshall[i][j] = 1;
            }
        }
    }

    for(int k = 1; k < coordCount; k ++)
    {
        for(int i = 1; i < coordCount; i ++)
        {
            for(int j = 1; j < coordCount; j ++)
            {
                if(warshall[i][k] + warshall[k][j] < warshall[i][j])
                {
                    warshall[i][j] = warshall[i][k] + warshall[k][j];
                }
            }
        }
    }

    // Find maximum
    int maxDist = 0;
    for(int i = 1; i < coordCount; i ++)
    {
        for(int j = 1; j < coordCount; j ++)
        {
            if(maxDist < warshall[i][j])
            {
                maxDist = warshall[i][j];
            }
        }
    }
    printf("%d",maxDist);
}

Measured memory_bytes: 2896
//#include "debug.h"
#include <string.h>
#include <limits.h>
#include <map>
#include <set>
#include <vector>
#include <algorithm>
using namespace std;

#define MAXN 100000

int n;
char s[MAXN+1];
int f[MAXN];
int a[MAXN];

int input() {
	if (scanf("%s", s) < 0) return 0;
	n = strlen(s);
	return 1;
}

void init() {
}

int solve() {
	if (s[0]!='1' || s[n-1]!='0') return 0;
	int m = 0;
	for (int i=0; i<n-1; i++) {
		if (s[i] != s[n-2-i]) return 0;
		if (s[i]=='1' && i+1 >= (n+1)/2) {
			a[m++] = i+1;
		}
	}
	sort(a, a+m);
	memset(f, -1, sizeof(*f)*n);
	int v = m;
	for (int i=0; i<m; i++) {
		int k = a[i] - (i? a[i-1]: 0) - 1;
		for (int j=0; j<k; j++)
			f[v++] = i;
		if (i<m-1)
			f[i] = i+1;
		//printa(f, n);
	}
	f[v++] = m-1;
	//printa(a, m);
	return 1;
}

void output(int ans) {
	if (!ans) {
		printf("-1\n");
		return;
	}
	for (int i=0; i<n; i++)
		if (f[i]>=0) printf("%d %d\n", i+1, f[i]+1);
}

void cleanup() {
}

int main() {
	//int ca; scanf("%d", &ca);
	while (input()) {
		init();
		output(solve());
		cleanup();
		//printf("\n");
		//break;
	}
}





Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define len(x) (int)(x.size())
#define all(vs) vs.begin(), vs.end()
using ii = pair<int, int>;
using ll = long long;

int32_t main(){
	ios::sync_with_stdio(0);	
	int n, m;
	cin >> n >> m;
	string ans;
	for(int i=0; i<n; ++i) ans.push_back('$');
	for(int i=0; i<m; ++i){
		int j, x;
		cin >> j >> x;
		j-=1;
		if(ans[j]!='$' and int(ans[j]-'0')!=x){
			cout << -1 << endl;
			return 0;
		}
		ans[j] = x+'0';
	}
	if(ans[0]=='0' and len(ans)>1){
		cout << -1 << endl;
		return 0;
	}
	if(ans[0]=='$' and len(ans)>1) ans[0] = '1';
	for(auto &x:ans)
		if(x=='$') x = '0';
	cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define eps 1e-9
#define mod 1000000007
#define pi 3.14159265359
#define inf 1e18

using namespace std;

typedef long long ll;
typedef long double ld;

ll n, x, y;
vector<ll> V[200005];
ll dp[200005];

ll DFS(ll x, ll &dist, ll &target, ll lvl = 0, ll last = -1)
{
    if (lvl > dist)
    {
        dist = max(dist, lvl);
        target = x;
    }
    for (auto i : V[x])
    {
        if (i == last)
            continue;
        DFS(i, dist, target, lvl+1, x);
    }
}

int main()
{
    // freopen("input.txt", "r", stdin);
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    cin>>n;
    for (ll i=1; i<n; i++)
    {
        cin>>x>>y;
        V[x].push_back(y);
        V[y].push_back(x);
    }

    if (n==1)
    {
        cout<<"First";
        return 0;
    }

    ll d = 0;
    ll far1;
    DFS(1, d, far1);

    d = 0;
    ll far2;
    DFS(far1, d, far2);
    dp[0] = 1;
    dp[1] = 0;
    for (ll i=2; i<=d; i++)
    {
        dp[i] = (dp[i-1] == 0) || (dp[i-2] == 0);
    }
    // cout<<d<<endl;
    if (dp[d] == 1)
        cout<<"First";
    else
        cout<<"Second";
    return 0;
}

Measured memory_bytes: 28416
def judge():
    a, b = map(int, input().split())
    s = input()

    if len(s) != a + b + 1:
        return False
    for i, c in enumerate(s):
        if i == a:
            if c != '-':
                return False
        elif not c.isdecimal():
            return False
    return True


print('Yes' if judge() else 'No')


Measured memory_bytes: 2940