akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<string.h>
int main()
{
    char s[4];
    char s1[]="SAT";
    char s2[]="SUN";
    char s3[]="MON";
    char s4[]="TUE";
    char s5[]="WED";
    char s6[]="THU";
    char s7[]="FRI";
    int a,b,c,d,e,f,g;
    gets(s);
    a=strcmp(s,s1);
    if(a==0){
        printf("1\n");
    }
    b=strcmp(s,s2);
    if(b==0){
        printf("7\n");
    }
    c=strcmp(s,s3);
    if(c==0){
        printf("6\n");
    }
    d=strcmp(s,s4);
    if(d==0){
        printf("5\n");
    }
    e=strcmp(s,s5);
    if(e==0){
        printf("4\n");
    }
    f=strcmp(s,s6);
    if(f==0){
        printf("3\n");
    }
    g=strcmp(s,s7);
    if(g==0){
        printf("2\n");
    }
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPS(i, _s, n) for(int i = _s, i##_len = (n); i < i##_len; ++i)
#define ALL(x) (x).begin(), (x).end()
using namespace std;

#define repi(itr, ds) for(auto itr = ds.begin(); itr != ds.end(); itr++)
// vector
template <typename T>
istream &operator>>(istream &is, vector<T> &vec) {
  for(T &x : vec) is >> x;
  return is;
}
// pair
template <typename T, typename U>
ostream &operator<<(ostream &os, pair<T, U> &pair_var) {
  os << "(" << pair_var.first << ", " << pair_var.second << ")";
  return os;
}
// vector
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
  os << "{";
  for(int i = 0; i < vec.size(); i++) {
    os << vec[i] << (i + 1 == vec.size() ? "" : ", ");
  }
  os << "}\n   ";
  return os;
}
// map
template <typename T, typename U>
ostream &operator<<(ostream &os, map<T, U> &map_var) {
  os << "{";
  repi(itr, map_var) {
    os << *itr;
    itr++;
    if(itr != map_var.end()) os << ", ";
    itr--;
  }
  os << "}";
  return os;
}
// set
template <typename T>
ostream &operator<<(ostream &os, set<T> &set_var) {
  os << "{";
  repi(itr, set_var) {
    os << *itr;
    itr++;
    if(itr != set_var.end()) os << ", ";
    itr--;
  }
  os << "}";
  return os;
}

#define DUMPOUT cerr

void dump_func() { DUMPOUT << endl; }
template <class Head, class... Tail>
void dump_func(Head &&head, Tail &&... tail) {
  DUMPOUT << head;
  if(sizeof...(Tail) > 0) {
    DUMPOUT << ", ";
  }
  dump_func(std::move(tail)...);
}
#ifdef DEBUG_
#define DEB
#define dump(...)                                                             \
  DUMPOUT << "  " << string(#__VA_ARGS__) << ": "                             \
          << "[" << to_string(__LINE__) << ":" << __FUNCTION__ << "]" << endl \
          << "    ",                                                          \
      dump_func(__VA_ARGS__)
#else
#define DEB if(false)
#define dump(...)
#endif

typedef long long int ll;

int main() {
  string S;
  cin >> S;
  int len = S.length();
  int ans = 0;
  for(int i = 0; i < len / 2; i++) {
    int j = len - i - 1;
    if(S[i] != S[j]) {
      ans++;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 101;
/* math */
ll dp[N][N][N];
int v[N][N][N],n;
char E[N][N];
inline ll solve(int a,int b,int c){
	if(a==b&&b==c)return 1;
	if(v[a][b][c])return dp[a][b][c];
	v[a][b][c]=1;
	for(int d=a;d<b;d++){
		for(int e=b+1;e<=c;e++){
			for(int f=a;f<=d;f++){
				for(int g=e;g<=c;g++){
					if(E[f][g]=='1'){
						dp[a][b][c] = dp[a][b][c] + solve(a,f,d)*solve(d+1,b,e-1)*solve(e,g,c);
					}
				}
			}
		}
	}
	return dp[a][b][c];
}

int main()
{
	cin >> n;
	for(int i=1;i<=n*2;i++)for(int j=1;j<=n*2;j++){
		while(E[i][j]<'0'||E[i][j]>'1')E[i][j]=getchar();
	}
	ll ans = 0;
	for(int i=2;i<=n*2;i++){
		if(E[1][i]=='1')ans = ans + solve(2,i,n*2);
	}
	cout << ans << endl;
}

Measured memory_bytes: 4864
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner scan = new Scanner(System.in);
		int a = scan.nextInt();
		int b = scan.nextInt();
		int cnt = 0;
		for(int i = a; i <= b; i++) {
			int v1 = i % 10;//一の位
			int v2 = i / 10 % 10;//十の位
			int v3 = i / 1000 % 10;//千くらい
			int v4 = i / 10000 % 10;//万の位
			if(v1 == v4 && v2 == v3) {
				cnt++;
			}
		}
		System.out.println(cnt);
	}
}

Measured memory_bytes: 23508
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
#include <string>

#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
typedef long long ll;

using namespace std;


int inputValue(){
    int a;
    cin >> a;
    return a;
};

void inputArray(int * p, int a){
    rep(i, a){
        cin >> p[i];
    }
};

void inputVector(vector<int> * p, int a){
    rep(i, a){
        int input;
        cin >> input;
        p -> push_back(input);
    }
}

template <typename T>
void output(T a, int precision) {
    if(precision > 0){
        cout << setprecision(precision)  << a << "\n";
    }
    else{
        cout << a << "\n";
    }
}

int main(int argc, const char * argv[]) {
    
  // source code
  string ss;
  cin >> ss;
  int vccount = 0;
  vector<string> vc;

  rep(i,ss.length())
  {
    vc.push_back(string() + ss[i]);
    if(vc.size() > 1 && (vc.at(vc.size() - 2) == string() + ss[i]))
    {
      if(i == ss.length() - 1)
      {
        cout << vc.size() - 1;
        return 0;
      }
      else
      {
        vc.at(vc.size() - 1) = vc.at(vc.size() - 1) + ss[i + 1];
        i++;
      }
    }
  }
  cout << vc.size();
  return 0;
  
  
}


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

	public void doIt(){
		Scanner sc = new Scanner(System.in);
		int n = 5;
		int [] data = new int[n];
		for(int i=0; i < 5; i++){
			data[i] = sc.nextInt();
		}
		Arrays.sort(data);
		for(int i = 4; i > 0 ;i--){
			System.out.print(data[i] + " ");
		}
		System.out.println(data[0]);
		
	}
	public static void main(String[] args) {
		Main obj = new Main();
		obj.doIt();
	}
}

Measured memory_bytes: 12000
d,n=[int(i) for i in input().split()]
if n!=100:
    if d==0:
        print(n)
    elif d==1:
        print(n*100)
    else:
        print(n*10000)
else:
    if d==0:
        print(n+1)
    elif d==1:
        print(n*100+100)
    else:
        print(n*10000+10000)  

Measured memory_bytes: 3060
#include <iostream>
#include <cstring>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <map>
#include <cmath>
#include <queue>
#include <utility>
#include <functional>
#include <deque>
#include <cctype>
#include <stack>
#include <bitset>

using ll = long long;
using namespace std;
typedef unsigned long long ull;
typedef pair<ll, ll>P;
const ll mod = 1000000007;
const ll INF = 1 << 30;
const ll INF2 = 9000000000000000000LL;
bool fl = true;;
int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };
struct edge { ll to, cost; };

int main() {
	ll n, ma, mb, a[100], b[100], c[100], dp[45][450][450], ans = INF;
	cin >> n >> ma >> mb;
	for (int i = 0;i < n;i++) {
		cin >> a[i] >> b[i] >> c[i];
	}
	for (int i = 0;i <= n;i++) {
		for (int j = 0;j <= n * 10;j++) {
			for (int k = 0;k <= n * 10;k++) {
				dp[i][j][k] = INF;
			}
		}
	}
	dp[0][0][0] = 0;
	for (int i = 0;i <= n;i++) {
		for (int j = 0;j <= n*10;j++) {
			for (int k = 0;k <= n * 10;k++) {
				if (dp[i][j][k] == INF)continue;
				dp[i + 1][j][k] = min(dp[i + 1][j][k], dp[i][j][k]);
				dp[i + 1][j + a[i]][k + b[i]] = min(dp[i + 1][j + a[i]][k + b[i]], dp[i][j][k] + c[i]);
			}
		}
	}
	for (int i = 1;i <= n * 10;i++) {
		for (int j = 1;j <= n * 10;j++) {
			if (i*mb == j*ma)ans = min(ans, dp[n][i][j]);
		}
	}
	if (ans == INF)cout << -1 << endl;
	else cout << ans << endl;
	}

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

int main(void){
  int n;
  cin >> n;
  int a[n];
  for(int i = 0; i < n; i++) cin >> a[i];
  int ans = 0;
  int ptr = 0;
  while(ptr <= n - 2){
    if(a[ptr] == a[ptr + 1]){
      ans++;
      ptr += 2;
    }else{
      ptr++;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
  
int m[101][101];
  
void matrixChainMultiplication(int n, int *p){
  int i,j,k,l;
    
  for(i=1; i<n+1; i++){
    m[i][i]=0;
  }
  for(l=2; l<n+1; l++){
    for(i=1; i<n-l+2; i++){
      j=i+l-1;
      m[i][j]=100000000;
      for(k=i; k<j; k++){
    if(m[i][j]>m[i][k]+m[k+1][j]+p[i-1]*p[k]*p[j]){
      m[i][j]=m[i][k]+m[k+1][j]+p[i-1]*p[k]*p[j];
    }
      }
    }
  }
}
  
int main(){
  int i,p[101],n;
  scanf("%d", &n);
  for(i=1; i<n+1; i++){
    scanf("%d%d", &p[i-1], &p[i]);
  }
  matrixChainMultiplication(n,p);
  printf("%d\n", m[1][n]);
    
  return 0;
}

Measured memory_bytes: 636
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int P=1e9+7;
const int M=1e5+5;
int head[M],to[M<<1],nxt[M<<1],tot;
void Add(int x,int y){
	to[++tot]=y;
	nxt[tot]=head[x];
	head[x]=tot;
}
int n,m;
int in[M];
ll dfs(int x,int f){
	ll res=1,tmp;
	if(f==0)tmp=m-1;
	else tmp=m-2;
	for(int i=head[x];i;i=nxt[i]){
		int y=to[i];
		if(y==f)continue;
		(res*=tmp)%=P;tmp--;
		(res*=dfs(y,x))%=P;
	}
	return res;
}
int main(){
	scanf("%d%d",&n,&m);
	for(int i=1,x,y;i<n;i++){
		scanf("%d%d",&x,&y);
		Add(x,y),Add(y,x);
		in[x]++,in[y]++;
	}
	printf("%lld",dfs(1,0)*m%P);
	return 0;
}

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

using namespace std;

#define REP(i, N) for (int i = 0; i < (int)N; i++)
#define RREP(i, N) for (int i =(int)N-1; i >= 0; i--)
#define FOR(i, a, b) for (int i = a; i < (int)b; i++)
#define ALL(x) (x).begin(), (x).end()
#define INF (1 << 30)
#define LLINF (1LL << 62)
#define DEBUG(...) debug(__LINE__, ":" __VA_ARGS__)

typedef long long ll;
typedef pair<int, int> Pii;
typedef pair<ll, ll> Pll;
typedef pair<int,string> Pis;

int main(){
  int n,r;
  cin>>n>>r;
  if(n>=10){
    cout<<r<<endl;
  }else{
    cout<<r+100*(10-n)<<endl;
  }
}


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

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

int main() {
    int h,w; cin >> h >> w;
    vector<vector<char>> c(h,vector<char> (w));
    rep(i,h){
        rep(j,w){
            cin >> c[i][j];
        }
    }
    rep(i,h){
        rep(k,2){
            rep(j,w){
                cout << c[i][j];
            }
            cout << endl;
        }
    }
}

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

using namespace std;

typedef long long ll;

const int N = 1e8;
const int INF = 1e9;
const int MOD = 998244353;



int main() {
    int a[3];
    cin >> a[0] >> a[1] >> a[2];
    sort(a, a + 3);
    if (a[0] + a[1] == a[2])
        cout << "Yes";
    else
        cout << "No";
}

Measured memory_bytes: 256
import java.util.Scanner;

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

        int count = 0;
        int[] x;
        x = new int[100];
        int N = sc.nextInt();

        for(int i = 0;i<N;i++){
            x[i] = sc.nextInt();
        }

        for(int i = N-1;i>0;i--){
            for(int j = 0;j<i;j++){
                if(x[j]>x[j+1]){
                    int temp = x[j];
                    x[j] = x[j+1];
                    x[j+1] = temp;
                    count++;
                }
            }
        }

        for(int i = 0;i<N-1;i++){
            System.out.print(x[i] + " ");
        }
        System.out.println(x[N-1]);
        System.out.println(count);
    }
}



Measured memory_bytes: 26440
#include <bits/stdc++.h>
#define REP(i, a, n) for(ll i=a; i<n; i++)
#define RREP(i, a, n) for(ll i=n-1; i>=a; i--)
typedef long long ll;
const ll mod =1e9+7;
const ll inf =1e18;
using namespace std;

ll n, x;
ll a[101];
int main() {
    cin>>n>>x;
    REP(i, 0, n) cin>>a[i];

    sort(a, a+n);

    ll ans=0;
    REP(i, 0, n){
        if(x<=0){
            break;
        }
        ans++;
        x-=a[i];
    }

    if(x!=0) ans--;
    
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define int ll
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define endl "\n"
#define pb push_back
#define all(a) (a).begin(),(a).end()
#define rev(a) (a).rbegin(),(a).rend()
#define pll pair<ll,ll>
#define rep(i,a,b) for(long long i = (a); i < (b); i++)
#define derep(i,a,b) for(long long i = (a); i>=(b); i--)
ll modi = 1000000007;

int32_t main(){
    fast;
    int k, n;
    cin>>k>>n;
    int arr[n+1];
    rep(i, 1, n+1){
        cin>>arr[i];
    }
    int c, a;
    c = k - (k - arr[n] + arr[1] );
    a = k - (arr[2] - arr[1]);
       int mini = min(c, a);
    for(int i = 2; i<n; i++){
        c = k - (arr[i] - arr[i-1]);
        a = k - (arr[i+ 1] - arr[i]);
        mini = min(mini, min(c, a));
    }
    c = k - (arr[n] - arr[n-1]);
    a = k - (k - arr[n] + arr[1]);
    mini = min(mini, min(c, a));
    cout<<mini<<endl;
}

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

int main() {
	// your code goes here
	long long int N, i;
	cin >> N;
	long long int count[N], A[N-1];
	count[0] = 0;
	for(i=0; i<(N-1); i++){
		cin >> A[i];
		count[i] = 0;
		count[A[i]-1] += 1;
	}
	count[i] = 0;
	for(i=0; i<N; i++)
		cout << count[i] << endl;
	
	return 0;
}

Measured memory_bytes: 6756
#include <iostream>
#include <iomanip>
#include <cstring>
#include <algorithm> 
#include <math.h>
#include <queue>
#include <functional>
#include <map>
#include <vector>
#include <string>
using namespace std;
 
typedef long long ll;
typedef pair<int, int> P;
 
int dx[] = { 1, 0, -1, 0 };
int dy[] = { 0, 1, 0, -1 };
 
const ll MOD = 1000000007;
const ll INF = 1000000000;
 
int main(void){
    int n;
    string a[3];
    int ans  = 0;
    cin >> n ;
    for(int i=0;i<3;i++) cin >> a[i];
    for(int i=0;i<n;i++){
        int cnt = 0;
        for(int j=0;j<3;j++){
            if(a[j%3][i] != a[(j+1)%3][i]) cnt++;
        }

        ans += max(0,cnt-1);
    
    }
    
    cout << ans <<endl;
    
}

Measured memory_bytes: 256
import sys

n = int(input())
s = input()
ans = 0

for i in range(1, len(s)):
    x_set = set(s[0:i])
    y_set = set(s[i::])
    xy_insect = x_set & y_set
    if len(xy_insect) and ans < len(xy_insect):
        ans = len(xy_insect)

print(ans)

Measured memory_bytes: 3060
# 半分全列挙
from itertools import permutations, combinations
M = int(input())
C = list(map(int, input()))
if len(C)==1 and M==0:
    print(0)
    exit()
mod = 10**9 + 7
L = [0] * 10
b = 1
for c in C[::-1]:
    L[c] += b
    b = b * 10 % mod

for t_half1 in combinations(range(10), 5):
    L1, L2 = L[:5], L[5:]
    t_half2 = list(set(range(10)) - set(t_half1))
    if int(C[0]) < 5:
        s1 = {sum(l * n for l, n in zip(L1, t1)) % mod: t1 for t1 in reversed(list(permutations(t_half1))) if t1[int(C[0])] != 0}
    else:
        s1 = {sum(l * n for l, n in zip(L1, t1)) % mod: t1 for t1 in reversed(list(permutations(t_half1)))}
    for t2 in permutations(t_half2):
        s = sum(l * n for l, n in zip(L2, t2))
        if (M-s) % mod in s1:
            t = s1[(M-s) % mod] + t2
            if t[int(C[0])] != 0:
                print("".join(map(lambda x: str(t[x]), C)))
                exit()
print(-1)



Measured memory_bytes: 13404
import heapq
N, M, s, t = map(int, input().split())
s, t = s - 1, t - 1
G_yen = [[] for i in range(N)]
G_snuuk = [[] for i in range(N)]
for i in range(M):
    u, v, a, b = map(int, input().split())
    u, v = u - 1, v - 1
    G_yen[u].append([v, a])
    G_yen[v].append([u, a])
    G_snuuk[u].append([v, b])
    G_snuuk[v].append([u, b])


def dijkstra(x, G):
    d = [float('inf')] * N
    d[x] = 0
    visited = {x}

    # d, u
    hq = [(0, x)]

    while hq:
        u = heapq.heappop(hq)[1]
        visited.add(u)

        for node, cost in G[u]:
            if (node not in visited) and d[node] > d[u] + cost:
                d[node] = d[u] + cost
                heapq.heappush(hq, (d[u]+cost, node))
    return d


d_yen = dijkstra(s, G_yen)
d_snuuk = dijkstra(t, G_snuuk)

ans = 10 ** 15
ans_list = []
for i in reversed(range(N)):
    ans = min(ans, d_yen[i] + d_snuuk[i])
    ans_list.append(10 ** 15 - ans)

print(*ans_list[::-1], sep='\n')


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

#define ll int64_t
#define Rep(i, n) for (ll i = 0; i < n; i++)

using namespace std;

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

    ll N, K;
    string S;
    cin >> N >> K >> S;

    vector<ll> length;
    if (S[0] == '0') length.push_back(0);
    
    ll cnt = 1;
    Rep (i, N-1) {
        if (S[i] == S[i+1]) {
            cnt++;
        } else {
            length.push_back(cnt);
            cnt = 1;
        }
    }
    length.push_back(cnt);
    if (length.size() % 2 == 0) {
        length.push_back(0);
    }

    // for (ll e : length) {
    //     cout << e << " ";
    // }
    // cout << endl;

    ll n = length.size();
    ll ans = 0;
    ll left = 0, right = 2 * K;
    for (ll i = left; i <= right && i < n; i++) {
        ans += length[i];
    }

    ll sub = ans;

    while (right + 2 < n) {
        sub -= (length[left] + length[left+1]);
        sub += (length[right+1] + length[right+2]);
        
        // cout << left+2 << "\t" << sub << endl;
        ans = max(ans, sub);

        left += 2;
        right += 2;
    }

    cout << ans << endl;
}

Measured memory_bytes: 1528
#pragma region include
#include <iostream>
#include <iomanip>
#include <stdio.h>

#include <sstream>
#include <algorithm>
#include <iterator>
#include <cmath>
#include <complex>

#include <string>
#include <cstring>
#include <vector>
#include <tuple>
#include <bitset>

#include <queue>
#include <complex>
#include <set>
#include <map>
#include <stack>
#include <list>

#include <fstream>
#include <random>
//#include <time.h>
#include <ctime>
#pragma endregion //#include
/////////
#define REP(i, x, n) for(int i = x; i < n; ++i)
#define rep(i,n) REP(i,0,n)
#define ALL(X) X.begin(), X.end()
/////////
#pragma region typedef
typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;
typedef std::pair<LL,LL> PLL;//
typedef std::pair<int,int> PII;//
#pragma endregion //typedef
////定数
const int INF = (int)1e9;
const LL MOD = (LL)1e9+7;
const LL LINF = (LL)4e18+20;
const LD PI = acos(-1.0);
const double EPS = 1e-9;
/////////
using namespace::std;

void solve(){
	int N,A,B;
	cin >> N >> A >> B;
	cout << min(N*A,B) << endl;
}

#pragma region main
signed main(void){
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	std::cout << std::fixed;//小数を10進数表示
	cout << setprecision(16);//小数点以下の桁数を指定//coutとcerrで別	

	solve();
}
#pragma endregion //main()

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n,x,t;
  cin >> n >> x >> t;
  int count = 0;
  if(n%x != 0) {
    count++;
  }
  count += n/x;
  int ans = count*t;
  cout << ans << endl;
}

Measured memory_bytes: 3632
#include<iostream>
#include<sstream>
#include<fstream>
#include<vector>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<algorithm>
#include<functional>
#include<climits>
#include<utility>
#include <iomanip>
#include<map>

using namespace std;

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

#define max(a,b) (a>b?a:b)
#define min(a,b) (a<b?a:b)
#define FOR(i,s,e) for (int i = int(s); i < int(e); i++)
#define REP(i,x) FOR(i,0,x)
#define CLR(a) memset((a), 0 ,sizeof(a))


const int MOD = 1e+9+7;
const double PI  = acos(-1.0);

ll calc_p(int n){
    ll ret=1;
    while(n>0){
        ret=ret*n;
        ret=ret%MOD;
        n--;
    }
    return ret;
}

int main(){
    int n,m;
    cin>>n>>m;
    if(abs(n-m)>=2){
        cout<<"0\n";
        return 0;
    }
    ll ret=1;
    ret=(ret*calc_p(n))%MOD;
    ret=(ret*calc_p(m))%MOD;
    if(n==m)ret=(ret*2)%MOD;
    cout<<ret<<"\n";

}


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

using namespace std;

#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)((x).size()))

typedef pair<int, int> PII;
typedef vector<int> VI;
typedef long long int64;
typedef unsigned int uint;
typedef unsigned long long uint64;

#define gi(x) ((x) = F())
#define gii(x, y) (gi(x), gi(y))
#define giii(x, y, z) (gii(x, y), gi(z))

int F()
{
	char ch;
	int x, a;
	while (ch = getchar(), (ch < '0' || ch > '9') && ch != '-');
	if (ch == '-') ch = getchar(), a = -1;
	else a = 1;
	x = ch - '0';
	while (ch = getchar(), ch >= '0' && ch <= '9')
		x = (x << 1) + (x << 3) + ch - '0';
	return a * x;
}

const int N = 2010;

int n, a[N], t[N][N], deg[N];

bool vis[N];

VI edge[N];

void dfs(int u)
{
	vis[u] = 1;
	for (int j = 1; j <= n; ++j)
		if (!vis[j] && t[u][j])
			edge[u].pb(j), ++deg[j], dfs(j);
}

priority_queue<int> pq;

int main()
{
	gi(n);
	for (int i = 1; i <= n; ++i) gi(a[i]);
	sort(a + 1, a + n + 1);
	for (int i = 1; i <= n; ++i)
		for (int j = 1; j <= n; ++j)
			if (__gcd(a[i], a[j]) != 1)
				t[i][j] = 1;
	for (int i = 1; i <= n; ++i)
		if (!vis[i]) dfs(i);
	for (int i = 1; i <= n; ++i) if (!deg[i]) pq.push(i);
	while (!pq.empty())
	{
		int u = pq.top(); pq.pop();
		printf("%d ", a[u]);
		for (auto v : edge[u])
		{
			--deg[v];
			if (!deg[v]) pq.push(v);
		}
	}
	return 0;
}

Measured memory_bytes: 16256
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;
const int MOD = 1e9 + 7;

int main() {
  ll n, a, b;
  cin >> n >> a >> b;
  ll x = a + b;
  ll y = n / x;
  cout << a * y + min(a, n % x) << endl;
  return 0;
}

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

int main(){
    ll h,w;
    cin>>h>>w;
    ll ans=0;
    ll iti,ni;
    iti=(h+1)/2;
    ni=h/2;
    ans+=iti*((w+1)/2);
    ans+=ni*(w/2);
    if(h==1 || w==1){
        cout<<1<<endl;
        return 0;
    }
    cout<<ans<<endl;
    return 0;
}


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

using namespace std;

int main() {
    int n, tmp, max = -1e9, min;
    cin >> n;
    vector<int> r(n);
    for(int i = 0; i < n; i++) cin >> r.at(i);
    min = r.at(0);
    for(int i = 1; i < n; i++) {
        if(r.at(i) - min > max) max = r.at(i) - min;
        if(min > r.at(i)) min = r.at(i);
    }
    cout << max << endl;
}


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

int n,k;
int a[200001];
int cnt[200001];

int main(void){
	scanf("%d%d",&n,&k);
	for(int i=0;i<n;i++){
		scanf("%d",&a[i]);
		a[i]--;
		cnt[a[i]]++;
	}
	sort(cnt,cnt+n);
	int all=0;
	for(int i=0;i<n-k;i++){
		//printf("%d\n",cnt[i]);
		all+=cnt[i];
	}
	printf("%d\n",all);
	return 0;
}

Measured memory_bytes: 1792
class UnionFind():
  def __init__(self, n):
    self.n = n
    self.parents = [-1] * n

  def find(self, x):
    if self.parents[x] < 0:
      return x
    else:
      self.parents[x] = self.find(self.parents[x])
    return self.parents[x]

  def union(self, x, y):
    x = self.find(x)
    y = self.find(y)

    if x == y:
      return

    if self.parents[x] > self.parents[y]:
      x, y = y, x

    self.parents[x] += self.parents[y]
    self.parents[y] = x

  def same(self, x, y):
    return self.find(x) == self.find(y)

  def roots(self):
    return [i for i, x in enumerate(self.parents) if x < 0]

  def num_roots(self):
    return len([i for i, x in enumerate(self.parents) if x < 0])

  def members(self, x):
    root = self.find(x)
    return [i for i in range(self.n) if self.find(i) == root]

  def num_members(self,x):
    return abs(self.parents[self.find(x)])

  def __str__(self):
    return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

N, M = map(int, input().split())
uf = UnionFind(N)
cnt = 0
for i in range(M):
  a,b = map(int, input().split())
  if not uf.same(a-1,b-1):
    cnt += 1
    uf.union(a-1,b-1)
print(N-1-cnt)


Measured memory_bytes: 75740
import java.util.*;

public class Main {
  static final String ascii = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
  public static void main(String args[]){
    Scanner sc = new Scanner(System.in);
    int index = sc.nextInt();
    String str = sc.next();
    
    if (index == 0){
      System.out.println(str);  
    }else {
    
      String replaced = "";
      for (int i = 0 ; i < str.length() ; i++){
        char c = str.charAt(i);
        int si = ascii.indexOf(String.valueOf(c));
        int ri = si + index;
        if(ri >= ascii.length()){
          ri = ri - ascii.length();
        }
        replaced = replaced + String.valueOf(ascii.charAt(ri));
      }
      System.out.println(replaced);
    }
  }
}

Measured memory_bytes: 147108
#include<stdio.h>
#include<string.h>
//20000桁のマージソート(1単語10文字以下)
char c[101][11];
int sort(int a,int b,char s[][11]){
  if(a==b)
    return 0;
  sort(a,(a+b)/2,s);
  sort((a+b)/2+1,b,s);
  int i=a,j=(a+b)/2+1,k=a;
  while(k<=b){
    if(i<(a+b)/2+1 && j<b+1){
      if(strcmp(s[i],s[j])<0){
        strcpy(c[k],s[i]);
        i++;
      }
      else{
        strcpy(c[k],s[j]);
        j++;
      }
    }
    else if(j>b){
      strcpy(c[k],s[i]);
      i++;
    }
    else{
      strcpy(c[k],s[j]);
      j++;
    }
    k++;
  }
  for(i=a;i<=b;i++)
    strcpy(s[i],c[i]);
  return 0;
}

int main(){
  int n,m,i,max=0;
  scanf("%d",&n);
  char s[n+1][11];
  for(i=0;i<n;i++)
    scanf("%*c%s",s[i]);
  scanf("%d",&m);
  sort(0,n-1,s);
  char t[m+1][11];
  for(i=0;i<m;i++)
    scanf("%*c%s",t[i]);
  sort(0,m-1,t);
  int count=1,tnum=0;
  for(i=0;i<n;i++){
    if(strcmp(s[i],s[i+1])==0 && i<n-1)
      count++;
    else{
      while(strcmp(t[tnum],s[i])<0 && tnum<m)
        tnum++;
      while(strcmp(t[tnum],s[i])==0 && tnum<m){
        tnum++;
        count--;
      }
      if(max<count)
        max=count;
      count=1;
    }
  }
  printf("%d\n",max);
  return 0;
}


Measured memory_bytes: 128
int main()
{
    int A, B, ans=0;
    scanf("%d%d", &A, &B);
    if(A < 6){
        ans=0;
    } else if (A < 13) {
        ans = B/2;
    } else {
        ans = B;
    }
    printf("%d", ans);
    return 0;
}


Measured memory_bytes: 128
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.HashSet;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Main main = new Main();
        main.solve();
    }
    public void solve() {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int N = scan.nextInt();
        int K = scan.nextInt();
        int[] p = new int[N];
        for (int i = 0; i < N; i++) {
            p[i] = scan.nextInt();
        }
        int [] e = new int[N];
        for (int i = 0; i < N; i++) {
            e[i] = p[i] + 1;
        }
        int[] sum = new int[N+1];
        for (int i = 1; i <= N; i++) {
            sum[i] = sum[i-1] + e[i-1];
        }
        int max = Integer.MIN_VALUE;
        for (int i = K; i <= N; i++) {
            max = Math.max(max, sum[i] - sum[i - K]);
        }
        double ans = (double) max / 2;
        System.out.printf("%.9f\n", ans);
    }
}


Measured memory_bytes: 62748
#include<bits/stdc++.h>
using namespace std;
int d1[200055],d2[200055],n;
int main()
{
        cin>>n;
        for(int i=1;i<=n;i++)
        {
            int x,y;
            cin>>x>>y;
            d1[i]=x+y;
            d2[i]=x-y;
        }
        sort(d1+1,d1+1+n);
        sort(d2+1,d2+1+n);
        cout<<max(d1[n]-d1[1],d2[n]-d2[1])<<'\n';
    return 0;
}

Measured memory_bytes: 5064
from itertools import accumulate
import sys
sdin = sys.stdin.readline

n,m,q = map(int, sdin().split())

lr = []
for i in range(m):
    l,r = map(int, sdin().split())
    lr.append(tuple([l-1, r-1]))
        
pq = []
for _ in range(q):
    p,q = map(int, sdin().split())
    pq.append(tuple([p-1, q-1]))

    
# n×nフィールドを用意して各列車のl,r点をプロット
field = [[0 for _ in range(n)] for _ in range(n)]
for l, r in lr:
    field[l][r] += 1
    
# fieldのx方向の累積和を取る
field_cum = [list(accumulate(field[i])) for i in range(n)]    

# field_cumのy方向の累積和をとる
for r in range(1,n):
    for l in range(n):
        field_cum[r][l] += field_cum[r-1][l]

        
# 各クエリに対し、長方形内部にあるものの個数を求める
for p,q in pq:
    if p > 0:
        print(field_cum[q][q] - field_cum[p-1][q] - field_cum[q][p-1] + field_cum[p-1][p-1])
    else:
        print(field_cum[q][q])

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

using namespace std;

namespace {

    typedef double real;
    typedef long long ll;

    template<class T> ostream& operator<<(ostream& os, const vector<T>& vs) {
        if (vs.empty()) return os << "[]";
        os << "[" << vs[0];
        for (int i = 1; i < vs.size(); i++) os << " " << vs[i];
        return os << "]";
    }
    template<class T> istream& operator>>(istream& is, vector<T>& vs) {
        for (auto it = vs.begin(); it != vs.end(); it++) is >> *it;
        return is;
    }

    const ll MOD = ll(1e6);

    int N, M;
    void input() {
        cin >> N >> M;
    }

    int opposite(int i) {
        return (!i) * 2;
    }

    const int MAX_N = 101;
    const int MAX_M = 3;

    int memo[MAX_N][MAX_M];
    ll dfs(int k, int p) {
        if (k == N) return 1;
        if (memo[k][p] >= 0) return memo[k][p];
        ll ret = 0;
        if (k < N && M == 2 && p == 0) ret += 1;
        if (M == 2 && p != 1) {
            for (int i = k + 1; i < N; i++) {
                ret += dfs(i + 1, opposite(p));
                ret %= MOD;
            }
        }
        for (int i = 0; i <= M; i++) {
            ret += dfs(k + 1, i);
            ret %= MOD;
        }
        //cerr << k << " " << p << " -> " << ret << endl;
        return memo[k][p] = ret;
    }

    void solve() {
        memset(memo, -1, sizeof(memo));
        cout << dfs(0, 0) << endl;
    }
}

int main() {
    input(); solve();
    return 0;
}

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

typedef long long int   ll;
typedef pair<ll, ll>    pll;
typedef pair<int, int>  pii;

#define all(x)          x.begin(), x.end()
#define kill(x)         return cout << x << endl, 0
#define X               first
#define Y               second
#define sep             ' '
#define endl            '\n'

ll pw(ll a, ll b, ll mod) {
    if (!b)    return 1;
    if (b & 1) return a * pw(a * a % mod, b / 2, mod) % mod;
    return pw(a * a % mod, b / 2, mod) % mod;
}

const ll N    = 3e3 + 10;
const ll MOD  = 998244353;
const ll INF  = 1e18;

ll a, b, c, d, dp[N][N];

int main() {
    ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
    cin >> a >> b >> c >> d;
    dp[a][b] = 1;
    for (int i = a; i <= c; i++)  {
        for (int j = b; j <= d; j++) {
            if (i == a && j == b)
                continue;
            dp[i][j] = (dp[i - 1][j] * j % MOD + dp[i][j - 1] * i % MOD) % MOD;
            dp[i][j] = (dp[i][j] + MOD - dp[i - 1][j - 1] * (i - 1) % MOD * (j - 1) % MOD) % MOD;
        }
    }
    cout << dp[c][d] << endl;
    return 0;
}


Measured memory_bytes: 74188
# vim: fileencoding=utf-8


def main():
    n = int(input())
    a = list(map(int, input().split()))

    evenAns, oddAns = 0, 0
    evenTotal, oddTotal = 0, 0

    # 奇数を負に
    for i in range(n):
        oddTotal += a[i]
        if i % 2 == 0:
            if oddTotal <= 0:
                oddAns += abs(oddTotal) + 1
                oddTotal += abs(oddTotal) + 1
        else:
            if oddTotal >= 0:
                oddAns += abs(oddTotal + 1)
                oddTotal -= abs(oddTotal) + 1

    # 偶数を負に
    for i in range(n):
        evenTotal += a[i]
        if i % 2 == 1:
            if evenTotal <= 0:
                evenAns += abs(evenTotal) + 1
                evenTotal += abs(evenTotal) + 1
        else:
            if evenTotal >= 0:
                evenAns += abs(evenTotal) + 1
                evenTotal -= abs(evenTotal) + 1
    print(min(evenAns, oddAns))


if __name__ == "__main__":
    main()


Measured memory_bytes: 85252
#include <iostream>
#include <queue>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
ll n, m, s, t, yen[100010], snook[100010], ans[100010];
vector<P> eroad[100010], sroad[100010];
priority_queue<P, vector<P>, greater<P>> que;
const ll INF = 100000000000000000;
int main(void){
    // Your code here!
    cin >> n >> m >> s >> t;
    for (ll i = 0; i < m; i++){
        ll u, v, a, b;
        cin >> u >> v >> a >> b;
        eroad[u].push_back(P(v, a));
        eroad[v].push_back(P(u, a));
        sroad[u].push_back(P(v, b));
        sroad[v].push_back(P(u, b));
    }
    for (ll i = 1; i <= n; i++) yen[i] = INF, snook[i] = INF;
    yen[s] = 0, snook[t] = 0;
    que.push(P(0, s));
    while(!que.empty()){
        P p = que.top(); que.pop();
        ll v = p.second;
        if (yen[v] < p.first) continue;
        for (ll i = 0; i < eroad[v].size(); i++){
            P e = eroad[v][i];
            if (yen[e.first] > yen[v] + e.second){
                yen[e.first] = yen[v] + e.second;
                que.push(P(yen[e.first], e.first));
            }
        }
    }
    que.push(P(0, t));
    while(!que.empty()){
        P p = que.top(); que.pop();
        ll v = p.second;
        if (snook[v] < p.first) continue;
        for (ll i = 0; i < sroad[v].size(); i++){
            P e = sroad[v][i];
            if (snook[e.first] > snook[v] + e.second){
                snook[e.first] = snook[v] + e.second;
                que.push(P(snook[e.first], e.first));
            }
        }
    }
    for (ll i = n; i > 0; i--){
        ans[i] = 1000000000000000 - yen[i] - snook[i];
        if (i != n){
            ans[i] = max(ans[i], ans[i + 1]);
        }
    }
    for (ll i = 1; i <= n; i++) cout << ans[i] << endl;
}


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

#define rep(i,n) for(ll i = 0; i < n; i++)
#define per(i,n) for(ll i = n-1; i >= 0; i--)
#define REP(i,n) for(ll i = 1; i < n; i++)
#define PER(i,n) for(ll i = n; i >= 1; i--)
#define sz(x) int(x.size())
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define YesorNo(a) printf(a ? "Yes\n" : "No\n")
#define endl '\n'
#define fi first
#define se second
using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
using vi = vector<int>;
using vii = vector<vi>;
using vl = vector<ll>;
using vll = vector<vl>;
using vs = vector<string>;
using vb = vector<bool>;
using vc = vector<char>;
using vcc = vector<vc>;
using vP = vector<P>;
using vPP = vector<vP>;
using vPl = vector<Pl>;
const int dx[] = {0,1,0,-1,1,1,-1,-1};
const int dy[] = {1,0,-1,0,1,-1,-1,1};
const int inf = (1<<30)-1;
const ll infll = (1LL<<62)-1;
ll ceil(const ll &a, const ll &b){return ((a)+(b)-1)/b;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }



int main(){
  int n;
  cin >> n;
  map<int, int> mp;
  rep(i,n) {
    int a;
    cin >> a;
    mp[a]++;
  }
  vi l;
  for(auto it = mp.rbegin(); it != mp.rend(); it++) {
    P p = *it;
    rep(ci,2) {
      if(p.se >= 2) {
        l.push_back(p.fi);
        p.se -= 2;
      }
    }
  }
  if(sz(l) < 2) cout << 0 << endl;
  else cout << 1LL * l[0] * l[1] << endl;
}

Measured memory_bytes: 8088
#include <bits/stdc++.h>
    #include <cstdio>
    #include <cstring>
    #include <cmath>
    #include <cstring>
    #include <chrono>
    #include <complex>
    #define endl "\n"
    #define int long long int
    #define vi vector<int>
    #define vll vector<ll>
    #define vvi vector < vi >
    #define pii pair<int,int>
    #define pll pair<long long, long long>
    #define mod 1000000007
    #define inf 1000000000000000001;
    #define all(c) c.begin(),c.end()
    #define mp(x,y) make_pair(x,y)
    #define mem(a,val) memset(a,val,sizeof(a))
    #define eb emplace_back
    #define f first
    #define s second

    using namespace std;
int power(int base, int exp)
{
    if (exp == 0)
       return 1;
    else if (exp == 1)
       return base;
    else
    {
       int calc;
       if (exp % 2 == 0)
       {
         calc = power(base, exp/2);
         calc =(calc* calc)%mod;
       }
       else
       {
         calc = (base*power(base, exp-1))%mod;
       }
       return calc%mod;
    }
}

void con(int A[], int n)
{

	int XOR = 0;
	for (int i = 0; i < n; i++)
		XOR ^= A[i];
	for (int i = 0; i < n; i++)
		A[i] = XOR ^ A[i];
}
int32_t main()
{
	 int n;
	cin>>n;
	int A[n];
	for(int i=0;i<n;i++)
    {
        cin>>A[i];
    }

	con(A, n);
	for (int i = 0; i < n; i++)
		cout << A[i] << " ";
	return 0;
}


Measured memory_bytes: 5156
#include<iostream> 
#include<cstdio>
#include<algorithm>
using namespace std;
int main(){
	int n;
	cin>>n;
	int f,m,b;
	f=n/100;
	b=n%10;
	m=n/10%10;
	if(b>f || m>f){
		f++; 
	}
		cout<<f<<f<<f<<endl;
	return 0;
}

Measured memory_bytes: 256
### constant

DXYS = [[1, -1], [0, -1], [-1, 0], [-1, 1], [0, 1], [1, 0]]
CH_A = 'a'.ord

### subroutines

def same?(p0, p1)
  return false if p0.length != p1.length

  x = y = 0
  eggs = {[0, 0] => true}
  
  for b0 in p0.each_byte
    d = b0 - CH_A
    x += DXYS[d][0]
    y += DXYS[d][1]
    eggs[[x, y]] = true
  end

  pts = eggs.keys

  for k in (0...6)
    pts.each do |x, y|
      ok = true
      for b1 in p1.each_byte
        d = (b1 - CH_A + k) % 6
        x += DXYS[d][0]
        y += DXYS[d][1]
        if eggs[[x, y]].nil?
          ok = false
          break
        end
      end
      return true if ok
    end
  end

  false
end

### main

n = gets.to_i

n.times do
  p0 = gets.strip
  p1 = gets.strip
  gets
  #p [p0, p1]

  puts same?(p0, p1) ? 'true' : 'false'
end

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

int main() {
  string n;
  cin >> n;
  bool flg = false;
  for(char x : n) {
    if(x == '9') flg = true;
  }
  
  if(flg) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}


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

#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

#define int long long
#define pb push_back
#define pii pair<int,int>
#define fr(i,n) for(int i=0;i<n;i++)
#define F first
#define S second
#define nl '\n'
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

int32_t main()
{   fastio;

    int n;
    cin>>n;
    int arr[n];
    for(int i=0; i<n; i++)
        cin>>arr[i];
    int s=0;
    map<int , int>mp;
    for(auto x:arr)s += x , mp[x]++;

    int q;
    cin>>q;
    while(q--) {
        int a , b;
        cin>>a>>b;

        if(mp.find(a) != mp.end()) {
            int p = mp[a];
            int x = a*p;
            s -= x;
            s += p*b;
            mp.erase(a);
            mp[b] += p;
        }
        cout<<s<<"\n";

    }
}

Measured memory_bytes: 8400
#include<cstdio>  
#include<cstring>  
#include<algorithm>  
#include<iostream>  
#include<string>  
#include<vector>  
#include<stack>  
#include<bitset>  
#include<cstdlib>  
#include<cmath>  
#include<set>  
#include<list>  
#include<deque>  
#include<map>  
#include<queue>
using namespace std;
typedef long long ll;
const ll inf=1<<29;
const ll Maxn=1e6;

int main(){
	ll x,y,mid,sid,nid;
	cin>>x>>y;
	if(x==y) printf("-1\n");
	if(x>y){
		if(x%y!=0) mid=x*(y+1);
		if(x%y==0) mid=-1;
	}
	if(x<y){
		if(y%x==0) mid=x*((y/x)+1);
		if(y%x!=0) mid=x*2;
	}
	if(x!=y) printf("%lld",mid);
}

Measured memory_bytes: 256
import java.io.FileNotFoundException;
import java.util.Scanner;

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

		//    	File file = new File("src/in.txt");
		//    	Scanner sc = new Scanner(file);

		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();
		String S = sc.next();
		sc.close();

		char[] s = S.toCharArray();
		for(int i=0;i<S.length();i++) {
			char c = s[i];
			int x = (int)c;
			int y = (x+N-(int)'A')%26;
			x = (int)'A'+y;
			s[i] = (char) x;
		}
		String ans = String.copyValueOf(s);
		System.out.println(ans);
	}
}

Measured memory_bytes: 22100
program sample
    implicit none
    
    integer(8) :: i,j,m,n,a
    integer(8),allocatable :: x(:),y(:)
  
    read(*,*) n
    allocate(x(n))
    read(*,*)x
    read(*,*) m
    allocate(y(m))
    read(*,*)y
    if(m>n)then
        write(*,*)'NO'
        stop
    end if
    call msort(x)
    call msort(y)
    a=1
    do i=1,m
        do 
            if(a>n)then
                write(*,*)'NO'
                stop
            elseif(y(i)==x(a))then
                a=a+1
                exit
            elseif(y(i)<x(a))then
                write(*,*)'NO'
                stop
            
            else
                a=a+1
            end if
        end do
    end do
    write(*,*)'YES'
    stop
    contains
    recursive subroutine msort(x)
    implicit none
    integer(8), intent(inout) :: x(:)
 
    integer(8) :: n, mid, i, j, k
    integer(8), allocatable :: tmp(:)
    
    n = size(x)
    
    if(n == 1) then
      return
    end if
 
    !
    ! 前半と後半に分けてソート
    ! 1~midとmid+1~nをそれぞれソート済みにする
    !
    mid = n / 2
    call msort(x(:mid))
    call msort(x(mid+1:))
 
    !
    ! tmpという配列にxを一時的に保管
    ! マージソートは外部ソート
    !
    allocate(tmp(n))
    tmp = x
 
    ! tmpの後半部分を左右反転
    do k = n, mid+1, -1
      tmp(k) = x(mid + n - k + 1)
    end do
 
    ! iは前半のリストのうちまだ見ていないものの最小値
    ! jは後半のリストのうちまだ見ていないものの最小値
    ! kは見た回数の合計
    i = 1
    j = n
 
    do k = 1, n
      !
      ! 一番左と一番右のうち小さい方をxに入れていく
      ! ここが等号つき不等号なので、安定ソートとなる
      !
      if(tmp(i) <= tmp(j)) then
        x(k) = tmp(i)
        i = i + 1
      else
        x(k) = tmp(j)
        j = j - 1
      end if
    end do
    
    deallocate(tmp)
    return
  end subroutine msort
end program sample
  



Measured memory_bytes: 8432
#include <stdio.h>
int main(void) {
	int m,f,r;
	while(scanf("%d %d %d\n",&m,&f,&r)!=EOF && (m>=0 || f>=0 || r>=0)){
		if(m<0 || f<0){
			printf("F\n");
		}else if(m+f>=80){
			printf("A\n");
		}else if(m+f>=65){
			printf("B\n");
		}else if(m+f>=50 || r>=50){
			printf("C\n");
		}else if(m+f>=30){
			printf("D\n");
		}else{
			printf("F\n");
		}
	}
	return 0;
}

Measured memory_bytes: 588
#include <assert.h>
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>
using namespace std;
const int N = 1e5 + 5;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9 + 7;
typedef long long ll;

int A[N];
int B[N];
int C[N];
ll tree[N * 2];
int n;
void Add(int pos, int num) {
    for (int i = pos; i <= 2 * n; i += i & -i) tree[i] += num;
}
ll Sum(int pos) {
    ll ans = 0;
    for (int i = pos; i > 0; i -= i & -i) ans += tree[i];
    return ans;
}

bool solve(int x) {
    memset(tree, 0, sizeof(tree));
    for (int i = 1; i <= n; ++i) {
        if (A[i] >= x)
            C[i] = 1;
        else
            C[i] = -1;
    }
    ll ans = 0;
    Add(n, 1);
    for (int i = 1; i <= n; ++i) {
        C[i] += C[i - 1];
        ans += Sum(C[i] + n);
        Add(C[i] + n, 1);
    }
    //    printf("%d\n", ans);
    return (ans >= (1ll * n * (n + 1) / 4));
}
int main() {
    while (~scanf("%d", &n)) {
        for (int i = 1; i <= n; ++i) {
            scanf("%d", &A[i]);
            B[i] = A[i];
        }
        sort(B + 1, B + n + 1);
        int tot = unique(B + 1, B + n + 1) - B - 1;
        int l = 1;
        int r = tot;

        while (l <= r) {
            int mid = (l + r) >> 1;
            if (solve(B[mid]))
                l = mid + 1;
            else
                r = mid - 1;
        }
        //    for(int i = 1; i <= tot; ++i) printf("%d ", B[i]); printf("\n");
        printf("%d\n", B[r]);
    }
    return 0;
}

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

int main() {
  int N;
  cin >> N;
  int min=10000000;
  for(int i=0;i<N;i++){
    int a,b=0;
    cin >> a;
    while(a%2==0){
      a=a/2;
      b++;
    }
    if(b<min)min=b;
  }
  cout << min;
}

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

using VS = vector<string>;    using LL = long long;
using VI = vector<int>;       using VVI = vector<VI>;
using PII = pair<int, int>;   using PLL = pair<LL, LL>;
using VL = vector<LL>;        using VVL = vector<VL>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
//#pragma GCC optimize ("-O3") 
#ifdef YANG33
#include "mydebug.hpp"
#else
#define DD(x) 
#endif
const int INF = 1e9;                          const LL LINF = 1e16;
const LL MOD = 1000000007;                    const double PI = acos(-1.0);
int DX[8] = { 0, 0, 1, -1, 1, 1, -1, -1 };    int DY[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };

/* -----  2019/03/12  Problem: ABC 078 D / Link: http://abc078.contest.atcoder.jp/tasks/abc078_d  ----- */



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

	LL N, Z, W; cin >> N >> Z >> W;
	vector<LL> a(N + 1);
	a.front() = W;
	for (int i = 0; i < N; ++i) {
		cin >> a[i + 1];
	}
	VVL dp(N + 1, VL(2, -1e18));
	function<LL(int, bool)> f = [&](int pos, bool turn) {
		if (dp[pos][turn] != -1e18)return dp[pos][turn];
		LL ret;
		if (!turn) {
			ret = -LINF;
			FOR(i, pos + 1, N + 1) {
				if (i == N)ret = max(ret, abs(a[pos] - a.back()));
				else ret = max(ret, f(i, !turn));
			}
		}
		else {
			ret = LINF;
			FOR(i, pos + 1, N + 1) {
				if (i == N)ret = min(ret, abs(a[pos] - a.back()));
				else ret = min(ret, f(i, !turn));
			}
		}
		return dp[pos][turn] = ret;
	};

	LL ans = f(0, 0);


	cout << (ans) << "\n";

	return 0;
}


Measured memory_bytes: 512
#include <algorithm>
#include<iostream>
#include<vector>
#include<deque>
#include<queue>
#include<stack>
#include<list>
#include<map>
#include<set>
#include<string>
#include <sstream>
#include<bitset>

#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<limits.h>
const int INF = 0x7fffffff;
using lll = long long;
using ull = unsigned long long;
using namespace std;


int main(){
  lll ii,jj,kk;
  vector<int> ret;
  int n,x,t;
  int ans;
  cin >> n >> x >> t;

  ans = n/x * t;

  if(n % x != 0){
    ans += t;
  }

  cout << ans << endl;
  

  return 0;
}


Measured memory_bytes: 3632
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define cinf(n,x) for(int i=0;i<(n);i++)cin>>x[i];
#define max3(a,b,c) max(max(a,b),c)
#define min3(a,b,c) min(min(a,b),c)
#define ft first
#define sc second
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(),(v).end()
#define mod 1000000007
using namespace std;
using Graph = vector<vector<int>>;
typedef long long lint;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ldouble;
typedef vector<int> vec;
typedef vector<ll> lvec;
typedef vector<ull> ulvec;
typedef vector<double> dvec;
typedef vector<pair<int,int>> pvec;
typedef vector<pair<ll,ll>> plvec;
typedef vector<tuple<ll,ll,ll>> tvec;
typedef vector<string> svec;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

int main(){
    int n;
    cin>>n;
    vec p(n),q(n);
    rep(i,n)cin>>p[i];
    rep(i,n)cin>>q[i];
    vec a(n);
    rep(i,n) a[i]=i+1;
    int u,b;
    bool ok=0;
    int cnt=1;
    do{
        bool ok1=1,ok2=1;;
        rep(i,n){
            
                if(p[i]!=a[i])ok1=0;
            
                if(q[i]!=a[i])ok2=0;
            
        }
        if(ok1)u=cnt;
        if(ok2)b=cnt;
        cnt++;
    }while(next_permutation(all(a)));
    cout<<abs(u-b);
}

Measured memory_bytes: 256
a=input()
for i in range(1<<3):
    num=int(a[0])
    ans=a[0]
    for j in range(3):
        if 1& i>>j:
            num+=int(a[j+1])
            ans+="+"
            ans+=a[j+1]
        else:
            num-=int(a[j+1])
            ans+="-"
            ans+=a[j+1]
    #print(num)
    if num==7:
        ans+="=7"
        print(ans)
        exit()


Measured memory_bytes: 38256