akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
using namespace std;
int main(void){
    int a,b,c;
    cin>>a>>b>>c;
    if (a>b) swap (a,b);
    if (b>c) swap (b,c);
    if (a>b) swap (a,b);
    
    cout<<a<<" "<<b<<" "<<c<<endl;
    
    return 0;
    
}




Measured memory_bytes: 3092
#include "bits/stdc++.h"
using namespace std;
 
/** Template Begins **/
typedef pair<int, pair<int, int>> piii;


#define ll          long long 
#define IOS         ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl        '\n'
#define y1          y12312

const int N = 5e6+7, INF = 1e9;

template<class L, class R> ostream &operator<<(ostream &os, pair<L,R> P) {
  return os << "(" << P.F << "," << P.S << ")";
} 

template<class T> ostream &operator<<(ostream& os, vector<T> V) {
  os << "["; for (auto vv : V) os << vv << ","; return os << "]";
}
 
template<class TH> void _dbg(const char *sdbg, TH h){ cerr << sdbg << '=' << h << endl; }
 
template<class TH, class... TA> void _dbg(const char *sdbg, TH h, TA... a) {
  while(*sdbg!=',') cerr << *sdbg++;
  cerr<<'='<<h<<','; _dbg(sdbg+1, a...);
}
 
#ifdef LOCALi
#define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#else
#define debug(...) (__VA_ARGS__)
#define cerr if(0)cout
#endif

/** Template Ends **/
int n, m, k, x1, x2, y1, y2;

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

bool valid(int x, int y) 
{
    return (x >= 1 && x <= n && y >= 1 && y <= m);
}

signed main() 
{ 
    IOS;
    cin >> n >> m >> k >> x1 >> y1 >> x2 >> y2;
    vector<vector<char> > a(n + 1, vector<char>(m + 1));
    vector<vector<int> > dis(n + 1, vector<int>(m + 1, INF));
    for (int i = 1; i <= n; i++) for (int j = 1; j <= m; j++) cin >> a[i][j];

    queue<piii> q;
    q.push({0, {x1, y1}});

    while (!q.empty())
    {
        auto p = q.front();   q.pop();
        int st = p.first;
        int x = p.second.first, y = p.second.second;

        if (dis[x][y] < st)    continue;
        if (x == x2 && y == y2){ cout << st << endl; return 0; }

        for (int l = 0; l < 4; l++)
        {
            for (int d = 1; d <= k; d++)
            {
                int nx = x + dx[l] * d;
                int ny = y + dy[l] * d;
                // debug(nx, ny);
                if (!(valid(nx, ny) && a[nx][ny] != '@'))   break;

                if (dis[nx][ny] > st + 1)
                {
                    dis[nx][ny] = st + 1;
                    q.push({st + 1, {nx, ny}});
                }
                else if (dis[nx][ny] == st + 1) continue;
                else break;
            }
        }
    }
    cout << -1 << endl;

    return 0;
}

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

using namespace std;

int main()
{
    int n;        
    int a;
    int zahyo;
    vector<int> x(2040,0);
    cin >> n;
    vector<bool> masu(2040,false);
    for(int i=1;i<=n;i++)
    {
        // int l;
        cin >> x.at(i);
        masu.at(x.at(i))=true;
    }
    int m;
    cin >> m;
    for(int i=1;i<=m;i++)
    {

        cin >> a;
        if(masu.at(x.at(a)+1)!=true&&x.at(a)+1<=2019)
        {
            masu.at(x.at(a))=false;
            masu.at(x.at(a)+1)=true;
            x.at(a)+=1;
        }
    }
    for(int i=1;i<=2019;i++)
    {
        if(masu.at(i)==true)
        {
            cout << i << endl;
        }
    }
    return(0);
}    


Measured memory_bytes: 3136
MAX = 300000001

N, K = map(int, input().split())
xn = [int(i) for i in input().split()]


def main():
    if 0 < xn[0]:
        print(xn[K - 1])
        return

    if xn[N - 1] < 0:
        print(abs(xn[N - K]))
        return

    ans = MAX

    for i in range(N - K + 1):
        if xn[i + K - 1] < 0 and i + K <= N - 1 and 0 < xn[i + K]:
            ans = min(ans, abs(xn[i]))

        elif 0 < xn[i] and 0 != i and xn[i - 1] < 0:
            ans = min(ans, abs(xn[i + K - 1]))

        elif 0 <= xn[i + K - 1]:
            ans = min(ans,
                      2 * abs(xn[i]) + abs(xn[i + K - 1]),
                      abs(xn[i]) + 2 * abs(xn[i + K - 1]))

    print(ans)
    return


main()


Measured memory_bytes: 14568
N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))

count = 0
for i in range(0,N,1):
    tmp = min(A[i],B[i])
    count += tmp
    B[i] -= tmp
    A[i] -= tmp
    tmp = min(B[i],A[i+1])
    count += tmp
    A[i+1] -= tmp
    B[i] -= tmp

print(count)

Measured memory_bytes: 18624
#include<iostream>
#include<string>
using namespace std;
int main() {

	int x, y;

	cin >> x >> y;
	for (int i = 1;i<10e18; i++) {
		int tmp = x * i;
		if (x%y==0&&x>=y)break;
		if (tmp%y != 0) { 
			cout << tmp << endl;
			return 0; 
		}
	}
	
	cout << -1 << endl;
	return 0;
}

Measured memory_bytes: 256
n,h = map(int,input().split())
a = [0]*n;b = [0]*n;ma = 0;mi = 0;ls = []
for i in range(n):
    a[i],b[i] = map(int,input().split())
    ma = max(ma,a[i])
for i in range(n):
    if ma < b[i]:ls.append(b[i])
ls.sort(reverse = True);count = 0
for i in ls:
    count += 1
    h -= i
    if h <= 0:break
if h > 0:        
    count += h // ma
    if h%ma > 0:count += 1
print(count)

Measured memory_bytes: 12144
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace AtCoder
{
    class ABC178A
    {
        static void Main(string[] args)
        {
            int x = int.Parse(Console.ReadLine());
            //string[] str = Console.ReadLine().Split(' ');
            if(x==1)
            {
                Console.WriteLine(0);
            }
            else
            {
                Console.WriteLine(1);
            }
        }
    }
}

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

int main() {
    int n, m;
    cin >> n >> m;
    vector<int> cnt(m, 0);
    for (int i = 0; i < n; i++) {
        int k;
        cin >> k;
        for (int j = 0; j < k; j++) {
            int a;
            cin >> a;
            a--;
            cnt[a]++;
        }
    }

    int ans = 0;
    for (int i = 0; i < m; i++){
        if (cnt[i] == n) ans++;
    }
    cout << ans <<endl;
}

Measured memory_bytes: 256
N,M=map(int,input().split())
k=[list(map(int,input().split())) for _ in range(M)] 
*p,=map(int,input().split())
t=0
a=0
for i in range(2 ** N):
 t=0
 for j in range(M):
  if sum(1 for h in k[j][1:] if i>>(h-1)&1)%2==p[j]:t+=1
 if t==M:a+=1
print(a)

Measured memory_bytes: 9128
#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 puf push_front
#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; }
template<typename T> void remove(T & vector, unsigned int index){vector.erase(vector.begin() + index);}

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

    int a,b,c; cin>>a>>b>>c;

    if(a == b and b == c) cout << "Yes" << endl;
  	else cout << "No" << endl;
    return 0;
}



Measured memory_bytes: 256
a=int(input())
b=int(input())
c=int(input())
z=int(input())

ans=0

for A in range(a+1):
  for B in range(b+1):
    for C in range(c+1):
      if 500*A+100*B+50*C==z:
        ans+=1

print(ans)        
        

Measured memory_bytes: 3060
// ===================================
//   author: M_sea
//   website: http://m-sea-blog.com/
// ===================================
#include <bits/stdc++.h>
#define re register
using namespace std;

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

const int N=400000+10;

struct Tree {
    struct edge { int v,nxt; } e[N<<1];
    int head[N];
    inline void addEdge(int u,int v) {
        static int cnt=0;
        e[++cnt]=(edge){v,head[u]},head[u]=cnt;
    }

    int dep[N],sz[N],fa[N],hson[N],top[N];
    inline void dfs1(int u,int f) {
        dep[u]=dep[fa[u]=f]+1,sz[u]=1;
        for (re int i=head[u];i;i=e[i].nxt) {
            int v=e[i].v; if (v==f) continue;
            dfs1(v,u),sz[u]+=sz[v];
            if (sz[v]>sz[hson[u]]) hson[u]=v;
        }
    }
    inline void dfs2(int u,int anc) {
        top[u]=anc;
        if (hson[u]) dfs2(hson[u],anc);
        for (re int i=head[u];i;i=e[i].nxt)
            if (e[i].v!=fa[u]&&e[i].v!=hson[u]) dfs2(e[i].v,e[i].v);
    }
    
    inline int getlca(int u,int v) {
        while (top[u]!=top[v]) {
            if (dep[top[u]]<dep[top[v]]) swap(u,v);
            u=fa[top[u]];
        }
        return dep[u]<dep[v]?u:v;
    }
    inline int getdis(int u,int v) {
        int t=getlca(u,v);
        return dep[u]+dep[v]-(dep[t]<<1);
    }
} A,B;

int n,x,y,vis[N];

inline void bfs() {
    queue<int> Q; vis[x]=1,Q.push(x);
    while (!Q.empty()) {
        int u=Q.front(); Q.pop();
        for (re int i=A.head[u];i;i=A.e[i].nxt) {
            int v=A.e[i].v; if (vis[v]) continue;
            if (A.dep[v]<B.dep[v]) vis[v]=1,Q.push(v);
        }
    }
}

int main() {
    n=read(),x=read(),y=read();
    for (re int i=1;i<n;++i) {
        int u=read(),v=read();
        A.addEdge(u,v),A.addEdge(v,u);
    }
    for (re int i=1;i<n;++i) {
        int u=read(),v=read();
        B.addEdge(u,v),B.addEdge(v,u);
    }
    A.dfs1(x,0),A.dfs2(x,x); B.dfs1(y,0),B.dfs2(y,y);
    bfs(); int ans=0;
    for (re int u=1;u<=n;++u) {
        if (!vis[u]) continue;
        for (re int i=A.head[u];i;i=A.e[i].nxt) {
            int v=A.e[i].v;
            if (B.getdis(u,v)>2) { puts("-1"); return 0; }
        }
        ans=max(ans,B.dep[u]-1);
    }
    printf("%d\n",ans<<1);
    return 0;
}


Measured memory_bytes: 58624
import java.util.*;
class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        String s = sc.next(),t = sc.next();
        String ans = "No";
        for(int i =0;i<s.length();i++){
            if(s.equals(t)){
                ans = "Yes";
                break;
            }
            String tmp = s.substring(s.length()-1);
            String tmpB = s.substring(0,s.length()-1);
            s = tmp + tmpB;
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 21972
x,y,z,k = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = list(map(int,input().split()))
a.sort(reverse=True)
b.sort(reverse=True)
c.sort(reverse=True)
cand = []
for xi in range(x):
  if xi+1 > k:
    break
  for yi in range(y):
    if (xi+1)*(yi+1) > k:
        break
    for zi in range(z):
      if (xi+1)*(yi+1)*(zi+1) > k:
        break
      cand.append(a[xi]+b[yi]+c[zi])
cand.sort(reverse=True)
for i in range(k):
  print(cand[i])
      

Measured memory_bytes: 8708
#include<bits/stdc++.h>
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define full(a) a.begin(),a.end()
#define rfull(a) a.rbegin(),a.rend()

using namespace std;
const double pi=acos(-1.0);
const double pii=2*pi;
const double eps=1e-6;
const long long MOD=1e9+7;

void solve(){
    long long n,x,m;
    cin>>n>>x>>m;
    if(x==0){
        cout<<"0\n";
        return;
    }
    if(x==1){
        cout<<n<<"\n";
        return;
    }
    vector<bool> prev(m,false);
    queue<int> rem;
    long long ax=x,rep=-1,sm=0;

    while(!prev[ax] && n>0){
        n--;
        sm+=ax;
        prev[ax]=true;
        rem.push(ax);
        ax=(ax*ax)%m;
    }
    rep=ax;
    if(n<=0){
        cout<<sm<<"\n";
        return;
    }
    
    while(rem.front()!=rep)
        rem.pop();
    rep=n/(1ll*int(rem.size()));
    n%=(1ll*int(rem.size()));
    long long sm_rem=0,sm_div=0;
    while(!rem.empty()){
        if(n>0){
            sm_rem+=rem.front();
            n--;
        }
        sm_div+=rem.front();
        rem.pop();
    }
    sm+=rep*sm_div+sm_rem;
    cout<<sm<<"\n";
}

int main(){
    std::ios::sync_with_stdio(false);
    std::cin.tie(NULL);
    std::cout.tie(NULL);

    solve();
    return 0;
}

Measured memory_bytes: 3768
import java.io.*;

class Main{
 public static void main(String[] args)throws IOException{

  BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
  String str = br.readLine();
  String[] strAry = str.split(" ");
  int S = Integer.parseInt(strAry[0]);
  int h,m,s;  
  h=S/3600;
  m=(S%3600)/60;  
  s=(S%3600)%60;

  System.out.println(h +":"+ m +":"+ s);
 }
}

Measured memory_bytes: 24364
#include <stdio.h>

int main() {
	long int n;
	long int r;
	long int count = 0;
	long int x,y;
	scanf("%ld %ld",&n,&r);
// 	printf("%d %d",n,r);
    
    for(int i=0;i<n;i++){
        scanf("%ld %ld",&x,&y);
        if(x*x+y*y<=r*r)
        count = count + 1;
    }
    
    printf("%ld",count);
	return 0;
}

Measured memory_bytes: 1708
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;

namespace ConsoleApplication7
{
    class Program
    {
        static void Main()
        {
            string[] s_data = Console.ReadLine().Split(' ');

            int[] data = new int[s_data.Length];
            for (int i = 0; i < data.Length; i++) data[i] = int.Parse(s_data[i]);

            if (data[0] + data[1] < data[2] + data[3]) Console.WriteLine("Right");
            else if (data[0] + data[1] > data[2] + data[3]) Console.WriteLine("Left");
            else Console.WriteLine("Balanced");
        }
    }
}


Measured memory_bytes: 11092
#include <bits/stdc++.h>
using namespace std;
int main(void){
    long long int n,a,b;
    cin>>n;
    std::deque<long long int> A;
    std::deque<long long int> B;
    for (int i=0;i<n;i++) {
        cin>>a;
        A.emplace_back(a);
        cin>>b;
        B.emplace_back(b);
    }
    long long int tmp=0;
    for (int i=n-1;i>=0;i--) {
        if ((A[i]+tmp)%B[i]!=0) {
            tmp+=B[i]-((A[i]+tmp)%B[i]);
        }
    }
    cout<<tmp<<endl;
}

Measured memory_bytes: 5248
/* bellman_ford.cpp
    ベルマンフォード法で、ある頂点から各頂点への最短距離を求めるアルゴリズム
    負の辺が含まれる場合も適用でき、負の閉路も検出可能

    始点から終点に行くまでに通らない負の閉路は検出したくない時:
        http://sigma1113.hatenablog.com/entry/2019/08/12/130042

    verified: AOJ GRL_1_B
        http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=GRL_1_B
*/

#include <bits/stdc++.h>
using namespace std;

struct Edge {
    long long from;
    long long to;
    long long cost;
};
using Edges = vector<Edge>;
const long long INF = 1LL << 60;

/* bellman_ford(Es,s,t,dis)
    入力: 全ての辺Es, 頂点数V, 開始点 s, 最短経路を記録するdis
    出力: 負の閉路が存在するなら ture
    計算量：O(|E||V|)
    副作用：dis が書き換えられる
*/
bool bellman_ford(const Edges &Es, int V, int s, vector<long long> &dis) {
    dis.resize(V + 2, INF);
    dis[s] = 0;
    int cnt = 0;
    while (cnt < 2 * V) {
        bool end = true;
        for (auto e : Es) {
            if (dis[e.from] != INF && dis[e.from] + e.cost < dis[e.to]) {
                if (cnt >= V) {
                    dis[e.to] = -INF;
                } else {
                    dis[e.to] = dis[e.from] + e.cost;
                }
                end = false;
            }
        }
        if (end) break;
        cnt++;
    }
    // cout << cnt << endl;  // debug
    return (cnt == 2 * V);
}

int main() {
    int V, E, P;
    cin >> V >> E >> P;
    Edges Es;
    for (int i = 0; i < E; i++) {
        long long s, t, d;
        cin >> s >> t >> d;
        Es.push_back({s, t, -(d - P)});
    }
    vector<long long> dis;
    if (bellman_ford(Es, V, 1, dis) && dis[V] == -INF) {
        cout << -1 << endl;
    } else {
        cout << max(0LL, -dis[V]) << endl;
    }

    return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#include <string>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define repp(i,n,m) for (int i = m; i < (n); ++i)
#define repl(i,n) for (long long i = 0; i < (n); ++i)
#define reppl(i,n,m) for (int i = m; i < (n); ++i)
using namespace std;
using ll = long long;
const int INF = 1001001007;

int main(){
    int a,b,c;
    cin >> a >> b >> c;
    cout << c << " " << a << " " << b << endl;
}

Measured memory_bytes: 256
#include <iostream>

int64_t get_relationship_num(const int max_value, const int k) {
  int64_t total = 0;
  if ((k % 2 == 0) && (max_value >= k / 2)) {
    const int64_t addable_k = (max_value - k / 2) / k + 1;
    total += addable_k * addable_k * addable_k;
  }
  if (max_value >= k) {
    const int64_t addable_k2 = (max_value - k) / k + 1;
    total += addable_k2 * addable_k2 * addable_k2;
  }
  return total;
}

int main() {
  int n, k;
  std::cin >> n >> k;
  std::cout << get_relationship_num(n, k) << std::endl;
  return 0;
}

Measured memory_bytes: 256
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.NoSuchElementException;

import java.util.*;

public class Main{
  static char[] s;
  static int x, y;

  static final boolean DEBUG = false;

  public static void main(String[] args){
    FastScanner sc = new FastScanner();
    s = sc.next().toCharArray();
    x = sc.nextInt(); y = sc.nextInt();

    List< Integer > ax = new ArrayList< >();
    List< Integer > ay = new ArrayList< >();
    boolean turn = true;
    int dx = 0, dy = 0;
    for(int i = 0; i < s.length; i++){
      if(s[i] == 'T'){
        if(turn) ax.add(dx);
        else ay.add(dy);
        turn = !turn;
        dx = dy = 0;
      }
      else if(turn) ++dx;
      else ++dy;
    }
    if(s[s.length - 1] != 'T'){
      if(turn) ax.add(dx);
      else ay.add(dy);
    }

    if(DEBUG){
      System.out.println(ax);
      System.out.println(ay);
    }

    Set< Integer > s0 = new HashSet< >();
    s0.add(ax.get(0));
    for(int i = 1; i < ax.size(); i++){
      Set< Integer > s1 = new HashSet< >();
      for(int xx: s0){
        s1.add(xx + ax.get(i));
        s1.add(xx - ax.get(i));
      }
      s0 = s1;
    }

    if(!s0.contains(x)){
      System.out.println("No");
      return;
    }

    s0.clear();
    s0.add(0);
    for(int i = 0; i < ay.size(); i++){
      Set< Integer > s1 = new HashSet< >();
      for(int yy: s0){
        s1.add(yy + ay.get(i));
        s1.add(yy - ay.get(i));
      }
      s0 = s1;
    }

    if(s0.contains(y)){
      System.out.println("Yes");
    }
    else{
      System.out.println("No");
    }
  }
}

class FastScanner {
  private static final InputStream in = System.in;
  private static final PrintWriter out = new PrintWriter(System.out);
  private final byte[] buffer = new byte[2048];
  private int p = 0;
  private int buflen = 0;

  public FastScanner(){
  }

  private boolean hasNextByte() {
    if(p < buflen){
      return true;
    }
    p = 0;
    try{
      buflen = in.read(buffer);
    }catch (IOException e) {
      e.printStackTrace();
    }
    if(buflen <= 0){
      return false;
    }
    return true;
  }

  public boolean hasNext() {
    while(hasNextByte() && !isPrint(buffer[p])){
      p++;
    }
    return hasNextByte();
  }

  private boolean isPrint(int ch) {
    if(ch >= '!' && ch <= '~'){
      return true;
    }
    return false;
  }

  private int nextByte() {
    if(!hasNextByte()){
      return -1;
    }
    return buffer[p++];
  }

  public String next() {
    if(!hasNext()){
      throw new NoSuchElementException();
    }
    StringBuilder sb = new StringBuilder();
    int b = -1;
    while(isPrint((b = nextByte()))){
      sb.appendCodePoint(b);
    }
    return sb.toString();
  }

  public int nextInt() {
    return Integer.parseInt(next());
  }

  public long nextLong() {
    return Long.parseLong(next());
  }

  public double nextDouble() {
    return Double.parseDouble(next());
  }
}


Measured memory_bytes: 111864
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
const int INT_INF = 2147483647;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
typedef pair<int,int> P;

int main(){
  int n;
  cin >> n;
  int p[n];
  rep(i,n)cin >> p[i];
  int res = 1;
  int now = p[0];
  rep(i,n){
    if(now>p[i]){
      res++;
      now = p[i];
    }
  }
  cout << res << endl;
}


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

	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		String s=sc.next();
		String t=sc.next();
		int n=sc.nextInt();
		int m=sc.nextInt();
		String u=sc.next();
		if(u.contentEquals(s))
			n=n-1;
		else if(u.equalsIgnoreCase(t))
			m=m-1;
		System.out.print(n + " " +m); 
		
	}

}


Measured memory_bytes: 21844
import java.util.*;

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

        int N = sc.nextInt();
        int[] X = new int[N];
        int[] Y = new int[N];
        int[] H = new int[N];

        int xbase = -1;
        int ybase = -1;
        int hbase = -1;

        for (int i = 0; i < N; i++) {
            X[i] = sc.nextInt();
            Y[i] = sc.nextInt();
            H[i] = sc.nextInt();

            if (H[i] > 0) {
                hbase = H[i];
                xbase = X[i];
                ybase = Y[i];
            }
        }

        for (int i = 0; i <= 100; i++) {
            NEXT: for (int j = 0; j <= 100; j++) {
                int height = hbase + Math.abs(xbase - j) + Math.abs(ybase - i);

                for (int k = 0; k < N; k++) {
                    if (H[k] != Math.max(0, height - Math.abs(j - X[k]) - Math.abs(i - Y[k]))) continue NEXT;
                }

                System.out.println(String.format("%d %d %d", j, i, height));
                return;
            }
        }
    }
}

Measured memory_bytes: 21844
def resolve():
    n, k = map(int, input().split())
    if n > k:
        m = n % k
        a = abs(m - k)
        b = abs(a - k)
        print(min(a, b))
        return
    else:
        a = abs(n - k)
        b = abs(a - k)
        print(min(a, b))



if __name__ == "__main__":
    resolve()

Measured memory_bytes: 3060
import math


def calc_angle(X, Y):
    assert X != 0 or Y != 0
    TREND_INF = 10**6 + 1
    if X == 0:
        angle = math.atan(TREND_INF)
        if Y < 0:
            angle += math.pi
    else:
        angle = math.atan(Y / X)
        if X < 0:
            angle += math.pi
    return angle  # 0 ~ 2*pi


def main():
    N = int(input())
    engines = list()
    for _ in range(N):
        X, Y = list(map(int, input().split(' ')))
        if X == Y == 0:
            continue
        angle = calc_angle(X, Y)
        engines.append((angle, X, Y))
    N = len(engines)
    if N == 0:
        print(0)
        return
    engines.sort()  # 角度でソート
    # エンジンi～jを使った時の原点からの距離
    dist = [[0 for _ in range(N)] for _ in range(N)]
    for i in range(N):
        for j in range(N):
            k = i
            sx = engines[k][1]
            sy = engines[k][2]
            while k != j:
                k = (k + 1) % N
                sx += engines[k][1]
                sy += engines[k][2]
            dist[i][j] = math.sqrt(sx**2 + sy**2)
    ans = 0
    for i in range(N):
        for j in range(N):
            ans = max(ans, dist[i][j])
    print(ans)


if __name__ == '__main__':
    main()

Measured memory_bytes: 68708
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <bitset>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <numeric>
#include <iostream>
#include <iomanip>
#include <string>
#include <chrono>
#include <random>
#include <cmath>
#include <cassert>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <functional>
#include <sstream>

using namespace std;

class Solution {
public:
    long long solve(vector<int>& A, vector<int>& F, long long K) {
        int n = A.size();
        sort(A.begin(), A.end());
        sort(F.begin(), F.end());

        auto ok = [&](long long T) {
            long long cost = 0;
            for (int i = 0, j = n - 1; i < n; ++i, --j) {
                if (T < A[i] * 1LL * F[j]) {
                    cost += max(0LL, A[i] - T / F[j]); 
                }
            }
            return cost <= K;
        };

        long long lo = 0, hi = A.back() * 1LL * F.back() + 1;

        while (lo < hi) {
            auto mi = (lo + hi) >> 1;
            if (ok(mi)) {
                hi = mi;
            } else {
                lo = mi + 1;
            }
        }

        return lo;
    }
};

int main(int argc, char** argv) {
    ios::sync_with_stdio(false);
    cin.tie(0);

    int n;
    long long K;
    cin >> n >> K;
    vector<int> A(n);
    vector<int> F(n);
    for (int i = 0; i < n; ++i) {
        cin >> A[i];
    }
    for (int j = 0; j < n; ++j) {
        cin >> F[j];
    }

    Solution sol;
    cout << sol.solve(A, F, K) << "\n";

    return 0;
}

Measured memory_bytes: 1792
import numpy as np


N,M=map(int,input().split())
# A=np.array(list(map(int,input().split())))
A=np.array(list(map(int,input().split())),dtype=np.int32)
A=np.sort(A)

EXC=[]

for i in range(M):
    exc=list(map(int,input().split()))
    EXC.append(exc)
excArry=np.array(EXC,dtype=np.int32)

col_num=1
Arr=excArry[np.argsort(excArry[:,col_num])[::-1]]
# print(A)
# print(Arr)

point=0


for j in range (M):
    # change_Num=Arr[j][1]
    count=np.count_nonzero(A<Arr[j][1])
    if count > 0:
        m=min(count,Arr[j][0])
        A[point:point+m]=Arr[j][1]
        point+=m
        # A=np.sort(A)
    else:
        break

print(np.sum(A))
    
#     for j in range (B):
#         count=np.count_nonzero(A<C)
#         if count>0:
#             m=min(B,count)
#             A[:m]=C
#         else:
#             continue
    
#     A=np.sort(A)

# print(np.sum(A))

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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define VIN(v) for(auto&elem_: (v) )cin>>elem_
#define VOUT(v, sep) for(_loop_int idx=0; idx<(_loop_int)v.size(); idx++) {cout<<v[idx]; if(idx<v.size()-1) cout<<sep;} cout<<endl

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG2(x,y) cout<<#x<<": "<<x<<" "<<#y<<": "<<y<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(debugidx,v.size())cout<<" "<<v[debugidx];cout<<endl
#define DEBUG_ARR(v,n) cout<<#v<<":";REP(debugidx,n)cout<<" "<<v[debugidx];cout<<endl
#define ALL(a) (a).begin(),(a).end()

const ll MOD = 1000000007ll;
const int IINF = numeric_limits<int>::max()/2-1;
const ll LINF = numeric_limits<ll>::max()/2-1;
#define FIX(a) ((a)%MOD+MOD)%MOD
int n,c;
int main() {
    ios::sync_with_stdio(false); cin.tie(0);
    cin>>n>>c;

    if(n==1){
        //n=1のグリッドは常に条件を満たしている
        cout << "0" << endl;
        return 0;
    }
    vector<vi> d(c, vi(c,0));
    vector<vi> g(n, vi(n,0));

    map<int,int> lines[3];
    int sz=3;

    REP(i,c) REP(j,c){
        cin>>d[i][j];
    }

    REP(i,n) REP(j,n){
        cin>>g[i][j];
        lines[ (i+j) % 3 ][ g[i][j] ] += 1;
    }

    ll ans = LINF;
    FOR(c1, 1, c+1)
    FOR(c2, c1+1, c+1)
    FOR(c3, c2+1, c+1)
    {
        vi cls = {c1, c2 , c3}; //lines[i]をcls[i]の色に塗り替える
        do{
            ll tmp = 0;
            REP(i,sz){
                for(auto e:lines[i]){
                    tmp += d[e.first-1][cls[i]-1] * e.second;
                }
            }
            ans = min(ans,tmp);
        }while( next_permutation(ALL(cls)) );
    }

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

Measured memory_bytes: 1408
#include<iostream>
#include<algorithm>
#include<set>
#include<math.h>
#include<vector>
#include<sstream>
#include<queue>
#include<functional>
#include<bitset>
#include<cstdio>
#include<iomanip>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include <string.h>
using ll = long long;

#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define reps(i,x) for(ll i=1;i<=(ll)(x);i++)
#define rrep(i,x) for(ll i=((ll)(x)-1);i>=0;i--)
#define rreps(i,x) for(ll i=(ll)(x);i>0;i--)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))
#define vll vector<ll>
#define vi vector<int>
#define vpll vector<pair<ll,ll>>
#define vpi vector<pair<int,int>>
#define mod 1000000007 
using namespace std;
int a[1000];
int b[1000];
int main() {
  int n, h,w;
  cin >> n >> h >> w;
  rep(i, n)
    cin >> a[i] >> b[i];
  int ans = 0;
  rep(i, n){
    if(h <= a[i] && w <= b[i])ans++;
  }
  cout << ans << endl;
}


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

void print(vector<int> const & a, int n )
{
    for(int i = 0 ; i < n ; i++)
    {
        cout << a.at(i) ;
        if(i != n - 1)
        {
            cout << " " ;
        }
    }
    cout << endl ;
}

int main()
{
    int n ;
    cin >> n ;
    vector<int> data(n) ;
    for(int i = 0; i < n ; i++)
    {
        cin >> data.at(i) ;
    }

    int count = 0 ;
    for(int i = 0 ; i < n - 1 ; i++)
    {
        //cout << i << endl ;
        if(data.at(i) > data.at(i + 1))
        {
            //cout << data.at(i) << " " << data.at(i + 1) << endl ;
            swap(data.at(i), data.at(i + 1)) ;
            count++ ;
            i = -1 ;
        }
    }

    print(data, n) ;
    cout << count << endl ;
}



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

#undef int
int main() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
#define int long long int
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	int t = 1;
	//cin >> t;
	while (t--) {
		int n;
		cin >> n;
		set<string> s;
		for (int i = 0; i < n; i++) {
			string z;
			cin >> z;
			s.insert(z);
		}
		cout << s.size() << endl;
	}
	return 0;
}

Measured memory_bytes: 19220
#include <iostream>

using namespace std;

#define int long long

const int N = 2e5 + 10, mod = 998244353;

int n, q, ten[N], seg[N << 2], lazy[N << 2];

int t(int l, int r) {
  return ((ten[n - l + 1] - ten[n - r]) % mod + mod) % mod;
}

void push(int n, int i, int j) {
  if (lazy[n]) {
    if (i != j) {
      lazy[n << 1] = lazy[n << 1 | 1] = lazy[n];
    }
    seg[n] = (lazy[n] * t(i, j)) % mod;
    lazy[n] = 0;
  }
}

int query(int i, int j, int l, int r, int n) {
  if (i > r || j < l) {
    return 0;
  }
  if (i >= l && j <= r) {
    push(n, i, j);
    return seg[n];
  }
  int m = (i + j) >> 1;
  return (query(i, m, l, r, n << 1) + query(m + 1, j, l, r, n << 1 | 1)) % mod;
}

void update(int i, int j, int l, int r, int v, int n) {
  push(n, i, j);
  if (i > r || j < l) {
    return;
  }
  if (i >= l && j <= r) {
    lazy[n] = v;
    push(n, i, j);
    return;
  }
  int m = (i + j) >> 1;
  update(i, m, l, r, v, n << 1);
  update(m + 1, j, l, r, v, n << 1 | 1);
  seg[n] = (seg[n << 1] + seg[n << 1 | 1]) % mod;
}

int32_t main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);    
  cin >> n >> q;
  ten[1] = 1;
  for (int i = 2; i <= n; ++i) {
    ten[i] = (ten[i - 1] * 10) % mod;
  }
  for (int i = 2; i <= n; ++i) {
    ten[i] = (ten[i - 1] + ten[i]) % mod;
  }
  update(1, n, 1, n, 1, 1);
  while (q--) {
    int l, r, d;
    cin >> l >> r >> d;
    update(1, n, l, r, d, 1);
    cout << query(1, n, 1, n, 1) << '\n';
  }
  return 0;
}


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

ll modinv(ll a){
    ll b = mod, u = 1, v = 0;
    while(b){
        ll t = a/ b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= mod;
    if(u < 0) u+=mod;
    return u;
}

ll comb(ll a, ll b){
    if(a==b||b==0)return 1;
    if(b*2>a)b = a - b;
    ll x = 1;
    rep(i, b){
        x *= a-i;
        x %= mod;
        x *= modinv(b-i);
        x %= mod;
    }
    return x;
}

int main(){
    ll n, m, k;
    cin >> n >> m >> k;
    ll nm = n * m;
    ll memo = 0, ans = 0;
    rep(i, m){
        memo += (i+1)*(m-1-i);
        memo %= mod;
    }
    memo *= n; memo %= mod;
    memo *= n; memo %= mod;
    memo *= comb(nm-2, k-2); memo %= mod;
    ans += memo;
    memo = 0;
    rep(i, n){
        memo += (i+ 1) * (n-1-i);
        memo %= mod;
    }
    memo *= m; memo %= mod;
    memo *= m; memo %= mod;
    memo *= comb(nm-2, k-2); memo %= mod;
    ans += memo; ans %= mod;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
def main():
    n = int(input())
    a = list(map(int,input().split()))
    s = sum(a)
    l1 = 0
    for i in range(n):
        if i%2==0:
            l1 += a[i]
        else:
            l1 -= a[i]
    print(l1,end=" ")
    for i in range(n-1):
        l1 = 2*a[i]-l1
        print(l1,end=" ")
    print()
if __name__ == '__main__':
    main()

Measured memory_bytes: 63984
import java.util.Scanner;

class Main{



	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);			//文字の入力
		int n = sc.nextInt();
		int[] a = new int[n];
		int ans = 1000000000;
		for(int i = 0;i < n;i++){
			a[i] = sc.nextInt();
		}
		
		for(int i = -100;i <= 100;i++){
			int count = 0;
			for(int j = 0;j < n;j++){
				count += Math.abs(i-a[j])*Math.abs(i-a[j]);
			}
			ans = Math.min(ans, count);
		}
		System.out.println(ans);
		
		

	}
}

Measured memory_bytes: 21844
#include<iostream>
#include<vector>
#include<string>
#include<cmath>
#include<algorithm>
#include <numeric>
#include<map>
#include<unordered_map>
 
using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0;i<n;++i)
#define all_map(itr,mp) for(auto itr=mp.begin();itr!=mp.end();itr++)
#define ALL(a) (a).begin(),(a).end()

int main(){
    ll n, k, q;
    cin >> n >> k >> q;
    ll cnt[100010] = {};
    rep(i, q){
        ll a;
        cin >> a;
        cnt[a]++;
    }
    for(ll i = 1; i <= n; ++i){
        if(k - q + cnt[i] > 0)cout << "Yes\n";
        else cout << "No\n";
    }
}

Measured memory_bytes: 1408
import sys

sys.setrecursionlimit(10 ** 8)

input = sys.stdin.readline


def main():
    S = input().strip()

    ans = 0
    if "R" in S:
        ans += 1

    if S[0] == "R" and S[1] == "R" and S[2] == "R":
        print(3)
        return
    elif (S[0] == "R" and S[1] == "R") or (S[1] == "R" and S[2] == "R"):
        print(2)
        return
    else:
        print(ans)




if __name__ == '__main__':
    main()



Measured memory_bytes: 9052
#include <bits/stdc++.h>
using namespace std;
#define int long long
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);cout.tie(0);
  int no_of_input;
  int input;
  vector<int> vect1;
  cin >> no_of_input;
  for(int i=0;i<no_of_input;i++){
    cin >> input;
    vect1.push_back(input);
  }
  int ans = 0;
  map<int,int> map1;
  for(int i=0;i<no_of_input;i++){
    if(map1.count((i-vect1[i]))!=0){
      ans += map1[(i-vect1[i])];
    }
    if(map1.count((vect1[i]+i))==0){
      map1.insert({vect1[i]+i,0});
    }
    map1[vect1[i]+i]++;
  }
  cout << ans;
}

Measured memory_bytes: 17088
#include <bits/stdc++.h>
  
using namespace std;
  
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define repr(i, n) REPR(i, n, 0)
#define REPR(i, s, e) for(int i=(int)(s-1); i>=(int)(e); i--)
#define pb push_back
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()
#define fi first
#define se second
  
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
 
const int INF = 1e9;
const ll MOD = 1e9 + 7;
double EPS = 1e-8;

int main(){
    string s;
    cin >> s;
    int n = s.size();
    int x = 0;
    rep(i, n) if(s[i] == 'o') x++;
    string yes = "YES", no = "NO";
    if(x + 15-n >= 8) cout << yes << endl;
    else cout << no << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pi pair<int,int>
#define ff first
#define ss second
#define boost ios::sync_with_stdio(false);cin.tie(nullptr)
#define endl "\n"
#include "string"

const int inf = LLONG_MIN;
int maxsum(vector < int > &a , int k) {
	if(a.empty())
		return inf;
	int ans = inf, sum = 0,s = 0;
	int n = a.size();
	for(int i = 0; i < n; i++) {
		s += a[i];
		a.push_back(a[i]);
	}
	for(int i = 0; i < n; i++)
		a.push_back(a[i]);
	int tt = k/ n;
	k -= tt * n;
	if(k < n && tt > 0) {
		k += n;
		tt--;
	}
	s *= tt;
	for(int i = 0; i < 2 * n; i++) {
		sum = 0;
		for(int j = i; j < min(i + k, 3 * n); j++){
			sum += a[j];
			ans = max(ans , sum);
		}
	}
	ans = max(ans , ans + s);
	return ans;
}

int32_t main() {
	boost;
	int n, k;
	cin >> n >> k;
	int p[n + 1] , c[n + 1];
	for(int i = 1; i <= n; i++)
		cin >> p[i];
	int ans = inf;
	for(int i = 1; i <= n; i++) {
		cin >> c[i];
		ans = max(ans , c[i]);
	}
	for(int i = 1; i <= n; i++) {
		if(p[i] == 0)
			continue;
		vector < int > v;
		int id = i;
		while(p[id] != 0) {
			v.push_back(c[id]);
			int tt = p[id];
			p[id] = 0;
			id = tt;
		}
		ans = max(ans , maxsum(v, k));
	}
	cout << ans << endl;
}

Measured memory_bytes: 3864
// Why I am so dumb? :c
#include <bits/stdc++.h>

#define pb push_back
#define mp make_pair

#define all(x) (x).begin(), (x).end()

#define fi first
#define se second

using namespace std;

typedef long long ll;

int a, b;

void solve() {                   
	scanf("%d %d", &a, &b);

	if (a >= 0 && b >= 0) {
		if (a <= b) {
			printf("%d\n", b - a);
		}	
		else {
			printf("%d\n", a - b + 1 + (b > 0));		
		}

		return;
	}

    if (a >= 0 && b < 0) {
    	printf("%d\n", abs(a + b) + 1);
		return;
    }

    if (a < 0 && b >= 0) {
    	printf("%d\n", abs(a + b) + (b > 0));    	
    	return;
    }

    if (a < 0 && b < 0) {
    	if (a <= b) {
    		printf("%d\n", b - a);
    	}	
    	else {
			printf("%d\n", a - b + 2);    		
    	}

    	return;
    }
}

int main() {    
    int tt = 1;

    while (tt--) {
        solve();
    }

    return 0;
}

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

const int64_t MOD = 1e9+7;
void add(int64_t& a, int64_t b){
    a = (a+b) % MOD;
}
void mul(int64_t& a, int64_t b){
    a = a*b % MOD;
}

int64_t power_mod(int64_t num, int64_t power){
    int64_t prod = 1;
    num %= MOD;
    while(power > 0){
        if(power&1) prod = prod * num % MOD;
        num = num * num % MOD;
        power >>= 1;
    }
    return prod;
}

int64_t extgcd(int64_t a, int64_t b, int64_t& x, int64_t& y){
    int64_t d = a;
    if(b != 0){
        d = extgcd(b, a%b, y, x);
        y -= (a/b) * x;
    }else{
        x = 1; y = 0;
    }
    return d;
}

int64_t inv_mod(int64_t a){
    int64_t x, y;
    extgcd(a, MOD, x, y);
    return (MOD + x%MOD) % MOD;
}

vector<int64_t> fact, fact_inv;

void create_mod_tables(int num){
    fact.assign(num+1, 1);
    fact_inv.assign(num+1, 1);
    for(int i=1; i<=num; i++) fact[i] = fact[i-1] * i % MOD;
    fact_inv[num] = inv_mod(fact[num]);
    for(int i=num; i>0; i--) fact_inv[i-1] = fact_inv[i] * i % MOD;
}

int64_t comb_mod(int n, int k){
    return fact[n] * fact_inv[n-k] % MOD * fact_inv[k] % MOD;
}

int64_t perm_mod(int n, int k){
    return fact[n] * fact_inv[n-k] % MOD;
}

int64_t gcd(int64_t a, int64_t b){
    return b==0 ? a : gcd(b, a%b);
}

int main(){
    int H, W;
    cin >> H >> W;
    int N = (H+1)*(W+1);
    create_mod_tables(N);

    // 1直線に並ぶ3点を数える
    int64_t L = 0;
    
    // 両端のxとyの距離を全探索
    for(int i=0; i<=H; i++) for(int j=0; j<=W; j++){
        if(i == 0 && j == 0) continue;
        
        // 両端の取り方、i > 0 かつ j > 0 のときは反転も考慮
        int64_t res = (H+1-i) * (W+1-j);
        if(i > 0 && j > 0) mul(res, 2);
        // 間に取れる格子点の個数
        mul(res, gcd(i, j)-1);

        add(L, res);
    }

    // 1直線に並ばない3点
    int64_t ans = comb_mod(N, 3) - L + MOD;
    // 集合の選び方
    mul(ans, power_mod(2, N-3));

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



Measured memory_bytes: 18320
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;
#define ep emplace_back
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i=0;i<(n);++i)
#define all(v) v.begin(), v.end()
#define revall(v) v.rbegin(), v.rend()
constexpr int mod=1000000007;
constexpr int mod1=998244353;
vector<int> dx={0,1,0,-1},dy={-1,0,1,0};
inline bool inside(int y,int x,int h,int w){ if(y<h && y>=0 && x<w && x>=0) return true; return false; }
template<class T> inline bool chmin(T& a, T b){ if(a > b){ a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b){ if(a < b){ a = b; return true; } return false; }





int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;cin >> n;
	vector<int> x(n);
	rep(i,n) cin >> x.at(i);
	int ans = 1000000000;
	rep(i,101){
		int sum = 0;
		rep(j,n){
			sum += (x[j] - i) * (x[j] - i);
		}
		ans = min(ans, sum);
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include<math.h>
using namespace std;
using ll = long long;
const ll INF = 100100100100100;

int main()
{
	vector<ll> num(3);
	cin >> num[0] >> num[1] >> num[2];
	sort(num.begin(), num.end());
	ll ans = 0;
	ll one = num[2];
	ll two = num[1];
	ll three = num[0];
	if ((two - three) % 2 == 1) {
		two++; one++; ans++;
		ans += (two - three) / 2;//two == three ninaru
		ans += one - two;
	}
	else {
		ans += (2 * one - two - three) / 2;
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MAXN=1e5+50;
int main()
{
    string a;
    cin>>a;
    int n=a.size()-1;
    int ans=0;
    for(int i=0;i<n;i++,n--){
        if(a[i]!=a[n])
            ans++;
    }
    cout<<ans;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
int n, k, a[5005], l, r;

int main(){
    scanf("%d%d", &n, &k);
    rep(i,n) scanf("%d", a+i);
    sort(a, a+n);
    l = -1; r = n;
    while(l+1 < r){
        int mid = (l + r) / 2;
        bool dp[9999] = {true}, ok = false;
        rep(i,n) if(i-mid && a[i]<k) for(int j = k; j >= 0; j--) if(dp[j]) dp[a[i]+j] = true;
        for(int i = max(0,k-a[mid]); i < k; i++) if(dp[i]) ok = true;
        (ok ? r : l) = mid;
    }
    printf("%d\n", r);
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<cstring>
#include<queue>
#include<stack>
#include<numeric>
using namespace std;
#define INF (1 << 30) - 1
#define LINF 1LL << 60
const int MOD = 1000000007;
using ll = long long;
using P = pair<int, int>;

int main(){
  int s, w;
  cin >> s >> w;
  if(w >= s)cout << "unsafe" << endl;
  else cout << "safe" << endl;
  return 0;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
int main(){
int N; cin >> N;
int t[100100], x[100100], y[100100];
t[0]=0; x[0]=0; y[0]=0;
for (int i=1; i<=N; i++) {
    cin >> t[i] >> x[i] >> y[i];
}
int dist[100100], dt[100100];
for (int i=0; i<N; i++){
    dist[i]=abs(x[i+1]-x[i])+abs(y[i+1]-y[i]);
    dt[i]=t[i+1]-t[i];
}
bool feas=true;
for(int i=0; i<N; i++){
    if(!((dist[i]<=dt[i]) && (dist[i]%2==dt[i]%2) )) feas=false;
}

if(feas) cout << "Yes" << endl;
else cout << "No" << endl;

}

Measured memory_bytes: 2176
//In the name of Allah :)
#include <bits/stdc++.h>
using namespace std;
string to_string(char c) { return string(1,c); }
string to_string(bool b) { return b ? "true" : "false"; }
string to_string(const char* s) { return (string)s; }
string to_string(string s) { return s; }
template<class A> string to_string(complex<A> c) { 
	stringstream ss; ss << c; return ss.str(); }
string to_string(vector<bool> v) { 
	string res = "{"; for(int i = 0; i < (int)v.size(); i++) res += char('0'+v[i]);
	res += "}"; return res; }
template<size_t SZ> string to_string(bitset<SZ> b) {
	string res = ""; for(size_t i = 0; i < SZ; i++) res += char('0'+b[i]);
	return res; }
template<class A, class B> string to_string(pair<A,B> p);
template<class T> string to_string(T v) { // containers with begin(), end()
	bool fst = 1; string res = "{";
	for (const auto& x: v) {
		if (!fst) res += ", ";
		fst = 0; res += to_string(x);
	}
	res += "}"; return res;
}
template<class A, class B> string to_string(pair<A,B> p) {
	return "("+to_string(p.first)+", "+to_string(p.second)+")"; }
void DBG() { cerr << "]" << endl; }
template<class H, class... T> void DBG(H h, T... t) {
	cerr << to_string(h); if (sizeof...(t)) cerr << ", ";
	DBG(t...); }
#ifdef LOCAL // compile with -DLOCAL
#define wis(...) cerr << "LINE(" << __LINE__ << ") -> [" << #__VA_ARGS__ << "] : [", DBG(__VA_ARGS__)
#else
#define wis(...) 0
#endif
typedef long long ll;
const int MOD = 1e9 + 7, INF = 1e9 + 5;
const ll LONG_INF = 1e18 + 10;
inline ll powmod(ll a, ll b){ll res=1;for(;b;b>>=1,a=a*a%MOD)if(b&1)res=res*a%MOD;return res;}
inline ll power(ll a, ll b){ll res=1;for(;b;b>>=1,a=a*a)if(b&1)res=res*a;return res;}

const int MAXN = 2e5 + 10;

int main(){
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int n;
        cin >> n;
        vector <int> a(n);
        for(int i = 0; i < n; i++){
                cin >> a[i];
        }
        ll ans = 0, mx = a.front();
        for(int i = 1; i < n; i++){
                ans += max(0ll, mx - a[i]);
                mx = max(mx, 1ll * a[i]);
        }
        cout << ans << '\n';
}


Measured memory_bytes: 3996
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,b,a) for(int i=b;i>=a;i--)
#define fori(a) for(auto i : a )
#define all(a) begin(a), end(a)
#define set(a,b) memset(a,b,sizeof(a))
#define sz(a) a.size()
#define pi 3.14159
#define ll long long
#define ull unsigned long long
#define pb push_back
#define PF push_front //deque
#define mp make_pair
#define pq priority_queue
#define mod 1000000007
#define f first
#define s second
#define pii pair< int, int >
#define vi vector<int>
#define vpii vector<pii>
#define debug(v) for(auto i:v) cout<<i<<" ";
#define tc int t; cin >> t; while(t--)

using namespace std;
string repeat(string s, int n) {
    string s1 = "";
    for (int i=0; i<n;i++)
        s1+=s;
    return s1;
}
string getString(char x) {
    string s(1, x);
    return s;
}

void optimizeIO(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}
int gcd(int a, int b){
    if (a == 0)  return b;
    return gcd(b % a, a);
}
void  solve(){
  int n;
  cin>>n;
  char x;
  int a[n];
  rep(i,0,n){
    cin>>x;
    if(x=='W') a[i]=-1;
    else a[i]=1;
  }
  if(n==1){
    cout<<0<<endl;
    return;
  }
  vector<int> pre(n,0),suf(n,0);
  pre[0]=(a[0]==-1 ?1:0);
  rep(i,1,n){
    pre[i]= (a[i]==-1 ?1:0)+pre[i-1];
  }

  suf[n-1]=(a[n-1]==1 ?1:0);
  rrep(i,n-2,0){
    suf[i]= (a[i]==1 ?1:0)+suf[i+1];
  }

  int ans=INT_MAX;
  rep(j,0,n){
    if(j==0) ans=min(ans,suf[j+1]);
    else if(j==n-1) ans=min(ans,pre[j-1]);
    else if(n>=3) ans=min(ans,pre[j-1]+suf[j+1]);
  }
  cout<<ans<<endl;
}
int main(){
    optimizeIO();
    // tc
    { solve();
    }
}


Measured memory_bytes: 6628