akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
    #include <cmath>
    #include <vector>
    using namespace std;
    #define rep(i,q) for(int i = 0; (q) > i; i++)
    char mp[501][501];
    int heightemp(int n){
      int ret = 0;
      rep(i,n){
        rep(j,n){
          if(mp[j][i] == '.'){
            ret++;
            break;
          }
        }
      }
      return ret;
    }
    int yokokazu_kakunin(int n,int h){
      int ret = 0;
      rep(i,n){
        if(mp[h][i] == '#')ret++;
      }
      return ret;
    }
    int main(){
      int kekk = 20000;
      int n;cin>>n;
      bool can = false;
      rep(i,n){
        rep(j,n){
          cin >> mp[i][j];
          if(mp[i][j] == '#'){
            can = true;
          }
        }
      }
      if(!can){
        cout << "-1" << endl;
        return 0;
      }
      int kaisu = heightemp(n);
      //以下処理
      int mx = -1;
      vector<int> xmp;
      rep(i,n){
        int tmp = yokokazu_kakunin(n,i);
        if(n == tmp){
          cout << kaisu << endl;
          return 0;
        }else if(mx < tmp){
          if(n-1 == tmp){
            int t;
            rep(j,n){
              if(mp[i][j] == '.'){
                t = j;
                break;
              }
            }
            rep(j,n){
              if(mp[j][t] == '#'){
                kekk = kaisu+1;
              }
            }
          }

          mx = tmp;
          xmp.clear();
          xmp.push_back(i);
        }else if(mx == tmp){
          xmp.push_back(i);
        }
      }
      bool ok = false;
      for(int i = 0; xmp.size() > i; i++){
        for(int j = 0; n > j; j++){
          if(mp[j][xmp[i]] == '#')ok = true;
        }
      }
      cout << min((n-mx) + kaisu + (ok ? 0 : 1),kekk)<< endl;
    }

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

int main(){
    int n;
    cin>>n;
    map<int,int>mp;
    int mx=0;
    rep(i,n){
        int a; cin>>a;
        mp[a]++;
    }
    for(auto&p:mp){
        if(p.second>=2){
            mx=max(mx,p.first);
        }
    }
    int a=0,b=0;
    a=mx;
    mp[mx]-=2;
    mx=0;
    for(auto&p:mp){
        if(p.second>=2){
            mx=max(mx,p.first);
        }
    }
    b=mx;
    cout<<(ll)a*b<<endl;
}

Measured memory_bytes: 4992
#include<algorithm>
#include<clocale>
#include<cmath>
#include<complex>
#include<csetjmp>
#include<csignal>
#include<cstdarg>
#include<cstddef>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<deque>
#include<iostream>
#include<istream>
#include<map>
#include<math.h>
#include<ostream>
#include<queue>
#include<set>
#include<sstream>
#include<string>
#include<vector>
using namespace std;
string s;
int k,l,last,num=1;
std::set<string> st;
int main()
{
	cin>>s>>k;
	for (int i=0;i<s.size();i++){
		string t="";
		for (int j=0;j+i<s.size();j++){
			t+=s[i+j];
			st.insert(t);
			if (st.size()>k) st.erase(--st.end());
		}
	}
	cout<<*(--st.end());
	return 0;
}

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

using namespace std;

int main(){

  int a[3];
  int x, num;
  num = 0;

  for(int i = 0; i < 3; i++)
    scanf("%d", &a[i]);
  scanf("%d", &x);

  for(int i = 0; i <= a[0]; i++){
    for(int j = 0; j <= a[1]; j++){
      for(int k = 0; k <= a[2]; k++){
        int sm = i * 500 + j * 100 + k * 50;
        if(sm == x)
          num++;
      }
    }
  }
  printf("%d", num);
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  long long n,ans=1,tmp,mod=1e9+7;
  cin >> n;
  map<long long,long long> mp;
  for(int i=1;i<=n;i++){
    tmp=i;
    for(int j=2;j<=i;j++){
      while(tmp%j==0){
        mp[j]++;
        tmp/=j;
      }
    }
  }
  for(int i=2;i<=n;i++){
    ans*=mp[i]+1;
    ans%=mod;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
// -*- mode: cpp; coding=utf-8-unix; -*-
// vim: filetype=cpp fileencoding=utf-8 fileformat=unix
#include <iostream>
#include <iomanip>
#include <math.h>
#include <map>
#include <list>
#include <set>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>
#include <string>
#include <sstream>
#include <string.h>
// #include <limits.h>

#define FOR(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define FORUL(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))
#define FORULE(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define FOREACH(it, X) for(__typeof((X).begin()) it = (X).begin(); it != (X).end(); it++)
#if defined(_MSC_VER) || __cplusplus > 199711L
#define AUTOVAR(newvar,v) auto newvar = (v)
#else
#define AUTOVAR(newvar,v) __typeof(newvar) r = (v)
#endif
#define PB(x) push_back(x)
#define MP(x,y) make_pair((x),(y))
#define MEMSET(m,v) memset(m,v,sizeof(m))

typedef long long				 ll;
typedef unsigned long long		ull;

#define INTMAX  99999999

#define DEBUG 1

#if DEBUG
#define DOUT cout<<"["<<__LINE__<<"]:"
#else
#define DOUT 0 && cout
#endif

using namespace std;


int main(int argc, char *argv[])
{
	ios::sync_with_stdio(false);

	int r, D, x[11];
	
	cin >> r >> D >> x[0];

	for(int i=1; i<=10; i++) {
		x[i] = r*x[i-1] - D;
		cout << x[i] << endl;
	}


	return 0;
}



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

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


  int Y = false;

  for (int i = 1 ; i <= N; i++) {
      string color;
      cin >> color;

      if (color == "Y") {
          Y = true;
          break;
      } 
  }

  if (Y) {
    cout << "Four" << endl;
  } else {
    cout << "Three" << endl;
  }
}


Measured memory_bytes: 256
#include <iostream>
#define rep(i,n) for(int i=0; i<(n); i++)
using namespace std;

int main(){
  int x;
  cin >> x;
  
  if(x >= 30){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
  
  return 0;
}


Measured memory_bytes: 3596
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; ++i)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = int64_t;
using ld = long double;
using P = pair<int, int>;
using vs = vector<string>;
using vi = vector<int>;
using vvi = vector<vi>;
template<class T> using PQ = priority_queue<T>;
template<class T> using PQG = priority_queue<T, vector<T>, greater<T> >;
const int INF = 100010001;
const ll LINF = (ll)INF*INF*10;
template<typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) {return a < b && (a = b, true);}
template<typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) {return a > b && (a = b, true);}
template<typename T1, typename T2>
istream &operator>>(istream &is, pair<T1, T2> &p) { return is >> p.first >> p.second;}
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) { return os << p.first << ' ' << p.second;}

const int Q = 55;

//head

int n, m, q;
int a[Q], b[Q], c[Q], d[Q];

int dfs(int i, vi& x) {
  if(!i) {
    int res = 0;
    rep(k, q) {
      if(x[b[k]]-x[a[k]] == c[k]) res += d[k];
    }
    return res;
  }
  int res = 0;
  int nn;
  if(x.empty()) nn = 1;
  else nn = x[x.size()-1];
  for(int j = nn; j <= m; j++) {
    x.emplace_back(j);
    chmax(res, dfs(i-1, x));
    x.pop_back();
  }
  return res;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> m >> q;
  rep(i, q) cin >> a[i] >> b[i] >> c[i] >> d[i];
  rep(i, q) {
    a[i]--;
    b[i]--;
  }

  vi j;
  cout << dfs(n, j) << endl;

}

Measured memory_bytes: 3640
#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<unordered_map>
#include<queue>
#include<iomanip>
#include<math.h>
#include<bitset>
#include<cassert>
#include<random>
#include<time.h>
using namespace std;
using ll=long long;
using ld=long double;
using P=pair<int,int>;
#define MOD 1000000007LL
#define INF 1000000000LL
#define EPS 1e-10
#define FOR(i,n,m) for(ll i=n;i<(ll)m;i++)
#define REP(i,n) FOR(i,0,n)
#define DUMP(a) REP(d,a.size()){cout<<a[d];if(d!=a.size()-1)cout<<" ";else cout<<endl;}
#define ALL(v) v.begin(),v.end()
#define UNIQUE(v)  sort(ALL(v));v.erase(unique(ALL(v)),v.end());
#define pb push_back

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

class union_find {
public:
	union_find(int n)
	: par_(n, P(-1, 0))
	{}

	P root(int x) {
		if(par_[x].first < 0) return P(x, 0);
		P tmp = root(par_[x].first);
		par_[x].first = tmp.first;
		par_[x].second += tmp.second;
		return par_[x];
	}

	bool unite(int x, int y, int w) {
		ll px = root(x).first, py = root(y).first;
		if(px == py) {
			return false;
		} else {
			if(par_[px].first < par_[py].first) {
				par_[px].first += par_[py].first;
				par_[py].first = px;
				par_[py].second = (par_[x].second + w) - par_[y].second;
			} else {
				par_[py].first += par_[px].first;
				par_[px].first = py;
				par_[px].second = (par_[y].second - w) - par_[x].second;
			}
			return true;
		}
	}

	bool same(int x, int y) {
		return root(x).first == root(y).first;
	}

	bool compare(int x, int y, ll& result) {
		if(!same(x, y)) return false;
		result = root(y).second - root(x).second;
		return true;
	}
	std::vector<P> par_;
};

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	while(1) {
		ll n, m;
		cin >> n >> m;
		if(n == 0 && m == 0) break;
		union_find uf(n);
		REP(i,m) {
			char c;
			cin >> c;
			if(c == '!') {
				ll a, b, w;
				cin >> a >> b >> w;
				a--; b--;
				uf.unite(a, b, w);
			}
			if(c == '?') {
				ll a, b;
				cin >> a >> b;
				a--; b--;
				ll result = 0;
				if(!uf.compare(a, b, result)) {
					cout << "UNKNOWN" << endl;
				} else {
					cout << result << endl;
				}
			}
		}
	}
	return 0;
}

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



Measured memory_bytes: 3908
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pll = pair<ll,ll>;
using pii = pair<int,int>;
#define ALL(x) (x).begin(),(x).end()

int main(){
	double R; cin >> R;
	cout << fixed << setprecision(5) << M_PI * R * 2 << endl;
}

Measured memory_bytes: 3804
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <cstring>
#include <math.h>
#include <bitset>
#include <queue>
#include <set>
#include <iomanip>
#include <math.h>
#include <assert.h>
// #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr long long int INFLL = 1001001001001001LL;
constexpr long long int infll = 1001001001001001LL;
constexpr int INF = 1000000007;
constexpr int inf = 1000000007;
const int mod = 1000000007;

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

ll gcd(ll a, ll b)
{
    if (a % b == 0)
    {
        return (b);
    }
    else
    {
        return (gcd(b, a % b));
    }
}

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

inline double nCr(const int n, int r)
{
    if (n == 0)
    {
        return 0;
    }
    if (r == 0)
    {
        return 1;
    }
    if (r == 1)
    {
        return n;
    }
    if (n == r)
    {
        return 1;
    }

    if (r > n / 2)
    {
        r = n / 2;
    }

    double result = 1;
    for (double i = 1; i <= r; i++)
    {
        result *= (n - i + 1) / i;
    }

    return (result);
}

template <typename T>
T seinomi(T a)
{
    if (a > 0)
    {
        return a;
    }
    else
    {
        return 0;
    }
}

template <typename T>
map<T, T> soinsuubunkai(T n) //連想配列[素因数f.first][個数f.second]
{
    map<T, T> ret;
    for (T i = 2; i * i <= n; i++)
    {
        while (n % i == 0)
        {
            ret[i]++;
            n /= i;
        }
    }
    if (n != 1)
        ret[n] = 1;
    return ret;
}

template <typename T>
T ketasuu(T num)
{
    return std::to_string(num).length();
}

int kaizyou(int k)
{
    int sum = 1;
    for (int i = 1; i <= k; ++i)
    {
        sum *= i;
    }
    return sum;
}

template <class ForwardIt, class T>
void iota(ForwardIt first, ForwardIt last, T value)
{
    while (first != last)
    {
        *first++ = value;
        ++value;
    }
}

//nの階乗を計算
int factorial(int n)
{
    int answer = 1;
    while (n > 1)
    {
        answer *= n;
        n--;
    }
    return answer;
}
int comb(int n, int r)
{
    return factorial(n) / (factorial(r) * factorial(n - r));
}

long long modpow(long long a, long long n, long long mod)
{
    long long res = 1;
    while (n > 0)
    {
        if (n & 1)
            res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

//小数点以下10桁テンプレート（main関数内の最初に貼付け）
//std::cout << std::fixed << std::setprecision(10);

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


int main(){
ll x;
cin>>x;
vector<bool>era(pow(10,5)+10);
for(auto f:era){
    f=true;
}
era[0]=false;
era[1]=false;
for(int i=2;i<era.size();i++){
    ll j=2;
    while(i*j<era.size()){
        era[i*j]=false;
        j++;
    }
}
for(int i=x;i<era.size();i++){
    if(era[i]==true){
        cout<<i<<endl;
        break;
    }
}
}





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


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

void cdfs(int y,int x,int fromcolor,int tocolor,int &count,vector<vector<int> >&p){
    //printf("  y: %d, x: %d, %d -> %d\n", y, x, fromcolor, tocolor);


    p[y][x]=tocolor;
    count++;

    for(int i = 0; i < 4; i++){
        int nexty = y + dy[i];
        int nextx = x + dx[i];
        if(nexty<0||nexty>p.size()-1||nextx<0||nextx>p[0].size()-1)continue;
        //printf("[%d][%d]\n", nexty, nextx);
        if(p[nexty][nextx]==fromcolor)cdfs(nexty,nextx,fromcolor,tocolor,count,p);

    }
}

int dfs(int depth,int color,vector<vector<int> >p){
    int ans=0;
    int h = p.size();
    int w = p[0].size();
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            //printf("[%d][%d] = %d\n", i, j, p[i][j]);
            if(p[i][j]==color) {
                int count = 0;
                cdfs(i, j, color, 0, count, p);
                //printf("count : %d\n", count);
                ans=ans<count?count:ans;
            }
        }
    }

    //printf("OK?\n");
    if(depth==5)return ans;
    //printf("OK?\n");

    for(int i=0;i<h;i++) {
        for (int j = 0; j < w; j++) {
            //printf("[%d][%d] = %d\n", i, j, p[i][j]);
            if(p[i][j]==0) {
                int count = 0;
                cdfs(i, j, 0,color, count, p);
            }
        }
    }


    vector<vector<int> > q = p;
    for(int i=1;i<=6;i++){
        p = q;
        //printf("depth: %d, i: %d\n", depth, i);
        if(i == p[0][0]){ continue; }
        //printf("GOGO %d -> %d\n", p[0][0], i);
        int count = 0;
        cdfs(0, 0, p[0][0], i, count, p);
        //printf("GOGO?\n");
        int temp=dfs(depth+1,color,p);
        ans=ans<temp?temp:ans;
    }
    return ans;
}




int main(void){
    int h,w,c;
    vector<vector<int> >p;
    while(true){
        cin>>h>>w>>c;
        if(h==0)break;
        p=vector<vector<int> >(h,vector<int>(w));
        for(int i=0;i<h;i++){
            for(int j=0;j<w;j++){
                cin>>p[i][j];
            }
        }
        //printf("OK\n");
        cout<<dfs(0,c,p)<<endl;
    }
    return 0;
}


Measured memory_bytes: 3136
#include <bits/stdc++.h>
using ll = long long;
#define FOR(i, k, n) for(ll i = (k); i < (n); i++)
#define FORe(i, k, n) for(ll i = (k); i <= (n); i++)
#define FORr(i, k, n) for(ll i = (k)-1; i > (n); i--)
#define FORre(i, k, n) for(ll i = (k)-1; i >= (n); i--)
#define REP(i, n) FOR(i, 0, n)
#define REPr(i, n) FORre(i, n, 0)
#define ALL(x) (x).begin(), (x).end()
#define ALLr(x) (x).rbegin(), (x).rend()
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
using namespace std;

const int INF = 1001001001;

struct UnionFind{
  vector<int> par;
  UnionFind(int n) : par(n, -1){}
  int root(int x){ return (par[x] < 0) ? x : par[x] = root(par[x]); }
  int size(int x){ return -par[root(x)]; }
  bool issame(int x, int y){ return root(x) == root(y); }
  void marge(int x, int y){
    x = root(x); y = root(y);
    if(x == y) return;
    if(x > y) swap(x, y);
    par[x] += par[y];
    par[y] = x;
  }
};

int main(void){
  ll n, m;
  cin >> n >> m;
  vector<ll> a(m), b(m);
  REP(i, m) cin >> a[i] >> b[i];
  UnionFind uf(n);
  REP(i, m) uf.marge(--a[i], --b[i]);
  ll ans = 0;
  REP(i, n) chmax(ans, (ll)uf.size(i));
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 7128
#!/usr/bin/env python3
#ABC141 B

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(1000000000)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

s = input()
n = len(s)
lst = ['R','U','D']
lst2 = ['L','U','D']
for i in range(n):
    if i % 2 == 0:
        if s[i] in lst:
            continue
        else:
            print('No')
            quit()
    else:
        if s[i] in lst2:
            continue
        else:
            print('No')
            quit()
print('Yes')

Measured memory_bytes: 38448
import java.util.*;
import java.util.stream.Collectors;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int x = sc.nextInt();
		List<Integer> ms = new ArrayList<>();
		int count = n-1;
		
		for(int i=0; i<n; i++) {
			ms.add(sc.nextInt());
		}
		
		x = x - ms.stream().mapToInt(m -> m.intValue()).sum();
		int minm = ms.stream().mapToInt(m -> m.intValue()).min().getAsInt();
		
		while(x >= 0) {
			x = x - minm;
			count++;
		}
		
		System.out.println(count);
		
		sc.close();
	}
}


Measured memory_bytes: 26964
N = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
K = int(input())
print(N[K - 1])

Measured memory_bytes: 3060
#include<iostream>
#include<cmath>
using namespace std;
//凹んでたら小さい方の角をとってしまう
//内角の和が360度か
double check(double x1, double y1, double x2, double y2, double x3, double y3) {
    double e1 = sqrt(pow(x1 - x2, 2) + pow(y1 - y2, 2));
    double e2 = sqrt(pow(x3 - x2, 2) + pow(y3 - y2, 2));
    double e3 = sqrt(pow(x3 - x1, 2) + pow(y3 - y1, 2));
    double Cos = (e1 * e1 + e2 * e2 - e3 * e3) / (2 * e1 * e2);
    double PI = (double)acos(-1);
    return acos(Cos) * 180 / PI;
}
int main() {
    double xa, ya, xb, yb, xc, yc, xd, yd;
    char c;
    while (cin >> xa >> c >> ya >> c >> xb >> c >> yb >> c >> xc >> c >> yc >> c >> xd >> c >> yd) {
        double r1, r2, r3, r4;
        r1 = check(xa, ya, xb, yb, xc, yc);
        r2 = check(xb, yb, xc, yc, xd, yd);
        r3 = check(xc, yc, xd, yd, xa, ya);
        r4 = check(xd, yd, xa, ya, xb, yb);
        //cout << r1 << " " << r2 << " " << r3 << " " << r4 << endl;
        double sum =  r1 + r2 + r3 + r4;
        //cout << sum << endl;
        if (sum >= 359 && sum <= 361) {
            cout << "YES" << endl;
        } else {
            cout << "NO" << endl;
        }
    }
    return 0;
}



Measured memory_bytes: 3324
#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<string>
#include<map>
#include<queue>
#include<vector>
#include<algorithm>
#include<climits>
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)

using namespace std;

const int dx[2] = {1, -1};
const int dy[2] = {0, -1};
int x_w[32][32];
int y_w[32][32];
int dist[32][32];

void bfs(int w, int h){
  pair<int, int> p,tmp;
  queue<pair<int, int> > q;

  REP(i,32)
  REP(j,32)
  dist[i][j] = INT_MAX;

  p.first = p.second = 1;
  dist[1][1] = 1;
  q.push(p);

  while(!q.empty()){
    p = q.front();
    q.pop();

    REP(i,2){
      if(x_w[p.first + dy[i]][p.second -1] == 0 && dist[p.first + dx[i]][p.second] == INT_MAX){
        dist[p.first + dx[i]][p.second] = dist[p.first][p.second]+1;
        tmp.first = p.first + dx[i];
        tmp.second = p.second;
        q.push(tmp);
      }
      if(y_w[p.first -1][p.second + dy[i]] == 0 && dist[p.first][p.second + dx[i]] == INT_MAX){
        dist[p.first][p.second + dx[i]] = dist[p.first][p.second]+1;
        tmp.first = p.first;
        tmp.second = p.second + dx[i];
        q.push(tmp);
      }
    }
  }
}

int main(){
  int w,h;

  while(true){
    cin >> w >> h;
    if(w == 0 && h == 0) break;

    REP(i,h){
      REP(j,w+1){
        if(j == 0 || j == w) y_w[i][j] = 1;
        else cin >> y_w[i][j];
      }
      if(i == h-1) break;
      REP(j,w){
        cin >> x_w[i+1][j];
      }
    }
    REP(i,w){
      x_w[0][i] = 1;
      x_w[h][i] = 1;
    }

    bfs(w,h);
    if(dist[h][w] == INT_MAX) cout << 0 << endl;
    else cout << dist[h][w] << endl;

  }
  return 0;
}

Measured memory_bytes: 1228
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef pair<int,int> P;
 
const int INF = 1e9;
const int mod = 1e9+7;
const double EPS = 1e-10;
const double PI = acos(-1.0);

int main()
{
    string s;
    cin >> s;
    for(int i = 0; i < s.size(); i += 2) cout << s[i];
    cout << endl;
    return 0;
}


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

ll f(ll n1, ll n2){
    ll max_n = max(n1, n2);
    ll min_n = min(n1, n2);
    return max_n*(max_n+1)/2 + min_n*(min_n-1)/2;
}

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

    vector<ll> a(s.size()+1, 0);

    ll ans = 0;
    ll end_i = -1;
    ll cnt1 = 0;
    ll cnt2 = 0;
    rep(i, s.size()){
        if (s[i] == '<'){
            if (end_i != -1) {
                ans += f(cnt1, cnt2);
                end_i = -1;
                cnt1 = 0;
                cnt2 = 0;
            }
            cnt1++;
        }else{
            cnt2++;
            end_i = i;
        }
    }

    ans += f(cnt1, cnt2);
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 7688
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

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

    while(--t >= 0){
        int p, q;
        cin >> p >> q;

        int ret = 0;
        for(int m=0; m*m<20000; ++m){
            for(int n=0; m*m+n*n<20000; ++n){
                if(m == 0 && n == 0)
                    continue;
                for(int i=0; i<4; ++i){
                    if(i & 1)
                        m *= -1;
                    if(i & 2)
                        n *= -1;

                    int a = m * m + n * n;
                    if((m*p+n*q) % a == 0 && (m*q-n*p) % a == 0)
                        ++ ret;

                    if(i & 1)
                        m *= -1;
                    if(i & 2)
                        n *= -1;
                }
            }
        }

        if(ret <= 16)
            cout << 'P' << endl;
        else
            cout << 'C' << endl;
    }

    return 0;
}

Measured memory_bytes: 1148
#include "bits/stdc++.h"
using namespace std;
const int maxn  = 100100;
vector<pair<int, int> > nxt[maxn];
set<tuple<int, int, int> > direct;
long long dist[maxn], ways[maxn];
const long long inf = 1ll<<60;
const long long mod = 1000000007;
long long aug(int s){
  if(ways[s] != -1) return ways[s];
  long long ans = 0;
  for(auto e : nxt[s]){
    int v, w;
    tie(v, w) = e;
    if(dist[v] == dist[s] + w){
      ans += aug(v);
      if(ans >= mod) ans -= mod;
    }
  }
  return ways[s] = ans;
}
int n;
void djk(int s, int t){
  for(int e = 0; e < maxn; e++) dist[e] = inf;
  priority_queue<pair<long long, int> > pq;
  pq.push({0, s});
  dist[s] = 0;
  while(!pq.empty()){
    long long dis; int cur;
    tie(dis, cur) = pq.top(); pq.pop();
    dis *= -1;
    if(dis != dist[cur]) continue;
    for(auto e : nxt[cur]){
      int v, w;
      tie(v, w) = e;
      if(dist[v] > dist[cur] + w){
        dist[v] = dist[cur] + w;
        pq.push({-dist[v], v});
      }
    }
  }
  memset(ways, -1, sizeof(ways));
  ways[t] = 1;
  aug(s);
  direct.clear();
  for(int u = 0; u < n; u++){
    for(auto e : nxt[u]){
      int v, w;
      tie(v, w) = e;
      if(dist[v] == dist[u] + w){
        direct.insert(make_tuple(u, v, w));
      }
    }
  }
  for(int u = 0; u < n; u++) if(ways[u] == -1) ways[u] = 0;
}
int MAIN(){
  int m;
  if(!(cin >> n >> m)) return 0;
  for(int e = 0; e < n; e++) nxt[e].clear();
  int s, t;
  cin >> s >> t; s--; t--;
  for(int e = 0; e < m; e++){
    int u, v, w;
    scanf("%d %d %d", &u, &v, &w);
    u--; v--;
    nxt[u].push_back({v, w});
    nxt[v].push_back({u, w});
  }
  djk(s, t);
  vector<long long> ways_s(n, 0);
  vector<long long> dist_s(n, 0);
  for(int e = 0; e < n; e++) ways_s[e] = ways[e];
  for(int e = 0; e < n; e++) dist_s[e] = dist[e];
  set<tuple<int, int, int> > dir_s = direct;
  djk(t, s);
  vector<long long> ways_t(n, 0);
  vector<long long> dist_t(n, 0);
  for(int e = 0; e < n; e++) ways_t[e] = ways[e];
  for(int e = 0; e < n; e++) dist_t[e] = dist[e];
  set<tuple<int, int, int> > dir_t = direct;
  long long walk = dist_s[t];
  long long ans = ways_s[s] * ways_t[t] % mod;
  auto mul = [&](long long a, long long b){
      return a * b % mod;
  };
  for(auto e : dir_s){
    int u, v, w; tie(u, v, w) = e;
    if(dir_t.count(make_tuple(v, u, w))){
      if(dist_s[u] + dist_t[v] + w != dist_s[t]) continue;
      // long long md = min(dist_s[u], dist_t[v]);
      if(dist_s[u] >= dist_s[t] / 2) continue;
      if(dist_t[v] >= dist_s[t] / 2) continue;
      // cout << "intersect at " << u << " " << v << endl;
      long long bad = mul(mul(mul(ways_s[v], ways_s[v]), ways_t[u]), ways_t[u]);
      ans -= bad;
      // cout << "bad "<< bad << endl;
      if(ans < 0) ans += mod;
    }
  }
  for(int e = 0; e < n; e++){
    if(dist_s[e] + dist_t[e] != walk) continue;
    if(dist_s[e] == dist_t[e]){
      long long bad = mul(mul(mul(ways_s[e], ways_s[e]), ways_t[e]), ways_t[e]);
      ans -= bad;
      if(ans < 0) ans += mod;
    }
  }
  cout << ans << endl;
  return 1;
}
int main(){
  while(MAIN());
  return 0;
}


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

public class Main {
  private static int solve(int x) {
    int max = 1;
    for (int i = 2; i <= x; i++) {
      int power = i;
      while (power * i <= x) {
        power *= i;
        max = Math.max(max, power);
      }
    }
    return max;
  }
  
  private static void execute(ContestReader reader, PrintWriter out) {
    int x = reader.nextInt();
    out.println(solve(x));
  }
  
  public static void main(String[] args) {
    ContestReader reader = new ContestReader(System.in);
    PrintWriter out = new PrintWriter(System.out);
    execute(reader, out);
    out.flush();
  }
}

class ContestReader {
  private BufferedReader reader;
  private StringTokenizer tokenizer;
  
  ContestReader(InputStream in) {
    reader = new BufferedReader(new InputStreamReader(in));
  }
  
  public String next() {
    while (tokenizer == null || !tokenizer.hasMoreTokens()) {
      try {
        tokenizer = new java.util.StringTokenizer(reader.readLine());
      } catch (Exception e) {
        throw new RuntimeException(e);
      }
    }
    return tokenizer.nextToken();
  }
  
  public int nextInt() {
    return Integer.parseInt(next());
  }
  
  public long nextLong() {
    return Long.parseLong(next());
  }
  
  public double nextDouble() {
    return Double.parseDouble(next());
  }
  
  public String[] next(int n) {
    String[] array = new String[n];
    for (int i = 0; i < n; i++) {
      array[i] = next();
    }
    return array;
  }
  
  public int[] nextInt(int n) {
    int[] array = new int[n];
    for (int i = 0; i < n; i++) {
      array[i] = nextInt();
    }
    return array;
  }
  
  public long[] nextLong(int n) {
    long[] array = new long[n];
    for (int i = 0; i < n; i++) {
      array[i] = nextLong();
    }
    return array;
  }
  
  public double[] nextDouble(int n) {
    double[] array = new double[n];
    for (int i = 0; i < n; i++) {
      array[i] = nextDouble();
    }
    return array;
  }
  
  public char[] nextCharArray() {
    return next().toCharArray();
  }
  
  public int[][] nextInt(int n, int m) {
    int[][] matrix = new int[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        matrix[i][j] = nextInt();
      }
    }
    return matrix;
  }
  
  public long[][] nextLong(int n, int m) {
    long[][] matrix = new long[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        matrix[i][j] = nextLong();
      }
    }
    return matrix;
  }
  
  public double[][] nextDouble(int n, int m) {
    double[][] matrix = new double[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        matrix[i][j] = nextDouble();
      }
    }
    return matrix;
  }
  
  public char[][] nextCharArray(int n) {
    char[][] matrix = new char[n][];
    for (int i = 0; i < n; i++) {
      matrix[i] = next().toCharArray();
    }
    return matrix;
  }
}


Measured memory_bytes: 21076
/*
累積和でとってTLE
DPでとる?
1 2 3 4 5 6 7
DP[3]=3
DP[4]=6 = 
DP[5]=8 = max(DP[3]+A[4],DP[4])
DP[6]=12 = max(DP[4]+A[5]
DP[n]=max(DP[n-1],DP[1]+A[3])
みたいなかんじ
*/
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
int main(){
  ll N,ans=-1e15, tmp=-1e15; cin>>N;
  vector<ll> A(N,0),O(N+1,0), DP(N+1,-1e15);
  for(int i=0; i<N; i++){
    ll a; cin>>a; A[i]=a;
    if(i%2==0) O[i+1]=a;
    if(i<=2) DP[i+1]=max(DP[i],a);
    //DP[4]、2個とる。DP[2]+aかO[1]+O[3]
    //DP[5]、2個とる。DP[4]かDP[3]+a
    //DP[6]、3個とる。DP[4]+aかO[1]+O[3]+O[5](aを使わないとなると奇数番目をとるだけ）
    //DP[7]、3個とる。DP[6]かDP[5]+a
  }
  //奇数累積和
  for(int i=1; i<=N; i++)
    O[i]=O[i-1]+O[i];
  //DPつくる
  for(int i=4; i<=N; i++){
    if(i%2==0)
      DP[i]=max(DP[i-2]+A[i-1], O[i-1]);
    else
      DP[i]=max(DP[i-1],DP[i-2]+A[i-1]);
  }
  cout<<DP[N]<<endl;
}


Measured memory_bytes: 7968
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
typedef long long ll;
typedef std::vector<long long> vll;
typedef std::vector<std::vector<long long>> vvll;
typedef long double ld;
typedef std::vector<long double> vld;
typedef std::vector<std::vector<long double>> vvld;
using namespace std;
void yesno(bool state);

void Main(){
    ll X;
    cin >> X;
    if(X < 600)
        cout << 8 << endl;
    else if(X < 800)
        cout << 7 << endl;
    else if(X < 1000)
        cout << 6 << endl;
    else if(X < 1200)
        cout << 5 << endl;
    else if(X < 1400)
        cout << 4 << endl;
    else if(X < 1600)
        cout << 3 << endl;
    else if(X < 1800)
        cout << 2 << endl;
    else if(X < 2000)
        cout << 1 << endl;
        
}

int main(int argc, char const *argv[])
{
    Main();
    return 0;
}

void yesno(bool state){
    if(state)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}

Measured memory_bytes: 3640
#line 1 "D.cpp"
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <complex>
#include <queue>
#include <string>
#include <tuple>
#include <utility>
#include <vector>

#line 1 "~/git/library/Graph/adjacency_list.cpp"



/**
 * @brief 重みつきグラフの隣接リスト
 * @author えびちゃん
 */

#include <cstddef>
#line 11 "~/git/library/Graph/adjacency_list.cpp"
#include <type_traits>
#line 13 "~/git/library/Graph/adjacency_list.cpp"

template <typename WeightType>
class weighted_edge {
public:
  using size_type = size_t;
  using weight_type = WeightType;

protected:
  size_type M_src, M_dst;
  weight_type M_weight;

public:
  weighted_edge() = default;
  weighted_edge(weighted_edge const&) = default;
  weighted_edge(weighted_edge&&) = default;

  weighted_edge(size_type s, size_type d, weight_type w):
    M_src(s), M_dst(d), M_weight(w)
  {}

  weighted_edge& operator =(weighted_edge const&) = default;
  weighted_edge& operator =(weighted_edge&&) = default;

  bool operator <(weighted_edge const& other) const {
    if (M_weight < other.M_weight) return true;
    if (other.M_weight < M_weight) return false;
    if (M_src != other.M_src) return M_src < other.M_src;
    return M_dst < other.M_dst;
  }

  size_type source() const { return M_src; }
  size_type target() const { return M_dst; }
  weight_type weight() const { return M_weight; }
};

struct directed_tag {};
struct undirected_tag {};

template <typename Edge, typename Directedness>
class adjacency_list {
public:
  using size_type = size_t;
  using edge_type = Edge;
  using weight_type = typename Edge::weight_type;

private:
  std::vector<std::vector<edge_type>> M_g;

public:
  adjacency_list() = default;
  adjacency_list(adjacency_list const&) = default;
  adjacency_list(adjacency_list&&) = default;
  explicit adjacency_list(size_type n): M_g(n) {}

  template <typename... Args>
  void emplace(size_type src, size_type dst, Args... args) {
    M_g[src].emplace_back(src, dst, args...);
    if (std::is_same<Directedness, undirected_tag>::value)
      M_g[dst].emplace_back(dst, src, args...);
  }

  void sort_by_index() {
    auto cmp = [](auto const& e1, auto const& e2) {
      return e1.target() < e2.target();
    };
    for (auto v: M_g) std::sort(v.begin(), v.end(), cmp);
  }

  size_type size() const { return M_g.size(); }
  auto const& operator [](size_type i) const { return M_g[i]; }
};


#line 13 "D.cpp"

int main() {
  size_t n, m;
  scanf("%zu %zu", &n, &m);

  adjacency_list<weighted_edge<int>, undirected_tag> g(n);
  for (size_t i = 0; i < m; ++i) {
    size_t a, b;
    scanf("%zu %zu", &a, &b);
    --a, --b;
    g.emplace(a, b, 1);
  }

  std::vector<size_t> prev(n, n);
  prev[0] = -1;
  std::queue<size_t> q;
  q.push(0);
  while (!q.empty()) {
    size_t v = q.front();
    q.pop();
    for (auto const& e: g[v]) {
      size_t u = e.target();
      if (prev[u] != n) continue;
      prev[u] = v;
      q.push(u);
    }
  }

  puts("Yes");
  for (size_t i = 1; i < n; ++i)
    printf("%zu\n", prev[i]+1);
}


Measured memory_bytes: 20292
#include <bits/stdc++.h>
using namespace std;
#define x first
#define y second
#define dbg(x) cout << #x << '=' << x << '\n';
#define ll long long
#define pi pair<int,int>
#define pl pair<long long,long long>
#define lg length()
#define pb push_back
ifstream in("file.in");
ofstream out("file.out");
#define MAXN 100005
#define INF 1000000005
#define LINF 1000000000000000005

int n,x,a,b,c,d,j=1;

int main(){
    cin >> n >> x;
    if(x==1 || x==2*n-1) cout << "No";
    else if(n==2){
        cout << "Yes\n1\n2\n3";
    }
    else{
        cout << "Yes\n";
        if(x>2) a=x-2,b=x+1,c=x,d=x-1;
        else a=3,b=2,c=1,d=4;
        for(int i=1;i<=n-2;i++){
            while(j==a || j==b || j==c || j==d) j++;
            cout << j << '\n'; j++;
        }
        cout << a << '\n' << b << '\n' << c << '\n' << d << '\n';
        for(int i=1;i<=n-3;i++){
            while(j==a || j==b || j==c || j==d) j++;
            cout << j << ' '; j++;
        }
    }
}


Measured memory_bytes: 1536
#include<stdio.h>
#include<math.h>
#include<string.h>
#include<algorithm>
#include<iostream>
#include<stack>
#include<queue>
#define ll long long
using namespace std;
int main()
{
	char num[40005];
	int  n;
	while(cin>>n) {
		stack <int> p;
		int a;
		if(n == 0)
			cout<<0<<endl;
		else {
			while(n!=0) {
				a = abs(n%(-2));
				p.push(a);
				n = (n-a) / (-2);
			}
		}
		while(!p.empty()) {
			cout<<p.top();
			p.pop();
		}
		cout<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
using System;
using System.Linq;

namespace HelloWorld
{
    class Program
    {
        static void Main()
        {
            Dice sai = new Dice();
            bool flag = true;
            int num = int.Parse(Console.ReadLine());
            const int MAX_N = 100;
            int[][] die = new int[MAX_N][];
            int[][] auth = new int[MAX_N][];
            for (int i = 0; i < num; ++i)
            {
                die[i] = Console.ReadLine().Split().Select(int.Parse).ToArray();
                auth[i] = die[i];
            }
            for (int i = 1; i < num; ++i)
            {
                for (int j = 1; j <= i; ++j)
                {
                    if (i < j)
                    {
                        break;
                    }
                    if (!sai.AreSame(die[i], auth[i - j]))
                    {
                        flag = false;
                        break;
                    }
                }
                if (!flag)
                {
                    break;
                }
            }
            Console.WriteLine(flag ? "Yes" : "No");
        }
    }

    internal class Dice
    {
        const int TIMES = 500;
        internal bool AreSame(int[] pips, int[] auth)
        {
            Random rnd = new Random();
            for (int i = 0; i < TIMES; ++i)
            {
                if (rnd.Next(2) == 1)
                {
                    GoNorth(pips);
                }
                else
                {
                    GoEast(pips);
                }
                if (auth[0] == pips[0] && auth[1] == pips[1] && auth[2] == pips[2] && auth[3] == pips[3] && auth[4] == pips[4] && auth[5] == pips[5])
                    return false;
            }
            return true;
        }
        private void GoNorth(int[] pips)
        {
            int tmp = pips[0];
            pips[0] = pips[1];
            pips[1] = pips[5];
            pips[5] = pips[4];
            pips[4] = tmp;

        }
        private void GoEast(int[] pips)
        {
            int tmp = pips[3];
            pips[3] = pips[5];
            pips[5] = pips[2];
            pips[2] = pips[0];
            pips[0] = tmp;
        }
    }
}


Measured memory_bytes: 20308
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;

namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            new Program().Solve(new ConsoleInput(Console.In, ' '));
        }

        public void Solve(ConsoleInput cin)
        {
            // 解答はココに書く
            var N = cin.ReadInt;
            var a = cin.ReadLongArray(3*N);
            Array.Sort(a);
            
            long ans = 0;
            
            for(int i=0 ;i<N; i++){
                ans += a[3 * N -2 -(i * 2)];
            }
            
            
            
            WriteLine(ans);
        }
    }

    public class ConsoleInput
    {
        private readonly System.IO.TextReader _stream;
        private char _separator = ' ';
        private Queue<string> inputStream;
        public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
        {
            this._separator = separator;
            this._stream = stream;
            inputStream = new Queue<string>();
        }
        public string Read
        {
            get
            {
                if (inputStream.Count != 0) return inputStream.Dequeue();
                string[] tmp = _stream.ReadLine().Split(_separator);
                for (int i = 0; i < tmp.Length; ++i)
                    inputStream.Enqueue(tmp[i]);
                return inputStream.Dequeue();
            }
        }
        public string ReadLine { get { return _stream.ReadLine(); }}
        public int ReadInt { get { return int.Parse(Read); }}
        public long ReadLong { get { return long.Parse(Read); }}
        public double ReadDouble { get { return double.Parse(Read); }}
        public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret;}
        public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret;}
        public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret;}
    }
}

Measured memory_bytes: 44180
#include <bits/stdc++.h>
using namespace std;
int atom(string &S, int &p, map<string, int> &mp){
  string tmp;
  tmp += S[p];
  p++;
  if (p < S.size()){
    if ('a' <= S[p] && S[p] <= 'z'){
      tmp += S[p];
      p++;
    }
  }
  if (mp.count(tmp)){
    return mp[tmp];
  } else {
    return -1;
  }
}
int number(string &S, int &p, map<string, int> &mp){
  int ans = 0;
  while ('0' <= S[p] && S[p] <= '9'){
    ans *= 10;
    ans += S[p] - '0';
    p++;
    if (p == S.size()){
      break;
    }
  }
  return ans;
}
int molecule(string &S, int &p, map<string, int> &mp){
  int ans = 0;
  while (1){
    if (S[p] == '('){
      p++;
      int a = molecule(S, p, mp);
      p++;
      int b = 1;
      if (p < S.size()){
        if ('0' <= S[p] && S[p] <= '9'){
          b = number(S, p, mp);
        }
      }
      if (a == -1 || ans == -1){
        ans = -1;
      } else {
        ans += a * b;
      }
    } else if (S[p] == ')'){
      break;
    } else {
      int a = atom(S, p, mp);
      int b = 1;
      if (p < S.size()){
        if ('0' <= S[p] && S[p] <= '9'){
          b = number(S, p, mp);
        }
      }
      if (a == -1 || ans == -1){
        ans = -1;
      } else {
        ans += a * b;
      }
    }
    if (p == S.size()){
      break;
    }
  }
  return ans;
}
int main(){
  map<string, int> mp;
  while (1){
    string S;
    cin >> S;
    if (S == "END_OF_FIRST_PART"){
      break;
    }
    int w;
    cin >> w;
    mp[S] = w;
  }
  while (1){
    string S;
    cin >> S;
    if (S == "0"){
      break;
    }
    int p = 0;
    int ans = molecule(S, p, mp);
    if (ans == -1){
      cout << "UNKNOWN" << endl;
    } else {
      cout << ans << endl;
    }
  }
}


Measured memory_bytes: 3176
#include<stdio.h>
#define N 8
#define FREE -1
#define NOT_FREE 1
#define FALSE 0
#define TRUE 1
int row[N],col[N],dpos[2*N -1],dneg[2*N-1];
int X[N][N];

void initialize(){
  int i;
  for(i=0;i<N;i++){
    row[i]=0;
    col[i]=0;
  }
  for(i=0;i<2*N-1;i++){
    dpos[i]=FREE;
    dneg[i]=FREE;
  }
}
void print(){
  int i;
  int j;
  for(i=0;i<N;i++){
    for(j=0;j<N;j++)
      {
	if(X[i][j]!=0){
	  if(row[i]!=j) return ;
	}
      }
  }
  for(i=0;i<N;i++){
    for(j=0;j<N;j++){
      if(row[i]==j)printf("Q");
      else printf(".");
    }
    printf("\n");
  }
  }
void recursive(int i){
  int j;
   if(i==N){
     print();
    return ;
   }
     for(j=0;j<N;j++){
    if(col[j] == NOT_FREE||dpos[i+j]==NOT_FREE||dneg[i-j+N-1]==NOT_FREE)continue;
    row[i]=j;
    col[j]=dpos[i+j]=dneg[i-j+N-1]=NOT_FREE;
    recursive(i+1);
    col[j]=dpos[i+j]=dneg[i-j+N-1]=FREE;
    
  }
}
int main(){
  int i,j;
  int k,r,c;
  initialize();//?????????
  for(i=0;i<N;i++)
    for(j=0;j<N;j++)
      X[i][j]=FALSE;
      scanf("%d",&k);
      for(i=0;i<k;i++){
	scanf("%d%d",&r,&c);
	X[r][c]=TRUE;
      }
      recursive(0);
      return 0;
}

    

Measured memory_bytes: 572
#078-C 
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(input())
def S(): return list(input())
n=S()
for i in range(4):
    n[i]=int(n[i])
if n[0]+n[1]+n[2]+n[3]==7:
    print(str(n[0])+"+"+str(n[1])+"+"+str(n[2])+"+"+str(n[3])+"=7")
elif n[0]+n[1]+n[2]-n[3]==7:
    print(str(n[0])+"+"+str(n[1])+"+"+str(n[2])+"-"+str(n[3])+"=7")
elif n[0]+n[1]-n[2]+n[3]==7:
    print(str(n[0])+"+"+str(n[1])+"-"+str(n[2])+"+"+str(n[3])+"=7")
elif n[0]+n[1]-n[2]-n[3]==7:
    print(str(n[0])+"+"+str(n[1])+"-"+str(n[2])+"-"+str(n[3])+"=7")
elif n[0]-n[1]+n[2]+n[3]==7:
    print(str(n[0])+"-"+str(n[1])+"+"+str(n[2])+"+"+str(n[3])+"=7")
elif n[0]-n[1]+n[2]-n[3]==7:
    print(str(n[0])+"-"+str(n[1])+"+"+str(n[2])+"-"+str(n[3])+"=7")
elif n[0]-n[1]-n[2]+n[3]==7:
    print(str(n[0])+"-"+str(n[1])+"-"+str(n[2])+"+"+str(n[3])+"=7")
elif n[0]-n[1]-n[2]-n[3]==7:
    print(str(n[0])+"-"+str(n[1])+"-"+str(n[2])+"-"+str(n[3])+"=7")

Measured memory_bytes: 3192
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <list>
#include <iterator>
#pragma warning(disable:4996)
 
typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223300000000000000
#define INF 2140000000
#define MOD 1000000007
using namespace std;


int main(int argc, char* argv[])
{
    long hh, ww;
    scanf("%ld%ld", &hh, &ww);

    long h, w;
    scanf("%ld%ld", &h, &w);

    printf("%ld\n", (hh-h)*(ww-w) );



    return 0;
}



Measured memory_bytes: 128
#include<bits/stdc++.h>
#define forn(i,a,b)for(int i=(a),_b=(b);i<=_b;i++)
#define fore(i,b,a)for(int i=(b);_a=(a);i>=_a;i--)
#define rep(i,n)for(int i=0,_n=n;i<n;i++)
#define ll long long
#define pii pair<int,int>
#define vector<pii> vpii
#define m_p make_pair
#define re return
#define pb push_back
#define si set<int>
#define ld long double
#define X first
#define Y second
#define st string
#define ull unsigned long long
#define mod 1000000007
#define INF 1000000007
#define x1 XZVJDFADSPFOE
#define y1 GASDIJSLDAEJF
#define x2 DFDAJKVOHKWIW
#define y2 PSFSAODSXVNMQ
#define LLINF 0x3f3f3f3f3f
using namespace std;
inline void read(int &x)
{
	short negative=1;
    x=0;
    char c=getchar();
    while(c<'0' || c>'9')
    {
		if(c=='-')
			negative=-1;
		c=getchar();
	}
    while(c>='0' && c<='9')
        x=(x<<3)+(x<<1)+(c^48),c=getchar();
    x*=negative;
}
ll quickpower(ll n,ll k){
	ll ans=1;
	while(k){
		if(k%2){
			ans*=n;
			ans%=mod;
		}
		n*=n;
		n%=mod;
		k/=2;
	}
	return ans;
}
string int_to_string(int n)
{
	string s="";
	while(n)
	{
		int now=n%10;
		s+=now+'0';
		n/=10;
	}
	reverse(s.begin(),s.end());
	return s;
}
int string_to_int(string s)
{
	int n=0;
	rep(i,s.size())
	{
		n*=10;
		n+=s[i]-'0';
	}
	return n;
}
bool ok(string s)
{
	rep(i,s.size()/2)
		if(s[i]!=s[s.size()-i-1])return 0;
	return 1;
}
int main()
{
	ios::sync_with_stdio(0);
	string s;
	string s1,s2;
	cin>>s;
	s1=s.substr(0,s.size()/2);
	s2=s.substr(s.size()/2+1);
	if(ok(s)&&ok(s1)&&ok(s2))cout<<"Yes";
	else cout<<"No";
	return 0;
}



Measured memory_bytes: 256
import java.util.*;
import java.util.Map.Entry;

public class Main {
    public static void main(String[] args) throws Exception {
        
        Scanner sc = new Scanner(System.in);
        String S = sc.next();
        char n[] = S.toCharArray();
        
        int A = n[0] - 48;
        int B = n[1] - 48;
        int C = n[2] - 48;
        int D = n[3] - 48;
        int nums[] = {A, B, C, D};

 
        for( int i = 0; i < (1 << 3); i++ ) {
            int sum = nums[0];
            for( int j = 0; j < 3; j++ ) {
                if( (i>>j & 1) == 1 ) {
                    sum += nums[j+1];
                } else {
                    sum -= nums[j+1];
                }
            }
            
            if( sum == 7 ) {
                StringBuilder sb = new StringBuilder();
                sb.append(nums[0]);
                for( int j = 0; j < 3; j++ ) {
                    if( (i >> j & 1) == 1  ) {
                        sb.append("+");
                    } else {
                        sb.append("-");
                    }
                    sb.append(nums[j+1]);
                }
                sb.append("=7");
                System.out.println(sb.toString());
                break;
            }
        }
    }
}


Measured memory_bytes: 35456
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using static System.Math;
public static class P
{
    public static void Main()
    {
        var nm = Console.ReadLine().Split().Select(int.Parse).ToArray();
        var students = Enumerable.Repeat(0, nm[0]).Select(_ => Console.ReadLine().Split().Select(int.Parse).ToArray()).ToArray();
        var point = Enumerable.Repeat(0, nm[1]).Select(_ => Console.ReadLine().Split().Select(int.Parse).ToArray()).ToArray();
        foreach (var student in students)
        {
            int minDist = int.MaxValue;
            int minInd = -1;
            for (int i = 0; i < point.Length; i++)
            {
                var dist = Abs(student[0] - point[i][0]) + Abs(student[1] - point[i][1]);
                if (dist < minDist)
                {
                    minInd = i;
                    minDist = dist;
                }
            }
            Console.WriteLine(minInd + 1);
        }
    }
}

Measured memory_bytes: 11476