akhauriyash/Code-Regression huggingface dataset:
x = y = 0.0
deg = 90
while line = gets
  d, a = line.split(',').map(&:to_i)
  break if d.zero? && a.zero?

  rad =  (Math::PI / 180) * deg
  x += d * Math.cos(rad)
  y += d * Math.sin(rad)
  deg -= a
end

printf("%d\n%d\n", x, y)

Measured memory_bytes: 8988
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<map>
#include<set>
#include<queue>
#include<cstdio>
#include<climits>
#include<cmath>
#include<cstring>
#include<string>
#include<sstream>
#include<numeric>
#include<cassert>

#define f first
#define s second
#define mp make_pair

#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define rep(i,s,n) for(int i=(s); i<(int)(n); i++)
#define FOR(i,c) for(__typeof((c).begin()) i=(c).begin(); i!=(c).end(); i++)
#define ALL(c) (c).begin(), (c).end()
#define IN(x,s,g) ((x) >= (s) && (x) < (g))
#define ISIN(x,y,w,h) (IN((x),0,(w)) && IN((y),0,(h)))
#define print(x) printf("%d\n",x)

using namespace std;

typedef unsigned int uint;
typedef long long ll;

const int _dx[] = {0,1,0,-1};
const int _dy[] = {-1,0,1,0};

int getInt(){
  int ret = 0,c;
  c = getchar();
  while(!isdigit(c)) c = getchar();
  while(isdigit(c)){
    ret *= 10;
    ret += c - '0';
    c = getchar();
  }
  return ret;
}

int l[2][500][500];
bool c[2][500][500];
int memo[2][250001];

struct level{
  int l;
  int x;
  int y;
  level(int a,int b,int c){
    l=a; x=b; y=c;
  }
};

bool operator < (const level &a, const level &b){
  return a.l > b.l;
}

int main(){
  int r;
  while(r = getInt()){
    int w[2],h[2],x[2],y[2];
    REP(k,2){
      w[k] = getInt();
      h[k] = getInt();
      x[k] = getInt() - 1;
      y[k] = getInt() - 1;
      REP(i,h[k]) REP(j,w[k]){
        l[k][i][j] = getInt();
        c[k][i][j] = false;
      }

      priority_queue<level> pq;
      pq.push(level(1,x[k],y[k]));
      c[k][y[k]][x[k]] = true;

      int cnt = 0;
      int now = 1;

      memo[k][cnt++] = 0;
      while(!pq.empty()){
        level lv = pq.top();
        int ll = lv.l;
        int xx = lv.x;
        int yy = lv.y;
        pq.pop();
        //printf("%d %d %d\n",ll,xx,yy);

        memo[k][cnt++] = (now = max(ll, now));

        REP(i,4){
          int xxx = xx + _dx[i];
          int yyy = yy + _dy[i];

          if(ISIN(xxx,yyy,w[k],h[k]) && !c[k][yyy][xxx]){
            c[k][yyy][xxx] = true;
            pq.push(level(l[k][yyy][xxx], xxx, yyy));
          }
        }
      }

      //REP(i, w[k]*h[k]+1) printf("%d ",memo[k][i]); puts("");
    }

    int end = min(r, w[0] * h[0]) + 1;
    int start = max(0, r - w[1] * h[1]);
    int ans = INT_MAX;
    rep(i,start,end)
      ans = min(ans, memo[0][i] + memo[1][r-i]);
    print(ans);
  }

  return 0;
}

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

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

    int p; cin >> p;
    int num = p / 500;
    cout << num * 500 << endl;
    return 0;
}




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

#define deb(var) cout << "[" << (#var) << " : " << var <<"]" << " "
#define debv(v) cout << "[" << (#v) << " : {";for(int i = 0; i < v.size() - 1; ++i)\
					cout << v[i] <<", ";cout << v.back() << "}] "
#define deba(a,n) cout << "[" << (#a) << " : {";for(int i = 0; i < n - 1; ++i)\
					cout << a[i] << ", ";cout << a[n - 1] << "}] "
#define debp(p) cout << "[" << (#p) << " : {" << p.first << ", " << p.second << "}] "
#define debs(s) cout << "[" << (#s) << " : {";auto _itr = s.begin();\
					for(int k = s.size(); k > 1; --k) {cout << *_itr << ", "; ++_itr;} cout << *_itr << "}] "

typedef long long ll;

/*LETS BEGIN WITH THE NAME OF LORD MAHADEV*/
const int mxN = 100;
int ar[mxN];

int main(){
	int x, n;
	cin >> x >> n;
	for(int i = 0; i < n; ++i){
		cin >> ar[i];
	}

	sort(ar, ar + n);

	for(int i = 0; i <= 100; ++i){
		int lwr = x - i, upr = x + i;
		if(!binary_search(ar, ar + n, lwr)){
			cout << lwr << endl;
			exit(0);
		}else if(!binary_search(ar, ar + n, upr)){
			cout << upr << endl;
			exit(0);
		}
	}
	return 0;
}

Measured memory_bytes: 3652
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        String[] keyStrArr = new String[]{
                "dream",
                "dreamer",
                "erase",
                "eraser",
        };

        String sReverse = new StringBuilder(s).reverse().toString();
        for (int i = 0; i < keyStrArr.length; i++) {
            keyStrArr[i] = new StringBuilder(keyStrArr[i]).reverse().toString();
        }

        boolean isEqual = true;
        for (int i = 0; i < sReverse.length();) {
            boolean flg = false;// 文字列が部分一致するか
            for (int j = 0; j < keyStrArr.length; j++) {
                String partStr = "";
                if (i + keyStrArr[j].length() > sReverse.length()) {
                    partStr = sReverse.substring(i);
                } else {
                    partStr = sReverse.substring(i, i + keyStrArr[j].length());// iからの部分文字列
                }

                if (partStr.equals(keyStrArr[j])) {
                    // 部分一致したためroopを抜ける
                    i += keyStrArr[j].length();
                    flg = true;
                    break;
                }
            }

            // 文字列が一致しなかったためroopを抜ける
            if (!flg) {
                isEqual = false;
                break;
            }
        }

        System.out.println(isEqual ? "YES" : "NO");
    }
}


Measured memory_bytes: 27672
#pragma region head
    #include <bits/stdc++.h>
    using namespace std;
    using ll = long long;
    using vi = vector<int>;
    using vll = vector<ll>;
    using pi = pair<int, int>;
    using pll = pair<ll,ll>;
    template <class T> using vv = vector<vector<T>>;
    #define rep(i,n) for(int i = 0; i < (int)(n); i++)
    #define repi(i,a,b) for(int i = (int)(a); i < (int)(b); i++)
    #define rrep(i,n) for(int i = (int)(n)-1; i >= 0; i--)
    #define rrepi(i,a,b) for(int i = (int)(b)-1; i >= (int)(a); i--)
    #define all(x) (x).begin(), (x).end()
    #define rall(x) (x).rbegin(), (x).rend()    
    #define bit(n) (1LL<<(n))
    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; }
    const int INF = 1002003004;
    const ll LINF = 1002003004005006007ll;
    struct preprocess{preprocess()
    {cin.tie(nullptr);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20);}}____;
#pragma endregion head

#pragma region library
// Time Complexity: faster than O(logN)[O(ArkInv(N))]
// UnionFind.data: if minus -> size of subtree (node is root)
// if plus -> parent of the node
struct UnionFind {
    vector<int> data;
    UnionFind(int sz){
        data.assign(sz,-1);
    }
    int find(int x){
        if(data[x]<0) return x;
        return data[x]=find(data[x]);
    }
    bool unite(int x, int y){
        x = find(x); y = find(y);
        if(x==y) return false;
        if(data[x]>data[y]) swap(x,y);
        data[x]+=data[y];
        data[y]=x;
        return true;
    }
    int size(int x){
        return (-data[find(x)]);
    }
    bool same(int x,int y){
        return find(x)==find(y);
    }
};
#pragma endregion library

int main(){
    int n,m; cin >> n >> m;
    UnionFind uf(n);
    rep(i,m){
        int a,b; cin >> a >> b;
        a--; b--;
        uf.unite(a,b);
    }
    int ans = 0;
    rep(i,n){
        chmax(ans, uf.size(i));
    }
    cout << ans << '\n';
    
}


Measured memory_bytes: 3988
#include<iostream>
using namespace std;
main(){
    int n;
    cin>>n;
    int a[3][101];
    for(int i=0;i<n;i++)
    cin>>a[0][i];
    for(int i=0;i<n;i++)
    cin>>a[1][i];
    int ans=-1;
    for(int i=0;i<n;i++){
        int m=0;
        for(int j=0;j<=i;j++){
            m+=a[0][j];
        }
        for(int j=i;j<n;j++){
            m+=a[1][j];
        }
        if(m>ans) ans=m;    
    }
    cout<<ans;
}

Measured memory_bytes: 256
import java.util.*;

public class Main{
   public static void main(String[] args){
       Scanner sc = new Scanner(System.in);
       int n = Integer.parseInt(sc.next());

       //最初に出てくるSについて、keyを小文字アルファベット valueを回数
       Map<String, Integer> map = new TreeMap<>();

       //Sで文字列を受け取り、sに分割
       String S = sc.next();
       String[] s = S.split("");
       for(int i=0; i<s.length; i++) {
           if(map.containsKey(s[i])) {
               map.put(s[i], map.get(s[i])+1);
           }else {
               map.put(s[i], 1);
           }
       }

       //2番目以降に出てくるSについて、keyを小文字アルファベット valueを回数
       Map<String, Integer> mmap = new TreeMap<>();

       //最初のSに出てきたが、2番目以降のSには出てこなかった小文字アルファベットを格納
       ArrayList<String> delete = new ArrayList<>();
       
       for(int x=1; x<n; x++) {
           S = sc.next();
           s = S.split("");
           mmap = new HashMap<>();
           for(int i=0; i<s.length; i++) {
               if(mmap.containsKey(s[i])) {
                   mmap.put(s[i], mmap.get(s[i])+1);
               }else {
                   mmap.put(s[i], 1);
               }
           }
           
           
           for(String key : map.keySet()) {
               if(mmap.containsKey(key)) {

                   //mmapにもmapにもある=>共通なので頻出回数が少ない方の値を入れる
                   map.put(key, Math.min(map.get(key), mmap.get(key)));
               }else {

                   //mapにあってmmapにない=>共通ではないのでmapから削除するためdeleteに入れる
                   delete.add(key);
               }
           }
       }
       
       //deleteの中身を取り出してmapから削除
       if(delete.size() > 0) {
           for(String str : delete) {
               map.remove(str);
           }
       }
       
       String ans = "";

       //mapの中身を取り出してvalueの回数だけ追加
       for(String key : map.keySet()) {
           for(int i=0; i<map.get(key); i++) {
               ans += key;
           }
       }
       System.out.println(ans);
   }
}

Measured memory_bytes: 22996
#include<iostream>
int s[200006];
int q[200006] = { 0 };
using namespace std;
int main ()
{
	int n; cin >> n;
	for (int i = 0; i < n - 1; i++)
	{
		cin >> s[i];
		q[s[i]]++;
	}
	for (int i = 1; i <= n ; i++)
	{
		cout << q[i] << endl;
	}
}

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

int main() {
  
  string s;
  cin >> s;
  
  for ( int i = 0; i < s.size(); i++){
    int count = 0;
    for ( int j = 0; j < s.size(); j++){
      if ( s[i] == s[j] ){
        count++;
      }
    }
    if ( count % 2 != 0 ){
      cout << "No" << endl;
      return 0;
    }
  }
  
  cout << "Yes" << endl;  
  
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A, B, a = 0;
  cin >> A >> B;
  if ((B - 1) % (A - 1) != 0) {
    a++;
  }
  cout << (B - 1)/(A - 1) + a << endl;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
    int a,b;
    cin>>a>>b;
    if(a==b)
        cout <<"a == b"<< "\n" ;
    else if(a<b)
        cout <<"a < b"<< "\n" ;
    else
        cout << "a > b" << "\n" ;


    return 0;
}


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

typedef long long LL;

const int N=100000,mod=1000000007;

int add(int a,int b,int p=mod){return a+b>=p?a+b-p:a+b;}
int sub(int a,int b,int p=mod){return a-b<0?a-b+p:a-b;}
int mul(int a,int b,int p=mod){return (LL)a*b%p;}
void sadd(int &a,int b,int p=mod){a=add(a,b,p);}
void ssub(int &a,int b,int p=mod){a=sub(a,b,p);}
void smul(int &a,int b,int p=mod){a=mul(a,b,p);}
int Power(int a,int k,int p=mod){int res=1;for (;k;k>>=1,smul(a,a,p)) if (k&1) smul(res,a,p);return res;}
int Get_inv(int a,int p=mod){return Power(a,p-2,p);}

int n,a,b,c;

void into(){
  scanf("%d%d%d%d",&n,&a,&b,&c);
  smul(a,Get_inv(100));
  smul(b,Get_inv(100));
  smul(c,Get_inv(100));
}

int pw[2][N+9];

void Get_pw(){
  int inv=Get_inv(add(a,b));
  smul(a,inv);smul(b,inv);
  pw[0][0]=pw[1][0]=1;
  for (int i=1;i<=n;++i){
	pw[0][i]=mul(pw[0][i-1],a);
	pw[1][i]=mul(pw[1][i-1],b);
  }
}

int inv[N*2+9],fac[N*2+9],ifac[N*2+9];

void Get_inv(){
  inv[1]=1;
  fac[0]=fac[1]=1;
  ifac[0]=ifac[1]=1;
  for (int i=2;i<=n<<1;++i){
	inv[i]=mul(mod-mod/i,inv[mod%i]);
	fac[i]=mul(fac[i-1],i);
	ifac[i]=mul(ifac[i-1],inv[i]);
  }
}

int Get_c(int n,int m){return n<m||m<0?0:mul(fac[n],mul(ifac[m],ifac[n-m]));}

int ans;

void Get_ans(){
  c=Get_inv(sub(1,c));
  for (int i=0;i<n;++i){
	int t=mul(mul(i+n,c),Get_c(i+n-1,i));
	sadd(ans,mul(t,mul(pw[0][i],pw[1][n])));
	sadd(ans,mul(t,mul(pw[0][n],pw[1][i])));
  }
}

void work(){
  Get_pw();
  Get_inv();
  Get_ans();
}

void outo(){
  printf("%d\n",ans);
}

int main(){
  into();
  work();
  outo();
  return 0;
}

Measured memory_bytes: 6960
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int r = sc.nextInt();
		int c = sc.nextInt();
		int[][] matrix = new int[r][c];
		for(int i = 0; i < r; i++){
			for(int k = 0; k < c; k++){
				matrix[i][k] = sc.nextInt();
			}
		}
		for(int i = 0; i < r; i++){
			int subtotal = 0;
			for(int k = 0; k < c; k++){
				System.out.print(matrix[i][k] + " ");
				subtotal += matrix[i][k];
			}
			System.out.println(subtotal);
		}
		int total = 0;
		for(int i = 0; i < c; i++){
			int subtotal = 0;
			for(int k = 0; k < r; k++){
				subtotal += matrix[k][i];
			}
			total += subtotal;
			System.out.print(subtotal + " ");
		}
		System.out.println(total);
	}
}



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

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

    int A, B, C; cin >> A >> B >> C;
    if ((A == 5 && B == 5 && C == 7) || \
        (A == 5 && B == 7 && C == 5) || \
        (A == 7 && B == 5 && C == 5))
        cout << "YES" << endl;
    else
        cout << "NO" << endl;

    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
int main()
{
    char s[100];
    scanf("%s",&s);
    if(s[0]==s[1]||s[1]==s[2]||s[2]==s[3]||s[3]==s[4])
    {
        printf("Bad\n");
    }
    else
    {
        printf("Good\n");
    }
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define whole(x) (x).begin(),(x).end()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
using P = pair<int, int>;
#define debug(var) cerr << "[" << #var << "] " << var << endl
#define chmin(x, y) x = min(x, y)
const ll mod = 1000000007;
const int dx[] = {-1,0,1,0};
const int dy[] = {0,-1,0,1};

ll f(ll i, ll x) {
    i++;
    ll p = 2*x;
    ll res = 0;
    res += (i - i%p)/2;
    res += max(0LL, i%p-x);
    return res;
}

int main(){
    ll a, b;
    cin >> a >> b;
    ll ans = 0;
    //debug(f(7, 2));

    for (ll i=60; i>=0; i--) {
        ll now = 1LL<<i;
        ll big = f(b, now);
        ll small = f(a-1, now);
        if ((big-small)%2==1) {
            ans += now;
        }
    }
    
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    double v[] = new double[n];
    double tmp = 0;
    for(int i=0;i<n;i++){
      v[i]=sc.nextDouble();
    }
    Arrays.sort(v);
    tmp = v[0];
    for(int i=0;i<n-1;i++){
      tmp = (tmp+v[i+1])/2;
    }
    System.out.println(tmp);
    
  }
}

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

using namespace std;

int n;

void solve(){
    int i,j;
    string str;
    cin >> n;
    vector<int> a(n);
    for(i = 0;i < n;i++){
        cin >> a[i];
    }
    vector<int> b(n);
    for(i = n-1;i >= 0;i--){
        int s = 0;
        for(j = 2*(i+1);j <= n;j += i+1){
            s += b[j-1];
        }
        if(s%2 != a[i]) b[i] = 1;
        else b[i] = 0;
    }
    long long ans = 0;
    for(i = 0;i < n;i++) if(b[i] == 1) ans++;
    cout << ans << endl;
    for(i = 0;i < n;i++) if(b[i] == 1) cout << i+1 << endl;
}

int main(){
    solve();
}


Measured memory_bytes: 2432
#include<bits/stdc++.h>
using namespace std;
typedef pair<double, int> P;
typedef pair<int, int> Point;
typedef pair<Point, Point> Segment; // (frm, to)
const double eps = 1e-9;

double norm(Point a) {
    return sqrt(a.first * a.first + a.second * a.second);
}
Point getv(Point frm, Point to) {
    return Point(to.first - frm.first, to.second - frm.second);
}
Point getv(Segment a) {
    return getv(a.first, a.second);
}
double dist(Point a, Point b) {
    return norm(getv(a, b));
}
double getlen(Segment a) {
    return dist(a.first, a.second);
}

int cross(Point v, Point w) {
    return v.first * w.second - v.second * w.first;
}
bool iscross(Segment a, Segment b) {
    return (cross(getv(a), getv(a.first, b.first)) > 0) != (cross(getv(a), getv(a.first, b.second)) > 0) && (cross(getv(b), getv(b.first, a.first)) > 0) != (cross(getv(b), getv(b.first, a.second)) > 0);
}



vector<double> dijkstra(int s, vector<vector<P>> edge) {
    int n = edge.size();
    vector<double> dist(n, 1e16);
    priority_queue<P, vector<P>, greater<P>> q;
    dist[s] = 0;
    q.push(P(0, s));
    while (!q.empty()) {
        P p = q.top();
        q.pop();
        for (auto& e : edge[p.second]) {
            if (dist[e.second] > p.first + e.first) {
                dist[e.second] = p.first + e.first;
                q.push(P(p.first + e.first, e.second));
            }
        }
    }
    return dist;
}



int main() {
    int na, nb;
    cin >> na >> nb;
    vector<P> a(na);
    vector<P> b(nb);
    for (int i = 0; i < na; ++i)
        cin >> a[i].first >> a[i].second;
    for (int i = 0; i < nb; ++i)
        cin >> b[i].first >> b[i].second;

    Segment sa = Segment(a[0], a[1]);
    Segment sb = Segment(b[0], b[1]);
    vector<vector<P>> eda(na);
    vector<vector<P>> edb(nb);
    for (int i = 0; i < na; ++i) {
        for (int j = i + 1; j < na; ++j) {
            if (!iscross(Segment(a[i], a[j]), sb)) {
                eda[i].push_back(P(dist(a[i], a[j]), j));
                eda[j].push_back(P(dist(a[i], a[j]), i));
            }
        }
    }
    for (int i = 0; i < nb; ++i) {
        for (int j = i + 1; j < nb; ++j) {
            if (!iscross(Segment(b[i], b[j]), sa)) {
                edb[i].push_back(P(dist(b[i], b[j]), j));
                edb[j].push_back(P(dist(b[i], b[j]), i));
            }
        }
    }
    double ans = min(getlen(sa) + dijkstra(0, edb)[1], getlen(sb) + dijkstra(0, eda)[1]);
    if (ans > 1e15)
        puts("-1");
    else
        printf("%.16lf\n", ans);

    return 0;
}

Measured memory_bytes: 64468
#include <iostream>
#include <vector>
#include <string>

using namespace std;

int main(){
    int N, P;
    while(cin >> N >> P){
        string S; cin >> S;
        long long res = 0;
        if(P == 2 || P == 5){
            for(int i=0;i<N;i++){
                if((S[i]-'0')%P == 0) res += i+1;
            }
        } else {
            int m = 1;
            vector<int> mod(N);
            int val = 0;
            for(int i=N-1;i>=0;i--){
                val += m * (S[i]-'0');
                val %= P;
                mod[i] = val;
                m = 10 * m % P;
            }
            vector<int> cnt(P, 0);
            for(int i=0;i<N;i++){
                ++cnt[mod[i]];
                res += (mod[i] == 0 ? cnt[mod[i]] : cnt[mod[i]] - 1);
            }
        }
        cout << res << endl;
    }
}

Measured memory_bytes: 1284
#include<bits/stdc++.h>
using namespace std;
typedef pair<int ,int> P;
int inf = 100000000;

int main(){
    int n;
    cin >> n;
    vector<P> vec(n);
    for(int i=0;i<n;i++) {
        cin >> vec[i].first;
        vec[i].second = i;
    }
    sort(vec.begin() ,vec.end());
    reverse(vec.begin() ,vec.end());
    for(int i=0;i<n;i++){
        if(i == vec[0].second)cout << vec[1].first << endl;
        else cout << vec[0].first << endl;
    }
}

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

#define pii pair<int,int>
#define se second
#define fi first
#define pb push_back
#define pob pop_back()
#define pf push_front
#define pof pop_front()
#define mp make_pair
#define endl '\n'
#define fast ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define ll long long
const ll INF=2e17;

int main(){
	ll a,b,ans=0;
	cin>>a>>b;
	while(a<=b){
		ans++;
		a*=2;
	}
	cout<<ans;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#define len(X) ((int)(X).size())

#ifdef __LOCAL
#define DBG(X) cout << #X << "=" << (X) << '\n';
#define SAY(X) cout << (X) << '\n';
#else
#define DBG(X)
#define SAY(X)
#endif

#define M_PI       3.14159265358979323846

using namespace std;

using ll = long long int;
using ull = unsigned long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

const int INT_INF = (int)(2e9);
const ll  LL_INF = (ll)(2e18);

const int NIL = -1;
static mt19937 _g(time(nullptr));

inline ll randint(ll a, ll b) { ll w = (_g() << 31LL) ^ _g(); return a + w % (b - a + 1); }
inline void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); };
template<typename T> inline T sign(T x) { return T(x > 0) - T(x < 0); }
template<typename T, typename S> inline ostream& operator<<(ostream& os, const pair<T, S> p) { cout << "[" << p.first << ";" << p.second << "]"; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const vector<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline T fetch() { T ret; cin >> ret; return ret; }
template<typename T> inline vector<T> fetch_vec(int sz) { vector<T> ret(sz); for (auto& elem : ret) cin >> elem; return ret; }

void dfs(int node, vector<vector<int>>& graph, vector<ll>& counters, vector<bool>& visited, int sum)
{
    visited[node] = true;
    counters[node] += sum;

    for (int child : graph[node])
    {
        if (!visited[child])
            dfs(child, graph, counters, visited, counters[node]);
    }
}

int solve()
{
    int N, Q;

    std::cin >> N >> Q;

    vector<vector<int>> graph(N, vector<int>());
    int a, b;
    for (int i = 0; i < N - 1; ++i)
    {
        cin >> a >> b;

        graph[a-1].push_back(b-1);
        graph[b - 1].push_back(a - 1);
    }

    vector<ll> counters(N, 0);

    for (int i = 0; i < Q; ++i)
    {
        cin >> a >> b;
        counters[a-1] += b;
    }

    vector<bool> visited(N, false);

    dfs(0, graph, counters, visited, 0);

    for (int i = 0; i < N; ++i)
        cout << counters[i] << " ";
    cout << endl;

    return 0;
}

int main()
{
    solve();

    return 0;
}

Measured memory_bytes: 30592
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>

// https://atcoder.jp/contests/abc122/submissions/4920926

using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
 
int main(void) {
    int N, Q;
    char S[100001];
    scanf("%d %d", &N, &Q);
    scanf("%s", S);

    int ans[100001]={0};
    int i, j;
    for( i=0; i<N; i++) {
      // 「右隣がCであるようなA」を数える
      ans[i+1] = ans[i];
      if( S[i]=='A' && S[i+1]=='C') {
        ans[i+1]++;
      }
    }

    int ans2[100001];
    int l, r;
    for( i=0; i<Q; i++) {
      scanf("%d %d", &l, &r);
      ans2[i] = ans[r-1]-ans[l-1];
    }

    for( i=0; i<Q; i++) {
      printf("%d\n", ans2[i]);
    }

return 0;
}

Measured memory_bytes: 1664
package main

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

func main() {
    scanner := bufio.NewScanner(os.Stdin)
    var r string
    var eof bool
    var strs []string
    r, eof = readOneLine(scanner)
    for {
        r, eof = readOneLine(scanner)
        if (eof) {
            break;
        }
        strs = split(r)
    }
    fmt.Print(tradeStr(strs[0], strs[1]))
}

func tradeStr(a string, b string) string {
    var str string
    for i:=0;i<len(a);i++ {
        str += string(a[i]) + string(b[i])
    }
    return str
}

func readOneLine(scanner *bufio.Scanner) (string, bool) {
    var s string
    var eof = false
    if scanner.Scan() {
        s = scanner.Text()
    } else {
        eof = true
    }
    return s, eof
}

func s2i(s string) int {
    var intVal,_ = strconv.Atoi(s)
    return intVal
}

func i2s(i int) string {
    return string(i)
}

func s2f(s string) float64 {
    var floatVal,_ = strconv.ParseFloat(s, 64)
    return floatVal
}

func sum(i []int) int {
    sum := 0
    for _,val := range i {
        sum += val
    }
    return sum
}

func split(s string) []string {
    return strings.Fields(s)
}

func strAry2intAry(strs []string) []int {
    var ret = make([]int, 0, len(strs))
    for _ , str := range strs {
        var intVal, _ = strconv.Atoi(string(str));
        ret = append(ret, intVal)
    }
    return ret
}

func intAry2strAry(nums []int) []string {
    var ret = make([]string, 0, len(nums))
    for _ , num := range nums {
        var strVal = strconv.Itoa(num);
        ret = append(ret, strVal)
    }
    return ret
}

func ary2str(strs []string) string {
    return strings.Join(strs, " ")
}


Measured memory_bytes: 640
using System;
class DivP{
	static void Main(string[] args){
		int N = int.Parse(Console.ReadLine());
		string[] dN = Console.ReadLine().Split();
		int[] di = new int[N];
		for(int i = 0;i < N;i++){
			di[i] = int.Parse(dN[i]);
		}
		Array.Sort(di);
		if(N % 2 == 1)Console.WriteLine(0);
		else{
			Console.WriteLine(di[N / 2] - di[N / 2 - 1]);
		}
	}
}

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

using namespace std;

typedef long long ll;

ll MOD = 1000000007;

int main(int, char**) {
        string n;
        cin >> n;
        ll len = n.size();
        int prev = 0;
        ll ans = 0;
        for (int i=len-1; i>=0; i--) {
                int num = n.at(i) - '0';
                num += prev; 
                if (num>5 || (num==5 && i!=0 && n.at(i-1)-'0'>4)) {
                        ans += (10 - num);
                        prev = 1;
                } else {
                        ans += num;
                        prev = 0;
                }
        }
        cout << ans+prev << endl;
        return 0;
}


Measured memory_bytes: 1412
import java.io.IOException;
import java.io.InputStream;
import java.util.*;
import java.lang.Math;

public class Main {
    public static void main(String[] args) {
        FS reader = new FS();
        // write reader
        int N = reader.nextInt();
        int[] B = new int[N];
        for (int i=0; i<N; i++) {
            int a = reader.nextInt();
            B[a-1] = i+1;
        }
        for (int i=0; i<N; i++) {
            System.out.print(B[i]);
            if (i != N-1) System.out.print(" ");
        }
        System.out.println();
    }

    // Read Class
    static class FS {
        private final InputStream in = System.in;
        private final byte[] buffer = new byte[1024];
        private int ptr = 0;
        private int buflen = 0;
        private boolean hasNextByte() {
            if (ptr < buflen) {
                return true;
            } else {
                ptr = 0;
                try {
                    buflen = in.read(buffer);
                } catch (IOException e) {
                    e.printStackTrace();
                }
                if (buflen <= 0) {
                    return false;
                }
            }
            return true;
        }
    
        private int readByte() { return hasNextByte() ? buffer[ptr++] : -1;}
        private boolean isPrintableChar(int c) {return 33 <= c && c <= 126;}
        private void skipUnprintable() {while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++;}
    
        public boolean hasNext() { skipUnprintable(); return hasNextByte();}
        public String next() {
            if (!hasNext()) throw new NoSuchElementException();
            StringBuilder sb = new StringBuilder();
            int b = readByte();
            while(isPrintableChar(b)) {
                sb.appendCodePoint(b);
                b = readByte();
            }
            return sb.toString();
        }
        public int nextInt() {
            return (int)nextLong();
        }
        public long nextLong() {
            if (!hasNext()) throw new NoSuchElementException();
            long n = 0;
            boolean minus = false;
            int b = readByte();
            if (b == '-') {
                minus = true;
                b = readByte();
            }
            if (b < '0' || '9' < b) {
                throw new NumberFormatException();
            }
            while(true) {
                if ('0' <= b && b <= '9') {
                    n *= 10;
                    n += b - '0';
                } else if(b == -1 || !isPrintableChar(b)) {
                    return minus ? -n : n;
                } else {
                    throw new NumberFormatException();
                }
                b = readByte();
            }
        }
    }
}



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

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    map < char,char>a;
    a['T']='A';
    a['C']='G';
    a['A']='T';
    a['G']='C';
    char c;
    cin>>c;
    cout<<a[c];
    return 0;
}


Measured memory_bytes: 256
s = input()
n = len(s)
s1 = '01' * 50000
s2 = '10' * 50000

ans1 = 0
ans2 = 0

for i in range(n):
    if s[i] != s1[i]:
        ans1 += 1
    if s[i] != s2[i]:
        ans2 += 1

print(min(ans1,ans2))


Measured memory_bytes: 3444
#include <iostream>
#include <set>

using namespace std;

int main(void)
{
  set <int> s;
  int N;
  cin >> N;
  for(int i=0; i<N; i++){
    int d;
    cin >> d;
    s.insert(d);
  }
  cout  << s.size() << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#define pb push_back
#define pll pair <ll, ll>
#define MOMI using namespace std;
#define mp make_pair
#define pyshnapyshnakaa ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
#pragma optimize("TKACHENKO-GORYACHENKO")
#pragma GCC optimize("O3")
 
//#pragma GCC optimize("unroll-loops")
 
typedef long long ll;
 
typedef long double ld;
 
using namespace std;
 
const ll maxn = 1e3;
const ll inf = 1e14;

struct edge{
    ll to;
    ll c;
};

std :: vector<ll> x;

vector <edge> V[maxn];
 
ll n, m, k, l;

ll D[maxn][maxn];

ll used[maxn];

int main() {
    ll q, w, e, a, b, c;
    cin >> n >> m >> l;
    for (q = 0; q < m; q++) {
        cin >> a >> b >> c;
        a--; b--;
        if (c > l) {
            continue;
        }
        edge x, y;
        x.to = b; y.to = a;
        x.c = y.c = c;
        V[a].pb(x); V[b].pb(y);
    }
    for (q = 0; q < n; q++) {
        for (w = 0; w < n; w++) {
            D[q][w] = inf;
            used[w] = 0;
        }
        D[q][q] = 0;
        // cout << endl;
        for (w = 0; w < n; w++) {
            ll mni = -1; 
            for (e = 0; e < n; e++) {
                if (used[e]) {
                    continue;
                }
                if (mni == -1) {
                    mni = e;
                }
                if (D[q][mni] > D[q][e]) {
                    mni = e;
                }
            }
            // cout << mni << " MNI" << endl;
            used[mni] = 1;
            ll ost = l - D[q][mni] % l;
            ll cnt = D[q][mni] / l;
            if (D[q][mni] % l == 0) {
                ost = 0;
                cnt--;
            }
            for (e = 0; e < V[mni].size(); e++) {
                ll c1 = V[mni][e].c, v1 = V[mni][e].to;
                ll dmn;
                if (c1 <= ost) {
                    dmn = D[q][mni] + c1;
                }
                else {
                    dmn = (cnt + 1) * l + c1;
                }
                D[q][v1] = min(D[q][v1], dmn);
            }
        }
    }
    cin >> k;
    for (e = 0; e < k; e++) {
        cin >> a >> b;
        a--; b--;
        // cout << "DANS " << a << " " << b << " " << D[a][b] << endl;
        ll ans = D[a][b] / l;
        if (D[a][b] >= inf - 100) {
            cout << -1 << endl;
            continue;
        }
        if (D[a][b] % l == 0) {
            ans--;
        }
        cout << ans << endl;
    }
}

Measured memory_bytes: 6656
import java.util.Scanner;

class Main{
	public static void main(String[] args) {
		Scanner scan=new Scanner(System.in);
		int a=scan.nextInt(),b=scan.nextInt(),c=scan.nextInt(),t=a,i;
		scan.close();
		for(i=1;i<b;i++) {
			if(t%b==c) break;
			t+=a;
		}
		if(i==b) System.out.print("NO");
		else System.out.print("YES");
	}
}

Measured memory_bytes: 22868
while True:
    try:
        n,a,b=map(int,input().split())
    except:
        break
    thelist=list(map(int,input().split()))
    t=b//a
    sum=0
    for i in range(1,n):
        tt=thelist[i]-thelist[i-1]
        if tt>t:
            sum+=b
        else:
            sum+=a*tt
    print(sum)


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

const ll LINF = 1e18;
const int INF = 1e9;
const ll MOD = 1000000007;


int main(){

    int a;
    cin >> a;
    ll ans = a+ a * a + a * a * a;
    cout  << ans << endl;    

    return 0;
}

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

using namespace std;

typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;

const int iinf = 1 << 29;
const long long linf = 1ll << 61;

#define modp(x, y) (((y) + (x) % (y)) % (y))
template<typename T> inline T gcd(T x, T y) { if(x < y) swap(x, y); T mod = x % y; if(mod == 0) return y; return gcd(y, mod); }
template<typename T> inline T lmc(T x, T y) { return x / gcd(x, y) * y; }

int main(int argc, char* argv[])
{
	int one = 0, two = 0, four = 0;
	int N;
	scanf("%d", &N);
	for(int n = 0; n < N; n++)
	{
		int i;
		scanf("%d", &i);
		if(i % 4 == 0) four++;
		else if(i % 2 == 0) two++;
		else one++;
	}

	bool ans = false;
	if(two == 0)
	{
		if(one - 1 <= four) ans = true;
	}
	else
	{
		if(one <= four) ans = true;
	}
	printf("%s\n", ans ? "Yes" : "No");

	return 0;
}


Measured memory_bytes: 384
//package abc176;

import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) throws Exception{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int N = Integer.parseInt(br.readLine());
		String[] ip = br.readLine().split(" ");
		int[] ary = new int[N];
		
		for(int i = 0 ; i < N ; i++) {
			ary[i] = Integer.parseInt(ip[i]);
		}
		
		int prev = ary[0];
		long ans = 0;
		
		for(int i = 1 ; i < N ; i++) {
			if(prev > ary[i]) {
				ans += Math.abs(prev-ary[i]);
				ary[i] += Math.abs(prev-ary[i]);
			}
			prev = Math.max(ary[i], prev);
		}
		
		System.out.println(ans);
	}
	
}


Measured memory_bytes: 61180
// #define DEBUGGING
#include <bits/stdc++.h>
#define endl '\n'
#define ALL(V) (V).begin(), (V).end()
#define ALLR(V) (V).rbegin(), (V).rend()
template <typename T> using V = std::vector<T>;
template <typename T> using VV = V<V<T>>;
using ll = std::int64_t;
using ull = std::uint64_t;
using PLL = std::pair<ll, ll>;
using TLL = std::tuple<ll, ll, ll>;
template <typename T> const T& var_min(const T &t) { return t; }
template <typename T> const T& var_max(const T &t) { return t; }
template <typename T, typename... Tail> const T& var_min(const T &t, const Tail&... tail) { return std::min(t, var_min(tail...)); }
template <typename T, typename... Tail> const T& var_max(const T &t, const Tail&... tail) { return std::max(t, var_max(tail...)); }
template <typename T, typename... Tail> void chmin(T &t, const Tail&... tail) { t = var_min(t, tail...); }
template <typename T, typename... Tail> void chmax(T &t, const Tail&... tail) { t = var_max(t, tail...); }
template <typename T> const T& clamp(const T &t, const T &low, const T &high) { return std::max(low, std::min(high, t)); }
template <typename T> void chclamp(T &t, const T &low, const T &high) { return t = clamp(t, low, high); }
namespace init__ { struct InitIO { InitIO() { std::cin.tie(nullptr); std::ios_base::sync_with_stdio(false); std::cout << std::fixed << std::setprecision(30); } } init_io; }
#define mv_rec make_v(init, tail...)
template <typename T> T make_v(T init) { return init; }
template <typename T, typename... Tail> auto make_v(T init, size_t s, Tail... tail) { return V<decltype(mv_rec)>(s, mv_rec); }
#undef mv_rec
using namespace std;
#ifdef DEBUGGING
#include "../../debug/debug.cpp"
#else
#define DEBUG(...) 0
#define DEBUG_SEPARATOR_LINE 0
#endif

ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }

int main() {
    ll a, b;
    cin >> a >> b;
    cout << a * b / gcd(a, b) << endl;
    return 0;
}


Measured memory_bytes: 256
str = input()
count = 0
isCount = False
answer = 0
for id in range(len(str)):
    if isCount == False and str[id] == "A": 
        count = 0
        isCount = True
    if isCount == False: continue
    count += 1
    if str[id] == "Z": 
        answer = max(answer, count)
print(answer)

Measured memory_bytes: 3516
/*
これを入れて実行
g++ code.cpp
./a.out
 */

#include <iostream>
#include <vector>
#include <string>
#include <queue>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <cmath>
#include <tuple>
#include <iomanip>

using namespace std;
typedef long long ll;
typedef long double ld;

int dy4[4] = {-1, 0, +1, 0};
int dx4[4] = {0, +1, 0, -1};
int dy8[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
int dx8[8] = {0, 1, 1, 1, 0, -1, -1, -1};

const long long INF = 1LL << 60;
const ll MOD = 1e9 + 7;

bool greaterSecond(const pair<int, int>& f, const pair<int, int>& s){
    return f.second > s.second;
}

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

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

ll nCr(ll n, ll r){
    if(r == 0 || r == n){
        return 1;
    } else if(r == 1){
        return n;
    }
    return (nCr(n - 1, r) + nCr(n - 1, r - 1));
}

ll nPr(ll n, ll r){
    r = n - r;
    ll ret = 1;
    for (ll i = n; i >= r + 1; i--) ret *= i;
    return ret;
}

//-----------------------ここから-----------

int main(void){
    string a, s, c;
    cin >> a >> s >> c;

    cout << 'A' << s[0] << 'C' << endl;
}

Measured memory_bytes: 256
#include"iomanip"
#include"iostream"
#include"limits"
#include"cmath"
#include"vector"
#include"algorithm"
#include"list"
#include"queue"
#include"stack"
#include"set"
#include"unordered_set"
#include"map"
#include"unordered_map"
#include"string"
#include"cstring"
#include"assert.h"
using namespace std;
#define ff first
#define ss second
#define all(v) v.begin(),v.end()
#define mp make_pair
#define pb push_back
#define mset(a,b) memset(a,b,sizeof(a))
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	int n;
	cin>>n;
	set<ll>my;
	while(n--)
	{
		ll a;
		cin>>a;
		if(my.find(a)==my.end())
		{
			my.insert(a);
		}
		else
		{
			my.erase(a);
		}
	}
	cout<<my.size()<<'\n';
}

Measured memory_bytes: 4992
N = int(input())

t0 = 0
x0 = 0
y0 = 0

for _ in range(N):
    t, x, y = map(int, input().split())

    d = abs(x - x0) + abs(y - y0)
    if t - t0 < d or ((t - t0) - d) % 2:
        print('No')
        exit()

    t0 = t
    x0 = x
    y0 = y

print('Yes')


Measured memory_bytes: 3060
import java.util.Scanner;

public class Main{
    public static void main(String[] arg){
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        if(a<b){
            if(b<c){
                System.out.printf("%d %d %d\n",a,b,c);
            }else if(a<c){
                System.out.printf("%d %d %d\n",a,c,b);
            }else{
                System.out.printf("%d %d %d\n",c,a,b);
            }
        }else{
            if(a<c){
                System.out.printf("%d %d %d\n",b,a,c);
            }else if(b<c){
                System.out.printf("%d %d %d\n",b,c,a);
            }else{
                System.out.printf("%d %d %d\n",c,b,a);
            }
        }
    }
}


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

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

    int d[N + 2];
    bool check;
    for (int i = 0; i <= 1; i++) {
        for (int j = 0; j <= 1; j++) {
            d[1] = i;
            d[2] = j;

            for (int k = 3; k <= N; k++) {
                if (s[(k - 1) - 1] == 'o') {
                    if (d[k - 1] == 0) {
                        d[k] = d[k - 2];
                    } else {
                        d[k] = !d[k - 2];
                    }
                } else {
                    if (d[k - 1] != 0) {
                        d[k] = d[k - 2];
                    } else {
                        d[k] = !d[k - 2];
                    }
                }
            }

            d[0] = d[N];
            d[N + 1] = d[1];

            check = true;
            for (int k = 1; k <= N; k++) {
                if (d[k] == 0) {
                    if (s[(k - 1)] == 'o' && d[k - 1] != d[k + 1]) {
                        check = false;
                        break;
                    } else if (s[(k - 1)] == 'x' && d[k - 1] == d[k + 1]) {
                        check = false;
                        break;
                    }
                } else {
                    if (s[(k - 1)] == 'o' && d[k - 1] == d[k + 1]) {
                        check = false;
                        break;
                    } else if (s[(k - 1)] == 'x' && d[k - 1] != d[k + 1]) {
                        check = false;
                        break;
                    }
                }
            }

            if (check) {
                for (int i = 1; i <= N; i++) {
                    if (d[i]) {
                        cout << "W";
                    } else {
                        cout << "S";
                    }
                }
                cout << endl;
                return 0;
            }
        }
    }

    cout << -1 << endl;
    return 0;
}


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

class Main {
	public static void main(String args[]) throws IOException {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		Solver solver = new Solver();
		solver.init();
		solver.readHead(in.readLine());
		solver.readA(in.readLine());
		// for (; solver.hasNext();) {
		// solver.readBody(in.readLine());
		// }
		// solver.solve();
	}
}

class Solver {
	int N;
	int cnt;

	public void init() {
		N = 0;
		cnt = 0;
	}

	public void readHead(String str) {
		String[] strArr = str.split("\\s+");
		N = Integer.parseInt(strArr[0]);
		// System.out.println(N);
	}

	public void readA(String str) {
		String[] strArr = str.split("\\s+");
		int[] ord = new int[N + 1];
		for (int i = 0; i < N; i++) {
			int a = Integer.parseInt(strArr[i]);
			ord[a] = i + 1;
		}
		String sep = "";
		for (int i = 1; i <= N; i++) {
			System.out.print(sep + ord[i]);
			sep = " ";
		}
		System.out.println();
	}

	public boolean hasNext() {
		return cnt < N;
	}

	public void readBody(String str) {
		// System.out.println(str);
		cnt++;
	}

	public void solve() {

	}
}


Measured memory_bytes: 43704
#include<bits/stdc++.h>
using namespace std;
#define int long long 
#define sz(x) (int)(x.size())

vector<int> z_function(string s) {
    int n = (int) s.length();
    vector<int> z(n);
    for (int i = 1, l = 0, r = 0; i < n; ++i) {
        if (i <= r)
            z[i] = min (r - i + 1, z[i - l]);
        while (i + z[i] < n && s[z[i]] == s[i + z[i]])
            ++z[i];
        if (i + z[i] - 1 > r)
            l = i, r = i + z[i] - 1;
    }
    return z;
}

signed main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int n;
    cin >> n;
    string s, t;
    cin >> s >> t;
    reverse(s.begin(), s.end());
    reverse(t.begin(), t.end());
    auto v = z_function(s + "$" + t);
    int mx = 0;
    for (int i = n; i < sz(v); i++) {
        mx = max(v[i], mx);
    }
    cout << 2 * n - mx << "\n";
}

Measured memory_bytes: 256
<?php

$building = array();
for ($i = 1; $i <= 4; $i++) {
  for ($j = 1; $j <= 3; $j++) {
    $building[$i][$j] = array_fill(1,10,0);
  }
}

$num = (int)fgets(STDIN);

while (--$num >= 0) {
  fscanf(STDIN, "%d%d%d%d", $b, $f, $r, $v);
  $building[$b][$f][$r] += $v;
}

$res = array_fill(1,4,'');
for ($i = 1; $i <= 4; $i++) {
  for ($j = 1; $j <= 3; $j++) {
    $res[$i] .= ' ' . implode(' ', $building[$i][$j]) . PHP_EOL;
  }
}

echo implode('####################'.PHP_EOL, $res);

Measured memory_bytes: 15416
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n = 0;
    int ans = 0;
    cin >> n;
    int L[n];
    for (int i = 0; i < n; i++)
    {
        cin >> L[i];
    }
    
    for (int i = 0; i < n; i++)
    {
        for (int j = i; j < n; j++)
        {
            for (int k = j; k < n; k++)
            {
                if((L[i] == L[j]) | (L[j] == L[k]) | (L[k] == L[i])){
                    continue;
                }
                if((L[i]+L[j] > L[k]) & (L[i]+L[k] > L[j]) & (L[j]+L[k] > L[i])){
                    ans++;
                }
            }
            
        }
        
    }
    cout << ans << endl;
}


Measured memory_bytes: 3672
// ===================================
//   author: M_sea
//   website: http://m-sea-blog.com/
// ===================================
#include <algorithm>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <map>
#define re register
using namespace std;
typedef long long ll;

inline int read() {
    int X=0,w=1; char c=getchar();
    while (c<'0'||c>'9') { if (c=='-') w=-1; c=getchar(); }
    while (c>='0'&&c<='9') X=X*10+c-'0',c=getchar();
    return X*w;
}

int H,W,n;
struct node { int lx,ly,rx,ry; };
bool operator <(node a,node b) {
    if (a.lx!=b.lx) return a.lx<b.lx;
    else if (a.ly<b.ly) return a.ly<b.ly;
    else if (a.rx<b.rx) return a.rx<b.rx;
    else return a.ry<b.ry;
}
map<node,int> mp;
ll ans[10];

int main() {
    H=read(),W=read(),n=read();
    for (re int i=1;i<=n;++i) {
        int x=read(),y=read();
        for (re int dx=-2;dx<=0;++dx) {
            int lx=x+dx,rx=lx+2;
            if (lx<1||lx>H||rx<1||rx>H) continue;
            for (re int dy=-2;dy<=0;++dy) {
                int ly=y+dy,ry=ly+2;
                if (ly<1||ly>W||ry<1||ry>W) continue;
                node t=(node){lx,ly,rx,ry};
                if (!mp.count(t)) mp[t]=1;
                else ++mp[t];
            }
        }
    }
    for (re auto i:mp) ++ans[i.second];
    ans[0]=1ll*(W-2)*(H-2);
    for (re int i=1;i<10;++i) ans[0]-=ans[i];
    for (re int i=0;i<10;++i) printf("%lld\n",ans[i]);
    return 0;
}


Measured memory_bytes: 56448