akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
using namespace std;
#define REP(i, n) for(ll i = 0;i < n;i++)
#define ll long long
#define MOD 1000000007LL
#define llMAX 9223372036854775807LL
#define llMIN -9223372036854775808LL
using vi = vector<ll>; // intの1次元の型に vi という別名をつける
using vvi = vector<vi>; // intの2次元の型に vvi という別名をつける

ll x,k,d;

int main(){
  ll ans=0;
  cin >> x>>k>>d;


  ll amari=x%d;
  ll ap=0;
  ll am=0;
  ll apnum=0;
  ll amnum=0;
  if (amari<0){
    am=amari;
    amnum=abs((x-am)/d);
    ap=amari+d;
    apnum=abs((x-ap)/d);
  }else{
    ap=amari;
    apnum=abs((x-ap)/d);
    am=amari-d;
    amnum=abs((x-am)/d);
  }




  if ((apnum>k)&(amnum>k)){
    if (x<0)ans=x+d*k;
    if (x>=0)ans=x-d*k;
    cout<<abs(ans)<<endl;
    return 0;
  }


  ll k2=k%2;
  if (k2==1){
    if (apnum%2==1)ans=ap;
    if (amnum%2==1)ans=am;
  }else{
    if (apnum%2==0)ans=ap;
    if (amnum%2==0)ans=am;
  }

  cout<<abs(ans)<<endl;
  return 0;
}
/*
1000000000000000 1000000000000000 1000000000000000
1000000000000000 2 999999999999999
*/


Measured memory_bytes: 3640
#import numpy as np
def isprime(x):
  if x<=1:return False
  if x==2:return True
  for i in range(2,int(x**0.5)+1):
    if x%i==0:return False
  return True

prime=[isprime(i) for i in range(10**5+1)]

def like2017(x):
  return (prime[x] and prime[(x+1)//2])

a=[like2017(i) for i in range(10**5+1)]

ac=[0]*(10**5+1)
for i in range(2,10**5+1):
  ac[i]=ac[i-1]+a[i]
#print(a[:10])
#print(ac[:10])
#a_cum=np.cumsum(a)

q=int(input())
for i in range(q):
  l,r=map(int,input().split())
  print(ac[r]-ac[l-1])


Measured memory_bytes: 55776
n = int(input())
abc = [list(map(int, input().split())) for _ in range(n)]

a = abc[0][0]
b = abc[0][1]
c = abc[0][2]

for i in range(1, n):
  a, b, c = abc[i][0]+max(b, c), abc[i][1]+max(c, a), abc[i][2]+max(a, b)
  
print(max(a, b, c))


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

int mx[8]={-1,-1,-1,0,0,1,1,1},my[8]={1,0,-1,1,-1,1,0,-1};

int main()
{
  int H,W;scanf("%d %d",&H,&W);
  char S[H][W];
  for(int i=0;i<H;i++)for(int j=0;j<W;j++)cin>>S[i][j];
  for(int i=0;i<H;i++)for(int j=0;j<W;j++)
  {
    if(S[i][j]=='#')continue;
    int count=0;
    for(int k=0;k<8;k++)
    {
      int x=j+mx[k],y=i+my[k];
      if(x<0||y<0||x>=W||y>=H)continue;
      if(S[y][x]=='#')count++;
    }
    S[i][j]='0'+count;
  }
  for(int i=0;i<H;i++){for(int j=0;j<W;j++)cout<<S[i][j];cout<<endl;}
}

Measured memory_bytes: 3768
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,flag=0,a=0,b=0;
    cin>>n;
    flag=0;
    for(int i=1; i<10; i++)
    {
        if(n%i==0)
        {
            a=n/i;
            b=i;

            if((a>=1&&a<=9)&&(b>=1&&b<=9))
            {
                cout<<"Yes"<<endl;
                flag=1;
                break;

            }
        }
        else continue;
    }
    if(flag==0) cout<<"No"<<endl;

}


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

int main() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  
  int n;
  cin >> n;
  int b[n][n];
  rep(i,n) rep(j,n) b[i][j] = -1;
  rep(i,n) {
    int q;
    cin >> q;
    rep(j,q) {
      int x, y;
      cin >> x >> y;
      --x;
      b[i][x] = y;
    }
  }
  
  int ans = 0;
  rep(i,1<<n) {
    vector<int> d(n);
    rep(j,n) {
      if(i>>j & 1) d[j] = 1;
    }
    bool flag = true;
    rep(j,n) {
      if(d[j]) {
        rep(k,n) {
          if(b[j][k] == -1) continue;
          if(b[j][k] != d[k]) flag = false;
        }
      }
    }
    if(flag) ans = max(ans, __builtin_popcount(i));
  }
  cout << ans << endl;
  return 0;
}

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


signed main()
{

    //#ifndef ONLINE_JUDGE
    //    freopen ("./INPUT.txt" , "r" , stdin);
    //    freopen ("./OUTPUT.txt" , "w" , stdout);
    //#endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);


    string s,t;
    cin>>s>>t;

    int n=s.length();
    int m=t.length();
    set<int>a[26];
    for (int i = 0; i < n; ++i) {
        a[s[i]-'a'].insert(i+1);
    }

    int ans=0;
    int x=0;
    for (int i = 0; i < m; ++i) {
        if(a[t[i]-'a'].lower_bound(0)==a[t[i]-'a'].end())
        {
            cout<<-1;
            return 0;
        }
        auto j=a[t[i]-'a'].lower_bound(x+1);
        if(j==a[t[i]-'a'].end())
        {
            ans+=n-x;
            x=0;
            i--;
        }
        else
        {
            ans+=*j-x;
            x=*j;
        }


    }

    cout<<ans;
}

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

#define INF 1e9

int main(){
	int n, m;
	cin >> n >> m;
	int dist[n][n];
	fill(dist[0], dist[n], INF);
	for(int i = 0; i < n; i++) dist[i][i] = 0;
	while(m--){
		int a, b, c;
		cin >> a >> b >> c;
		a--; b--;
		dist[a][b] = dist[b][a] = c;
	}
	int score[n][n];
	for(int i = 0; i < n; i++) for(int j = 0; j < n; j++) score[i][j] = dist[i][j];
	for(int k = 0; k < n; k++) for(int i = 0; i < n; i++) for(int j = 0; j < n; j++) score[i][j] = min(score[i][j], score[i][k] + score[k][j]);
	int ans = 0;
	for(int i = 0; i < n; i++) for(int j = i + 1; j < n; j++) if(dist[i][j] != INF && dist[i][j] > score[i][j]) ans++;
	cout << ans << endl;
}

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

int main() {
  int N;
  cin >> N;
  vector<int> P(N);
  for (int i = 0; i < N; i++) {
    cin >> P.at(i);
  }
  int ref;
  ref = P.at(0);
  int ans;
  ans = 0;
  for (int i = 0; i < N; i++) {
    if (P.at(i) <= ref) {
      ans += 1;
      ref = P.at(i);
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <stack>
#include <queue>
#include <functional>
#include <math.h>
#include <stdlib.h>
#include <map>
#include <deque>
#include <sys/timeb.h>
#include <fstream>

using namespace std;

#define repr(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repr(i,0,n)
#define reprrev(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)
#define reprev(i,n) reprrev(i,0,n)
#define repi(itr,ds) for(auto itr=ds.begin();itr!=ds.end();itr++)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define mp make_pair
#define mt make_tuple
#define INF 1050000000
#define INFL 1100000000000000000LL
#define EPS (1e-10)
#define MOD 1000000007
#define PI 3.1415926536
#define RMAX 4294967295

typedef long long ll;
typedef pair<int, int> Pi;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<Pi> vPi;
typedef vector<vector<int> > vvi;
typedef vector<vector<bool> > vvb;
typedef vector<vector<ll> > vvll;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<double> > vvd;
typedef vector<vector<Pi> > vvPi;
typedef priority_queue<int, vector<int>, greater<int> > pqli;
typedef priority_queue<ll, vector<ll>, greater<ll> > pqlll;
typedef priority_queue<Pi, vector<Pi>, greater<Pi> > pqlP;
struct Edge {
	int from, to, cost;
	bool operator<(Edge e) {
		return cost < e.cost;
	}
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;
template <class T>
using vec = vector<T>;
template<class T>
using pql = priority_queue<T, vector<T>, greater<T>>;
string debug_show(Pi a) {
	return "(" + to_string(a.first) + "," + to_string(a.second) + ")";
}

template<class T>
struct augEdge {
	T from, to;
	int cost;
	bool operator<(augEdge e) { return cost < e.cost; }
	bool operator>(augEdge e) { return cost > e.cost; }
};
template<class T>
using augGraph = vector<augEdge<T>>;


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

	int a, b;
	cin >> a >> b;
	if (a == 4 || a == 6 || a == 9 || a == 11) {
		a = 4;
	}
	else if(a ==2) {
		a = 2;
	}
	else {
		a = 1;
	}

	if (b == 4 || b == 6 || b == 9 || b == 11) {
		b = 4;
	}
	else if (b == 2) {
		b = 2;
	}
	else {
		b = 1;
	}

	if (a == b) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}



	return 0;
}


Measured memory_bytes: 384
#include "bits/stdc++.h"
using namespace std;
 
////////////// Prewritten code follows. Look down for solution. ////////////////

#define fs first
#define sc second
#define pb push_back
#define mp(a, b) make_pair(a, b)
#define len(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define fastio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);

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

template<typename T>
const T INF = (is_same<T, int>::value ? 1e9 : 1e18);
template<typename T>
inline T mod(T n, T mod){ T res = n%mod; if(res < 0) res += mod; return res; }

/// command for char arrays with spaces -> scanf(" %[^\n]", text);
 
////////////////////////// Solution starts below. //////////////////////////////

int main(){
	fastio;
	int n, m;
	cin >> n >> m;
	vvi adj(n+1, vi());
	vi inDegree(n+1, 0);
	while(m--){
		int a, b;
		cin >> a >> b;
		adj[a].pb(b);
		inDegree[b]++;
	}
	vi lista, dist(n+1, 0);
	for(int i = 1; i <= n; i++){
		if(!inDegree[i]) lista.pb(i);
	}
	for(int i = 0; i < len(lista); i++){
		int v = lista[i];
		for(int u : adj[v]){
			inDegree[u]--;
			dist[u] = max(dist[u], dist[v]+1);
			if(!inDegree[u]) lista.pb(u);
		}
	}
	int ans = -1;
	for(int i = 1; i <= n; i++){
		ans = max(ans, dist[i]);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 7164
using DataStructures
function main()
  t=readlines()
  n,m=parse.(Int,split(t[1]))
  s=IntDisjointSets(n)
  c=zeros(Int,n)
  for i=2:m+1
    a,b=parse.(Int,split(t[i]))
    union!(s,a,b)
  end
  for i=s.parents
    c[find_root!(s,i)]+=1
  end
  println(maximum(c))
end
main()


Measured memory_bytes: 235920
import sys
input = sys.stdin.readline
R,C,K = map(int,input().split())
RCV = [tuple(map(int,input().split())) for i in range(K)]

goods = [dict() for _ in range(R)]
for r,c,v in RCV:
    r,c = r-1,c-1
    goods[r][c] = v

dp0 = [[0]*4 for _ in range(C)]
dp1 = [[0]*4 for _ in range(C)]
if 0 in goods[0]:
    dp1[0][1] = goods[0][0]
for i in range(R):
    for j in range(C):
        if i:
            pre = max(dp0[j])
            dp1[j][0] = pre
            if j in goods[i]:
                dp1[j][1] = pre + goods[i][j]
        if j:
            for k in range(4):
                dp1[j][k] = max(dp1[j][k], dp1[j-1][k])
            if j in goods[i]:
                for k in reversed(range(3)):
                    dp1[j][k+1] = max(dp1[j][k+1], dp1[j-1][k] + goods[i][j])
    dp0 = dp1
    dp1 = [[0]*4 for _ in range(C)]
print(max(dp0[-1]))

Measured memory_bytes: 223956
import java.io.*;
import java.util.*;
public class Main{
    public static void main(String[] args) throws IOException{
        MyReader r = new MyReader();
        int N, W;
        {int[]a = r.ii(); N = a[0]; W = a[1];}
        int[] w = new int[N];
        int[] v = new int[N];
        int[][] things = new int[4][N+1];
        
        
        int[] a = r.ii();
        int w0 = a[0];
        things[0][0] = a[1];
        
        int w1 = w0+1;
        int w2 = w1+1;
        int w3 = w2+1;
        int[] num = {1, 0, 0, 0};

        for(int i = 0; i < N-1; i++){
            a = r.ii();
            int group = a[0]-w0;
            things[group][num[group]++] = a[1];
        }
        
        for(int i = 0; i < 4; i++)
            Arrays.parallelSort(things[i], 0, num[i]);
            
        long max = 0;
        for(int i = 0, v0 = 0; i <= Math.min(W/w0, num[0]); i++){
            if(i > 0)
                v0 += things[0][num[0]-i];
            for(int j = 0, v1 = 0; j <= Math.min((W-i*w0)/w1, num[1]); j++){
                if(j > 0)
                    v1 += things[1][num[1]-j];
                for(int k = 0, v2 = 0; k <= Math.min((W-i*w0-j*w1)/w2, num[2]); k++){
                    if(k > 0)
                        v2 += things[2][num[2]-k];
                    for(int l = 0, v3 = 0; l <= Math.min((W-i*w0-j*w1-k*w2)/w3, num[3]); l++){
                        if(l > 0)
                            v3 += things[3][num[3]-l];
                        max = Math.max(max, v0+v1+v2+v3);
                    }
                }
            }
        }
        println(max);
    }
    static void print(Object o){
        System.out.print(o.toString());
    }

    static void println(Object o){
        System.out.println(o.toString());
    }

    static int Int(String s){
        return Integer.parseInt(s);
    }

    static long Long(String s){
        return Long.parseLong(s);
    }
    static class MyReader extends BufferedReader{
        MyReader(){
            super(new InputStreamReader(System.in));
        }

        String s() throws IOException{
            return readLine();
        }

        String[] ss() throws IOException{
            return s().split(" ");
        }

        int i() throws IOException{
            return Int(s());
        }

        int[] ii() throws IOException{
            String[] ss = ss();
            int size = ss.length;
            int[] ii = new int[size];
            for(int j = 0; j < size; j++) ii[j] = Int(ss[j]);
            return ii;
        }

        long l() throws IOException{
            return Long(s());
        }

        long[] ll() throws IOException{
            String[] ss = ss();
            int size = ss.length;
            long[] ll = new long[size];
            for(int j = 0; j < size; j++) ll[j] = Long(ss[j]);            
            return ll;
        }
    }
}

Measured memory_bytes: 21332
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define stoi stoll
using ll=long long;
using vi=vector<int>;
using pii=pair<int,int>;
#define ALL(c) begin(c),end(c)
#define RALL(c) rbegin(c),rend(c)
#define ITR(i,b,e) for(auto i=(b);i!=(e);++i)
#define FORE(x,c) for(auto &&x:c)
#define REPF(i,a,n) for(int i=a,i##len=(int)(n);i<i##len;++i)
#define REP(i,n) REPF(i,0,n)
#define REPR(i,n) for(int i=(int)(n);i>=0;--i)
#define SZ(c) ((int)c.size())
#define CONTAIN(c,x) (c.find(x)!=end(c))
#define INSEG(l,x,r) ((l)<=(x)&&(x)<(r))
#define dump(...)
#define pb push_back
#define _ 0
const signed INF_=1001001001; const long long INF=1001001001001001001LL;
const int DX[9]={0,1,0,-1,1,1,-1,-1,0},DY[9]={-1,0,1,0,-1,1,1,-1,0};
template<class T> ostream& operator<<(ostream &os,const vector<T> &v) {
    ITR(i,begin(v),end(v))os<<*i<<(i==end(v)-1?"":" ");return os;}
template<class T> istream& operator>>(istream &is,vector<T> &v) {
    ITR(i,begin(v),end(v)) is>>*i;return is;}
template<class T,class U> istream& operator>>(istream &is, pair<T,U> &p) {
    is>>p.first>>p.second;return is;}
template<class T, class U> bool chmax(T &a,const U &b){return a<b?a=b,1:0;}
template<class T, class U> bool chmin(T &a,const U &b){return a>b?a=b,1:0;}
template <class T> void PSUM(T& c) {partial_sum(begin(c), end(c), begin(c));}
template<class T> using heap=priority_queue<T,vector<T>,greater<T>>;
struct before_main_function {
    before_main_function() {
        cin.tie(0); ios::sync_with_stdio(0);
        cout << setprecision(15) << fixed;
        // #define endl "\n"
    }
} before_main_function;
//------------------8<------------------------------------8<--------------------

signed main() {
    int N;
    cin >> N;
    vector<int> L(N), R(N);
    REP(i, N) {
        int l, r;
        cin >> l >> r;
        L[i] = l;
        R[i] = r;
    }
    sort(RALL(L));
    sort(ALL(R));

    int ans = 0;

    {
        int tmp = 0;
        int s = 0;
        REP(i, N) {
            s += L[i] * 2;
            chmax(tmp, s);
            s -= R[i] * 2;
            chmax(tmp, s);
        }
        chmax(ans, tmp);
    }
    {
        int tmp = 0;
        int s = 0;
        REP(i, N) {
            s -= R[i] * 2;
            chmax(tmp, s);
            s += L[i] * 2;
            chmax(tmp, s);
        }
        chmax(ans, tmp);
    }

    cout << ans << endl;
    return (0^_^0);
}



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

int main() {
  int a, b;

  cin >> a >> b;

  if (a <= 5) {
    cout << 0 << endl;
  } else if (a >= 13) {
    cout << b << endl;
  } else {
    cout << b/2 << endl;
  }

  return 0;

}

Measured memory_bytes: 256
#include <stdio.h>

char isNotPrime[555555] = {5, 5};

int main(void) {
	int i, j;
	int N;
	for (i = 5 >> (5 / 5); i * i < 555555; i++) {
		if (!isNotPrime[i]) {
			for (j = i * i; j < 555555; j += i) {
				isNotPrime[j] = 5;
			}
		}
	}
	if (scanf("%d", &N) != (5 == 5)) return 5;
	for (i = j = 5 || 5; i < 555555 && j <= N; i += 5 + 5) {
		if (!isNotPrime[i]) {
			if (j - (5 && 5)) printf(" ");
			printf("%d", i);
			j++;
		}
	}
	putchar('\n');
	return 5 - 5;
}


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

typedef long long LL;

const int N = 5e6+7, M = 998244353;
LL fac[N], invfac[N];
LL p2[N], p3[2*N];

LL power(LL a, LL p) {
    if (p==0)   return 1;
    LL ans = power(a, p/2);
    ans = (ans * ans)%M;
    if (p%2)    ans = (ans * a)%M;
    return ans;
}

LL pre() {
    fac[0] = 1;
    for (int i=1; i<N; i++) fac[i] = (fac[i-1]*i)%M;
    invfac[N-1]=  power(fac[N-1], M-2);
    for (int i=N-2; i>=0; i--)  invfac[i] = (invfac[i+1]*(i+1))%M;

    p2[0] = p3[0] = 1;
    for (int i=1; i<N; i++) p2[i] = (p2[i-1]*2)%M;
    for (int i=1; i<2*N; i++) p3[i] = (p3[i-1]*3)%M;
}

LL C(int n, int r) {
    if (r < 0 || r > n) return 0;
    LL num = fac[n];
    LL den = (invfac[r]*invfac[n-r])%M;
    return (num*den)%M;
}

LL f[N];
LL suf[N];

int main() {
    pre();
    int n;
    cin>>n;
    int m = n/2;

    for (int i=0; i<=m; i++)    {
        f[i] = (C(m, i)*p2[m-i])%M;
    }

    for (int i=m; i>=0; i--) {
        suf[i] = (suf[i+1] + f[i])%M;
    }

    LL ans =- 0;

    for (int i=0; i<=m; i++)    {
        ans = (ans + f[i] * suf[m-i+1])%M;
    }
    ans = (ans * 2)%M;
    ans = (p3[2*m] - ans + M)%M;
    cout<<ans<<endl;
}

Measured memory_bytes: 273664
#include <bits/stdc++.h>
#define ll long long int
#define MOD 1000000007
#define INF 1e18
#define PI 3.14159265358979

using namespace std;

int main(void){
  string s;
  cin >> s;
  ll n = s.size();
  
  vector<ll> height(n, 1), g(n, 1);
  for (int i = 1; i < n; i++){
    if (s[i] == 'g'){
      height[i] = height[i-1] + 1;
      g[i] = g[i-1] + 1;
    }
    else {
      height[i] = height[i-1] - 1;
      g[i] = g[i-1];
    }
  }

  int id = n - 1;
  while(height[id] > height[id-1] && id > 0){
    id--;
  }
  if (id == 0){
    cout << g[n-1]/2 << endl;
  }
  else {
    ll t = min(height[id]/2, g[id]);
    cout << t + (g[n-1] - g[id] + height[id] - 2*t)/2  << endl;
  }

  return 0;
}


Measured memory_bytes: 2048
#include <stdio.h>
#include <stdlib.h>

#define xMAX 1000000000

typedef struct _list{
    int data;
    struct _list *next;
}LIST;
typedef struct _que{
    LIST *head;
    LIST *tail;
}QUE;

int main(){
    int i;
    int n,q;
    scanf("%d %d\n",&n,&q);
    
    QUE Q[n];
    for(i=0;i<n;i++){
        Q[i].head=NULL;
        Q[i].tail=NULL;
    }
    
    LIST *p;
    int com,t,x;
    while(q--){
        scanf("%d %d \n",&com,&t);
        switch(com){
            case 0:
                //pushback
                scanf("%d\n",&x);
                if(Q[t].head==NULL){
                    Q[t].head=(LIST*)malloc(sizeof(LIST));
                    Q[t].head->data=x;
                    Q[t].head->next=NULL;
                    Q[t].tail=Q[t].head;
                }else{
                    Q[t].tail->next=(LIST*)malloc(sizeof(LIST));
                    Q[t].tail=Q[t].tail->next;
                    Q[t].tail->data=x;
                    Q[t].tail->next=NULL;
                }
                break;
            case 1:
                //dump
                if(Q[t].head!=NULL)printf("%d\n",Q[t].head->data);
                break;
            case 2:
                //clear
                if(Q[t].head==NULL)break;
                
                p=Q[t].head;
                if(Q[t].head->next!=NULL){
                    Q[t].head=Q[t].head->next;
                }else{
                    Q[t].head=NULL;
                    Q[t].tail=NULL;
                }
                free(p);
                break;
        }
    }
    
    LIST *tmp;
    for(i=0;i<n;i++){
        if(Q[i].head!=NULL){
            p=Q[i].head;
            while(p!=NULL){
                tmp=p;
                free(p);
                p=tmp->next;
            }
        }
    }
    
    return 0;
}


Measured memory_bytes: 7968
def is_gu_string(s)
  return false if s.size.odd?

  s[0...(s.size/2)] == s[(s.size/2)...s.size]
end

s = gets.chomp
s = s[0...(s.size-2)]
loop do
  if is_gu_string(s)
    puts s.size
    break
  end
  s = s[0...(s.size-2)]
end

Measured memory_bytes: 1788
#!/usr/bin/env python
# coding: utf-8

# In[7]:


N = int(input())
s = []
for _ in range(N):
    s.append(input())
M = int(input())
t = []
for _ in range(M):
    t.append(input())


# In[8]:


ans = 0
for i in range(N):
    ans = max(ans, s.count(s[i]) - t.count(s[i]))
print(ans)


# In[ ]:






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

using namespace std;

typedef long long ll;
typedef long double ld;

int niz[100];

int main(){
    ios_base::sync_with_stdio(false);
	cout.precision(10);
	cout << fixed;

    int n;
    cin >> n;
    for(int i=1; i<=n; i++){
        cin >> niz[i];
    }
    sort(niz+1, niz+1+n);
    ld res = niz[1];
    for(int i=2; i<=n; i++){
        res = (res+niz[i])/2;
    }
    cout << res;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){

int x,y;

while(1){
cin >> x >> y ;

if((x!=0)||(y!=0)){
if(y<x){
cout << y << " " << x << endl;
}else{
cout << x << " " << y << endl;
}

}else
break;
}
return 0;

}

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

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

signed main(){

  string s;
  cin>>s;

  auto solve = [](string const& s){
    int n  =size(s);
    vector dp(n+1,0);
    dp[1] = 1;
    for(int i=1;i<n;++i){
      if(s[i-1]==s[i])dp[i+1]=dp[i-1]+1;
      else dp[i+1]=dp[i]+1;
      if(i>=2)dp[i+1]=max(dp[i+1],dp[i-2]+2);
    }
    return dp[n];
  };

  int ans = solve(s);
  reverse(begin(s),end(s));
  ans = max(ans,solve(s));

  cout<<(ans)<<endl;

}

Measured memory_bytes: 4452
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;


int main() {
    int N, M, answer = 0;
    cin >> N >> M;

    vector<int> L;
    vector<int> R;
    L.push_back(0);
    R.push_back(0);


    for (int i = 1; i <= M; i++) {
        int l, r;
        cin >> l >> r;
        L.push_back(l);
        R.push_back(r);
    }

    sort(L.begin(), L.end());
    reverse(L.begin(), L.end());
    sort(R.begin(), R.end());

    answer = R[1] - L[0] + 1;
    if (answer >= 0)
        cout << answer << endl;
    else
        cout << 0 << endl;


    return 0;
}


Measured memory_bytes: 1276
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <string>
#include <cmath>
#include <iomanip>
#include <numeric>
#include <cmath>
 
using namespace std;
 
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, n) FOR(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())
#define INF (ll)1e18
#define MOD (ll)1e9 + 7
#define pb push_back
 
void no(){cout<<"No"<<endl;exit(0);}
void yes(){cout<<"Yes"<<endl;exit(0);}
void No(){cout<<"NO"<<endl;exit(0);}
void Yes(){cout<<"YES"<<endl;exit(0);}
 
typedef long long ll;
typedef long long int llt;
typedef pair<int, int> P;
typedef vector<int> V;
typedef map<int, int> M;

int main(void)
{
    cin.tie(0);
   	ios::sync_with_stdio(false);
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    int x = abs(a - b), y = abs(b - c), z = abs(a - c);
    if(x<=d&&y<=d)
        cout << "Yes" << endl;
        else if(z<=d)
            cout << "Yes" << endl;
        else
            cout << "No" << endl;
        return 0;
}

Measured memory_bytes: 256
import math
S=input()
N=len(S)
#mid=math.ceil(N/2)

firstS=S[:math.ceil(N/2)-1]
secondS=S[int((N+3)/2-1):]

if S==S[::-1] and firstS==firstS[::-1] and secondS==secondS[::-1]:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 3060
n,x=map(int,input().split())
a=list(map(int,input().split()))
temp=[0]*n
for i in range(0,n):
  temp[i]=abs(a[i]-x)
import fractions
ans=temp[0]
for i in range(1,n):
  ans=fractions.gcd(ans,temp[i])
print(ans)

Measured memory_bytes: 15020
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#define lop(i, n) for(i=0; i<n; i++)

int main()
{
	char s[3];
	scanf("%s", s);
	
	if(s[1]=='B'){ printf("ARC"); }
	else { printf("ABC"); }
	 
	return 0;
}

Measured memory_bytes: 1736
/* 
chirag11032000
Chirag Thakur
*/

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

using ll = long long;
using db = double;
using pii = pair < int, int >;
using pll = pair < ll, ll >;

template < typename T > using OrderedSet = tree < T, null_type, less < T >, rb_tree_tag, tree_order_statistics_node_update >;
template < typename T > using MinPriorityQueue = priority_queue < T, vector < T >, greater < T > >;

#ifndef ONLINE_JUDGE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template < typename Arg1 >
void __f(const char* name, Arg1&& arg1) {
	cerr << name << " : " << arg1 << std::endl;
}
template < typename Arg1, typename... Args >
void __f(const char* names, Arg1&& arg1, Args&&... args) {
	const char* comma = strchr(names + 1, ',');
	cerr.write(names, comma - names) << " : " << arg1 << " | ";
	__f(comma + 1, args...);
}
#else
#define trace(...)
#endif

#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define unique_sort(x) sort(all(x)), x.resize(distance(x.begin(), unique(all(x))))

const db PI = acos(-1);
const ll LINF = LLONG_MAX;
const int INF = INT_MAX, MOD = 1e9 + 7, N = 1e5 + 10;

void test_case();

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	test_case();
	cerr << "Time taken: " << int((clock() * 1000.) / CLOCKS_PER_SEC) << "ms\n";
	return 0;
}

void test_case() {
	vector < int > v(3);
	for (auto &el: v) {
		cin >> el;
	}
	sort(all(v));
	cout << v[0] + v[1] << "\n";
}

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

using namespace std;
typedef long long int lld;
#define rep(i,a,b) for(int i=a;i<b;i++)

int main(){
  string s;
  cin>>s;
  int a=0;
  int ptr=0;
  lld ans=0;
  while(ptr<s.size()){
    if(s.at(ptr)=='A'){
      ptr++;
      a++;
    }else{
      if(ptr+1<s.size() && s.at(ptr)=='B' && s.at(ptr+1)=='C'){
	ans+=a;
	ptr+=2;
      }else{
	a=0;
	ptr++;
      }
    }
  }
  cout<<ans<<endl;
  return 0;
}


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

int main(){
    int n;
    cin >> n;
    int a[n];
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
    int ans = __gcd(a[0],a[1]);
    for(int i = 2 ; i < n; i++){
        ans = __gcd(ans,a[i]);
    }
    cout << ans << endl;
    return 0;
}

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

using namespace std;

long long int s;

int main()
{
	cin>>s;
	long long int x;
	if(s!=(long long)1e18)
	    x=(long long)sqrt(s)+1;
	else
	    x=(long long)sqrt(s);
	long long int y=(long long)x*x-s;
	cout<<"0 0 1 "<<x<<" "<<x<<" "<<y<<"\n";
	return 0;
} 

Measured memory_bytes: 256
import java.util.Scanner;

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

        int x = sc.nextInt();
        int y = sc.nextInt();
        int z;

        do{
            z = x%y;
            x = y;
            y = z;

        }while(z != 0);

        System.out.println(x);

        sc.close();
    }
}


Measured memory_bytes: 26248
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

#define MAX 101

void initialize(void);
int isEmpty(void);
int isFull(void);
void push(int);
int pop();

int top;
int S[MAX];

int main(){
  int x, a, b;
  char s[MAX];

  initialize();
  while( scanf("%s", s) != EOF ){
    if ( s[0] == '+' ){
      a = pop();
      b = pop();
      push(a+b);
    }
    else if ( s[0] == '-' ){
      a = pop();
      b = pop();
      push(b-a);
    }
    else if ( s[0] == '*' ){
      a = pop();
      b = pop();
      push(a*b);
    }
    else {
      x = atoi(s);
      push(x);
    }
  }

  printf("%d\n", S[1]);

  return 0;
}

void initialize() {
  top = 0;
}

int isEmpty() {
  return top == 0;
}

int isFull () {
  return top >= MAX-1;
}

void push(int x) {
  if(isFull()) {
    printf("error\n");
  }
  top++;
  S[top] = x;
}

int pop(void) {
  if(isEmpty()) {
    printf("error\n");
  }
  top--;
  return S[top+1];
}

Measured memory_bytes: 548
import math
math.sin(math.radians(30))
a, b, h, m = list(map(int, input().split()))
a_angle = 30*h + 30 * m / 60.0
b_angle = 360 * m / 60.0
angle = abs(a_angle - b_angle)

answer = (a**2 + b ** 2 - 2 * a * b * math.cos(math.radians(angle))) ** 0.5
print(answer)

Measured memory_bytes: 9564
#include <iostream>
#include <string>
using namespace std;
int main()
{
    string pd;
    cin >> pd;
    for (long unsigned int i = 0; i < pd.size(); i++) {
        if (pd[i] == '?') {
            pd[i] = 'D';
        }
    }

    cout << pd;
    
    return 0;
}

Measured memory_bytes: 3744
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
#define inf (int)(1e9+7)
#define abs(x) (x >= 0 ? x : -(x))
#define ceil(a, b) a / b + !!(a % b)
template<typename T1, typename T2> inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }
ll pow(ll a, int b) { return b ? pow(a * a, b / 2) * (b % 2 ? a : 1) : 1; }
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }



int main() {
    
    int n, k;
    cin >> n >> k;
    
    int bef = n + 1;
    double ans = 0;
    int flg = 0;
    
    rep(i, 20) {
        if (k <= n) {
            double tmp = 1.0 / n;
            rep(j, i) tmp *= 1.0 / 2;
            tmp *= bef - k;
            ans += tmp;
            // cout << i << " " << ans << " " << bef << " " << k << '\n';
            bef = k;
            
        }
        
        k = (k + 1) / 2;
        
        if (flg) break;
        if (k == 1) flg = 1;
    }
    
    cout << fixed << setprecision(10) << ans << '\n';
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
        int X = sc.nextInt(); 
        
		if (X == 3 || X == 5 || X == 7) {
			System.out.println("YES");
		} else {
			System.out.println("NO");
		}
	}
}

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

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

using Graph = vector<vector<int>>;

ll calc(ll a, ll b, ll p){//aのb乗をpで割った余り
  if(b == 0) return 1;

  else if(b%2 == 0){
    ll d = calc(a,b/2,p);
    return (d*d)%p;
  }
  else if(b%2 == 1){
    return (a * calc(a,b-1,p))%p;
  }
}

typedef pair<int,int> P;

bool is_prime(int n){//nが素数であるかどうか判定 iで割り切れると素数でない
    if(n == 1) return false;//1は例外
    for(int i = 2;i*i <= n;i++){
        if(n%i == 0) return false;
    }
    
    return true;
}

int main(){
  int N;
  cin >> N;
  string S;
  cin >> S;
  vector<char> vc(26);
  char c = 'A';
  rep(i,26){
    vc[i] = c;
    c++;
  }
  
  rep(i,S.size()){
    int k = (int)S[i] - 65;//S[i]が何番目のアルファベットか
    S[i] = vc[(k+N)%26];
  }
  cout << S << endl;
 }

Measured memory_bytes: 256
#include<stdio.h>
 int main (void){
     int N;
     int i;
     int a=0;
     scanf("%d",&N);

     for(i=1; i<10; i++){
         if(N/i < 10 && N%i == 0){
             a++;
         }
     }

     if(a > 0){
         printf("Yes");
     }else{
         printf("No");
     }
     return 0;
 }

Measured memory_bytes: 128
#include<iostream>
#include<cstdio>
#include<set>
using namespace std;
long long h,w,n,x,y,ans[11],cur,sum;
set<pair<long long,long long> > s;
int main()
{
	scanf("%lld%lld%lld",&h,&w,&n);
	for (long long i=1;i<=n;i++)
	{
		scanf("%lld%lld",&x,&y);
		s.insert(make_pair(x,y));
	}
	for (set<pair<long long,long long> >::iterator it=s.begin();it!=s.end();it++)
	{
		x=it->first;y=it->second;
		for (long long i=x-2;i<=x;i++)
		{
			for (long long j=y-2;j<=y;j++)
			{
				if (i<=0 || j<=0 || i+2>h || j+2>w) continue;
				cur=0;
				for (long long k=i;k<=i+2;k++)
				{
					for (long long h=j;h<=j+2;h++)
					{
						if (s.find(make_pair(k,h))!=s.end()) cur++;
					}
				}
				ans[cur]++;
			}
		}
	}
	for (long long i=1;i<=9;i++)
	{
		ans[i]/=i;
		sum+=ans[i];
	}
	printf("%lld\n",(h-2)*(w-2)-sum);
	for (long long i=1;i<=9;i++)
	{
		printf("%lld\n",ans[i]);
	}
	return 0;
}

Measured memory_bytes: 6528
"use strict";function Main(t){const e=t=>{const e=t.length;for(let n=0;n<(e-1)/2;n++){if(t[n]!=t[e-1-n])return!1}return!0},n=(t=t.split("")).length;console.log(e(t)&&e(t.slice(0,(n-1)/2))&&e(t.slice((n+3)/2-1))?"Yes":"No")} Main(require("fs").readFileSync("/dev/stdin", "utf8").trim());

Measured memory_bytes: 7372
#include <iostream>
#include<sstream>
#include<vector>
#include<iterator>
using namespace std;

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

	vector<string> stage(H, "");
	for(int i=0; i<H; i++)
		cin >> stage[i];

	for(int i=0; i<H; i++)
		cout << stage[i] << endl << stage[i] << endl;

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <vector>
#include <stack>
#include <queue>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <cstdio>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <map>
#include <set>

using namespace std;

typedef long long ll;
typedef pair<int,int> PP;

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

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

int main() {
    ios::sync_with_stdio(false);
    ll N, X;
    cin >> N >> X;
    cout << 3 * (N - gcd(N, X)) << endl;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#define rep(i,N) for(int i=0;i<(int)N;i++)
const int MOD=998244353;
int main(void)
{
  int A,B,C,D,ans=0,powD=1,sum,dp[3000]={0};
  if(!scanf("%d %d %d %d",&A,&B,&C,&D))return 0;
  dp[A-1]=1;
  rep(i,D-B)
  {
    sum=0;
    rep(j,C)
    {
      sum=(1ll*sum*(B+i)%MOD+dp[j])%MOD;
      dp[j]=(1ll*j*dp[j]+sum)%MOD;
    }
  }
  rep(i,C){ans=(ans+1ll*dp[C-i-1]*powD%MOD)%MOD;powD=1ll*powD*D%MOD;}
  return printf("%d\n",ans),0;
}

Measured memory_bytes: 1688
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int maxn=3e3+10;
struct node{
    int c,v;
}a[maxn];
int dp[maxn][maxn]={},dp2[maxn][maxn]={};
main(){
    int n,m;
    cin>>n>>m;
    for(int i=1;i<=n;++i){
        cin>>a[i].c>>a[i].v;
    }
    for(int i=1;i<=n;++i){
        for(int j=m;j>=0;--j){
            if(j>=a[i].c)dp[i][j]=max(dp[i-1][j],dp[i-1][j-a[i].c]+a[i].v);
            else dp[i][j]=dp[i-1][j];
        }
    }
    for(int i=n;i>=1;--i){
        for(int j=m;j>=0;--j){
            if(j>=a[i].c)dp2[i][j]=max(dp2[i+1][j],dp2[i+1][j-a[i].c]+a[i].v);
            else dp2[i][j]=dp2[i+1][j];
        }
    }
    int ans=-1;
    for(int i=1;i<=n;++i){
        for(int j=0;j<=m-1;++j)
            ans=max(ans,a[i].v+dp[i-1][j]+dp2[i+1][m-1-j]);
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 141568
using System;
using System.Text;

namespace Aizu
{
    class OnlineJudge
    {
        public static void Main()
        {
            var input = Console.ReadLine();
            var output = new StringBuilder(input.Length);
            foreach(var item in input){
                if(item >= 'a' && item <= 'z') {
                    output.Append((char)(item - '\x20'));
                }
                else if(item >= 'A' && item <= 'Z') {
                    output.Append((char)(item + '\x20'));
                }
                else {
                    output.Append(item);
                }
            }
            Console.WriteLine(output.ToString());
        }
    }
}

Measured memory_bytes: 5288
import java.util.Scanner;

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

	String area = String.format("%.6f", r * r * Math.PI);
	String peri = String.format("%.6f", 2 * r * Math.PI);
	System.out.println(area+" "+peri);
    }
}



Measured memory_bytes: 28196
#include<iostream>
#include<vector>
#include<queue>
using namespace std;

const int INF = 1<<30;

int main(){
    int w, h;
    while(cin >> w >> h, w+h){
        int mat[2*h-1][w];
        for(int i = 0; i < 2*h-1; i++){
            for(int j = 0; j < w-((i+1)%2); j++){
                cin >> mat[i][j];
            }
        }
        vector<vector<int>> dp(h, vector<int>(w, INF));
        dp[0][0] = 1;
        queue<pair<int,int>> pq;
        pq.push({0,0});
        while(!pq.empty()){
            auto p = pq.front();    pq.pop();
            int i = p.first, j = p.second;
            // north
            if(i != 0 && mat[2*i-1][j] == 0 && dp[i][j]+1 < dp[i-1][j]){
                dp[i-1][j] = dp[i][j]+1;    pq.push({i-1, j});
            }
            // south
            if(i != h-1 && mat[2*(i+1)-1][j] == 0 && dp[i][j]+1 < dp[i+1][j]){
                dp[i+1][j] = dp[i][j]+1;    pq.push({i+1, j});
            }
            // west
            if(j != 0 && mat[2*i][j-1] == 0 && dp[i][j]+1 < dp[i][j-1]){
                dp[i][j-1] = dp[i][j]+1;    pq.push({i, j-1});
            }
            // east
            if(j != w-1 && mat[2*i][j] == 0 && dp[i][j]+1 < dp[i][j+1]){
                dp[i][j+1] = dp[i][j]+1;    pq.push({i, j+1});
            }
        }
        cout << (dp[h-1][w-1]==INF ? 0 : dp[h-1][w-1]) << endl;
    }
    return 0;
}


Measured memory_bytes: 3120
import java.util.*;
import java.io.*;
public class Main{
        public static void main(String[] args){
                Scanner sc = new Scanner(System.in);
                Map hs = new HashMap();
                PrintWriter ou = new PrintWriter(System.out);
                int n = Integer.parseInt(sc.next());
                int k = Integer.parseInt(sc.next());
                int[] a = new int[n];
                for(int i = 0 ; i < n ; i++){
                        a[i] = Integer.parseInt(sc.next());
                }
                sc.close();
                double le = 0;
                double ri = Math.pow(10 , 9);
                while(ri - le > 0.000001){
                        double now = (le + ri) / 2;
                        int yono = 0;
                        for(int i = 0 ; i < n ; i++){
                                yono += (int)(a[i] / now);
                        }
                        if(yono > k) le = now;
                        else ri = now;
                }
                if(ri % 1 < 0.000001 || ri % 1 > 0.99999) ou.print((int)Math.round(ri) + "\n");
                else ou.print((int)Math.ceil(ri)+ "\n");
                ou.flush();
        }
}

Measured memory_bytes: 62376
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int main(void){
    int N;
    cin >> N;
    for(int i=1;i<10;i++){
        int s=N/i;
        if(N%i==0 && s<10){
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    return 0;
}

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

typedef long long ll;
#define ar array
#define vi vector<int>
#define vvi vector<vector<int>>
#define vll vector<long long>
#define all(x) (x).begin(), (x).end()
#define en '\n'
#define FILL(x, v) memset(x, v, sizeof(x))
#define pb push_back
#define fast                     \
	ios::sync_with_stdio(false); \
	cin.tie(NULL);               \
	cout.tie(NULL);
#define F_OR(i, a, b, s) for (int i = (a); ((s) > 0 ? i < (b) : i > (b)); i += (s))
#define F_OR1(e) F_OR(i, 0, e, 1)
#define F_OR2(i, e) F_OR(i, 0, e, 1)
#define F_OR3(i, b, e) F_OR(i, b, e, 1)
#define F_OR4(i, b, e, s) F_OR(i, b, e, s)
#define GET5(a, b, c, d, e, ...) e
#define F_ORC(...) GET5(__VA_ARGS__, F_OR4, F_OR3, F_OR2, F_OR1)
#define FOR(...)       \
	F_ORC(__VA_ARGS__) \
	(__VA_ARGS__)

#define E_ACH2(x, a) for (auto &x : a)
#define E_ACH3(x, y, a) for (auto &[x, y] : a)
#define E_ACH4(x, y, z, a) for (auto &[x, y, z] : a)
#define E_ACHC(...) GET5(__VA_ARGS__, E_ACH4, E_ACH3, E_ACH2)
#define EACH(...)       \
	E_ACHC(__VA_ARGS__) \
	(__VA_ARGS__)

template <typename A, typename B>
inline void chmin(A &a, B b)
{
	if (a > b)
		a = b;
}
template <typename A, typename B>
inline void chmax(A &a, B b)
{
	if (a < b)
		a = b;
}

int main()
{
	fast;
	int n;
	cin >> n;
	vi a(n);
	FOR(n)
	cin >> a[i];
	int ans = 1e9 + 5;
	int l = a[0], r = a[0];
	FOR(n)
	{
		chmin(l, a[i]);
		chmax(r, a[i]);
	}
	for (int i = l; i <= r; i++)
	{
		int sum = 0;
		FOR(j, n)
		sum += (a[j] - i) * (a[j] - i);
		chmin(ans, sum);
	}
	cout << ans;
}

Measured memory_bytes: 3604
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;

internal static class CR
{
    public static string Get() { return Console.ReadLine(); }
    public static IEnumerable<string> GetTexts() { return Console.ReadLine().Split(' '); }
    public static int GetInteger() { return int.Parse(Console.ReadLine()); }
    public static IEnumerable<int> GetIntegers() { return Console.ReadLine().Split(' ').Select(x => int.Parse(x)); }
}

namespace AtCoderBeginnerContest
{
    internal class Program
    {
        public static int K { get; private set; }
        public static int X { get; private set; }

        private static void Main() { var r = GetResult(); Debug.WriteLine(r); Console.WriteLine(r); }

        private static object GetResult()
        {
            var inputs = CR.GetIntegers().ToList();
            K = inputs[0];
            X = inputs[1];

            return K * 500 >= X ? "Yes" : "No";
        }
    }
}


Measured memory_bytes: 13268
#include<bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vii vector<int>
#define vll vector<ll>
#define lb lower_bound
#define pb push_back
#define mp make_pair
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep2(i,a,b) for(ll i=a;i<b;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define all(x) x.begin(),x.end()
#define INF (1 << 30) - 1
#define LLINF (1LL << 61) - 1
// #define int ll
using namespace std;
const int MOD = 1000000007;
const int MAX = 510000;

const int MAX_N = 1<<17;
int dat[2 * MAX_N -1];
int n;

struct SegmentTree{
    SegmentTree(int n_){
        n=1;
        while(n<n_) n*= 2;
        for(int i=0;i<2*n-1;i++){
            dat[i]=0;
        }
    }
    int query(int k){
        k += n-1;
        int count=dat[k];
        while(k>0){
            k=(k-1)/2;
            count+=dat[k];
        }
        return count;
    }
    void update(int a,int b,int k,int p,int l,int r){
        if(r<=a || b<=l) return;
        if(a<=l && r<=b){
            dat[k]+=p;
        }
        else{
            update(a,b,k*2+1,p,l,(l+r)/2);
            update(a,b,k*2+2,p,(l+r)/2,r);
        }
    }
};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int _n,q;
    cin>>_n>>q;
    SegmentTree sg(_n);
    rep(i,q){
        int c;
        cin>>c;
        if(!c){
            int s,t,x;
            cin>>s>>t>>x;
            sg.update(s-1,t,0,x,0,n);
        } else{
            int x;
            cin>>x;
            cout<<sg.query(x-1)<<endl;
        }
    }
    return 0;
}



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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> P;
typedef pair<ll,P>  PP;
typedef vector<ll> Vector;
typedef vector<Vector> DVector;
typedef priority_queue<PP, vector<PP>, greater<PP>> PPQueue;

#define fi          first
#define se          second
#define sfi         se.fi
#define sse         se.se
#define pb          push_back
#define INF         INT_MAX
#define MOD         1000000007
#define bcnt        __builtin_popcount
#define all(x)      (x).begin(),(x).end()
#define uni(x)      x.erase(unique(all(x)),x.end())
#define ub(x,y)     (upper_bound(all(x),y)-x.begin())
#define lb(x,y)     (lower_bound(all(x),y)-x.begin())
#define rep(i,n)    repl(i,0,n-1)
#define usort(x)    sort(all(x))
#define dsort(x)    sort(all(x),greater<ll>())
#define mkp(x,y)    make_pair(x,y)
#define mmax(x,y)   (x>y?x:y)
#define mmin(x,y)   (x<y?x:y)
#define maxch(x,y)  x=mmax(x,y)
#define minch(x,y)  x=mmin(x,y)
#define exist(x,y)  (find(all(x),y)!=x.end())
#define each(itr,v) for(auto itr:v)
#define repl(i,a,b) for(ll i=(ll)(a);i<=(ll)(b);i++)

ll n;
string s1,s2;
ll ans = 0;
int main() {
  cin.sync_with_stdio(false);

  cin >> n;
  cin >> s1 >> s2;
  ans = 1;
  ll mode = -1;
  rep(i,n){
    switch(mode){
      case -1 :
      if (s1[i] == s2[i]) {
        mode = 0;
        ans = 3;
      }
      else {
        mode = 1;
        ans = 6;
      }
      break;
      case 0 :
      if (s1[i] == s2[i]) {
        mode = 0;
        ans *= 2;
      }
      else {
        mode = 1;
        ans *= 2;
      }
      break;
      case 1 :
      mode = 2;
      break;
      case 2 :
      if (s1[i] == s2[i]) {
        mode = 0;
        ans *= 1;
      }
      else {
        mode = 1;
        ans *= 3;
      }
      break;
    }
    ans %= MOD;
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
def int_raw():
    return int(raw_input())

def ss_raw():
    return raw_input().split()

def ints_raw():
    return map(int,ss_raw())

sx,sy,tx,ty = ints_raw()
dx = tx-sx
dy = ty-sy


f1st = "U"*dy + "R"*dx
b1st = "D"*dy + "L"*dx
f2nd = "L" + "U"*(dy+1) + "R"*(dx+1) + "D"
b2nd = "R" + "D"*(dy+1) + "L"*(dx+1) + "U"

print f1st+b1st+f2nd+b2nd


Measured memory_bytes: 2692
#include <iostream>
#include <algorithm>
#include <bitset>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <complex>
#include <string.h>
#include <numeric>
using namespace std;

//#define int long long
#define reps(i,s,n) for(int (i)=(s);(i)<(n);++(i))
#define rep(i,n) reps(i,0,n)
#define rept(i,n) rep(i,(n)+1)
#define repst(i,s,n) reps(i,s,(n)+1)
#define reprt(i,n,t) for(int (i)=(n);(i)>=(t);--(i))
#define repr(i,n) reprt(i,n,0)
#define each(i,v) for(auto &(i):(v))
#define eachr(i,v) for(auto &(i)=(v).rbegin();(i)!=(v).rend();(i)++)
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define tmax(x,y,z) max(x,max(y,z))
#define tmin(x,y,z) min(x,min(y,z))
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define ln '\n'
#define bln(i,n) (((i)==(n)-1)?'\n':' ')
#define dbg(x) cout<<#x" = "<<(x)<<ln<<flush
#define dbga(x,n) {cout<<#x" : ";for(int (i)=0;i<(n);++i){cout<<((x)[i])<<(i==((n)-1)?'\n':' ')<<flush;}}
#define zero(a) memset(a,0,sizeof(a))
#define unq(a) sort(all(a)),a.erase(unique(all(a)),a.end())
#define endl "\n"

//typedef complex<double> P;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<string> vst;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<vector<int> > mat;

const ll inf = (ll)1e9+10;
const ll linf = (ll)1e18+10;
const ll mod = (ll)(1e9+7);
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};
const double eps = 1e-10;

ll mop(ll a,ll b,ll m=mod) {ll r=1;a%=m;for(;b;b>>=1){if(b&1)r=r*a%m;a=a*a%m;}return r;}
ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b) {return a/gcd(a,b)*b;}
bool ool(int x,int y,int h,int w) {return((x<0)||(h<=x)||(y<0)||(w<=y));}
bool deq(double a,double b) {return abs(a-b)<eps;}

struct oreno_initializer {
	oreno_initializer() {
		cin.tie(0);
		ios::sync_with_stdio(0);
	}
} oreno_initializer;



int n, a, b, c;

signed main() {
	cin >> n >> a >> b;
	c = n - a - b;
	chmin(c,0);
	cout << min(a,b) << ' ' << -c << endl;
}


Measured memory_bytes: 256