akhauriyash/Code-Regression huggingface dataset:
//#include<cstdio>
#include<iostream>
#include<algorithm>
#define MAX 1000
#define VMAX 10000
using namespace std;
int n, s, A[MAX], B[MAX], T[VMAX+1];

int solve()
{
  int ans = 0;
  int m, an, S;
  bool V[MAX];
  sort(B, B+n);
  for(int i=0; i<n; i++)
  {
    T[B[i]] = i;
    V[i] = false;
  }
  for(int i=0; i<n; i++)
  {
    if(V[i]) continue;
    m = VMAX;
    an = 0;
    S = 0;
    int cur = i;
    while(1)
    {
      V[cur] = true;
      an++;
      int v = A[cur];
      m = min(v, m);
      S += v;
      cur = T[v];
      if(V[cur]) break;
    }
    ans += min(S + (an - 2)*m, S + m + (an+1)*s);
  }
  return ans;
}
int main()
{
  cin >> n;
  s = VMAX;
  for(int i=0; i<n; i++)
  {
    cin >> A[i];
    B[i] = A[i];
    s = min(s, A[i]);
  }
  int ans = solve();
  cout << ans << endl;

  return 0;
}



Measured memory_bytes: 3192
//include
//------------------------------------------
#include <bits/stdc++.h>
using namespace std;
//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef long long ll;
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const long long INF = 1000000007;
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))
//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
// chmax chmin
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int main(void){
    int N; cin >> N;
    int x=0, ans=0;
    REP(i,N){
        char s; cin >> s;
        if(s == 'I') x++;
        else x--;
        chmax(ans, x);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 384
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>

typedef long long ll;

using namespace std;

int mo[4]={0,1,0,-1};

int main(){
    int h,w,n,ans=0;
    bool fl[1000][1000]={0};
    char in[1000][1001];
    queue<pair<int,int> > qp;
    pair<int,int> p;
    
    scanf("%d%d%d",&h,&w,&n);
    
    for(int i=0;i<h;i++)
        scanf("%s",in[i]);
    
    for(int i=0;i<h;i++)
        for(int j=0;j<w;j++)
            if(in[i][j]=='S'){
                qp.push(make_pair(i,j));
                qp.push(make_pair(-5,-5));
                break;
            }
    
    for(int i=1;i<=n;i++){
        while(1){
            p=qp.front();
            qp.pop();
            if(p.first==-5 && p.second==-5){
                ans++;
                qp.push(make_pair(-5,-5));
                continue;
            }
            if(p.first<0 || h<=p.first || p.second<0 || w<=p.second || fl[p.first][p.second]) continue;
            if(in[p.first][p.second]=='0'+i) break;
            if(in[p.first][p.second]=='X') continue;
            
            fl[p.first][p.second]=true;
            
            for(int j=0;j<4;j++)
                qp.push(make_pair(p.first+mo[j],p.second+mo[(j+1)%4]));
            
        }
        while(!qp.empty())
            qp.pop();
        qp.push(make_pair(p.first,p.second));
        qp.push(make_pair(-5,-5));
        
        for(int k=0;k<h;k++)
            for(int j=0;j<w;j++)
                fl[k][j]=false;
    }
            
    printf("%d\n",ans);
    
    return 0;
}

Measured memory_bytes: 3168
import sys
input = sys.stdin.readline

N,L = map(int,input().split())
s=0;m=100000
for i in range(1,N+1):
  #print(L+i-1)
  s += L+i-1
  m = m if abs(L+i-1) >= m else abs(L+i-1)
#print(s)
print(s-m if s > 0 else s+m)



Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
  int n;
  cin >> n;
  vector <pair <int, int> > a(n);
  for (int i = 0; i < n; i++) {
	  int j;
	  cin >> j;
	  a[i] = make_pair(j, i);
	}
  sort(a.begin(), a.end());
  int ans = 0;
  for (int i = 0; i < n; i++) {
	  if (i % 2 != a[i].second % 2) {
		  ans++;
		}
	}
  cout << ans / 2 << endl;
  return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define P pair<int,int>
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define re(i,k,n) for(int i=k;i<n;i++)
#define mod 1000000007;
//最大公約数
int gcd(int s,int b){
    if(b==0)return s;
    return gcd(b,s%b);
}
signed main(){
    string s;
    cin>>s;
    rep(i,s.size()){
        if(i%2==0){
            if(s[i]=='R'||s[i]=='U'||s[i]=='D'){
                continue;
            }
            else{
                cout<<"No"<<endl;
                return 0;
            }
        }
        else{
            if(s[i]=='L'||s[i]=='U'||s[i]=='D'){
                continue;
            }
            else{
                cout<<"No"<<endl;
                return 0;
                }
        }
    }
    cout<<"Yes"<<endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <map>
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <cstring>
#include <unordered_map>
#include <iomanip>
#include <functional>
#include <stack>
#include <math.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const int maxn = 1000050;
const int inf = 0x3f3f3f3f;
const int mod = 1e9 + 7;
const ll linf = 2e18;
ll power(ll x, ll y)
{
    ll ans = 1;
    while (y)
    {
        if (y & 1)
            ans = ans * x % mod;
        x = x * x % mod;
        y >>= 1;
    }
    return ans;
}

ll gcd(ll x, ll y)
{
    if (x % y == 0)
        return y;
    return gcd(y, x % y);
}

char a[20][20];

int main()
{
    int i, j, k, m, t, n;
    for (i = 0; i < 10; i++)
    {
        a[i][0] = 'h';
        a[i][1] = 'o';
        a[i][2] = 'n';
        a[i][3] = '\0';
        if (i == 0 || i == 1 || i == 6 || i == 8)
            a[i][0] = 'p';
        if (i == 3)
            a[i][0] = 'b';
    }
    scanf("%d", &n);
    printf("%s\n", a[n % 10]);
    return 0;
}


Measured memory_bytes: 3660
#include <iostream>
using namespace std;
char m[20][21];
int h, w, n;
void dfs(int x, int y)
{
	int i, j, nx, ny, dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
	m[y][x] = '#';
	n++;
	for (i = 0; i < 4; i++)
	{
		nx = x + dx[i];
		ny = y + dy[i];
		if (0 <= nx && nx < w && 0 <= ny && ny < h && m[ny][nx] == '.') dfs(nx, ny);
	}
	return;
}
int main()
{
	int i, j;
	while (cin >> w >> h)
	{
		if (h == 0 && w == 0) break;
		for (i = 0; i < h; i++)
		{
			cin >> m[i];
			if (cin.eof()) return 0;
		}
		n = 0;
		for (i = 0; i < h; i++)
		{
			for (j = 0; j < w; j++)
			{
				if (m[i][j] == '@')
				{
					dfs(j, i);
				}
			}
		}
		cout << n << endl;
	}
}

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

using namespace std;

class Dice {
public:
	int F[6];
	void roleW() {
		int a = F[0]; F[0] = F[2]; F[2] = F[5]; F[5] = F[3]; F[3] = a;
	}
	void roleN() {
		int a = F[0]; F[0] = F[1]; F[1] = F[5]; F[5] = F[4]; F[4] = a;
	}
};

int main() {
	int n;
	cin >> n;
	Dice dice[n];
	int T = 0, t;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < 6; j++) {
			cin >> dice[i].F[j];
		}
	}
	for (int a = 0; a < n - 1; a++) {
		for (int b = a+1; b < n; b++) {
			for (int c = 0; c < 6; c++) {
				t = 0;
				for (int p = 0; p < 6; p++) {
					for (int q = 0; q < 6; q++) {
						if (dice[a].F[p] == dice[b].F[q]) { t += 1; break; }
					}
				}
				for (int p = 0; p < 6; p++) {
					for (int q = 0; q < 6; q++) {
						if (dice[b].F[p] == dice[a].F[q]) { t += 1; break; }
					}
				}
				if (t != 12) break;
				while (true) {
					if (dice[b].F[0] == dice[a].F[0]) break;
					else if (dice[b].F[2] == dice[a].F[0] || dice[b].F[3] == dice[a].F[0]) dice[b].roleW();
					else dice[b].roleN();
				}
				if (t == 0) break;
				int f[4] = { 1, 2, 4, 3 };
				for (int k = 0; k < 4; k++) {
					if (dice[b].F[f[k]] == dice[a].F[1] && dice[b].F[f[(k + 1) % 4]] == dice[a].F[2] &&
						dice[b].F[f[(k + 2) % 4]] == dice[a].F[4] && dice[b].F[f[(k + 3) % 4]] == dice[a].F[3]) T = 1;
				}
				if (T == 1) break;
				if (c + 1 == 1) dice[a].roleN();
				else if (c + 1 == 2) dice[a].roleW();
				else if (c + 1 == 3) { dice[a].roleW(); dice[a].roleW(); }
				else if (c + 1 == 4) dice[a].roleN();
				else if (c + 1 == 5) dice[a].roleN();
			}
			if (T == 1 || t != 12) break;
		}
		if (T == 1) break;
	}
	if (T == 1) cout << "No" << endl;
	else cout << "Yes" << endl;
	return 0;
}


Measured memory_bytes: 3092
//A,Elebereth Gilthoniel mantae!
//For Temeria!
#include<iostream>
#include<algorithm>
#include<cmath>
#include<string>
#include<vector>
#include<set>
#include<cstdio>
#include<map>
#include<stack>
#include<queue>
#include<cstring> 
using namespace std;
int cnt;int para[600008];
int main()
{
 	//freopen("","r",stdin);
	//freopen("","w",stdout);
	string s;cin>>s;string t="";
	for(int i=0;i<s.size();i++)
	{
		if(s[i]!='x') t+=s[i];
	}
	if(t=="")
	{
		cout<<0;return 0;
	} 
	string r=t;for(int i=0;i<=(r.size()-1)/2;i++) swap(r[i],r[r.size()-i-1]);
	if(r!=t)
	{
		cout<<-1;return 0;
	}
	for(int i=0;i<s.size();i++)
	{
		if(s[i]=='x')
		{
			para[cnt]++;
		}else cnt++;
	}int ans=0;
	for(int i=0;i<=(cnt)/2;i++)
	{
		ans+=max(para[i]-para[cnt-i],para[cnt-i]-para[i]);
	}cout<<ans;
	return 0;
}

Measured memory_bytes: 768
#include <iostream>
#include <math.h>
#include <algorithm>
#include <string>
#include <string.h>
#include <queue>
using namespace std;

int main() {
	string A,B,C;
	cin>>A>>B>>C;
	if(A[A.size()-1]==B[0]&&B[B.size()-1]==C[0])cout<<"YES";
	else cout<<"NO";
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
int main(){
  int n,m;
  cin >> n >> m;
  vector<string> a(n);
  vector<string> b(n);
  rep(i,n) cin >> a[i];
  rep(i,m) cin >> b[i];
  for (int i=0; i<=n-m; i++){
        for (int j=0; j<=n-m; j++){
            bool flag = true;
            rep(k,m){
                rep(l,m){
                    if (a[i+k][j+l] != b[k][l]) {
                        flag = false;
                        break;
                    }
                }
                if (flag == 0) break;
            }
            if (flag == true) {
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
  cout << "No" << endl;
    
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define loop(__x, __start, __end) for(int __x = __start; __x < __end; __x++)

vector<ll> divisors(ll n) {
  vector<ll> D;
  for (ll i=1; i*i<=n; i++) {
    if (n%i==0) {
      D.push_back(i);
      if (i*i!=n) D.push_back(n/i);
    }
  }
  return D;
}

int main() {
  ll n; cin >> n;
  int ans = 0;
  auto D = divisors(n);
  for (auto d: D) {
    ll m = n;
    if (d == 1) continue;
    while (m%d==0) m /= d;
    ans += m%d == 1;
  }

  // 1以外
  ans += divisors(n-1).size()-1;
  cout << ans << endl;
  return 0;
}


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

using namespace std;
int a;
int main() {
	int n, tr = 1;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a;
		if ((a % 2 == 0) && (a % 3 != 0 && a % 5 != 0)) {
			tr = 0;
		}
	}
	if (tr == 0) {
		cout << "DENIED";
	}
	else {
		cout << "APPROVED";
	}
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

class Main{
	static Scanner s=new Scanner(System.in);
	static int gInt(){return Integer.parseInt(s.next());}

	public static void main(String[]$){
		int n=gInt();
		long a=gInt(),b=gInt();

		for(int i=1;i<n;++i) {
			int A=gInt(),B=gInt();
			if(a*1.0/A<b*1.0/B) {
				b=(b+B-1)/B*B;
				a=b/B*A;
			}else {
				a=(a+A-1)/A*A;
				b=a/A*B;
			}
		}
		System.out.println(a+b);
	}
}

Measured memory_bytes: 23876
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG //エラーの出ないエラーを起こした時にデバッグできる
#define rep(i, n) for (int i = 0; i < (n); i++)

int main(){
  int  x, n, p;
  cin >> x >> n;
  
  
  bitset<101> aru;
  aru = 0;

  for (int i = 0; i < n; i++){
    cin >> p;
    aru.set(p, 1);
  }
  
   
  int shita = 0;
  int ue = 101;
  for (int i = x; i < 100; i++){
    if(!aru.test(i)){
      ue = i;
      break;
    }
  }
  
  for (int i = x; i > -1; i--){
    if(!aru.test(i)){
      shita = i;
      break;
    }
  }
  
  if (ue-x < x-shita){
    cout << ue << endl;
  }
  else{
    cout << shita << endl;
  }    
}

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

// types
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
typedef vector<ll> vll;

// macros
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define FI first
#define SE second
#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 FOR(i,a,b) for(int i=(a);i<(b);i++)
#define PB push_back
#define EB emplace_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL

// constants
const int inf = 1e9;
const ll linf = 1LL << 50;
const double eps = 1e-10;
const int MOD = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};


const int MAX = 1e7;

long long fac[MAX], finv[MAX], inv[MAX];

void COMinit() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < MAX; i++){
    fac[i] = fac[i - 1] * i % MOD;
    inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
    finv[i] = finv[i - 1] * inv[i] % MOD;
  }
}

long long COM(int n, int k){
  if (n < k) return 0;
  if (n < 0 || k < 0) return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}



int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  ll x,y;
  cin >> x >> y;

  ll ans = 0;
  if((2*x-y)%3 == 0 && (2*y-x)%3 == 0){
    COMinit();
    int r = (2*x-y)/3;
    int u = (2*y-x)/3;

    int n = r+u;
    ans = COM(n, r);
  }

  cout << ans << endl;

}



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

#define rep(i,n) for(long long i=0;i<(long long)(n);i++)
#define REP(i,k,n) for(long long i=k;i<(long long)(n);i++)
template<class T> void out(T a){cout<<a<<'\n';}

int main(){
  int n,q;
  cin>>n>>q;
  dsu d(n);
  rep(i,q){
    int k,u,v;
    cin>>k>>u>>v;
    if(k==0) d.merge(u,v);
    else out(d.same(u,v));
  }
}


Measured memory_bytes: 3888
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int count =0;
		
		while(sc.hasNext() && count < 201){
			
				String a = sc.nextLine();
	            String[] array = a.split(" ");
				int x = Integer.parseInt(array[0]);
				int y = Integer.parseInt(array[1]);
				int val = x+y;
				int valLen = String.valueOf( val ).length();
				System.out.println(valLen);
			
				count++;
			
		}
	}
}

Measured memory_bytes: 26328
#!/usr/bin/env python3
n = int(input())
hon = [2, 4, 5, 7, 9]
pon = [0, 1, 6, 8]
if n % 10 in hon:
    print("hon")
elif n % 10 in pon:
    print("pon")
else:
    print("bon")


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

#define REP(i, n) for(ll i = 0; i < n; i++)
#define ALL(x) (x).begin(),(x).end()
#define MSG(x) cout << x << endl;
#define YN(x) x ? cout << "YES" << endl : cout << "NO" << endl;
#define Yn(x) x ? cout << "Yes" << endl : cout << "No" << endl;
#define yn(x) x ? cout << "yes" << endl : cout << "no" << endl;

using namespace std;
using ll = long long;
const static ll MOD = 1e9 + 7;

int main(int argc, char *argv[]) {
    ll tab[3][3];

    REP(i, 3) {
        REP(j, 3) {
            cin >> tab[i][j];
        }
    }

    Yn((tab[1][0] - tab[0][0] == tab[1][1] - tab[0][1]) &&
       (tab[1][1] - tab[0][1] == tab[1][2] - tab[0][2]) &&
       (tab[2][0] - tab[1][0] == tab[2][1] - tab[1][1]) &&
       (tab[2][1] - tab[1][1] == tab[2][2] - tab[1][2]) &&
       (tab[0][1] - tab[0][0] == tab[1][1] - tab[1][0]) &&
       (tab[1][1] - tab[1][0] == tab[2][1] - tab[2][0]) &&
       (tab[0][2] - tab[0][1] == tab[1][2] - tab[1][1]) &&
       (tab[1][2] - tab[1][1] == tab[2][2] - tab[2][1]))

    return 0;
}



Measured memory_bytes: 256
import bisect
n, k = map(int, input().split())
v=list(map(int, input().split()))
ans=0
for i in range(n+1):
    for j in range(n-i+1):
        if k>=i+j:
            houseki=[]
            houseki+=v[:i]
            houseki+=v[n-j:]
            houseki=sorted(houseki)
            p=k-i-j
            p=(min(bisect.bisect_left(houseki, 0), p))
            ans=max(ans, sum(houseki[p:]))
print(ans)

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

using namespace std;

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

    if(S[6] <= '4' && S[5] == '0')
        cout << "Heisei" <<endl;
    else
        cout << "TBD" << endl;
    

    return 0;
}

Measured memory_bytes: 3612
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <utility>
#include <queue>
#include <set>
#include <map>
#include <deque>
#include <iomanip>
#include <cstdio>
#include <stack>

using namespace std;
typedef  long long ll;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
#define  MP make_pair
#define  PB push_back
#define inf  1000000007
#define mod 1000000007
#define rep(i,n) for(int i=0;i<(int)(n);++i)
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

ll dp[10010][101][2];

int main(){
    string s;
    cin >> s;
    int d;
    reverse(s.begin(),s.end());
    int n = s.size();
    cin >> d;
    ll ans = 0;
    dp[0][0][0] = 1;
    for(int i=1;i<=n;i++){
        int th = s[i-1]-'0';
        for(ll j=0;j<10;j++){
            ll q = j;
            for(ll k=0;k<d;k++){
                ll md = (k+q)%d;
                if(j<th){
                    dp[i][md][0] += dp[i-1][k][0];
                    dp[i][md][0] += dp[i-1][k][1];
                    dp[i][md][0] %= mod;
                }else if(j==th){
                    dp[i][md][0] += dp[i-1][k][0];
                    dp[i][md][0] %= mod;
                    dp[i][md][1] += dp[i-1][k][1];

                    dp[i][md][1] %= mod;
                }else{
                    dp[i][md][1] += dp[i-1][k][0]; 
                    dp[i][md][1] += dp[i-1][k][1];

                    dp[i][md][1] %= mod;
                }
            }
        }
    }   
    ans = mod+dp[n][0][0]-1;
    ans %= mod;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 16128
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll mod = 1e9 + 7;

int gcd(int x, int y) {
    if (x < y) swap(x, y);
    int r = x%y;
    if (r == 0) {
        return y;
    }
    return gcd(y, r);
}

ll mypow(ll x, ll n) {
    if (n == 0) return 1;
    if (n%2 == 0) return mypow(((x%mod)*(x%mod))%mod, n/2);
    else return ((x%mod) * mypow(((x%mod)*(x%mod))%mod, (n-1)/2))%mod;
}

int main(){
    int A, B, K;
    cin >> A >> B >> K;
    for (int i=A; i<=B; i++) {
        if (i < A + K) cout << i << endl;
        else if (i > B - K) cout << i << endl;
    }
}

Measured memory_bytes: 256
class UnionFind:

    def __init__(self):
        self.parents = {}
        self.sz = {}
        self.size = 0


    def add(self, a):
        if a in self.parents:
            return
        self.size += 1
        self.sz[a] = 1
        self.parents[a] = a 

    def find(self, a):
        if self.parents[a] != a:
            self.parents[a] = self.find(self.parents[a])

        return self.parents[a]

    def join(self, a, b):
        pa, pb = self.find(a), self.find(b)
        if pa == pb:
            return
        if self.sz[pa] > self.sz[pb]:
            self.parents[pb] = pa
            self.sz[pa] += self.sz[pb]
        else:
            self.parents[pa] = pb 
            self.sz[pb] += self.sz[pa]

        self.size -= 1


n,m = list(map(int,input().split(" ")))
uf = UnionFind()
ans = 0
if m == 0:
    print(1)
else:
    for _ in range(m):
        x,y = list(map(int,input().split(" ")))
        uf.add(x)
        uf.add(y)
        uf.join(x,y)
        ans = max(ans, uf.sz[x])

    print(max(uf.sz.values()))


Measured memory_bytes: 141424
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(ll i=0;i<((ll)n);i++)
#define rep1(i,n) for(ll i=1;i<=((ll)n);i++)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
#define meow(a) cout<<a<<" meow\n";
typedef pair<long long,long long> pii;
const ll maxn=200005;
const ll MOD=998244353;
double mypow(ll a,ll b){
	double res=1;
	while(b){
		if(b&1) res=res*a;
		a=a*a;

		b>>=1;
	}
	return res;
}
ll r,d,x;


int main()
{
    //IOS;
    while(cin>>r>>d>>x)
    {
        ll D=d;
        int t=10;
        while(t)
        {
            x=r*x-D;
            cout<<x<<"\n";
            t--;
        }
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void)
{
  int r, c;
  int a;

  while(1) {
    cin >> r >> c;
    if(r == 0 && c == 0) break;
    a = r * c;
    if(a % 2 == 0) cout << "yes" << endl;
    else cout << "no" << endl;
  }
  return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
typedef complex<double> P;

int main(){
  int n;
  double ax,ay,bx,by,cx,cy,dx,dy;
  scanf("%d",&n);
  while(n--){    
    scanf("%lf %lf %lf %lf",&ax,&ay,&bx,&by);
    scanf("%lf %lf %lf %lf",&cx,&cy,&dx,&dy);
    P k=P(bx-ax,by-ay)*P(dx-cx,cy-dy);
    if(k.imag()==0)printf("2\n");
    else if(k.real()==0)printf("1\n");
    else printf("0\n");
  }
  return 0;
}

Measured memory_bytes: 1212
#include <iostream>
#include <unordered_map>

std::unordered_map<int, long> memo;

long get_lucas(int n) {
    if (n == 0) {
        return 2;
    } else if (n == 1) {
        return 1;
    } else if (memo.find(n) != memo.end()) {
        return memo[n];
    } else {
        long lucas = get_lucas(n - 1) + get_lucas(n - 2);
        memo[n] = lucas;
        return lucas;
    }
}

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

    std::cout << get_lucas(N) << std::endl;
}


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

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

constexpr int INF = 1e9;
constexpr ll INFLL = 1e18;

void dfs(vector<vector<int>> const& g, int v, vector<int> const& a, vector<bool>& visited, vector<int>& res) {
    res.push_back(a[v]);
    visited[v] = true;
    for(auto to : g[v]) {
        if(!visited[to]) dfs(g, to, a, visited, res);
    }
}

int main() {
    int N, M;
    cin >> N >> M;
    vector<int> a(N);
    for(int i = 0; i < N; ++i) {
        cin >> a[i];
    }
    vector<vector<int>> g(N);
    for(int i = 0; i < M; ++i) {
        int x, y; cin >> x >> y;
        g[x].push_back(y);
        g[y].push_back(x);
    }
    if(M == N - 1) {
        cout << 0 << endl;
        return 0;
    } else if(N < 2 * (N - M - 1)) {
        cout << "Impossible" << endl;
        return 0;
    }
    vector<bool> visited(N);
    ll ans = 0;
    vector<int> cost;
    for(int i = 0; i < N; ++i) {
        if(!visited[i]) {
            vector<int> c;
            dfs(g, i, a, visited, c);
            sort(begin(c), end(c));
            ans += *c.begin();
            for(int j = 1; j < (int)c.size(); ++j) {
                cost.push_back(c[j]);
            }
        }
    }
    sort(begin(cost), end(cost));
    for(int i = 0; i < N - M - 2; ++i) {
        ans += cost[i];
    }
    cout << ans << endl;
}

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

int main(){
    string s;
    cin >> s;
    int i, j = 0;
    for(i = 0; i < 3; i++){
        if(s[i] == '7') j++;
    }

    if(j > 0) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 3624
(defun calc-cost (heights a b)
  (abs (- (aref heights a)
          (aref heights b))))


(defun min-cost (heights costs n)
  (min (+ (aref costs (- n 1)) 
          (calc-cost heights n (- n 1)))
       (+ (aref costs (- n 2)) 
          (calc-cost heights n (- n 2)))))

(defun set-cost (heights costs n)
  (cond
    ((zerop n)
      (setf (aref costs 0) 0))
    ((= n 1) 
      (setf (aref costs 1) (calc-cost heights 0 1)))
    (t 
      (setf (aref costs n) (min-cost heights costs n)))))

(defun recursive (heights costs n to)
  (if (= n (- to 1))
      (if (= to 2)
          (calc-cost heights 0 1)
          (min-cost heights costs n))
      (progn
        (set-cost heights costs n)
        (recursive heights costs (+ n 1) to))))
 
(defun main ()
  (let* ((n (read))
         (heights (make-array n 
                              :initial-contents (loop :repeat n :collect (read))))
         (costs (make-array n :initial-element -1)))
    (princ (recursive heights costs 0 n))))

(main)

Measured memory_bytes: 78608
#include <iostream>

int main() {
    std::ios_base::sync_with_stdio(false);

    int alphas[26];
    std::fill_n(alphas, 26, 0);

    char c;
    while (! (std::cin >> c).eof() ) {
        int idx = tolower(c) - 'a';
        if (0 <= idx && idx < 26) alphas[idx]++;
    }

    for (int i = 0; i < 26; i++) {
        c = (char)(i + 'a');
        std::cout << c << " : " << alphas[i] << "\n";
    }

    return 0;
}

Measured memory_bytes: 1176
S = input()
T = input()
Slen = len(S)
Tlen = len(T)
N = max(Slen - Tlen, 1)
ans = Tlen
for i in range(N):
	tmp = 0
	for j in range(Tlen):
		if S[i + j] != T[j]:
			tmp += 1
	ans = min(ans, tmp)
print(ans)


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

int compare_int(const void *a, const void *b)
{
    return *(int*)a - *(int*)b;
}

int main(void)
{
    int K, N;
    int i;
    int ans = 0;
    int A[200000];
    int dis[200000];
    
    scanf("%d %d", &K, &N);
    
    for (i = 0; i < N; i ++) {
        scanf(" %d", &A[i]);
    }
    
    for (i = 0; i < N - 1; i ++) {
        dis[i] = A[i + 1] - A[i];
    }
    
    dis[N - 1] = A[0] + (K - A[N - 1]);
    
    qsort(dis, N, sizeof(int), compare_int);
    
    for (i = 0; i < N - 1; i ++) {
        ans += dis[i];
    }
    
    printf("%d\n", ans);
    
    return 0;
}

Measured memory_bytes: 2556
import sys
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 6)
import math
from collections import Counter
from collections import deque
from operator import itemgetter
import time, random
MOD = 10 ** 9 + 7
from itertools import permutations

def dfs(s):
    if len(s) == N:
        return 1
    if (s[-2] == 'A' and s[-1] == 'G') or (s[-2] == 'G' and s[-1] == 'A'):
        return dfs(s+'A') % MOD + dfs(s+'G') % MOD + dfs(s+'T') % MOD
    elif s[-2] == 'A' and s[-1] == 'C':
        return dfs(s+'A') % MOD + dfs(s+'C') % MOD + dfs(s+'T') % MOD
    else:
        return dfs(s+'A') % MOD + dfs(s+'C') % MOD + dfs(s+'G') % MOD + dfs(s+'T') % MOD

def main():
    N = int(readline())
    A, G, C, T = 0, 1, 2, 3
    dp = [[[[0] * 4 for _ in range(4)] for _ in range(4)] for _ in range(N+1)]
    for j in range(4):  # i - 2 文字目
        for k in range(4):  # i - 1 文字目
            for l in range(4):  # i 文字目
                if j == A and k == G and l == C:  continue
                if j == A and k == C and l == G:  continue
                if j == G and k == A and l == C:  continue
                dp[3][j][k][l] = 1
    
    for i in range(4, N+1):
        for j in range(4):
            for k in range(4):
                for l in range(4):
                    for m in range(4):
                        if j == A and k == G and l == C:  continue
                        if j == A and k == C and l == G:  continue
                        if j == G and k == A and l == C:  continue
                        if m == A and k == G and l == C:  continue
                        if m == A and j == G and l == C:  continue
                        dp[i][j][k][l] += dp[i-1][m][j][k]
                        dp[i][j][k][l] %= MOD
    
    res = 0
    for j in range(4):
        for k in range(4):
            for l in range(4):
                res += dp[N][j][k][l]
                res %= MOD
    
    print(res)

if __name__ == '__main__':
    main()

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

int main(){
	int k;
	cin>>k;
//	if(k<7){
//		cout<<-1;
//		return 0;
//	}
	long long m = 7%k ;
	int count = 1;
	int j = 1;
	set<int> check;
	check.insert(m);
	while(true){
		if(m==0){
			cout<<count;
			return 0 ;
		}
		count++;
		m = m*10 + 7;
		m = m%k;
		if(check.find(m)!=check.end()){
			cout<<-1;
			return 0;
		}
		check.insert(m);
	}
	
	
}

Measured memory_bytes: 50472
//#pragma region ALL(include define etc)
#include <iostream>   // swap(a, b)
#include <string>
#include <cmath>      // abs(絶対値) sin cos tan(角度 / 180.0 * 3.141592)
#include <vector>     // vec.push_back(a) vec.pop_back()
#include <algorithm>  // max(a, b) min(a, b) reverse() sort()
#include <functional> // sort(a, a + N, greater<型>());
#include <math.h>
#include <iomanip>
#define int long long
#define ll long long
#define double long double
using namespace std;
//#pragma endregion

signed main()
{
	// 10^18 = 1000000000000000000

	//int h1, h2, m1, m2, k;
	//int box, box1,box2;

	//int N;
	int n;
	int a, b;
	//int m;
	//int k;
	//string s;
	//string t;
	//int m1, m2;
	//int a, b, c, k;

	//int box[1000000000000000000];
	int box;
	int box2;
	int x[5];

	//long double aaa;

	//int k, d;
	int all = 0;
	//double all;
	//double a, b;
	//double h, m;
	//int a[30000] = { 0 };
	//double c, d, e;

	//double mbox, hbox;
	//double box, box2;

	//int box[10000] = { 0 };

	//bool flag = true;
	//bool flag = false;

	//string str;

	//cin >> h1 >> m1 >> h2 >> m2 >> k;
	//cin >> n;
	//cin >> a >> b;

	for (int i = 0; i < 5; i++)
	{
		cin >> x[i];
		if (x[i] == 0)
		{
			cout << i + 1;
			break;
		}
	}

	//n = t.length();

	//cout << b << "\n";

	/*if (flag == true)
	{
		cout << "YES\n";
	}
	else
	{
		cout << "NO\n";
	}*/

	//cout << fixed << setprecision(111) << all;
}


Measured memory_bytes: 3628
n = int(input())
A = list(map(int,input().split()))
import collections

r1 = [(i+1)+A[i] for i in range(n)]
r2 = [(i+1)-A[i] for i in range(n)]
co1 = collections.Counter(r1)
co2 = collections.Counter(r2)
ans = 0
for num,c1 in co1.items():
    c2 = co2[num]
    ans+=c1*c2
print(ans)


Measured memory_bytes: 63280
n = int(input())

s_list = []
p_list = []

for _ in range(0, n):
    s, p = input().split()
    s_list.append(s)
    p_list.append(int(p))

result = list(enumerate(zip(s_list, p_list)))
result = sorted(result, key = lambda x: (x[1][0], -x[1][1]))

for i in [ x[0] + 1 for x in result ]:
    print(i)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0;i<n;i++)
#define ll long long
 
//const int INF = 1e8;
typedef pair<int,int>P;
int dx[4] = {1,0,-1,0};int dy[4] = {0,1,0,-1};
queue<P> que;

int main(void){
  int n,k;cin >> n >> k;
  cout << n-k+1 << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define REP(i, n) FOR(i, 0, (n))
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define LAR(a, b) ((a)=max((a),(b)))
#define SML(a, b) ((a)=min((a),(b)))
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pair<int, int>> vpii;
typedef pair<int, int> pii;
#define PB push_back
#define EB emplace_back
#ifdef LOCAL_DEBUG
#define DEBUG(...) printf(__VA_ARGS__)
#else
#define DEBUG(...)
#endif

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

char s[1024][1024];
vpii v, u;

int main(){
	int h, w; scanf("%d%d", &h, &w);
	REP(i, h) scanf("%s", s[i]);
	REP(i, h) REP(j, w) if(s[i][j]=='#') v.EB(i, j);
	int ans = -1;
	while(v.size()){
		ans++;
		u.clear();
		for(pii &p: v){
			REP(i, 4){
				int y=p.first+dy[i], x=p.second+dx[i];
				if(y<0 || x<0 || y>=h || x>=w) continue;
				if(s[y][x]=='#') continue;
				s[y][x]='#';
				u.EB(y, x);
			}
		}
		sort(u.begin(), u.end());
		u.erase(unique(u.begin(), u.end()), u.end());
		swap(v, u);
	}
	printf("%d\n", ans);
}


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

int main() {
    int N;
    cin >> N;
    vector<int> d(N);
    for(int i = 0; i < N; i++){
        cin >> d.at(i);
    }
    sort(d.begin(), d.end());
    reverse(d.begin(), d.end());
    int counter = 1;
    for(int i = 1; i < N; i++){
        if(d.at(i) < d.at(i-1)) counter++;
    }
    cout << counter << endl;
}


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

using namespace std;

bool is_arr_num(int x, const vector<int>& arr)
{
 for(int num : arr)
 {
   if(x == num)
     return true;
 }
 return false;
}


int main()
{
 int X,L;
 vector<int> arr;
  
 cin >> X >> L;
 arr.reserve(L);
  
 for(int i=0;i<L;i++)
 {
   int tmp;
  cin >> tmp;
   arr.push_back(tmp);
 }
  
 if(false == is_arr_num(X,arr))
 {
   cout << X << endl;
   return 0;
 }
  
 for(int i=1; true;i++)
 {
    if(false == is_arr_num(X-i,arr))
 	{
   		cout << X-i << endl;
      	return 0;
 	}
    if(false == is_arr_num(X+i,arr))
 	{
   		cout << X+i << endl;
      	return 0;
 	}
 }
}


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

using namespace std;

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

    int ans=0;
    for(int i=0;i<s.length()-1;i++){
        int cnt=0;
        string s1=s.substr(0,i+1);
        string s2=s.substr(i+1);
        // cout << s1 + " " + s2 << endl;
        vector<bool> check1(26,false);
        vector<bool> check2(26,false);
        for(int j=0;j<s1.length();j++) check1[s1[j]-'a']=true;
        for(int j=0;j<s2.length();j++) check2[s2[j]-'a']=true;
        for(int j=0;j<26;j++) if(check1[j] && check2[j]) cnt++;
        ans=max(ans,cnt);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
<?php
$stdin = trim(fgets(STDIN));
 
$fh = floor($stdin / 3600);
$m = ($stdin - $fh*3600) / 60;
$fm = floor($m);
$fs = floor(($stdin - $fh*3600 - $fm*60));
 
$time = "$fh:$fm:$fs";
echo $time;
?>

Measured memory_bytes: 15240
#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>;

int main(){
  int a,b;
  cin >> a >> b;
  int c = min(a,b);
  int d = max(a,b);
  rep(i,d) cout << c;
  cout << endl;
}
  


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <unordered_set>
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n) - 1; i >= 0; --i)
#define fin(ans) cout<<(ans)<<endl
#define STI(s) atoi(s.c_str())
#define mp(p,q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define itn int
template <class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template <class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
struct io{io(){ios::sync_with_stdio(false);cin.tie(0);};};
const ll MOD = 1000000007;
const double EPS = 1e-9;
const int INF = INT_MAX;
const ll LLINF = 1LL<<62;




int main(void){

    int n;
    cin>>n;
    vi p(n);
    rep(i,n)cin>>p[i];
    vi a(n),b(n);
    rep(i,n)a[i]=i*n+1;
    rep(i,n)b[i]=a[n-i-1];

    rep(i,n){
        int idx=p[i]-1;
        a[idx]+=i;
    }

    rep(i,n){
        if(!i)cout<<a[i];
        else cout<<" "<<a[i];
    }
    cout<<endl;
    rep(i,n){
        if(!i)cout<<b[i];
        else cout<<" "<<b[i];
    }
    cout<<endl;
}

Measured memory_bytes: 896
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ll long long
#define pp pair<ll,ll>
#define ld long double
#define all(a) (a).begin(),(a).end()
#define mk make_pair
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;
ll MOD=1000000007;

 
int main() {
    ll n;
    cin >> n;
    vector<pp> b(n);
    rep(i,n) cin >> b[i].first;
    rep(i,n) b[i].second=i;
    sort(all(b));
    reverse(all(b));
    vector<vector<ll>> d(n+1,vector<ll>(n+1));
    rep(i,n){
        rep(j,i+1){
            d[i+1][j]=max(d[i+1][j],d[i][j]+abs(n-1-i+j-b[i].second)*b[i].first);
            d[i+1][j+1]=max(d[i+1][j+1],d[i][j]+abs(b[i].second-j)*b[i].first);
        }
    }
    ll ans=0;
    rep(i,n+1){
        ans=max(ans,d[n][i]);
    }
    cout << ans << endl;
}

Measured memory_bytes: 34672
h,w,K = map(int,input().split())
c = [input() for i in range(h)]

blk = 0
ans = 0

for i in range(h):
    for j in range(w):
        if c[i][j] == '#':
            blk += 1

for i in range(2**(h+w)):
    tmp_blk = blk
    tmp = format(i, '0'+str(h+w)+'b')
    for j in range(h):
        if tmp[j] == '1':
            #print(i,j)
            for k in range(w):
                if c[j][k] == "#":
                    tmp_blk -= 1
    for j in range(w):
        if tmp[h+j] == '1':
            for k in range(h):
                if c[k][j] == "#" and tmp[k] == '0':
                    tmp_blk -= 1
    if tmp_blk == K:
        ans += 1
    #print(tmp_blk)
        
print(ans)

Measured memory_bytes: 68484
import java.util.Scanner;

/**
 * https://abc062.contest.atcoder.jp/tasks/abc062_a
 */
public class Main {

	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
		int x = sc.nextInt();
		int y = sc.nextInt();
		sc.close();
		
		int gx = getGroup(x);
		int gy = getGroup(y);
		
		String ans = gx==gy ? "Yes" : "No";
		System.out.println(ans);

	}

	private static int getGroup(int n) {
		if(n==2) return 1;
		if(n==4 || n==6 || n==9 || n==11) return 2;
		else return 3;
	}

}

Measured memory_bytes: 21972
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  long long N,K;
  cin>>N>>K;
  if(N>=K){
    if(abs(N%K-K)<N%K){
      cout<<abs(N%K-K)<<endl;
    }
    else{
      cout<<N%K<<endl;
    }
  }

  if(N<K&&K<=2*N){
    cout<<K-N<<endl;
  }
  if(K>2*N){
    cout<<N<<endl;
  }
}

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

int main(){
  int n;
  string s;
  std::cin >> n;
  std::cin >> s;
  bool ans = true;
  if(s.size() % 2 == 1){
    std::cout << "No" << '\n';
  }
  else{
    for(int i = 0; i < n / 2; i++){
      if(s.substr(0, n/2) != s.substr(n/2, n/2)){
        ans = false;
        break;
      }
    }
    if(ans){
      std::cout << "Yes" << '\n';
    }
    else{
      std::cout << "No" << '\n';
    }
  }
  return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#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, c;
	cin >> a >> b >> c;
	if (a == b)cout << c << endl;
	else if (b == c)cout << a << endl;
	else cout << b << endl;


	return 0;
}

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

#define MAX 32

using namespace std;

int main(void) {
	while(1) {
		int n, m;
		int x[MAX], y[MAX];
		int m_x = 10, m_y = 10;
		char d;
		int l;
		bool moved[MAX][MAX] = {false};
		moved[10][10] = true;
		bool collect = true;

		scanf("%d", &n);
		if(n == 0) break;
		for(int i = 0; i < n; i++) {
			scanf("%d %d", &x[i], &y[i]);
		}
		scanf("%d", &m);
		for(int i = 0; i < m; i++) {
			int dx = 0, dy = 0;
			cin >> d >> l;
			switch(d) {
			case 'N' : dy++; break;
			case 'E' : dx++; break;
			case 'S' : dy--; break;
			case 'W' : dx--; break;
			}
			while(l--) {
				m_x += dx;  m_y += dy;
				moved[m_x][m_y] = true;
			}
		}
		for(int i = 0; i < n; i++) {
			if(!moved[x[i]][y[i]]) collect = false;
		}

		printf("%s\n", collect ? "Yes" : "No");
	}
	return 0;
}

Measured memory_bytes: 1204
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bits/stdc++.h>
#include<cmath>
#include<bitset>
#include<queue>
#define ll long long
#define itn int
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n)  FFOR(i,1,n)
#define SORT(V) sort((V).begin(),(V).end())
#define REVERSE(V) reverse((V).begin(),(V).end())
#define INF ((1LL<<62)-(1LL<<31))
#define MOD 1000000007
using namespace std;

int main(){
  int N;
  cin>>N;
  bool CAN=false;
  
  for(int i=1; i<10; ++i){
    for(int j=1; j<10; ++j){
      if(i*j==N) CAN=true;
    }
  }
  
  if(CAN) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <climits>
#include <vector>
#include <iomanip>
#include <string>
#include <queue>
#include <numeric>
#include <functional>
#include <array>
#include <map>
#include <set>

using namespace std;
using P = pair<int, int>;
using T = tuple<int, int, int>;

long long MOD = 1000000007;
long long dp[100005][4];

bool compare_by_second(pair<int, int> a, pair<int, int> b) {
	if (a.second != b.second) {
		return a.second < b.second;
	}
	else {
		return a.first < b.first;
	}
}

int main() {

	int N;
	cin >> N;

	vector<int>t(N);
	vector<double>v(N);

	int tSum = 0;
	for (int i = 0; i < N; ++i) {
		cin >> t[i];
		tSum += t[i];
	}
	for (int i = 0; i < N; ++i)cin >> v[i];

	int length = 2 * tSum + 1;
	vector<double>train(length,100000);
	int start = 0;
	int end = 0;
	for (int i = 0; i < N; ++i) {
		start = end;
		end = start + t[i] * 2;
		for (int j = start; j <= end; ++j) {
			//境目は値の小さい方に引っ張られる
			train[j] = min(v[i],train[j]);
		}
	}

	train[0] = 0;
	train[length - 1] = 0;

	for (int i = 1; i < length; ++i) {
		train[i] = min(train[i - 1] + 0.5, train[i]);
	}
	for (int i = length - 2; 0 <= i; --i) {
		train[i] = min(train[i + 1] + 0.5, train[i]);
	}

	double ans = 0;
	for (int i = 1; i < length; ++i) {
		ans += (train[i - 1] + train[i]) * 0.5 / 2.0;
	}

	printf("%.4f\n", ans);
	return 0;
}


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

int main()
{
  int n;
  cin >> n;
  vector<int> p(n);

  for (int i = 0; i < n; i++)
  {
    cin >> p[i];
  }
  sort(p.begin(), p.end());
  int ans = 0;
  for (int i = 0; i < n; i++)
  {
    if (i == n - 1)
    {
      ans += p[i] / 2;
      break;
    }
    ans += p[i];
  }
  cout << ans << endl;
}


Measured memory_bytes: 3620
import java.util.Scanner;

class Main{
	public static void main(String[] args) {
		Scanner stdIn=new Scanner(System.in);
		int a=stdIn.nextInt(),b=stdIn.nextInt(),c=stdIn.nextInt(),d=stdIn.nextInt();
		if(a+b==c+d) System.out.print("Balanced");
		else if(a+b>c+d) System.out.print("Left");
		else System.out.print("Right");
	}
}

Measured memory_bytes: 23764
#include<bits/stdc++.h>
#define ll long long

using namespace std;

int main() {
  ll X, K, D, Kmin, dx1, dx2, ans;
  cin >> X >> K >> D;
  X = abs(X);
  Kmin = X / D;
  if (K <= Kmin) {
    cout << X - D*K << endl;
    return 0;
  }
  dx1 = X%D;
  dx2 = D - dx1;
  if ((K - Kmin)%2 == 0) {
    cout << dx1 << endl;
  } else {
    cout << dx2 << endl;
  }
  return 0;
}

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

typedef long long ll;

void couting_sort(const vector<int> &a,vector<int> &b,int k){
    vector<int> cou(k,0);
    for(int i=0;i<a.size();i++)cou[a[i]]++;
    for(int i=1;i<k;i++)cou[i]+=cou[i-1];
    for(int i=a.size()-1;i>=0;i--){
        b[cou[a[i]]-1]=a[i];
        cou[a[i]]--;
    }
}

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

    int n,ma=0;
    cin >> n;
    vector<int> a(n),b(n);
    for(int i=0;i<n;i++){
        cin >> a[i];
        ma=max(ma,a[i]);
    }
    couting_sort(a,b,ma+1);
    for(int i=0;i<b.size();i++)cout << b[i] <<(i!=b.size()-1?" ":"\n");
}



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

using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n - 1); }
template <class T> using V = vector<T>;
template <class T> using VV = V<V<T>>;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << setprecision(20) << fixed;
    string s;
    cin >> s;
    ll sm = 0, cnt = 0;
    for (char c: s) {
        if (c == 'B') {
            cnt++;
        } else {
            sm += cnt;
        }
    }
    cout << sm << endl;
    return 0;
}


Measured memory_bytes: 720