akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int r = sc.nextInt(); 
		int n = sc.nextInt();
		int[][] array = new int[n + 1][r + 1];
		
		for(int i = 0; i < r ;i ++) {
			for(int j = 0;j < n ; j++) {
				array[j][i] = sc.nextInt();
				array[n][i]  = array[n][i] + array[j][i];
				array[j][r]  = array[j][r] + array[j][i];
				array[n][r]  = array[n][r] + array[j][i];
			}
		}
		for(int i = 0; i <= r; i++) {
			for(int j = 0;j < n ; j++) {
				System.out.print(String.format("%d ",array[j][i]));
			}
			System.out.println(array[n][i]);
		}
	}	
}


Measured memory_bytes: 53572
import java.util.*;

//update 2020/1/1 23:01

public class Main{

  static Scanner sc = new Scanner(System.in);
  static StringBuilder sb = new StringBuilder();

  public static void main(String[] args) {

    String s = next();
    String[] ss = splitString(s);

    boolean ok0 = (ss[0].equals("7"));
    boolean ok1 = (ss[1].equals("7"));
    boolean ok2 = (ss[2].equals("7"));

    if(ok0 || ok1 || ok2){
      System.out.println("Yes");
    }
    else{
      System.out.println("No");
    }
    //System.out.println();

  }
  /*
    static String toSmall(String s){
      char c = s.charAt(0);
      //if(Character.isUpperCase(c)){
      if(c<=90){
        c += 32;
      }
      return String.valueOf(c);
    }
    static String toBig(String s){
      char c = s.charAt(0);
      //if(Character.isLowerCase(c)){
      if(c>=97){
        c -= 32;
      }
      return String.valueOf(c);
    }
  */

  static String toSmall(String s){
    return s.toLowerCase();
  }

  static String toBig(String s){
    return s.toUpperCase();
  }

  static String next(){
    return sc.next();
  }

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

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

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

  static String[] splitString(String s){
    return s.split("");
  }

  static char[] splitChar(String s){
    return s.toCharArray();
  }

  static int charToInt(char a){
    return a - 48;
  }

////////////////////////////////////////////
  public static int max(int[] a){
    int lng = a.length;
    int max = a[0];
    for(int i=1;i<lng;i++){
      max = Math.max(max,a[i]);
    }
    return max;
  }
  public static long max(long[] a){
    int lng = a.length;
    long max = a[0];
    for(int i=1;i<lng;i++){
      max = Math.max(max,a[i]);
    }
    return max;
  }
////////////////////////////////////////////

////////////////////////////////////////////
  public static int min(int[] a){
    int lng = a.length;
    int min = a[0];
    for(int i=1;i<lng;i++){
      min = Math.min(min,a[i]);
    }
    return min;
  }
  public static long min(long[] a){
    int lng = a.length;
    long min = a[0];
    for(int i=1;i<lng;i++){
      min = Math.min(min,a[i]);
    }
    return min;
  }
////////////////////////////////////////////

}


Measured memory_bytes: 35488
#include<iostream>
#include<vector>
#include<string>
using std::cout;
using std::cin;
using std::endl;
typedef long long ll;

ll chouse2(ll n) {
	return n * (n - 1) / 2;
}
int main() {
	int n;
	cin >> n;
	std::vector<int> A(n);
	for (int i = 0; i < n; i++) {
		cin >> A[i];
		A[i]--;
	}
	std::vector<int> cnt(n);
	for (int i = 0; i < n; i++) {
		cnt[A[i]]++;
	}
	ll tot = 0;
	for (int i = 0; i < n; i++) {
		tot += chouse2(cnt[i]);
	}
	for (int i = 0; i < n; i++) {
		ll ans = tot;
		ans -= chouse2(cnt[A[i]]);
		cnt[A[i]]--;
		ans += chouse2(cnt[A[i]]);
		cnt[A[i]]++;
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 4096
a=input().split()
b=input().split()
N=int(a[0])
K=int(a[1])
c=[]
s=0

for i in range(N):
 l=int(b[i])
 c.append(l)
c.sort(reverse=True)
for i in range(K):
 s +=c[i]
print(s)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
long long F(long long A, long long B){
    long long X = max(A,B);
    int count = 0;
    while(X > 0){
        count++;
        X /= 10;
    }
    return count;
}

int main() {
    long long N;
    cin >> N;
    int minimum = F(N, 1);
    for(int i = 1; i <= sqrt(N); i++){
        if(N % i == 0 && F(i, N/i) < minimum){
            minimum = F(i, N/i);
        }
    }

    cout << minimum << endl;
    return 0;
}


Measured memory_bytes: 256
//桁DPを考えるが, 桁数制限がないので最短経路問題にできる。
#include <iostream>
#include <algorithm>
#include <functional>
#include <queue>
#include <vector>
using namespace std;
typedef pair<int, int> P;

struct Edge {
	int from, to, cost;
	Edge(int from, int to, int cost) {
		this->from = from;
		this->to = to;
		this->cost = cost;
	}
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

void dijkstra(Graph &g, int start, int minCost[]) {
	static priority_queue<P, vector<P>, greater<P> > que;	//(cost, vertex), cost昇順で取り出せるようにする
	int i, INF = 1e+9;
	
	for (i = 0; i < g.size(); i++) minCost[i] = INF;
	
	que.push(P(0, start));
	minCost[start] = 0;
	
	while (!que.empty()) {
		P now = que.top(); que.pop();
		int cst = now.first;
		int pos = now.second;
		for (i = 0; i < g[pos].size(); i++) {
			int npos = g[pos][i].to;
			int ncst = cst + g[pos][i].cost;
			if (minCost[npos] > ncst) {
				que.push(P(ncst, npos));
				minCost[npos] = ncst;
			}
		}
	}
}

int k;
Graph g, rev_g;
int minCost[2][100000];

int main() {
	int i, j;
	
	cin >> k;
	g.resize(k);
	rev_g.resize(k);
	
	for (i = 0; i < k; i++) {
		for (j = 0; j < 10; j++) {
			int to = (10 * i + j) % k;
			int cst = j;
			g[i].push_back(Edge(i, to, cst));
			rev_g[to].push_back(Edge(to, i, cst));
		}
	}
	
	dijkstra(g, 0, minCost[0]);
	dijkstra(rev_g, 0, minCost[1]);
	
	int ans = 1e+9;
	for (i = 1; i < k; i++) {
		int loopCost = minCost[0][i] + minCost[1][i];
		ans = min(ans, loopCost);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 50040
#include <iostream>
#include <algorithm>
#include <cmath>
#include <queue>
#include <utility>
#include <map>
#include <climits>
#include <vector>
#include <set>
#include <string>
#include <numeric>

#define FAST_IO ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr)
#define flood(arr, char, size) for (int i=0; i<size; i++) arr[i] = char
//#define int long long
using namespace std;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<pair<int, int>> vii;
const int N = 1e5 + 2;
const int INF = 1e9 + 5;
const int MOD = 1e9 + 7;

int32_t main() {
    FAST_IO;
    set<char> unique;
    string s;
    cin >> s;
    int l = s.size();
    for (int i = 0; i < l; i++) {
        unique.insert(s[i]);
    }
    cout << (unique.size() == l ? "yes" : "no");
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a) for(int i = 0; i < (a); i++)
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const int MOD = 1e9 + 7;

int main(){
	int n,k;
	cin >> n >> k;
	string s;
	cin >> s;
	if(s[k - 1] == 'A') s[k - 1] = 'a';
	if(s[k - 1] == 'B') s[k - 1] = 'b';
	if(s[k - 1] == 'C') s[k - 1] = 'c';
	cout << s << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef pair<string, int>pii;
bool cmp(pii A, pii B) {
    if(A.second == B.second)
        return A.first < B.first;
    return A.second > B.second;
}
int main()
{
    map<string, int> mmp;
    int n;
    string str;
    cin >> n;
    for(int i = 0; i < n; ++i) {
        cin >> str;
        ++mmp[str];
    } 
    vector<pii>vec(mmp.begin(), mmp.end());
    sort(vec.begin(), vec.end(), cmp);
    int maxv = vec[0].second;
    for(int i = 0; i < n; ++i) {
        if(vec[i].second == maxv)
            cout << vec[i].first << endl;
        else
            break;
    }
    return 0;
}

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

using namespace std;

void printVector(vector<int> A) {
  for (int i = 0; i < A.size() - 1; ++i) {
    cout << A[i] << " ";
  }
  cout << A.back() << endl;
}

vector<int> insertionSort(vector<int> A) {
  for (int i = 1; i < A.size(); ++i) {
    int v = A[i];
    int j = i - 1;
    while (j >= 0 && A[j] > v) {
      A[j + 1] = A[j];
      --j;
    }
    A[j + 1] = v;
    printVector(A);
  }
  return A;
}

int main() {
  int N;
  cin >> N;
  vector<int> A;
  int a;
  while(cin >> a) {
    A.push_back(a);
  }
  printVector(A);
  insertionSort(A);
}


Measured memory_bytes: 3116
#define LOCAL
#define _USE_MATH_DEFINES
#include <array>
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>
#include <functional>
#include <random>
#include <ctime>

using namespace std;

template <typename A, typename B>
ostream& operator <<(ostream& out, const pair<A, B>& a) {
  out << "(" << a.first << "," << a.second << ")";
  return out;
}
template <typename T, size_t N>
ostream& operator <<(ostream& out, const array<T, N>& a) {
  out << "["; bool first = true;
  for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
  return out;
}
template <typename T>
ostream& operator <<(ostream& out, const vector<T>& a) {
  out << "["; bool first = true;
  for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
  return out;
}
template <typename T, class Cmp>
ostream& operator <<(ostream& out, const set<T, Cmp>& a) {
  out << "{"; bool first = true;
  for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "}";
  return out;
}
template <typename U, typename T, class Cmp>
ostream& operator <<(ostream& out, const map<U, T, Cmp>& a) {
  out << "{"; bool first = true;
  for (auto& p : a) { out << (first ? "" : ", "); out << p.first << ":" << p.second; first = 0;} out << "}";
  return out;
}
#ifdef LOCAL
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
#else
#define trace(...) 42
#endif
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}

typedef long long int64;
typedef pair<int, int> ii;
const int INF = 1 << 29;
const int MOD = 1e9 + 7;
mt19937 mrand(random_device{}());
int rnd(int x) { return mrand() % x; }

struct fast_ios {
  fast_ios() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
  };
} fast_ios_;

int main() {
  int n;
  cin >> n;
  double x = n * 1.0 / 3;
  cout << x * x * x << endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.*;
import java.io.*;

public class Main {

  void solve(InputReader in, PrintWriter out) {
    out.println(solve(in.nextLong()));
  }

  public long solve(long n) {
    if (n == 1) return 1;
    return 1 + 2 * solve(n >> 1);
  }

  public static void main(String[] args) throws Exception {
    InputReader in = new InputReader(System.in);
    PrintWriter out = new PrintWriter(System.out);
    Main solver = new Main();
    solver.solve(in, out);
    out.close();
  }

  static class InputReader {
    BufferedReader in;
    StringTokenizer st;

    public InputReader(InputStream is) {
      in = new BufferedReader(new InputStreamReader(is));
    }

    public String next() {
      try {
        while (st == null || !st.hasMoreTokens()) {
          st = new StringTokenizer(in.readLine());
        }
        return st.nextToken();
      } catch (Exception e) {
        throw new RuntimeException(e);
      }
    }

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

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


Measured memory_bytes: 21204
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		String s = scan.next();
		scan.close();

		String s_check[] = {"Sunny","Cloudy","Rainy"};
		for(int i=0;i<s_check.length;i++) {
			if(s_check[i].equals(s)) {
				if(i==s_check.length-1)System.out.println(s_check[0]);
				else System.out.println(s_check[i+1]);
			}
		}
	}

}

Measured memory_bytes: 21332
/* Great things never come from comfort zones,
"whatever the mind of a man can conceive and believe,it can achieve." */
 
#include <bits/stdc++.h>
#define ll long long
#define scf(n) scanf("%d",&n)
#define lscf(n) scanf("%lld",&n)
#define lpri(n) printf("%lld ",n)
#define pri(n) printf("%d ",(int)n)
#define prin(n) printf("%d\n",(int)n)
#define lprin(n) printf("%lld\n",n)
#define rep(i,ini,n) for(ll i=ini;i<(int)n;i++)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x)     x.begin(),x.end()
#define tc   int tt; scf(tt); while(tt--)
#define inf INT_MAX
#define ninf INT_MIN
#define gcd __gcd
#define bitcount(n) __builtin_popcount(n)
typedef double dd;
using namespace std;
const ll mod =1e9+7;
const int N = 1e8+7;


void my_dbg() { cout << endl; }
template<typename Arg, typename... Args> void my_dbg(Arg A, Args... B) 
{ cout << ' ' << A; my_dbg(B...); }
#define dbg(...) cout << "(" << #__VA_ARGS__ << "):", my_dbg(__VA_ARGS__)
 
  
int main()
{
    int n;
    scf(n);
    
    map<int,int>m;
    
    ll sum=0;
    
    int a[n];
    
    rep(i,0,n)
    {
        scf(a[i]);
        
        m[a[i]]++;
        
        sum+=a[i];
        
    }
      
    int q;
    scf(q);
    
    while(q--)
    {
        int b,c;
    
        scf(b),scf(c);
        
        m[c]+=m[b];
        
        sum-=(1LL*m[b]*b);
        
        sum+=(1LL*m[b]*c);
        
        m[b]=0;
        
        lprin(sum);
        
    }
}

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

string B[101];
int main(){
	int cnt,h,w;
	cin >> h >> w;
	vector<string> s(h);
	for(int i=0;i<h;i++)
		cin >> s.at(i);
	for(int y=0;y<h;y++)
		for(int x=0;x<w;x++)
			if(s.at(y).at(x)=='#'){
				cnt = 0;
				for(int dx=-1;dx<2;dx++)
					for(int dy=-1;dy<2;dy++){
						if(abs(dx)==abs(dy))
							continue;
						int xx = x + dx;
						int yy = y + dy;
						if(0<=xx&&xx<w&&0<=yy&&yy<h)
							if(s.at(yy).at(xx)=='.')
								cnt++;
					}
				if(cnt==4){
					cout<<"No"<<endl;
					goto OUT;
				}
			}
	cout<<"Yes"<<endl;
	OUT:;
}

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

signed main(){
	string a,b,c;
	
	cin>>a>>b>>c;
	
	cout<<"A"<<b[0]<<"C"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <complex>
#include <stack>
#include <queue>
#include <list>
#include <utility>
#include <map>
#include <set>
using namespace std;

int prime(int n){
    int flag = 1;
    int i;
    
    for(i = 2; i <= sqrt(n); i++){
        if(n%i == 0){
            flag = 0;
        }
    }
    
    return flag;
}

int main(){
    int count = 0;
    int i = 0;
    int a;
    int n;
    cin >> n;
    
    for(i = 0; i < n; i++){
        cin >> a;
        if(prime(a)){
            count++;
        }
    }
    
    cout << count << endl;
}


Measured memory_bytes: 3060
#include <stdio.h>

int main()
{
	int n,m;
	scanf("%d %d", &n, &m);
	int left_max = 1;
	int right_min = 100000;
	int tmp_left, tmp_right;
	for ( int i = 0; i < m; i++ ) {
		scanf("%d %d", &tmp_left, &tmp_right);
		if ( tmp_left > left_max ) left_max = tmp_left;
		if ( tmp_right < right_min ) right_min = tmp_right;
	}
	int count = 0;
	for ( int i = 1; i <= n; i++ ) {
		if ( ( i >= left_max ) && ( i <= right_min ) ) count++;
	}
	printf("%d\n", count);
	return 0;
}

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

int main(){
    int N;
    cin >> N;
    vector<int>vec(N);
    vector<int>copy(N);
    for(int i=0;i<N;i++){
        cin  >>vec[i];
    }
    for(int i=0;i<N;i++){
        copy[i] =vec[i];
    }
    sort(vec.rbegin(),vec.rend());
    if(vec[0]==vec[1]){
        for(int i=0;i<N;i++){
            cout <<vec[0] <<endl;
        }
    }
    else{
        int max=0;
        for(int i=0;i<N;i++){
            if(copy[i] == vec[0]){
                cout <<vec[1] << endl;
            }
            else{
                cout <<vec[0] <<endl;
            }
        }


    }
}

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

#define MAXN (100010)
#define ll long long

int n, a, b;
ll h[MAXN];
ll t[MAXN];

bool check(ll m){
	for(int i = 1; i <= n; ++ i){
		t[i] = h[i] - 1ll * m * b;
	}
	for(int i = 1; i <= n; ++ i){
		if(t[i] > 0){
			m -= (t[i] + a - b - 1) / (a - b);
		}
	}
	return m >= 0;
}

int main(){
	scanf("%d%d%d", &n, &a, &b);
	for(int i = 1; i <= n; ++ i){
		scanf("%lld", h + i);
	}
	
	ll left = 1, right = 1e9, ans = 1;
	while(left <= right){
		ll mid = left + right >> 1;
		if(check(mid)){
			right = mid - 1;
			ans = mid;
		}
		else{
			left = mid + 1;
		}
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
#define rep(i,m,n) for(int (i)=(m);(i)<(n);++(i))
#define rREP(i,m,n) for(int (i)=(n)-1;(i)>=(m);--(i))
#define all(x) (x).begin(),(x).end()
#define out(y,x,h,w) (y)<0||(x)<0||(y)>=(h)||(x)>=(w)
constexpr int INF = 1000000001;
constexpr ll mod = 1000000007;
constexpr double PI = 3.1415926535897932;
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;
}
inline void init() {
	cin.tie(nullptr); cout.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}

vector<bool>visit;
void dfs(int k,Graph G) {
	visit[k] = true;
	for (auto v : G[k]) {
		if (visit[v])continue;
		dfs(v, G);
	}
	return;
}
int main() {
	init();

	int N, M; cin >> N >> M;
	Graph G(N);
	rep(i, 0, M) {
		int a, b; cin >> a >> b;
		--a; --b;
		G[a].push_back(b);
		G[b].push_back(a);
	}
	int ans = 0;
	rep(i, 0, N) {
		rep(j, 0, G[i].size()) {
			Graph a = G;
			a[i].erase(a[i].begin() + j);
			vector<bool>vc(N, false);
			visit = vc;
			dfs(0, a);
			rep(k, 0, N) {
				if (!visit[k]) {
					ans++;
					break;
				}
			}
		}
	}
	cout << ans << "\n";


	return 0;
}

Measured memory_bytes: 384
#include<stdio.h>
int main(void)
{
    int a;
    int b;
    
    scanf("%d %d", &a, &b);
    if(a <= 1000 && a > -1000 && b <= 1000 && b > -1000)
    {
        if(a < b)
        {
            printf("a < b\n");
        }
        else if(a > b)
        {
            printf("a > b\n");
        }
        else if(a == b)
        {
            printf("a == b\n");
        }
    }
}


Measured memory_bytes: 2076
#include"bits/stdc++.h"
using namespace std;

using ll = long long;

void Main()
{
    ll a,b;
    std::cin >>  a >> b;

    ll start = b * 10;
    ll end = start + 10;
    for (ll i = start; i < end; i++)
    {
        int r = floor(i * 0.08);

        if (r == a)
        {
            cout << i;
            return;
        }
    }

    cout << -1;
}

int main()
{
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(15);
    Main();
}

Measured memory_bytes: 256
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;
import java.math.*;

class Main{
	 public static void main(String[] args){
		 Scanner scan = new Scanner(System.in);
		 double y = 0.0;
		double x = 0.0;
		 int angle = 0;
		 while(true){
			String[] ak = scan.next().split(",");
			int a = Integer.parseInt(ak[0]);
			int b = Integer.parseInt(ak[1]);
			if(a == 0 && b == 0){
				break;
			}
			
			x = x+ a * Math.sin(Math.toRadians(angle));
			y = y+ a* Math.cos(Math.toRadians(angle));
			
			angle = angle + b;
			
		 }
			System.out.println((int)x);
			System.out.println((int)y);
	 }
}

Measured memory_bytes: 26228
/*
    Author:zeke
    
    pass System Test!
    GET AC!!
*/
#include <iostream>
#include <queue>
#include <vector>
#include <iostream>
#include <vector>
#include <string>
#include <cassert>
#include <algorithm>
#include <functional>
#include <cmath>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <map>
#include <iomanip>
#include <utility>
#include <stack>
using ll = long long;
using ld = long double;
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define rep3(var, min, max) for (ll (var) = (min); (var) < (max); ++(var))
#define repi3(var, min, max) for (ll (var) = (max) - 1; (var) + 1 > (min); --(var))
#define Mp(a,b) make_pair((a),(b))
#define F first
#define S second
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef vector<V> VV;
typedef vector<P> VP;
ll MOD = 1e9 + 7;
ll INF =1e18;
int main(){
   ll n,a;
   cin>>n>>a;
//   cout<<n<<endl;
   ll dp[n+1][5000][n+1];
   
   rep(i,n+1)rep(j,5000)rep(k,n+1)dp[i][j][k]=0;
   
   dp[0][0][0]=1;
   
   rep(i,n){
      ll x;cin>>x;
      //cout<<x<<endl;
      rep(j,2500){
         // cout<<i<<endl;
         rep(k,n){
            // cout<<i+1<<" "<<j+x<<" "<<k+1<<endl;
            dp[i+1][j+x][k+1]+=dp[i][j][k];
            dp[i+1][j][k]+=dp[i][j][k];
         }
      }
   }
   ll res=0;
   rep3(i,1,n+1){
     // cout<<i<<" "<<dp[n][i*a][i]<<endl;
      res+=dp[n][i*a][i];
   }
   cout<<res<<endl;
}

Measured memory_bytes: 101888
S = gets.chomp

counter = Hash.new(0)

S.each_char do |s|
  counter[s] += 1
end

cond1 = (counter['S'] > 0 && counter['N'] > 0) || (counter['S'] == 0 && counter['N'] == 0)
cond2 = (counter['E'] > 0 && counter['W'] > 0) || (counter['E'] == 0 && counter['W'] == 0)

if cond1 && cond2
  puts 'Yes'
else
  puts 'No'
end


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

int main(){
  int k;
  cin>>k;
  string s;
  cin>>s;
  int len = s.length();

  if(len<=k)cout<<s;
  else{
    rep(i,k){
      cout<<s[i];
    }  
    cout<<"...";
  }
  return 0;
}

Measured memory_bytes: 3624
#include<iostream>

using namespace std;

int main(){
    while(1){
        int H,W;
        cin >> H >> W;
        if(H == 0&&W == 0)break;
        for(int i=0;i<H;i++){
            for(int j=0;j<W;j++){
                if((i+j)%2==0){
                    cout << "#";
                }else{
                    cout << ".";
                }
            }
            cout << endl;
        }
        cout << endl;
    }
    return 0;
}


Measured memory_bytes: 3116
package main

import "fmt"

func main() {
	var num int
	fmt.Scan(&num)

	var count int
	for num > 9 {
		if num%10 == 2 {
			count++
		}
		num /= 10
	}
	if num == 2 {
		count++
	}
	fmt.Println(count)
}


Measured memory_bytes: 512
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
printV = lambda x: print(*x, sep="\n")
printH = lambda x: print(" ".join(map(str,x)))
def IS(): return sys.stdin.readline()[:-1]
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LI1(): return list(map(int1, sys.stdin.readline().split()))
def LII(rows_number): return [II() for _ in range(rows_number)]
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def LLI1(rows_number): return [LI1() for _ in range(rows_number)]

def main():
	k,n = MI()
	a = LI()
	b = [0]*n
	for i in range(n):
		if i == n-1:
			b[i] = a[0]+k-a[i]
		else:
			b[i] = a[i+1]-a[i]
	b.sort()
	print(k-b[-1])


if __name__ == '__main__':
	main()

Measured memory_bytes: 25692
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
const int mod = 1000000007;
struct mint {
	ll x; // typedef long long ll;
	mint(ll x=0):x((x%mod+mod)%mod){}
	mint operator-() const { return mint(-x);}
	mint& operator+=(const mint a) {
		if ((x += a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator-=(const mint a) {
		if ((x += mod-a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator*=(const mint a) {
		(x *= a.x) %= mod;
		return *this;
	}
	mint operator+(const mint a) const {
		mint res(*this);
		return res+=a;
	}
	mint operator-(const mint a) const {
		mint res(*this);
		return res-=a;
	}
	mint operator*(const mint a) const {
		mint res(*this);
		return res*=a;
	}
	mint pow(ll t) const {
		if (!t) return 1;
		mint a = pow(t>>1);
		a *= a;
		if (t&1) a *= *this;
		return a;
	}
	
	// for prime mod
	mint inv() const {
		return pow(mod-2);
	}
	mint& operator/=(const mint a) {
		return (*this) *= a.inv();
	}
	mint operator/(const mint a) const {
		mint res(*this);
		return res/=a;
	}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}
int main() {
	string l;
	cin >> l;
	int n = l.size();
	vector<vector<mint>> dp(n+1, vector<mint>(2));
	dp[0][0] = 2;
	dp[0][1] = 1;
	rep(i, n) {
		if(i == 0) continue;
		if(l[i] == '0') {
			dp[i][0] += dp[i-1][0];
			dp[i][1] += dp[i-1][1] * 3;
		} else {
			dp[i][0] += dp[i-1][0] * 2;
			dp[i][1] += dp[i-1][1] * 3 + dp[i-1][0];
		}
	}
	mint ans = dp[n-1][0] + dp[n-1][1];
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 5760
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> l_l;
const int INF=1001001000;
const int mINF=-1001001000;
const ll LINF=1010010010010010000;
int main(){
    ll n,a,b;cin >> n >> a >> b;
    ll cnt=n/(a+b);
    ll rem=n-cnt*(a+b);
    ll ans=cnt*a;
    if(rem>a) ans+=a;
    else if(rem<=a) ans+=rem;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.*;
class Main {
  static Scanner scan = new Scanner(System.in);
  public static void main(String[] args) {
  	char c = scan.next().charAt(0);
    if(c >= 'A' && c <= 'Z'){
    	System.out.println("A");   
    }else if (c >= 'a' && c <= 'z'){
    	System.out.println("a");
    }
  }
}

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

#define REP(i,s,n) for(int i=s;i<n;++i)
#define rep(i,n) REP(i,0,n)

using namespace std;

typedef pair<int,int> ii;

int h[6],w[6];

bool check(map<ii,int> &mp) {
  rep(i,6) {
    if( mp[ii(h[i],w[i])] < 2 ) continue;
    set<int> base;
    for(auto v : mp) if( v.second ) {
	base.insert(v.first.first);
	base.insert(v.first.second);
    }
    for(auto v : base) {
      map<ii,int> mp2;
      mp2[ii(h[i],w[i])] += 2;
      rep(j,2) {
	ii s = ii(h[i],v);
	if( s.first > s.second ) swap(s.first,s.second);
	++mp2[s];
      }
      rep(j,2) {
	ii s = ii(w[i],v);
	if( s.first > s.second ) swap(s.first,s.second);
	++mp2[s];
      }
      if( mp2 == mp ) return true;
    }
  }
  return false;
}

int main() {
  map<ii,int> mp;
  rep(i,6) {
    cin >> h[i] >> w[i];
    if( h[i] > w[i] ) swap(h[i],w[i]);
    ++mp[ii(h[i],w[i])];
  }
  puts(check(mp)?"yes":"no");
  return 0;
}

Measured memory_bytes: 3112
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,n) for(int i=0;i<n;i++)
#define why(n,x) int n;while(cin >>n,n!=x)
#define iFOR(i,x,n)for(int i=x;i<n;i++)
#define unless(flg) if ( !(flg) )
#define read cin<<
#define echo cout<<
#define fin <<'\n'
#define __ <<" "<<
#define ___ <<" "
#define bash push_back
#define ALL(x) x.begin(),x.end()
#define SWAP(a,b) ((a != b) && (a += b,b = a - b,a -= b))
#define cinf(n,x) for(int UNCH=0;UNCH<(n);UNCH++) cin >> x[UNCH];
#define fcin(n,x) for(int UNCH=1;UNCH<=(n);UNCH++) cin>> x[UNCH];
#define memmin(x) memset((x),-1,sizeof((x)))
#define memzer(x) memset((x), 0,sizeof((x)))
#define meminf(x) memset((x),0x3f,sizeof((x)))

typedef long long ll;
typedef pair < int , int >  pii;
typedef vector < int > vit;
typedef map < string , int > mstit;
typedef vector < pii > vpi ;
typedef greater < pii > gpi;
typedef priority_queue < pii , vpi , gpi > dijk ;
static const signed int INF = 0x3f3f3f3f;
static const signed long long LINF = 0x3f3f3f3f3f3f3f3fLL;
static const signed int SMOD = 1000000007;
static const signed int NMOD = 1000000009;
static const signed int dx[]={1,0,-1,0,1,1,-1,-1};
static const signed int dy[]={0,-1,0,1,-1,1,-1,1};

bool inside(int x,int y,int w,int h){return (x>=0 && y>=0 && x<w && y<h);}
template<class T>T abs(T &x){return x<0 ? -x : x;}
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
int qp(int a,ll b,int mo){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a/gcd(a,b)*b;}
//#define int long long

int n, m;
vit edge[100005];
int dp[100005];

void dfs(int i){
    
    if(dp[i]) return;
    for(int j = 0; j < edge[i].size(); j++){
        int v = edge[i][j];
        dfs(v);
        chmax(dp[i],dp[v]+1);
    }
    return ;
}

inline void solve(){
    cin >> n >> m;
    for(int i = 0; i < m; i++) {
        int a, b;
        cin >> a >> b;
        edge[a].bash(b);
    }

    int ans = 0;
    for(int i = 1; i <= n; i++) {
        dfs(i);
        chmax(ans,dp[i]);
    }
    
    cout << ans fin;

}

struct xyz{ xyz(){ cin.tie(0), ios::sync_with_stdio(false); cout <<fixed<<setprecision(12);};}xyzzy;signed main(){solve();return 0;}



Measured memory_bytes: 8192
// package app;

import java.util.Arrays;
import java.util.Scanner;
import java.util.stream.Stream;

public class Main {

    public static void main(final String[] args) throws Exception {
        final Scanner sc = new Scanner(System.in);

        // final String N = sc.next();

        final int x = sc.nextInt();
        final int a = sc.nextInt();
        final int b = sc.nextInt();
        // final int N = sc.nextInt();
        // final int D = sc.nextInt();
        // System.out.println();

        int xa = Math.abs(x - a);
        int xb = Math.abs(x - b);

        System.out.println(xa < xb ? "A" : "B");

        // System.out.println(A <= X && A + B >= X ? "YES" : "NO");

    }
}

Measured memory_bytes: 23892
#include <algorithm>
#include <cassert>
#include <climits>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <vector>
#include <list>

using std::list;
using std::max;
using std::min;
using std::vector;

long long count_two(long long value)
{
  long long cnt = 0;
  while(value % 2 == 0) {
    value = value / 2;
    cnt++;
  }
  return cnt;
}

int main()
{
  int n;
  scanf("%d", &n);
  vector<int> values(n);
  long long cnt = 0;
  for(int i = 0; i < n; i++) {
    long long value;
    scanf("%lld", &value);
    cnt += count_two(value);
  }
  printf("%lld\n", cnt);
  return 0;
}


Measured memory_bytes: 888
#include <stdio.h>
#define N 250

typedef struct{
  int parent,left,right;
}node;


node H[N];

int main(){
  int i,k,s[N],n;

  scanf("%d",&n);
  for(i=1;i<=n;i++){
    scanf("%d",&s[i]);
  }

  for(i=1;i<=n;i++){
    printf("node %d: key = %d, ",i,s[i]);

    if(i/2 > 0){
      H[i].parent = s[i/2];
      printf("parent key = %d, ",H[i].parent);
    }
    if(2*i <= n){
      H[i].left = s[2*i];
      printf("left key = %d, ",H[i].left);
    }
    if(2*i+1 <= n){
      H[i].right = s[2*i+1];
      printf("right key = %d, ",H[i].right); 
    }
    printf("\n");
  }
  return 0;
}

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

using namespace std; 

int n; 
int x[101010], y[101010], vis[101010], vv[101010], dis[101010], maxdis, num, deg[101010]; 
char c[101010]; 
vector <int> G[101010], H[101010];
int d[101010], Q[101010]; 

void del() {    
    int h = 1, t = 0;
    for (int i = 1; i <= n; i++) {
        if (deg[i] == 1 && c[i] == 'B') {
            Q[++t] = i; 
        }
    } 
    while (h <= t) {
        int u = Q[h++];
        vis[u] = 1;  
        for (auto v : G[u]) {
            deg[v]--; 
            if (deg[v] == 1 && c[v] == 'B') {
                Q[++t] = v; 
            }
        }
    }
    memset(deg, 0, sizeof(deg)); 
    for (int i = 1; i <= n; i++) {
        G[i].clear(); 
    }
    for (int i = 1; i < n; i++) {
        if (!vis[x[i]] && !vis[y[i]]) {
            G[x[i]].push_back(y[i]); 
            G[y[i]].push_back(x[i]); 
            deg[x[i]]++; 
            deg[y[i]]++; 
            num += 2; 
        }
    }
    for (int i = 1; i <= n; i++) {
        if (!vis[i]) {
            if ((c[i] == 'B' && deg[i] & 1) or (c[i] == 'W' && deg[i] % 2 == 0)) {
                vv[i] = 2; 
                num++; 
            }
        }
    }
}

void dfs(int u, int pre) {
    dis[u] = vv[u]; 
    for (auto v : G[u]) {
        if (v == pre) continue ;
        dfs(v, u);  
        maxdis = max(maxdis, dis[u] + dis[v]);
        dis[u] = max(dis[u], dis[v] + vv[u]); 
    }
}

int main() {
    scanf("%d", &n);
    for (int i = 1; i < n; i++) {
        int u, v; 
        scanf("%d %d", &u, &v);
        x[i] = u, y[i] = v;  
        G[u].push_back(v); 
        G[v].push_back(u); 
        deg[u]++, deg[v]++; 
    }
    scanf("%s", c + 1); 
    del(); 
    for (int i = 1; i <= n; i++) {
        if (!vis[i]) {
            dfs(i, 0); 
            break ; 
        }
    }
    printf("%d\n", num - maxdis); 
    return 0; 
} 

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

#define REP(i,s,n) for(int i=s;i<n;++i)
#define rep(i,n) REP(i,0,n)
#define ALL(x) x.begin(),x.end()
#define EPS (1e-8)
#define equals(a,b) (fabs((a)-(b))<EPS)

using namespace std;

typedef long long ll;

inline bool LT(double a,double b) { return !equals(a,b) && b < b; }
inline bool LTE(double a,double b) { return equals(a,b) || b < b; }

int dp[200010][3];

int main() {
  string s;
  cin >> s;
  int n = s.size();
  memset(dp,-1,sizeof dp);
  dp[0][0] = 0;
  rep(i,n) {
    rep(j,3) {
      if( dp[i][j] == -1 ) continue;
      REP(use,1,3) {
	int nex = i + use;
	if( nex > n ) continue;
	if( j == use && s.substr(i,use) == s.substr(i-j,j) ) {
	  continue;
	} else {
	  dp[nex][use] = max(dp[nex][use],dp[i][j]+1);
	}
      }
    }
  }
  int maxi = 0;
  rep(i,3) maxi = max(maxi,dp[n][i]);
  cout << maxi << endl;
  return 0;
}


Measured memory_bytes: 2948
#include <string.h>
#include <stdio.h>

char map[10][8] = { "0111111", "0000110", "1011011", "1001111", "1100110",
		    "1101101", "1111101", "0100111", "1111111", "1101111" };

int main(){
  int n, m, f = 0,i;
  char res[8];

  while(scanf("%d", &n) && n != -1){
    f = 0;
    while(n--){
      scanf("%d", &m);
      if(f){
	for(i = 0; i < 7; i++){
	  if(res[i] == map[m][i]) res[i] = '0';
	  else res[i] = '1';
	}
      }
      else strcpy(res, map[m]);
      f = 1;
      puts(res);
      strcpy(res, map[m]);
    }
  }
  return 0;
}

Measured memory_bytes: 592
#[allow(unused_macros)]
macro_rules! p {
    ($x:expr $(, $tail:expr)*) => {
        let mut s = String::new();
        s.push_str(format!("{:?}", $x).as_str());
        $(
            s.push_str(format!(", {:?}", $tail).as_str());
        )*
        println!("{}", s);
    };
}

#[allow(unused_macros)]
macro_rules! pl {
    ($($x:expr), *) => {
        $(println!("{:?}", $x);)*
    };
}

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! stdin {
    () => {{
        use std::io::Read;
        let mut s = String::new();
        std::io::stdin().read_to_string(&mut s).unwrap();
        s
    }};
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    println!("{}", solve(stdin!()));
}

fn solve(src: String) -> String {
    input! {
        source = src,
        n: usize,
        a: usize,
        b: usize,
        c: usize,
        d: usize,
        e: usize,
    }
    let vec = vec![a,b,c,d,e];
    let min = vec.iter().min().unwrap();
    let partial_ans = (n + (min - 1)) / min;
    let ans = partial_ans + 4;
    ans.to_string()
}

// Test Code

macro_rules! test {
    ($($input:expr => $output:expr),* $(,)*) => {
        #[test]
        fn solve_test() {
            $(
                assert_eq!(solve($input.to_string()), $output);
            )*
        }
    };
}

test! {
r"5
3
2
4
3
5
" => "7",
r"10
123
123
123
123
123
" => "5",
r"10000000007
2
3
5
7
11
" => "5000000008",
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define clr(a,b) memset(a,b,sizeof(a))
#define all(v) ((v).begin()),((v).end())
double const EPS = 1e-8, PI = acos(-1);
const int N = 1e5 + 9, OO = 1e9;

int arr[26];

int main() {
  string str;
  cin >> str;
  int can = 0;
  map<char, int> mp;
  for (int i = 0; i < 4; ++i) {
    mp[str[i]]++;
  }
  for(auto it: mp) {
    if(it.second == 2)
      ++can;

  }
  if (can == 2)
    cout << "Yes\n";
  else
    cout << "No\n";
  return 0;
}


Measured memory_bytes: 256
N = int(input())
A = [int(i) for i in input().split()]
B = [0] * N
list_B = [0] * N

for i in range(N)[::-1]:
  if A[i] != (sum(B[i::i+1]) % 2):
    B[i] = 1
    list_B[i] = i + 1

print(int(sum(B)))
list_B = ' '.join([str(a) for a in [i for i in list_B if i != 0]])
print(list_B)


Measured memory_bytes: 76636
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <ctime>
#include <cassert>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>
#include <list>


using namespace std;

#ifdef _MSC_VER
#define __typeof__ decltype
template <class T> int __builtin_popcount(T n) { return n ? 1 + __builtin_popcount(n & (n - 1)) : 0; }
#endif

#define foreach(it, c) for (__typeof__((c).begin()) it=(c).begin(); it != (c).end(); ++it)
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define CLEAR(arr, val) memset(arr, val, sizeof(arr))

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

template <class T> void max_swap(T& a, const T& b) { a = max(a, b); }
template <class T> void min_swap(T& a, const T& b) { a = min(a, b); }

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

const double EPS = 1e-8;
const double PI = acos(-1.0);
const int dx[] = { 0, 1, 0, -1 };
const int dy[] = { 1, 0, -1, 0 };
bool valid_pos(int x, int y, int w, int h) { return 0 <= x && x < w && 0 <= y && y < h; }


int calc_required_level_to_rooms(int* res)
{
	int w, h, sx, sy;
	static int req[512][512];
	scanf("%d%d%d%d", &w, &h, &sx, &sy);
	--sx, --sy;
	for (int y = 0; y < h; ++y)
		for (int x = 0; x < w; ++x)
			scanf("%d", &req[y][x]);

	static bool visit[512][512];
	for (int y = 0; y < h; ++y)
		for (int x = 0; x < w; ++x)
			visit[y][x] = false;

	int c = 0;
	res[c++] = 0;

	typedef pair<int, pint> P;
	priority_queue<P, vector<P>, greater<P> > q;
	q.push(P(1, pint(sx, sy)));
	while (c <= w * h)
	{
		P tt = q.top(); q.pop();
		int level = tt.first;
		int x = tt.second.first, y = tt.second.second;
		if (visit[y][x])
			continue;

		visit[y][x] = true;
		res[c++] = level;

		for (int i = 0; i < 4; ++i)
		{
			int tx = x + dx[i], ty = y + dy[i];
			if (valid_pos(tx, ty, w, h) && !visit[ty][tx])
				q.push(P(max(level, req[ty][tx]), pint(tx, ty)));
		}
	}
	return w * h;
}
int main()
{
	int r;
	while (scanf("%d", &r), r)
	{
		static int a[512 * 512], b[512 * 512];
		int a_size = calc_required_level_to_rooms(a);
		int b_size = calc_required_level_to_rooms(b);

		int res = 1e9;
		for (int i = min<int>(r, a_size); i >= 0 && r - i <= b_size; --i)
			min_swap(res, a[i] + b[r - i]);
		printf("%d\n", res);
	}
}

Measured memory_bytes: 0
/*
* Author. Silviase(@silviasetitech)
* For AtCoder
*/

import java.util.*;

import java.lang.*;
import java.math.*;

public class Main {

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

        int n = sc.nextInt();
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        int[] take = new int[n];
        int makeper = 0;
        int tmpcost  = 0;
        int cost = Integer.MAX_VALUE;
        int atake = 0;
        int btake = 0;
        int ctake = 0;
        int counta =0;
        int countb =0;
        int countc =0;

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

        for (int i = 0; i < Math.pow(4, n); i++) {
            String base4 = Integer.toString(makeper,4);
            
            while (base4.length() < n) {
                base4 = "0"+base4;
            }
                for (int j = 0; j < n; j++) {
                    if (base4.charAt(j) == '0'){

                    } else if (base4.charAt(j) == '1') {
                        atake += take[j];
                        counta++;
                    } else if (base4.charAt(j) == '2') {
                        btake += take[j];
                        countb++;
                    } else {
                        ctake += take[j];
                        countc++;
                    }
                }
                if(atake != 0 && btake != 0 && ctake != 0){
                    tmpcost += 10 * (counta + countb + countc -3);
                    tmpcost += Math.abs(atake - a) + Math.abs(btake - b) + Math.abs(ctake - c);
                    if (tmpcost < cost) {
                        cost = tmpcost;
                    }
                }
                tmpcost = 0;
                makeper++;
                counta = 0;
                countb = 0;
                countc = 0;
                atake = 0;
                btake = 0;
                ctake = 0;
        }

        System.out.println(cost);

        sc.close();
    }
    
    private static long gcd(Long m, long n) {
        if(m < n) {
            return gcd(n, m);
        }
        if(n == 0){
            return m;
        } 
        return gcd(n, m % n);
    }

    private static long[][] Combination_nCk(long n, long k) {
        n++; k++;
        long[][] ans = new long[(int)n][(int)k];
        for (int i = 0; i < n; i++) {
            ans[i][0] = 1;
        }
        for (int i = 0; i < n-1; i++) {
            for (int j = 0; j < k-1; j++) {
                if (i < j) {
                    ans[i][j] = 0;
                }else{
                    ans[i+1][j+1] = ans[i][j] + ans[i][j+1];
                }
            }
        }
        return ans;
    }
}

Measured memory_bytes: 35988
l = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
print(l[int(input())-1])


Measured memory_bytes: 2940
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define P pair<int,int>
using ll=int64_t;
using namespace std;
#define ketasuu(n) fixed<<setprecision(n)
#define btoe(p) p.begin(),p.end()
#define etob(p) p.rbegin(),p.rend()




int main(){
    int n,q, cnt=0;
    string s;
    cin>>n>>q>>s;
    vector<int> p(n,0),ans;
    rep(i,n-1){
        if(s[i]=='A' && s[i+1]=='C'){
            cnt++;
        }
        p[i+1]=cnt;
    }
    rep(i,q){
        int l,r;
        cin>>l>>r;
        int a=0;
        a=p[r-1]-p[l-1];
        ans.push_back(a);
    }
    rep(i,q) cout<<ans[i]<<endl;
    return 0;
}

Measured memory_bytes: 1912
#include<iostream>
#include<string>
#include<vector>
#include<stdio.h>
#include<algorithm>
#include<stdlib.h>
#define _USE_MATH_DEFINES
#include<math.h>
#include<numeric>
#include<iomanip>

using namespace std;

int main() {
	int n; cin >> n;
	unsigned long long int c = pow(10, 9) + 7;
	unsigned long long ans = 1;
	for (int i = 1; i <= n; i++) {
		ans = ans * i%c;
	}
	cout << ans << endl;
}







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

using namespace std;

int A, B, C;

int main()
{
	scanf("%d %d %d",&A,&B,&C);

	if( A == B && A == C )
	{
		if( A%2 == 1 ) printf("0\n");
		else printf("-1\n");

		return 0;
	}

	int ans = 0;

	while( true )
	{
		if( A%2 == 1 || B%2 == 1 || C%2 == 1 )
		{
			printf("%d\n",ans);
			return 0;
		}
		
		ans++;

		int aux[3] = { (B + C)/2 , (A + C)/2 , (A + B)/2 };

		A = aux[0];
		B = aux[1];
		C = aux[2];
	}
}

Measured memory_bytes: 256
#!/usr/bin/env python3

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

s = input()
day = ['SUN', 'MON', 'TUE', 'WED', 'THU', 'FRI', 'SAT']
print(7 - day.index(s))

Measured memory_bytes: 83776
#include"bits/stdc++.h"

using namespace std;

#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;

void Main()
{
	while(1){
			int h, w;
		cin >> h >> w;
		if(h == 0 && w == 0){
			break;
		}
		bool flagh = true;
		bool flagw = true;
		rep(i, h){
			rep(j, w){
				if(i % 2 == 0){
					if(j % 2 == 0){
						cout << '#';
					}else{
						cout << '.';
					}
				}else{
					if(j % 2 == 0){
						cout << '.';
					}else{
						cout << '#';
					}
				}
			}
			cout << endl;
		}
		cout << endl;
	}
}

int main()
{
	std::cin.tie(nullptr);
	std::ios_base::sync_with_stdio(false);
	std::cout << std::fixed << std::setprecision(15);
	Main();
	return 0;
}



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

int main() {
  int a, b;
  cin >> a >> b;

  if (a % 3 == 0 || b % 3 == 0 || (a+b) % 3 == 0) {
    cout << "Possible" << endl;
  } else {
    cout << "Impossible" << endl;
  }
}

Measured memory_bytes: 3620
#include<iostream>
#include<stdio.h>

using namespace std;

int main(){

	int a, b, c;
	cin >> a >> b >> c;
	
	if (a > b){
		swap(a, b);
	}
	if (b > c){
		swap(b, c);
	}
	if (a > b){
		swap(a, b);
	}
	cout << a << " " << b << " " << c << endl;
	return 0;
}


Measured memory_bytes: 3112
#include<cstdio>
using namespace std;
int n, a, b, p;
int ans[1001010];
int x, y, r;
int cal(int x, int y){
    return (x+y-1) / y;
}
int main(){
    scanf("%d%d%d", &n, &a, &b);
    if(a == 1 && b != n){
        printf("-1");
        return 0;
    }
    if(b == 1 && a != n){
        printf("-1");
        return 0;
    }
    if(a == 1){
        for(int i = n; i >= 1; i --)
            printf("%d ", i);
        return 0;
    }
    if(b == 1){
        for(int i = 1; i <= n; i ++)
            printf("%d ", i);
        return 0;
    }
    if(a+b > n+1){
        printf("-1");
        return 0;
    }
    if(cal(n-a, b-1) > a){
        printf("-1");
        return 0;
    }
    int cnt = n - a;
    x = (cnt-b+1) / (a-1);
    y = (cnt-b+1) % (a-1);
    int r1, r2 = n - a;
    for(int i = cnt+1; i <= n; i ++){
        ans[++p] = i;
    }
    for(int i = 1; i <= x; i ++){
        r1 = r2 - a + 1;
        for(int j = r1; j <= r2; j ++){
            ans[++p] = j;
        }
        r2 -= a;
    }
    r1 = r2 - y;
    for(int i = r1; i <= r2; i ++)
        ans[++p] = i;
    for(int i = r1 - 1; i >= 0; i --)
        ans[++p] = i;
 
    for(int i = 1; i <= n; i ++)
        printf("%d ", ans[i]);
    return 0;
}

Measured memory_bytes: 3328