akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
#define MAXN 1000009
#define INF 1000000007
#define mp(x,y) make_pair(x,y)
#define all(v) v.begin(),v.end()
#define pb(x) push_back(x)
#define wr cout<<"----------------"<<endl;
#define ppb() pop_back()
#define tr(ii,c) for(__typeof((c).begin()) ii=(c).begin();ii!=(c).end();ii++)
#define ff first
#define ss second
#define my_little_dodge 46
#define debug(x)  cerr<< #x <<" = "<< x<<endl;
using namespace std;

typedef long long ll;
typedef pair<int,int> PII;
template<class T>bool umin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
template<class T>bool umax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
int fac[MAXN],inv[MAXN];
int mod(ll x){
	return (x%INF);
}
int C(int x,int y){
	if(x<y)
		return 0;
	return mod(fac[x]*1LL*mod(inv[y]*1LL*inv[x-y]));	
}
int Fe(int x,int y){
	if(!y)
		return 1;
	int h=Fe(x,y/2);
	h=mod(h*1LL*h);
	if(y&1)
		h=mod(h*1LL*x);
	return h;	
}
int main(){
	fac[0]=inv[0]=1;
	for(int i=1;i<MAXN;i++){
		fac[i]=mod(fac[i-1]*1LL*i);
		inv[i]=Fe(fac[i],INF-2);	
	}
    int n,m,ans=0;
	cin>>n>>m;
    for(int a=0;a<=n;a++){
    	if((n-a)%2)
    		continue;
		int b=(n-a)/2;
		if(b+2*a==m)
			ans=mod(ans+C(a+b,a));
    }
    printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 8064
using System;

namespace Sample
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            int count = 0;
            int p;
            LOOP: while (n-- > 0)
            {
                p = int.Parse(Console.ReadLine());
                if (p == 2) { count++; continue; }
                for(int i = 2; i * i <= p; i++)
                {
                    if (p % i == 0) goto LOOP;
                }
                count++;
            }
            Console.WriteLine(count);
        }
    }
}

Measured memory_bytes: 9032
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define MOD 1000000007
using namespace std;
vector<int> v[200005];
vector<int> ans;
void dfs(int a,int p = -1)
{
    for(int i = 0;i < v[a].size();i++)
    {
        if(v[a][i] == p)
        {
            continue;
        }
        ans[v[a][i]] += ans[a];
        dfs(v[a][i],a);
    }
}
int main()
{
    int n,q;
    cin >> n >> q;
    for(int i = 0;i < n - 1;i++)
    {
        int a,b;
        cin >> a >> b;
        a--;
        b--;
        v[a].push_back(b);
        v[b].push_back(a);
    }
    ans.resize(n);
    for(int i = 0;i < q;i++)
    {
        int p,x;
        cin >> p >> x;
        p--;
        ans[p] += x;
    }
    dfs(0);
    for(int i = 0;i < n;i++)
    {
        cout << ans[i] << "\n";
    }

    return 0;
}

Measured memory_bytes: 26624
parseInt(x)=parse(Int,x)
parseMap(x::Array{SubString{String},1})=map(parseInt,x)

function main()
	h,w,a,b = readline() |> split |> parseMap
	for i in 1:b
		for i in 1:a
			print(1)
		end
		for i in a+1:w
			print(0)
		end
		println("")
	end
	for i in b+1:h
		for i in 1:a
			print(0)
		end
		for i in a+1:w
			print(1)
		end
		println("")
	end
end

main()

Measured memory_bytes: 174168
#include<iostream>
#include<algorithm>
#define INF 1<<28
using namespace std;

int memo[1000001][6];
int memo2[1000001];

int solve(int n, int count){

  if(!n) return 0;
  if(n <= 0 || !count) return INF;
  if(memo[n][count]) return memo[n][count];

  int ans = INF;
  for(int i=0,k=0; k=i*(i+1)*(i+2)/6, k<=n; i++){
    ans = min(ans, solve(n-k, count-1)+1);
  }

  return memo[n][count] = ans;
}

int solve2(int n){
  
  if(!n) return 0;
  if(n<0) return INF;
  if(memo2[n]) return memo2[n];

  int ans = INF;
  for(int i=0,k=0;k=i*(i+1)*(i+2)/6, k<=n; i++){
    if(!(k%2)) continue;
    ans = min(ans, solve2(n-k)+1);
  }

  return memo2[n] = ans;
}

int main(){
  
  int n;
  for(int i=1;i<=1000000;i++) solve2(i);

  while(cin >> n, n)
    cout << solve(n, 5) << " " << solve2(n) << endl;
}

Measured memory_bytes: 27776
line = input()
if "C" in line and "F" in line:
    if line.index("C") < line.index("F"):
        print('Yes')
    elif line.index("C") > line.index("F"):        
        line1 = line[line.index("C"):]
        
        if "F" in line1:
            print('Yes')
        else:
            print('No')
    else:
        print('No')    
else:
    print('No')

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define loop(i, x, n) for (int i = (x); i < (n); i++)
#define all(v) (v).begin(), (v).end()
#define int long long
using namespace std;
const int MOD = 1e9 + 7;
const int INF = 1e10;
template<typename T> void cmax(T &a, T b) { a = max(a, b); }
template<typename T> void cmin(T &a, T b) { a = min(a, b); }

signed main() {
  int n;
  cin >> n;
  int ans = INF;
  loop(a, 1, n) {
    int b = n - a;
    string s, t;
    s = to_string(a);
    t = to_string(b);
    int tmp = 0;
    rep(i, s.size()) tmp += s[i] - '0';
    rep(i, t.size()) tmp += t[i] - '0';
    cmin(ans, tmp);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (long long i = 0; i < (n); ++i)
const int INF = 2147483647;//int max
const long long int MOD = 1000000007;
using namespace std;
using ll = long long;
using P = pair<int,int>;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

int main() {
    ll n;
    cin >> n;
    ll sum = 0;
    for(int i = 1;i<=n;i++){
        if(i%3 != 0 && i%5 != 0)sum += i;
    }
    cout << sum << endl;
    return 0;
}
/*
やっほい！
　　　　　　　やほほい！
　　　　+　　 　*
　　　 ∧∧　　. ∧∞∧　*
*　ヽ(=´ω｀)人(´ω｀*)ﾉ
　.～（ O x.） （ 　 O)～　+
。*　 　∪　　　　∪
*/

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

using namespace std;
using ll = long long;

#define INF (1LL << 60)
#define MOD 1000000007

#define REP(i,m,n) for(ll (i)=(m),i##_len=(n);(i)<(i##_len);++(i))
#define FORR(i,v) for(auto (i):v)
#define ALL(x) (x).begin(), (x).end()
#define _PR(x) cout << (x) << endl
#define _PS(x) cout << (x) << " "
#define SZ(x) ((int)(x).size())
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define pb push_back

int main()
{
    ll N, K;
    cin >> N >> K;
    ll L = (N-1) * (N-2) /2;
    ll c = L;
    if(K > L) _PR(-1);
    else {
        _PR(N-1+L-K);
        REP(i,2,N+1) cout << 1 << " " << i << endl;
        REP(i,2,N) {
            REP(j,i+1,N+1) {
                if(c > K) cout << i << " " << j << endl;
                --c;
            }
        }
    }

    return 0;
}

/*



*/

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

int main(){
    int n;
    std::cin>>n;
    std::vector<std::vector<int>> h(n,std::vector<int>(3));
    for (int i = 0; i < n; ++i) {
        std::cin>>h[i][0]>>h[i][1]>>h[i][2];
    }
    std::vector<std::vector<long long>> cost(n,std::vector<long long>(3,0));

    cost[0][0]=h[0][0];
    cost[0][1]=h[0][1];
    cost[0][2]=h[0][2];
    for (int i = 1; i < n; ++i) {
        for (int j = 0; j < 3; ++j) {
            for (int k = 0; k < 3; ++k) {
                if(j==k)continue;
                cost[i][j]=std::max(cost[i][j],cost[i-1][k]+h[i][j]);
            }
        }
    }
    std::cout<<std::max({cost[n-1][0],cost[n-1][1],cost[n-1][2]})<<std::endl;
    return 0;
}

Measured memory_bytes: 11264
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
using namespace std;
using ll = long long;
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 = 1e9;
const ll MOD = 1e9 + 7;


int main(){
    int n;
    cin >> n;
    set<string> st;
    rep(i, n){
        string s;
        cin >> s;
        st.insert(s);
    }

    cout << st.size() << endl;
}

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

int main(){
    int n, k;
    cin >> n >> k;
    int h[n+1];
    rep(i,n) cin >> h[i+1]; 
    vector<int> dp(n+1,INF);
    dp[1] = 0; dp[2] = abs(h[2]-h[1]);
    for(int i = 3; i <= n; i++){
        for(int j = 1; (i-j >= 1) && j <= k; j++){
            dp[i] = min(dp[i],dp[i-j]+abs(h[i]-h[i-j]));
        }
    }
    cout << dp[n] << endl;
    return 0;
}

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

int main()
{
	int N,A;
	cin >> N;
	cin >> A;

	int amari;
	amari = N % 500;

	if (amari == 0 || amari <= A)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>
#include <map>
#include <iomanip>
#include <set>
#include <ctime>
#include <tuple>
#include <bitset>
#include <assert.h>
#include <deque>
using namespace std;

/*
using PAIR = pair<string, int>;
sort(sp.begin(), sp.end(), [](PAIR l, PAIR r){
        return l.first<r.first || (l.first==r.first && l.second > r.second);
        });
*/

typedef long long ll;

#define fi first
#define se second
#define rep(i, n) for (ll i = 0; i < n; i++)
#define debugA() cerr << "AAAAA" << endl
#define debug_() cerr << "-------------" << endl
#define debug(x) cerr << #x << ": " << x << endl
#define debug_vec(v)                   \
    for (int i = 0; i < v.size(); i++) \
    {                                  \
        cout << v[i] << " ";           \
    }                                  \
    cout << endl;

using Graph = vector<vector<int>>;
using P = pair<int, int>;

int main()
{
    ll h, w;
    cin >> h >> w;
    if (h == 1 || w == 1)
    {
        cout << 1 << endl;
        return 0;
    }
    cout << (h * w + 1) / 2 << endl;

    return 0;
}


Measured memory_bytes: 256
//#include "stdc++.h"
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <queue>
//#include "my_gettime.hpp"
//#include "my_random.hpp"
//#include "my_util.hpp"
//using namespace std;

struct Edge{
	Edge(int f, int s, int w){first = f; second = s; weight = w;};
	int first;
	int second;
	int weight;
};

struct NodeP{
	NodeP(){};
	NodeP(int i, int p, int w){id = i; prev = p; weight = w;}
	int id;
	int prev;
	int weight;
	bool operator<(const NodeP & inRhs) const{ return weight < inRhs.weight; }
	bool operator>(const NodeP & inRhs) const{ return weight > inRhs.weight; }
};

#define INF (1<<30)
class Graph{
public:
	Graph(int numnodes);
	//~Graph();
	void addEdge(Edge a);
	void addEdge_nonDirect(Edge e);
	std::vector<NodeP> dijkstra(int start);
	int numNodes;
	//Edge *adj;
	std::vector < std::vector<Edge> > adj;
};
Graph::Graph(int n){
	numNodes = n;
	//adj = (Edge *)malloc(sizeof(Edge)*n*n);
	adj.resize(n);
}
void Graph::addEdge(Edge e){
	//adj[ e.first * numNodes + e.second ] = e;
	adj[e.first].push_back(e);
}
void Graph::addEdge_nonDirect(Edge e){
	adj[e.first].push_back(e);
	Edge e2 = e;
	e2.first = e.second;
	e2.second = e.first;
	adj[e2.first].push_back(e2);
}
std::vector<NodeP> Graph::dijkstra(int start){
	//using P = pair<int , int>;
	int *cost = (int *)malloc(sizeof(int)*numNodes);
	char *flag = (char *)malloc(sizeof(char)*numNodes);
	for(int i=0;i<numNodes;i++) flag[i] = 0;
	for(int i=0;i<numNodes;i++) cost[i] = INF;
	cost[start]=0;
	std::priority_queue < NodeP ,std::vector<NodeP>, std::greater<NodeP> > Q;
	Q.push(NodeP(start,-1, 0));
	std::vector <NodeP> nodeps(numNodes);

	while( !Q.empty() ){
		NodeP node = Q.top();
		Q.pop();
		if( flag[node.id] == 1 ) continue;
		flag[node.id] = 1;
		cost[node.id] = node.weight;

		nodeps[node.id] = node;

		typedef std::vector<Edge>::iterator ITR;
		for( ITR itr = adj[node.id].begin(); itr !=adj[node.id].end(); itr++ ){
			int dis = node.weight + itr->weight;
			if( cost[itr->second] > dis ){
				Q.push(NodeP(itr->second, node.id, dis));
			}
		}

	}

	free(cost);
	free(flag);

	return nodeps;
}

int main(int argc ,char **argv){
	using namespace std;

	int numNodes;
	cin >> numNodes;

	Graph g(numNodes);

	for(int i=0;i<numNodes;i++){
		int nodeid, numedge;
		cin >> nodeid >> numedge;
		for(int j=0;j<numedge;j++){
			int target, weight;
			cin >> target >> weight;
		//	cout<< nodeid<<" "<<target<<" "<<weight<<endl;
			g.addEdge(Edge(nodeid,target,weight));
		}
	}
	vector<NodeP> nodeps = g.dijkstra(0);
	typedef std::vector<NodeP>::iterator ITR;
	for( ITR itr = nodeps.begin(); itr !=nodeps.end(); itr++ ){
		printf("%d %d\n",/*itr->prev,*/itr->id,itr->weight);
	}
	return 0;
}

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

#define REP(i,num) for(int i=0;i<(num);++i)
#define LOOP(i) while(i--)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto pitr=c.begin();pitr!=c.end();++pitr){cout<<*pitr;if(next(pitr,1)!=c.end())cout<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

using namespace std;
using ll = long long;

constexpr ll atcoder_mod = 1e9+7;

template<typename T=int>
T in(){T x; cin >> x; return (x);}
template<typename T=int,typename C=vector<T>>
C vecin(int N){C x(N);REP(i,N){x[i]=in<T>();}return move(x);}

void vout(){cout << endl;}
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){cout << ' ' << h;vout(forward<Tail>(t)...);}
void out(){cout << endl;}
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){cout << h;vout(forward<Tail>(t)...);}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(10);
	
	int N=in();
	map<string,int> M;
	REP(i,N){
		M[in<string>()]++;
	}
	
	out(M.size());
	return 0;
}


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

using namespace std;

int main() {

	// freopen("input.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);

	long long n;
	cin >> n;
	string ans;
	while (n) {
		ans = string(1, 'a' + (n - 1) % 26) + ans;
		n = (n - 1) / 26;
	}
	cout << ans << '\n';
	return 0; 
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long int
#define rep(i, n) for(int i = 0; i < n; i++)
#define sort(v) sort((v).begin(), (v).end())
using vi = vector<int>;
const int MOD = 1e9+7;

bool IsPrime(int num){
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false; // 偶数はあらかじめ除く
    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2) { if (num % i == 0) return false; }
    return true;
}

int main() {
	char a,b;
  	cin >> a >>b;
  	char ans;
  	if(a == 'H' && b == 'H') ans = 'H';
  	else if(a == 'H' && b == 'D') ans = 'D';
  	else if(a == 'D' && b == 'H') ans = 'D';	
  	else if(a == 'D' && b == 'D') ans = 'H';
	cout << ans << endl;
}

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

int main(){
  string s,t;
  cin >> s >> t;
  int a,b;
  cin >> a >> b;
  string u;
  cin >> u;
  
  if(u == s){
    cout << a-1 << " " << b << endl;
  }
  else{
    cout << a << " " << b-1 << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define oo 666666666
#define ll long long
#define ld long double

int n;
ll DP[404][404];
ll pf[404];
ll A[404];

ll solve(int l, int r)
{
    if(l>=r)return 0;
    if(l+1==r)return A[l]+A[r];
    if(DP[l][r]!=0)return DP[l][r];

    DP[l][r]=LLONG_MAX;

    for(int k=l; k<=r; k++)
        DP[l][r]=min(DP[l][r], pf[k]-pf[l-1] + pf[r]-pf[k] + solve(l,k) + solve(k+1,r));

    return DP[l][r];
}

int main()
{
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    cin>>n;
    for(int i=1; i<=n; i++)
        cin>>A[i], pf[i]=pf[i-1]+A[i];

    cout<<solve(1,n);
}


Measured memory_bytes: 1536
N=gets.chomp.to_i
a = gets.chomp.split(' ').map{|n| n.to_i}

jous=[1,
 2,
 4,
 8,
 16,
 32,
 64,
 128,
 256,
 512,
 1024,
 2048,
 4096,
 8192,
 16384,
 32768,
 65536,
 131072,
 262144,
 524288,
 1048576,
 2097152,
 4194304,
 8388608,
 16777216,
 33554432,
 67108864,
 134217728,
 268435456,
 536870912,
 1073741824,
 2147483648,
 4294967296].reverse

a.sort!{|a,b| b<=>a}
answer = "Yes"

jous.each do |j|
  if a[0] >= j
    if a.map{|num| num&j}.reject{|num| num.zero?}.count%2 !=0
      answer = "No"
    end
  end
end

puts answer

Measured memory_bytes: 25816
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
const ld eps = 1e-9;

//// < "d:\d_download\visual studio 2015\projects\programing_contest_c++\debug\a.txt" > "d:\d_download\visual studio 2015\projects\programing_contest_c++\debug\b.txt"


int main() {
	int h1, h2, k1, k2, a, b, c, d; cin >> h1 >> k1 >> h2 >> k2 >> a >> b >> c >> d;
	int score1 = h1*a + (h1 / 10)*c + k1*b + (k1 / 20)*d;
	int score2 = h2*a + (h2 / 10)*c + k2*b + (k2 / 20)*d;
	if (score1 > score2)cout << "hiroshi" << endl;
	else if (score1 == score2)cout << "even" << endl;
	else cout << "kenjiro" << endl;
	return 0;
}

Measured memory_bytes: 3088
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;

int n;
vector<long long int> a;
long long int ans;

int main(){
	scanf("%d", &n);
	for(int i=0; i<3*n; ++i){
		long long int t;
		scanf("%lld", &t);
		a.push_back(t);
	}
	sort(a.begin(), a.end());
	for(int i=0; i<n; ++i) ans += a[n+2*i];
	printf("%lld\n", ans);
}

Measured memory_bytes: 6512
#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<array>
#include<map>
#include<iomanip>
#include<assert.h>
#include<bitset>
#include<stack>
#include<memory>
using namespace std;
using namespace std::chrono;
typedef long long int llint;
typedef double lldo;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase
/*cout<<fixed<<setprecision(20);cin.tie(0);ios::sync_with_stdio(false);*/
const llint mod=998244353;
const llint big=2.19e15+1;
const long double pai=3.141592653589793238462643383279502884197;
const long double eps=1e-15;
template <class T,class U>bool mineq(T& a,U b){if(a>b){a=b;return true;}return false;}
template <class T,class U>bool maxeq(T& a,U b){if(a<b){a=b;return true;}return false;}
llint gcd(llint a,llint b){if(a%b==0){return b;}else return gcd(b,a%b);}
llint lcm(llint a,llint b){if(a==0){return b;}return a/gcd(a,b)*b;}
template<class T> void SO(T& ve){sort(ve.begin(),ve.end());}
template<class T> void REV(T& ve){reverse(ve.begin(),ve.end());}
template<class T>llint LBI(vector<T>&ar,T in){return lower_bound(ar.begin(),ar.end(),in)-ar.begin();}
template<class T>llint UBI(vector<T>&ar,T in){return upper_bound(ar.begin(),ar.end(),in)-ar.begin();}
int main(void){
	llint n,i,ans=1,gen=0;cin>>n;
	string S;cin>>S;
	int R=0,G=0,B=0;
	for(auto it:S){
		int now;
		if(it=='R'){R++;now=R;}
		if(it=='G'){G++;now=G;}
		if(it=='B'){B++;now=B;}
		int dai=max(R,max(G,B)),syo=min(R,min(G,B));
		int chu=R+G+B-dai-syo;
		if(now==syo){ans*=chu-(now-1);ans%=mod;}
		else if(now==chu){ans*=dai-(now-1);ans%=mod;}
	}
	for(i=1;i<=n;i++){ans*=i;ans%=mod;}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 900
sq = []
1.upto(Math.sqrt(2**15).floor) do |i|
    sq.push(i*i)
end
dp = Array.new(5).map{Array.new(2**15+1,0)}
dp[0][0] = dp[1][0] = dp[2][0] = dp[3][0] = 1
1.upto(sq.size+1) do |i|
    1.upto(4) do |j|
        (i**2).upto(2**15) do |k|
            dp[j][k] += dp[j-1][k-i**2]
        end
    end
end
loop do
    n = gets.to_i
    break if n == 0
    puts dp[4][n]
end

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

int main()
{
	int n; cin >> n;
	string s; cin >> s;

	int pointer = 0;
	int need_left = 0;
	
	for (int i = 0; i < n; i++) {
		if (s[i] == '(') pointer++;
		else {
			if (pointer == 0) need_left++;
			else pointer--;
		}
	}

	int need_right = pointer;

	string ans = "";
	string tmp = "";
	for (int i = 0; i < need_left; i++) {
		tmp += '(';
	}
	ans += tmp;
	ans += s;
	for (int i = 0; i < need_right; i++) {
		ans += ')';
	}		

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

Measured memory_bytes: 256
import math

D, G = [int(x) for x in input().split()]

P = [0] * (D+1)
C = [0] * (D+1)

for i in range(D):
    p, c = [int(x) for x in input().split()]
    P[i] = p
    C[i] = c

INF = 10**10

def score_cnt(i):
    ret_score = 0
    ret_cnt = 0
    for j in range(D):
        if (1 << j) & i:
            ret_score += C[j]
            ret_score += (j + 1) * 100 *P[j]
            ret_cnt += P[j]
    return ret_score, ret_cnt


ret = INF
for i in range(2 ** D):
    score,cnt = score_cnt(i)
    # print("score:{},cnt:{}".format(score, cnt))
    for j in range(D):
        if score >= G:
            ret = min(ret, cnt)
        else:
            if (1 << j) & i:
                continue
            rest = G - score

            if (j+1)*100 * P[j] >= rest:
                add = math.ceil(rest / ((j+1)*100))
                ret = min(ret, cnt + add)



print(ret)


Measured memory_bytes: 3064
import math
import random
from operator import itemgetter
import re
import sys
from itertools import accumulate
from collections import defaultdict
from collections import deque
from bisect import bisect_left,bisect
from heapq import heappop,heappush
from fractions import gcd
from copy import deepcopy
import functools
N = int(input())
P = [int(i) for i in input().split()]
Q = [int(i) for i in input().split()]
ans = 0
for i in range(N):
    ans += (Q[i]-P[i])*math.factorial(N-1-i)
    for j in range(N-1-i):
        if Q[i+j+1] >Q[i]:
             Q[i+j+1] -= 1
        if P[i+j+1] >P[i]:
             P[i+j+1] -= 1
print(abs(ans))


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

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

using ll = long long;
using P = pair<int,int>;

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int INF = 1<<30;
const ll mod = 1000000007LL;

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

int main(){
    int H,W;
    cin>>H>>W;
    vector<vector<int>> dp(10,vector<int>(10,INF));
    rep(i,10){
        rep(j,10) cin>>dp[i][j];
    }
    map<int,int> A;
    rep(i,H){
        rep(i,W) {
            int x;
            cin>>x;
            A[x]++;
        }
    }
    rep(k,10){
        rep(i,10){
            rep(j,10) chmin(dp[i][j],dp[i][k]+dp[k][j]);
        }
    }
    int ans = 0;
    rep(i,10){
        ans+=A[i]*dp[i][1];
    }
    cout<<ans<<endl;
}

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

using namespace std;

using ll = long long;

const ll INF = 1LL << 50;

//const ll INF = MAX_LONG_LONG;

void bellmanford_k(int* a, int* b, int* c, ll* d, int m, int n){
  int i;
  d[0] = 0;
  for (i=1;i<n;i++){
    d[i] = INF;
  }

  int loop;
  for (loop = 0; loop < n - 1; loop++){
    for (i = 0; i < m; i++){
      if (d[a[i] - 1] == INF) continue;
      //cout << "i = " << i << endl;

      if(d[a[i] - 1] + c[i] < d[b[i] - 1]){
        /*cout << "Updated. a[i]-1 = " << a[i] - 1 << ", b[i] - 1 = " <<
            b[i] - 1 << ", c[i] = " << c[i] << ", d[a[i] - 1] = " << d[a[i] - 1] <<
            ", d[b[i] - 1] = " << d[b[i] - 1] << endl;*/
        d[b[i] - 1] = d[a[i] - 1] + c[i];
      }
    }
  }
  return;
} 

void bellmanford_b(int* a, int* b, int* c, ll* d, int m, int n, bool* negative){
  int i;

  int loop;
  for (loop = 0; loop < n; loop++){
    for (i = 0; i < m; i++){
      if (d[a[i] - 1] == INF) continue;

      //cout << "i = " << i << endl;

      if(d[a[i] - 1] + c[i] < d[b[i] - 1]){
        /*
        cout << "Updated. a[i]-1 = " << a[i] - 1 << ", b[i] - 1 = " <<
            b[i] - 1 << ", c[i] = " << c[i] << ", d[a[i] - 1] = " << d[a[i] - 1] <<
            ", d[b[i] - 1] = " << d[b[i] - 1] << endl;
        d[b[i] - 1] = d[a[i] - 1] + c[i];
        */
        negative[b[i] - 1] = true;
      }

      if(negative[a[i] - 1]) negative[b[i] - 1] = true;
    }
  }
  return;
}

int main (void){
  int n, m;
  cin >> n >> m;
  cin.ignore();

  int a[m], b[m], c[m];
  int i;

  // 最良スコア→最短経路
  for (i=0;i<m;i++){
    cin >> a[i] >> b[i] >> c[i];
    cin.ignore();
    c[i] = -c[i];
  }

  ll d[n];

  bellmanford_k(a, b, c, d, m, n);

  ll ans = -d[n-1];

  bool negative[n];
  for(i = 0; i < n; i++) negative[i] = false;

  //cout << "b" << endl;
  bellmanford_b(a, b, c, d, m, n, negative);

  if(negative[n-1]) cout << "inf" << endl;
  else cout << ans << endl;

  return 0;
}


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

int main() {
  int H, W;
  cin >> H >> W;

   //0行目 S_above
  string S_above = "..";
  for (int i = 0; i < W; i++)
    S_above += '.';
  
  //1～H行目
  string S, S_below;
  cin >> S;
  S = '.' + S + '.';
  for (int i = 1; i < H; i++) {    //　iは行番号 最下行は別に処理
    cin >> S_below;
    S_below = '.' + S_below + '.';
    for (int j = 1; j < W+1; j++) { //　行の処理　jは文字番号
      int k = 0; // kは#の数
      if (S.at(j) == '#')
        cout << '#';
      else {
        if (S_above.at(j-1) == '#')
          k+=1;
        if (S_above.at(j) == '#')
          k+=1;
        if (S_above.at(j+1) == '#')
          k+=1;
        if (S.at(j-1) =='#')
          k+=1;
        if (S.at(j+1) =='#')
          k+=1;
        if (S_below.at(j-1) =='#')
          k+=1;
        if (S_below.at(j) =='#')
          k+=1;
        if (S_below.at(j+1) =='#')
          k+=1;
      cout << k;
      }
    }                 // 各行ごとの処理おわり
    cout << endl;
    S_above = S;
    S = S_below;
  }
   // H-1行目まで処理おわり
  
   // H行目の処理
  for (int j = 1; j < W+1; j++) { //　jは文字番号
  int k = 0; // kは#の数
    if (S.at(j) == '#')
      cout << '#';
    else {
      if (S_above.at(j-1) == '#')
        k+=1;
      if (S_above.at(j) == '#')
        k+=1;
      if (S_above.at(j+1) == '#')
        k+=1;
      if (S.at(j-1) =='#')
        k+=1;
      if (S.at(j+1) =='#')
        k+=1;
      cout << k;
    }
  }
  cout << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define MAX 300003
#define MOD 1000000007
#define INF 1000000000000000000
using Graph=vector<vector<int>>;

int main(){
  int N,M;
  cin>>N>>M;
  vector<vector<int>> A(N,vector<int>(M));
  for(int i=0;i<N;i++){
    for(int j=0;j<M;j++){
      cin>>A.at(i).at(j);
    }
  }

  vector<int> select(N,0);
  vector<bool> done(M,true);
  int j=1;
  int ans=N;
  while(j<M){
    vector<int> count(M,0);
    for(int i=0;i<N;i++){
      if(select.at(i)==M){
        continue;
      }
      count.at(A.at(i).at(select.at(i))-1)++;
    }
    int k=0;
    while(done.at(k)==false){
      k++;
    }
    for(int i=0;i<M;i++){
      if(done.at(i)==false){
        continue;
      }
      if(count.at(i)>count.at(k)){
        k=i;
      }
    }
    ans=min(ans,count.at(k));
    done.at(k)=false;
    for(int i=0;i<N;i++){
      if(select.at(i)==M){
        continue;
      }
      while(done.at(A.at(i).at(select.at(i))-1)==false){
        select.at(i)++;
        if(select.at(i)==M){
          break;
        }
      }
    }
    j++;
  }

  cout<<ans<<endl;
}


Measured memory_bytes: 640
#include <stdio.h>

int main() {
	
	int N=0;
	scanf("%d", &N);
	if(N%N==0&N%2==0){
	printf("%d\n",N);
}
	if(N%2!=0){
	N*2;
	printf("%d\n", N*2);
}
	
	return 0;
}

Measured memory_bytes: 128
#include <stdio.h>

int main(void)
{
    unsigned int h, m, s;
    h = 0; m = 0; s = 0;
    
    scanf("%d", &s);
    if (s < 86400)
    {
        h = s / 3600;
        m = s % 3600 / 60;
        s = s % 3600 % 60;
        printf("%d:%d:%d\n", h, m, s);
    }
}


Measured memory_bytes: 2148
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(int i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(int i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(int i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define uniq(x) (x).erase(unique((x).begin(), (x).end()), (x).end())

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    const ll mod = 1e9 + 7;
    int n;
    cin >> n;
    // NG: AGC, ACG, GAC, A*GC, AG*C
    vector<map<string, ll>> dp(n, map<string, ll>());
    char s[] = {'A', 'C', 'G', 'T'};
    vector<string> sk;
    ll ans = 0;
    rep(i, 4) {
        rep(ii, 4) {
            rep(iii, 4) {
                sk.push_back({s[i], s[ii], s[iii]});
            }
        }
    }
    rep(i, sz(sk)) {
        if ((sk[i] == "AGC") || (sk[i] == "ACG") || (sk[i] == "GAC")) {
            dp[2][sk[i]] = 0;
        }
        else {
            dp[2][sk[i]] = 1;
        }
    }
    reps(i, 3, n) {
        for (auto x : dp[i - 1]) {
            set<char> kh;
            rep(ii, 4) kh.insert(s[ii]);
            if ((x.first[1] == 'A') && (x.first[2] == 'G')) kh.erase('C');
            if ((x.first[1] == 'A') && (x.first[2] == 'C')) kh.erase('G');
            if ((x.first[1] == 'G') && (x.first[2] == 'A')) kh.erase('C');
            if ((x.first[0] == 'A') && (x.first[2] == 'G')) kh.erase('C');
            if ((x.first[0] == 'A') && (x.first[1] == 'G')) kh.erase('C');
            for (auto y : kh) {
                string ns = {x.first[1], x.first[2], y};
                dp[i][ns] = (dp[i][ns] + x.second) % mod;
            }
        }
    }
    for (auto x : dp[n - 1]) {
        ans = (ans + x.second) % mod;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 896
#include<cstdio>
#include<algorithm>
#define fo(i,a,b) for(i=a;i<=b;i++)
using namespace std;
typedef long long ll;
typedef double db;
const int maxn=200+10,mo=998244353;
const db eps=1e-6;
int two[maxn],x[maxn],y[maxn];
int i,j,k,l,t,n,m,ans;
bool check(int i,int j,int k){
	if ((y[j]-y[i])*(x[k]-x[i])==(y[k]-y[i])*(x[j]-x[i])) return 1;else return 0;
}
int main(){
	scanf("%d",&n);
	two[0]=1;
	fo(i,1,n) two[i]=(ll)two[i-1]*2%mo;
	fo(i,1,n) scanf("%d%d",&x[i],&y[i]);
	ans=(two[n]-n-1)%mo;
	fo(i,1,n-1)
		fo(j,i+1,n){
			t=0;
			fo(k,j+1,n)
				if (check(i,j,k)) t++;
			(ans-=two[t])%=mo;
		}
	(ans+=mo)%=mo;
	printf("%d\n",ans);
}

Measured memory_bytes: 128
#include <cstdio>
using namespace std;

int main()
{
	int x, y;
	scanf("%d", &x);
	scanf("%d", &y);
	if (x + y < 10)
	{
		printf("%d\n", x + y);
	}
	else
	{
		printf("%s\n", "error");
	}
}

Measured memory_bytes: 128
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<tuple>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#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 Per(i,sta,n) for(int i=n-1;i>=sta;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 long double ld;
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;

template <typename T>
struct SegmentTree{
  using F = function<T(T,T)>;
  int n;
  F f;//二項演算
  T ti;//単位元
  vector<T> dat;

  SegmentTree(){}
  SegmentTree(F f,T ti):f(f),ti(ti){}

  void init(int n_){//sizeがn_のsegtreeを作る
    n=1;
    while(n<n_) n<<=1;
    dat.assign(n<<1,ti);
  }

  void build(const vector<T> &v){//vによってsegtreeをbuildする
    int n_=v.size();
    init(n_);
    for(int i=0;i<n_;i++) dat[n+i]=v[i];
    for(int i=n-1;i;i--)
      dat[i]=f(dat[(i<<1)|0],dat[(i<<1)|1]);
  }

  void set_val(int k,T x){//k番目をxにする
    dat[k+=n]=x;
    while(k>>=1)
      dat[k]=f(dat[(k<<1)|0],dat[(k<<1)|1]);
  }

  T query(int a,int b){//区間[a,b)に対しFを適応した値を返す
    if(a>=b) return ti;
    T vl=ti,vr=ti;
    for(int l=a+n,r=b+n;l<r;l>>=1,r>>=1) {
      if(l&1) vl=f(vl,dat[l++]);
      if(r&1) vr=f(dat[--r],vr);
    }
    return f(vl,vr);
  }

  template<typename C>
  int find(int st,C &check,T &acc,int k,int l,int r){//
    if(l+1==r){
      acc=f(acc,dat[k]);
      return check(acc)?k-n:-1;
    }
    int m=(l+r)>>1;
    if(m<=st) return find(st,check,acc,(k<<1)|1,m,r);
    if(st<=l&&!check(f(acc,dat[k]))){
      acc=f(acc,dat[k]);
      return -1;
    }
    int vl=find(st,check,acc,(k<<1)|0,l,m);
    if(~vl) return vl;
    return find(st,check,acc,(k<<1)|1,m,r);
  }

  template<typename C>
  int find(int st,C &check){
    T acc=ti;
    return find(st,check,acc,1,0,n);
  }
};

int n,m;
vector<PP> sec;

void solve(){
  cin >> n >> m;
  sec.push_back(PP(m+4,P(0,0)));
  rep(i,n){
    int l,r;cin >> l >> r;
    sec.push_back(PP(r-l+1,P(l,r+1)));
  }
  sort(sec.begin(),sec.end());
  auto f=[](int a,int b){return a+b;};
  SegmentTree<int> seg(f,0);
  seg.init(m+2);
  int k=0;
  Rep(i,1,m+1){
    while(sec[k].first==i-1){
      int l,r;l=sec[k].second.first;r=sec[k].second.second;
      //cout << l << " " << r << endl;
      seg.set_val(l,seg.query(l,l+1)+1);
      seg.set_val(r,seg.query(r,r+1)-1);
      k++;
    }
    int ans=n-k;
    for(int d=i;d<=m;d+=i){
      ans+=seg.query(0,d+1);
    }
    cout << ans << endl;
  }
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(50);
    solve();
}

Measured memory_bytes: 8560
#include <iostream>
#include <map>
#include <set>
#include <vector>
#define REP(i, n) for (int i = 0; i < (n); i++)
using namespace std;

void solve(long long s){
    int count = 0;
    if (s == 1) count = 0;
    else if (s == 2) count = 0;
    else {
        while (s != 4) {
            if (s % 2) s = 3 * s + 1;
            else s /= 2;
            count++;
        }
    }
    cout << count + 4<< '\n';
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    long long s;
    scanf("%lld",&s);
    solve(s);
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define rep2(i, s, n) for(int i=s; i<(n); ++i)

using namespace std;

typedef long long ll;

static const int INTINF = (2147483647);
static const ll LLINF = (9223372036854775807);
static const int MAX = 100001;
static const ll MOD = 1000000007;

//--global--//



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

int main(int argc, const char * argv[]) {
    //提出時、消す----//
    //--------------//
    
    string str;
    int res = 0;
    cin >> str;
    string a;
    string b;
    a = str.substr(0, str.size()/2);
    b = str.substr(str.size()/2 + str.size() % 2, str.size());
    reverse(b.begin(), b.end());

    rep(i, a.size()){
        if(a[i] != b[i]) res++;
    }
    cout << res << endl;
    return 0;

}


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

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

int dp[110][110];
int dp2[110][110];

int main(){
	int n,m,L,K,A,H;
	while(cin>>n>>m>>L>>K>>A>>H,n){
		rep(i,n) rep(j,n) dp[i][j] = dp2[i][j] = 1e9;
		vector<int> ll(L);
		rep(i,L) cin>>ll[i];
		ll.push_back(A);
		ll.push_back(H);
		L+=2;
		sort(ll.begin(), ll.end());

		rep(i,K){
			int a,b,c;
			cin>>a>>b>>c;
			dp[a][b] = dp[b][a] = c;
		}
		rep(i,n) dp[i][i] = 0;

		rep(k,n) rep(i,n) rep(j,n) dp[i][j] = min(dp[i][j], dp[i][k] + dp[k][j]);

		rep(i,L){
			rep(j,L){
				dp2[i][j] = (dp[ll[i]][ll[j]] > m ? 1e9: dp[ll[i]][ll[j]]);
			}
		}
		rep(i,L) dp2[i][i] = 0;

		rep(k,L) rep(i,L) rep(j,L) dp2[i][j] = min(dp2[i][j], dp2[i][k] + dp2[k][j]);

		int a,h;
		rep(i,L){
			if(ll[i]==A) a=i;
			if(ll[i]==H) h=i;
		}
		if(dp2[h][a]>1e8){
			cout<<"Help!"<<endl;
		}
		else{
			int t = dp2[h][a];
			if(t < m) cout<<t<<endl;
			else cout<<t+(t-m)<<endl;
		}
	}
}

Measured memory_bytes: 3228
#include <cstdio>
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <map>
#include <set>

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

#define reps(i, f, n) for (int i = (f); i < (int)(n); i++)
#define rep(i, n) reps(i, 0, n)

const int INF = 1111111111;
const double EPS = 1e-9;

using namespace std;

const int N = 222222;
int n;
int a[N];

void init()
{
	cin >> n;
	rep(i, n) cin >> a[i];
}

void solve()
{
	int all = 0;
	rep(i, n) all ^= a[i];

	rep(i, n)
	{
		cout << (all ^ a[i]) << endl;
	}
}

int main()
{
	init();
	solve();
}


Measured memory_bytes: 3840
#include <iostream>

 

using namespace std;

 

int main() 
{
    int a , b , g;
  
     for( g=1; g<=3000; g++)
    {
          cin >> a >> b;
    if (a== 0 && b== 0){
    break;
    }
    
    if (a > b)
    {
    a=a+b;
    b=a-b;
    a=a-b;
    }
    cout << a << " " << b << endl;
   
    }

    
    
}


Measured memory_bytes: 3072
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
typedef long long ll;
template<class T>inline bool chmax(T &a, const T &b){if(a < b){a = b; return 1;}return 0;}
template<class T>inline bool chmin(T &a, const T &b){if(a > b){a = b; return 1;}return 0;}
int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int A1, A2, A3;
  cin >> A1 >> A2 >> A3;
  if(A1+A2+A3 >= 22){
    cout << "bust" << endl;
  }else{
    cout << "win" << endl;
  }
}


Measured memory_bytes: 256
#include <set>
#include <cmath>
#include <string>
#include <cstring>
#include <vector>
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <queue>
#include <map>
#define MAXN 10010
#define LL long long
#define INF 0x7fffffff
using namespace std;

int main(){
	string s1;
	cin>>s1;
	string s="";
	//cout<<s1<<endl;
	for (int i=0;i<s1.length();i++){
		//cout<<s1[i]<<endl;
		//cout<<(i&1)<<endl;
		if ((i&1)==0){
			//cout<<i<<endl;
			s+=s1[i];
			//cout<<s1[i]<<endl;
		}
	}
	cout<<s<<endl;
	return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <iomanip>
#include <string>
#include <cstdlib>

using namespace std;  //このネームスペースを使う

int main(){
  int A,B,X;
  int max;
  cin >> A >> B >> X ;
  
  if(A-X > 0 || X > A+B){
    cout << "NO" << endl;
  }
  else{
  	cout << "YES" << endl;
  }
  return 0;
}



Measured memory_bytes: 256
sx,sy,tx,ty = map(int,input().rstrip().split())
tmp_x = sx
tmp_y = sy

def print_route(sx,sy,tx,ty,goback,route):
    if goback == 'go':
        for i in range(tx-sx):
            route += 'R'
        for j in range(ty-sy):
            route += 'U'
    elif goback == 'back':
        for i in range(tx-sx):
            route += 'L'
        for j in range(ty-sy):
            route += 'D'
    else:
        pass
    return route
    
route = ""
route = print_route(sx,sy,tx,ty,'go',route)
route = print_route(sx,sy,tx,ty,'back',route)
route += 'D'
route = print_route(sx,sy-1,tx+1,ty,'go',route)
route += 'LU'
route = print_route(sx-1,sy,tx,ty+1,'back',route)
route += 'R'
print(route)

Measured memory_bytes: 3064
n = gets.to_i
a = gets.split.map(&:to_i)
h = Hash.new(0)
a.each do |x|
  h[x] += 1
end
f = true
h.each do |k, v|
  if n.odd? && k == 0
    if v != 1
      f = false
      break
    end
  elsif v != 2
    f = false
    break
  end
end
MOD = 1_000_000_007
def mpow(n, p, mod)
  r = 1
  while p > 0
    r = r * n % mod if p & 1 == 1
    n = n * n % mod
    p >>= 1
  end
  r
end
puts (f ? mpow(2, n / 2, MOD) : 0)

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

using namespace std;

using ll = long long;

const double eps = 1e-10;
const int MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1ll<<50;

template<typename T>
void printv(const vector<T>& s) {
  for(int i=0;i<(int)(s.size());++i) {
    cout << s[i];
    if(i == (int)(s.size())-1) cout << endl;
    else cout << " ";
  }
}

int main () {
  cin.tie(0);
  cout << fixed << setprecision(10);
  int n, m; cin >> n >> m;
  vector<vector<char>> d(m, vector<char>(n));
  int cnt = 0;
  for(int i=0;i<m;++i) {
    for(int j=0;j<n;++j) {
      cin >> d[i][j];
      if(d[i][j] == 'W') cnt++;
    }
  }

  int mi = cnt, mipos = 0;
  for(int i=0;i<n;++i) {
    for(int j=0;j<m;++j) {
      if(d[j][i] == 'W') cnt--;
      else cnt++;
    }
    if(cnt < mi) {
      mi = cnt;
      mipos = i+1;
    }
  }

  cout << mipos << " " << mipos+1 << endl;
}



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


int k;

#define MAX 100002
long long int dp[MAX];

set<pair<int, int> > s;

int main() {
	cin >> k;
	memset(dp, -1, sizeof(dp));
	for (int i = 0; i < k; i++) {
		dp[i] = i;
	}
	int n = k;
	int sum = 0;
	while (k) {
		sum += k % 10;
		k /= 10;
	}
	k = n;
	dp[0] = sum;
	for (int i = 0; i < k; i++) {
		s.insert(make_pair(dp[i], i));
	}
	while (s.size()) {
		auto it = (*s.begin());
		s.erase(s.begin());
		int ich = it.second;
		int val = it.first;
		if (dp[ich] != val) {
			continue;
		}
		for (int j = 0; j < 10; j++) {
			int go = ich * 10 + j;
			go %= k;
			if (dp[go] > dp[ich] + j) {
				dp[go] = dp[ich] + j;
				s.insert(make_pair(dp[go],go));
			}
		}
	}
	cout << dp[0] << endl;
	//dp[(i*10+b)%k] 
	return 0;
}

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

#define FOR(i, a, b) for(long long int i=(a);i<=(b);i++)
#define RFOR(i, a, b) for(long long int i=(a);i>=(b);i--)
#define MOD 1000000007
#define INF 1000000000 //2000000000
#define LLINF 1000000000000000000 //9000000000000000000
#define PI 3.14159265358979

using namespace std;
typedef long long int ll;
typedef pair< long long int, long long  int> P;



int main(void) {
	
	while (1) {
		int N;
		int sx, lx, sy, ly;
		int n, d;
		int dp[450][450] = {};
		bool flag = true;

		cin >> N;
		if (N == 0) {
			break;
		}
		FOR(i, 0, 449) {
			FOR(t, 0, 449) {
				dp[i][t] = -1;
			}
		}

		dp[225][225] = 0;
		FOR(i, 1, N-1) {
			cin >> n >> d;
			FOR(t, 0, 449) {
				FOR(u, 0, 449) {
					if (dp[t][u] == n) {
						switch (d) {
						case 0:
							dp[t - 1][u] = i;
							break;
						case 1:
							dp[t][u + 1] = i;
							break;
						case 2:
							dp[t + 1][u] = i;
							break;
						case 3:
							dp[t][u - 1] = i;
							break;
						}
						goto end;
					}
				}
			}
		end:;
		}
		FOR(i, 0, 449) {
			FOR (t, 0, 449) {
				if (dp[i][t] != -1) {
					sx = i;
					flag = false;
					break;
				}
			}
			if (!flag) {
				break;
			}
		}
		flag = true;
		FOR(t, 0, 449) {
			FOR(i, 0, 449) {
				if (dp[i][t] != -1) {
					sy = t;
					flag = false;
					break;
				}
			}
			if (!flag) {
				break;
			}
		}
		flag = true;
		RFOR(t, 449, 0) {
			RFOR(i, 449, 0) {
				if (dp[i][t] != -1) {
					ly = t;
					flag = false;
					break;
				}
			}
			if (!flag) {
				break;
			}
		}
		flag = true;
		RFOR(i, 449, 0) {
			RFOR(t, 449, 0) {
				if (dp[i][t] != -1) {
					lx = i;
					flag = false;
					break;
				}
			}
			if (!flag) {
				break;
			}
		}
		//cout << sx << " " << lx << " " << sy << " " << ly << endl;
		cout << lx - sx + 1 << " " << ly - sy + 1 << endl;
	}

}


Measured memory_bytes: 3788
#include <vector>
#include <string>
#include <map>
#include <algorithm>
#include <queue>
#include <iostream>
#include <cmath>
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
typedef long long ll;
using namespace std;

/*  divisor(n)
    入力：整数 n
    出力：nのすべての約数
    計算量：O(√n)
*/
vector<long long> divisor(long long n) {
    vector<long long> ret;
    for (long long i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            ret.push_back(i);
            if (i * i != n) ret.push_back(n / i);
        }
    }
    // sort(ret.begin(), ret.end()); // 昇順に並べる
    return ret;
}

void solve(long long N){
    ll res = 0;
    for(int i = 1; i <= N; i++) { 
        res += (N - 1 ) / i;
    }
    cout << res << endl;
}

// Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long N;
    scanf("%lld",&N);
    solve(N);
    return 0;
}


Measured memory_bytes: 3668
n = int(input())
p = list(map(int,input().split()))
q = sorted(p)
ans = 0
for i in range(n):
  if p[i] != q[i]:
    ans += 1
if ans == 2:
  print('YES')
elif ans == 0:
  print('YES')
else:
  print('NO')


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

#define ll long long
#define vvi vector< vector<int> >
#define vi vector<int>
#define All(X) X.begin(),X.end()
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define pb push_back
#define pii pair<int,int>
#define mp make_pair
#define pi 3.14159265359
#define shosu(X) fixed << setprecision(X)
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

int main(){
	ll int a,b,c;
	cin >> a >> b >> c;
	if(a%2 == 0 || b%2 == 0 || c%2 == 0){
		cout << 0 << endl;
		return 0;
	}
	ll int ans;
	ans = b*c;
	ans = min(ans, a*b);
	ans = min(ans, a*c);
	cout << ans << endl;
}

Measured memory_bytes: 256
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define rep(i,n) for(ll i=0;i<(n);i++)
#define pll pair<ll,ll>
#define pq priority_queue
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define lb(c,x) distance(c.begin(),lower_bound(all(c),x))
#define ub(c,x) distance(c.begin(),upper_bound(all(c),x))

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;}

const ll INF=1e15;

int main(){
    ll x;
    cin >> x;
    ll n=x/200;
    cout << 10-n << endl;
    return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h> //AtCoder
#include <iostream> //Codeforces
#include <vector> //Codeforces

#define int long long
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repeq(i,a,b) for(int i=a;i<=b;i++)
#define Vi vector<int>
#define VVi vector<Vi>
#define Vs vector<string>
#define Vc vector<char>
#define cYES cout<<"YES"<<endl
#define cNO cout<<"NO"<<endl
#define cYes cout<<"Yes"<<endl
#define cNo cout<<"No"<<endl
#define cyes cout<<"yes"<<endl
#define cno cout<<"no"<<endl

using namespace std;
/****************************** START ******************************/

signed main(){
  int N,X,M;
  cin >> N >> X >> M;
  map<int,int> A,B;
  
  A[1] = X;
  int now = X;
  int start,end,last;
  int cnt = 1;
  int sum = 0;
  bool loop = false;
  
  rep(i,0,N){
    if(B[now]!=0){
      start = B[now];
      end = i+0;
      loop = 1;
      break;
    }
    B[now] = i+1;
    now = now*now%M;
  }
  
  repeq(i,2,200000){
    /*repeq(j,1,i-1){
      if (A[j] == A[i]){
        start = j;
        end = i - 1;
        loop = true;
        break;
      } else {
        if (j == i-1){
          A[i] = A[i-1] * A[i-1] % M;
        }
      }
    }*/
    A[i] = A[i-1] * A[i-1] % M;
    /*if (loop){
      break;
    }*/
  }
  
  int ans = 0;
  if (loop){
    repeq(i,1,start - 1){
      ans += A[i];
    }
    
    repeq(i,start,end){
      sum += A[i];
    }
    cnt = (N - (start - 1))/(end - (start - 1)); 
    ans += sum * cnt;
    
    last = start + (end - (start - 1)) * cnt;
    repeq(i,last,N){
      ans += A[i- (last - start)];
    }
  } else {
    repeq(i,1,N){
      ans += A[i];
    }
  }
  cout << ans;
  
}


Measured memory_bytes: 19196
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 300010;
int n;
int a[N];
int main() {
	//freopen("input.txt", "r", stdin);
	scanf("%d", &n);
	ll sum = 0;
	for (int i = 0; i < n; i++) {
		scanf("%d", &a[i]);
		sum += a[i];
	}
	ll sm1 = a[0];
	ll ans = 1e18;
	sum -= a[0];
	for (int i = 1; i < n; i++) {
		ll dif = abs(sm1 - sum);
		ans = min(ans, dif);
		sum -= a[i];
		sm1 += a[i];
	}
	printf("%lld", ans);
	return 0;
}


Measured memory_bytes: 1024