akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <string.h>
#include <vector>
#include <queue>

using namespace std;

#define pb push_back
#define mp make_pair
#define ll long long
#define ull unsigned ll
#define db double
#define INF 0x3f3f3f3f
#define MOD 1000000007
#define PII pair<int, int>

const int N=805;
int h,w,k;
char grid[N][N];
int v[N][N];

int foo(int x,int y)
{   int res=INF;
    res=min(res,x);
    res=min(res,h-1-x);
    res=min(res,y);
    res=min(res,w-1-y);
    return (res+k-1)/k;
}

int ans=INF;

struct node
{   int x,y;
};

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

void bfs(int x,int y)
{   queue<node> q;
    q.push({x,y});
    memset(v,INF,sizeof(v));
    v[x][y]=0;
    ans=min(ans,foo(x,y));
    while (!q.empty())
    {   node cur=q.front();
        q.pop();
        for (int i=0; i<4; i++)
        {   int xx=cur.x+d[i][0];
            int yy=cur.y+d[i][1];
            if (xx>=0&&xx<h&&yy>=0&&yy<w&&v[xx][yy]==INF&&grid[xx][yy]!='#')
            {   ans=min(ans,foo(xx,yy));
                v[xx][yy]=v[cur.x][cur.y]+1;
                if (v[xx][yy]<k) q.push({xx,yy});
            }
        }
    }
}

int main()
{   scanf("%d%d%d",&h,&w,&k);
    for (int i=0; i<h; i++)
    {   scanf("%s",grid[i]);
    }
    int sx,sy;
    for (int i=0; i<h; i++)
    {   for (int j=0; j<w; j++)
        {   if (grid[i][j]=='S')
            {   sx=i;
                sy=j;
            }
        }
    }
    bfs(sx,sy);
    printf("%d\n",ans+1);
}

Measured memory_bytes: 3456
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;
using T = tuple<string,int,int>;

int main(){
  int n,d; cin >> n >> d;
  vector<vector<int>> x(n,vector<int>(d));
  for(int i = 0; i < n; i++){
    for(int j = 0; j < d; j++){
      cin >> x[i][j];
    }
  }
  int ans = 0;
  for(int i = 0; i < n; i++){
    for(int j = 0; j < i; j++){
      int sq = 0;
      for(int k = 0; k < d; k++){
        int s = x[i][k]-x[j][k];
        sq += s*s;
      }
      int s = sqrt(sq)+0.5;
      if(s*s == sq) ans++;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
n= int(input())
if n==1:
  print('Yes')
  exit()
h=list(map(int,input().split()))
ans='Yes'
for i in range(n-1):
  if h[i+1]>h[i]:
    h[i+1]-=1
  elif h[i+1]<h[i]:
    print('No')
    exit()
print(ans)

Measured memory_bytes: 20600
function Main(input){
  var N = input.split("\n")[0].split(" ")[0];
  N = parseInt(N,10);
  var M = input.split("\n")[0].split(" ")[1];
  M =parseInt(M,10);
  var a =input.split("\n");
  a.shift();
  var dp = [];
  dp[0] = 1;
  dp[1] = 1;
  for(i=0;i<=(M-1);i++){
    dp[a[i]]= 0;
  }
  for(i=2;i<=N;i++){
    if(dp[i]!==0){
      dp[i] = (dp[i-1] + dp[i-2])%1000000007;
    }else{
      continue;
    }
  }
  console.log(dp[N]);
}     
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 29668
#include<iostream>
#include<string>
using namespace std;
int main(void){
  string a,b,c;
  cin>>a>>b>>c;
  size_t sizeA = a.length();
  size_t sizeB = b.length();
  size_t sizeC = c.length();
  if(a[sizeA-1]==b[0] && b[sizeB-1]==c[0])cout<<"YES"<<endl;
  else cout<<"NO"<<endl;
  return 0;
}

Measured memory_bytes: 256
N = gets.to_i
arr = Array.new(N, 0)

max = Math.sqrt(N).to_i
x, y, z = 1, 1, 1
while z < max do
  n = x ** 2 + y ** 2 + z ** 2 + x * y + y * z + z * x
  if x == y && y == z # 3つとも同じ
    count = 1
  elsif x != y && y != z && z != x # 3つとも異なる
    count = 6
  else
    count = 3
  end
  
  arr[n - 1] += count if n <= N

  # 進める
  x += 1
  if x > max
    y += 1
    x = y
  end
  if y > max
    z += 1
    y, x = z, z
  end
end

puts arr


Measured memory_bytes: 14244
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<cstdio>
#include<sstream>
#include<iomanip>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef pair<int,pii> pip;
typedef vector<pip>vip;
const double PI=acos(-1);
const double EPS=1e-8;
const int inf=1e8;
ll dp[2010][2010]={0};
int main(){
	int n;
	cin>>n;
	vi in(n);
	rep(i,n)cin>>in[i];
	queue<pip>q;
	rep(i,n){
		dp[i][1]=in[i];
		q.push(pip(1,pii(i,1)));
	}
	while(!q.empty()){
		pip a=q.front();
		pii b=a.second;
//		cout<<a.first<<" "<<b.first<<" "<<b.second<<" "<<dp[b.first][b.second]<<endl;
		q.pop();
		int s=b.first;
		int t=b.first+b.second;
		if(t>=n)t-=n;
		s--;
		if(s==-1)s=n-1;
		if(t==n)t=0;
//		cout<<s<<" "<<t<<endl;
		if(a.first){//IOI
			if(in[s]>in[t]){
				if(dp[s][b.second+1]<dp[b.first][b.second]){
					dp[s][b.second+1]=dp[b.first][b.second];
					if(b.second+1!=n)q.push(pip(0,pii(s,b.second+1)));
				}
			}else{
				if(dp[b.first][b.second+1]<dp[b.first][b.second]){
					dp[b.first][b.second+1]=dp[b.first][b.second];
					if(b.second+1!=n)q.push(pip(0,pii(b.first,b.second+1)));
				}
			}
		}else{//JOI
			if(dp[s][b.second+1]<dp[b.first][b.second]+in[s]){
				dp[s][b.second+1]=dp[b.first][b.second]+in[s];
				if(b.second+1!=n)q.push(pip(1,pii(s,b.second+1)));
			}
			if(dp[b.first][b.second+1]<dp[b.first][b.second]+in[t]){
				dp[b.first][b.second+1]=dp[b.first][b.second]+in[t];
				if(b.second+1!=n)q.push(pip(1,pii(b.first,b.second+1)));
			}
		}
	}
	ll out=0;
	rep(i,n)out=max(out,dp[i][n]);
	cout<<out<<endl;
}

Measured memory_bytes: 32688
#include<iostream>
using namespace std ;
int main()
{
    int p,q;
    string a,b,x="",y="";
    cin >> a >> b ;
    p=a[0]-'0';
    q=b[0]-'0';
    while(q--)
    {
        x+=a;
    }
    while(p--)
    {
        y+=b;
    }
    if(x>y)
    {
        cout << y << endl;
    }
    else
    {
        cout << x << endl;
    }
    return 0 ;
}

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

int a[100005], b[100005], c[100005];
ll dpb[100005];

int main(){

    ll n; cin >> n;
    for(int i = 0; i < n; i++)
        cin >> a[i];
    for(int i = 0; i < n; i++)
        cin >> b[i];
    for(int i = 0; i < n; i++)
        cin >> c[i];
    
    sort(a, a+n);
    sort(b, b+n);
    sort(c, c+n);

    for(int i = 0; i < n; i++){
        int pos = lower_bound(a, a+n, b[i])-a-1;
        if(pos < 0) dpb[i] = 0;
        else dpb[i] = pos+1;
    }
    for(int i = 1; i < n; i++)
        dpb[i] += dpb[i-1];

    ll res = 0;
    for(int i = 0; i < n; i++){
        int pos = lower_bound(b, b+n, c[i])-b-1;
        if(pos >= 0) res += dpb[pos];
    }
    cout << res << endl;
	return 0;
}


Measured memory_bytes: 2176
#include<iostream>
#include<algorithm>

using namespace std;

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

int main(){
    int n;
    cin >> n;
    pair<int, int> p[n];
    rep(i, n) cin >> p[i].second >> p[i].first;
    sort(p, p + n);
    int t = 0;
    rep(i, n){
        if (t + p[i].second <= p[i].first) {
            t += p[i].second;
        }else{
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
}

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

int main(void){
    int h,w;
    scanf("%d%d",&h,&w);
    char a[10][10];
    for (int i=0; i<h; i++){
            scanf("%s",a[i]);
    }
    for (int i=1; i<h; i++){
        for (int j=0; j<w-1; j++){
            if(a[i][j]=='#' && a[i-1][j+1]=='#'){
                printf ("Impossible\n");
                exit(0);
            }
        }
    }
    printf("Possible\n");
    return 0 ;
}

Measured memory_bytes: 128
// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<unordered_map>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(long long i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define FOR(i,a) for(auto i:a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define show1d(v) {rep(_,v.size())cout<<" "<<v[_];cout<<endl;}
#define show2d(v) {rep(__,v.size())show1d(v[__]);}
using namespace std;
//kaewasuretyuui
typedef long long ll;
#define int ll
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
#define mt make_tuple
typedef tuple<int,int,int,int> tp;
typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
const double PI=acos(-1);
const double EPS=1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10;
int dx[]={-1,0,1,0};
int dy[]={0,1,0,-1};
#define yes cout<<"Yes\n"
#define no cout<<"No\n"

signed main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	int n,m;
	cin>>n>>m;
	vi in(n);
	rep(i,n)cin>>in[i];
	int sum=0;
	rep(i,n)sum+=in[i];
	int c=0;
	rep(i,n)if(in[i]*4*m>=sum)c++;
	if(c>=m)yes;
	else no;
}











Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <math.h>

int main(void){
  long i;
  long N;
  long ans=0;
  char t;

  scanf("%ld",&N);
  char S[N+1];
  scanf("%s",S);

  for(i=0;i<N;i++){
    if(i==0){
      ans++;
    }else{
      //前の文字と違う
      if(t!=S[i]){
        ans++;
      }
    }
    t=S[i];
  }

  printf("%ld\n",ans);

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(void){
  long long int a,b,n;
  cin >> a >> b >> n;
  long long int res;
  if(n < b) {
      res = floor((a * n)/b);
  }
  else{
      res = floor((a*(b-1))/b);
  }
  cout << res << endl;
}

Measured memory_bytes: 3636
import collections
N = int(input())
A = list(map(int,input().split()))
Q = int(input())
Count = collections.Counter(A)
ans = sum(A)
for i in range(Q):
    B,C = map(int,input().split())
    n = Count[B]
    ans -= B*n
    ans += C*n
    Count[B] = 0
    if C in Count:
        Count[C] += n
    else:
        Count[C] = n
    print(ans)

Measured memory_bytes: 24192
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
#define ALL(c) (c).begin(), (c).end()
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end())

using namespace std;
typedef long long ll;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
const int INF = (1 << 29);
const long long INFL = (1LL<<60);
const double eps = (1e-9);

bool comp(pair<uint, int> a, int b) {
  return a.first < b;
}

int main(int argc, char* argv[])
{
  int n;
  cin >> n;
  vector<uint> a(n);
  vector<uint> b(n);
  vector<uint> c(n);
  rep(i, n) {
    cin >> a[i];
  }
  rep(i, n) {
    cin >> b[i];
  }
  rep(i, n) {
    cin >> c[i];
  }
  sort(ALL(a));
  sort(ALL(b));
  sort(ALL(c));

  vector<pair<uint, int>> aa;  // a の累積和
  aa.reserve(1e+5+5);
  int idx = -1;
  int cur = -1;
  rep(i, n) {
    if (a[i] != cur) {
      cur = a[i];
      aa.emplace_back(a[i], aa[idx].second + 1);
      idx++;
    } else {
      aa[idx].second++;
    }
  }

  /*
  for (int i = 0; i < aa.size(); i++) {
    cerr << aa[i].first << " " << aa[i].second << endl;
  }
  cerr << "----" << endl;
  */

  vector<pair<uint, ll>> bb;
  bb.emplace_back(0, 0);
  bb.reserve(1e+5 + 5);
  idx = -1;
  cur = -1;
  rep(i, n) {
    auto itr = lower_bound(aa.begin(), aa.end(), b[i], comp);
    itr--;
    bb.emplace_back(b[i], itr->second);
  }

  /*
  for (int i = 0; i < bb.size(); i++) {
    cerr << bb[i].first << " " << bb[i].second << endl;
  }
  cerr << "----" << endl;
  */

  vector<pair<uint, ll>> bbb;
  ll val = 0;
  bbb.emplace_back(0, 0);
  rep(i, bb.size()) {
    val += bb[i].second;
    bbb.emplace_back(bb[i].first, val);
  }

  /*
  for (int i = 0; i < bbb.size(); i++) {
    cerr << bbb[i].first << " " << bbb[i].second << endl;
  }
  */

  ll ans = 0;
  rep(i, n) {
    auto itr = lower_bound(bbb.begin(), bbb.end(), c[i], comp);
    itr--;
    ans += itr->second;
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 6004
from copy import deepcopy
n = int(input())
S = input()

accum = [[0,0,0]]
dic = {"R": 0, "G": 1, "B": 2}
accum[0][dic[S[0]]] += 1
for i in range(1, n):
    new_e = deepcopy(accum[i-1])
    new_e[dic[S[i]]] += 1
    accum.append(new_e)
ans = 0
for i in range(n):
    for j in range(i+1, n):
        if S[i] != S[j]:
            if (S[i] == "R" and S[j] == "G") or (S[i] == "G" and S[j] == "R"): 
                ans += accum[n-1][dic["B"]] - accum[j][dic["B"]]
                a = dic["B"]
            elif (S[i] == "R" and S[j] == "B") or (S[i] == "B" and S[j] == "R"):
                ans += accum[n-1][dic["G"]] - accum[j][dic["G"]]
                a = dic["G"]
            else:
                ans += accum[n-1][dic["R"]] - accum[j][dic["R"]]
                a = dic["R"]
            if j + j - i < n and j + j - i > j:
                ans -= accum[j+j-i][a] - accum[j+j-i-1][a]
print(ans)

Measured memory_bytes: 76840
import java.util.Scanner;
import static java.lang.System.out;

class Rectangle {
    public void run() {
        Scanner scan = new Scanner( System.in);
        int a = scan.nextInt();
        int b = scan.nextInt();

        out.printf( "%d %d\n", a * b, a * 2 + b * 2  );
    }
}

public class Main {
    public static void main( String... args) {
        Rectangle test = new Rectangle();
        test.run();
    }
}

Measured memory_bytes: 26316
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define endl "\n"
#define F first
#define S second
#define def(x) cerr << #x << " is " << x << endl;
#define mod 1000000007
#define pb push_back
#define FOR(i,a,n) for(ll i=a;i<n;i++)
#define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define all(a) a.begin(),a.end()
const int NUM = 2e5 + 5;
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cerr << *it << " = " << a << endl;
    err(++it, args...);
}
ll len,n,ans=0;
ll bp(ll x,ll y,ll MOD){
    ll ans = 1;
    while (y) {
        if (y & 1) ans = ans * x % MOD;
        x = x * x % MOD, y >>= 1;
    }
    return ans;
}
int main(){
    ios
    int num_tests=1; 
    //cin>>num_tests;
    while(num_tests-->0){
        string s; 
        cin>>len>>s;
        n = s.size();
        len+=n;
        vector<ll> comb(len+10,1);
        FOR(i,2,len+5) {comb[i] = comb[i-1]*i; comb[i] = comb[i]%mod;}
        // ans = summation of(C(len,i)*pow(25,len-i))
        for(int i=n;i<=len;i++){
            ll cur = bp(25,len-i,mod);
            // calculating C(len,i)
            cur = cur*comb[len]; cur = cur%mod; // multiply by len!
            cur = cur*bp(comb[i],mod-2,mod); cur = cur%mod; // divided by i!
            cur = cur*bp(comb[len-i],mod-2,mod); cur = cur%mod; // divided by (len-i)!*/
            ans += cur;
            ans = ans%mod;
        }
        cout<<ans;
    }   
}


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

#define M 998244353
#define inf 1e18
#define ins insert
#define pb push_back
#define ff first
#define ss second
#define li long long int
#define ld long double
#define pi pair<li, li>
#define vc vector
#define umap unordered_map
#define uset unordered_set
#define all(x) x.begin(), x.end()
#define fr(i, a, n) for (li i = a; i < n; i++)
#define frr(i, a, n) for (li i = n - 1; i >= a; i--)
#define file_in freopen("a.txt", "r", stdin);
int isPalin(string s,int i,int j)
{
    while(i<j)
    {
        if(s[i]==s[j])
        {
            i++;
            --j;
            continue;
        }
        return 0;
    }
    return 1;
}

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    string s; cin>>s;
    int len=s.length();
    int ans=(isPalin(s,0,len-1)&&isPalin(s,0,(len-1)/2-1)&&isPalin(s,(len+3)/2-1,len-1));
    if(ans)
        cout<<"Yes\n";
    else   cout<<"No\n";
    return 0;
}


Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;

/**
 *
 * @author must
 */
public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        ArrayList<Integer> list = new ArrayList<>();
        
        for(int i=0;i<N;i++){
            list.add(sc.nextInt());
        }
        
        ArrayList<Integer> sortedList = (ArrayList<Integer>) list.clone();
        
        Collections.sort(sortedList);
        
        int mediNum = N/2-1;
        
        for (int i=0;i<N;i++){
            
            int medi = sortedList.get(mediNum);
            int sele = list.get(i);
            //System.out.println(":" + medi + ":" + sele);
            
            if (medi >= sele){
                medi = sortedList.get(mediNum+1);
            }
            
            System.out.println(medi);
        }
        
    }
    
}


Measured memory_bytes: 95636
#include <bits/stdc++.h>
using namespace std;
int n,a[200005];
long long pre[200005],sum,ans=0x3f3f3f3f3f3f3f3f;
int main() {
    cin>>n;
    for (int i=1; i<=n; i++) {cin>>a[i]; sum+=a[i];}
    for (int i=1; i<=n; i++) pre[i]=pre[i-1]+a[i];
    for (int i=1; i<n; i++) {
        ans=min(ans,abs(2*pre[i]-sum));
    }
    cout<<ans<<'\n';
}

Measured memory_bytes: 5980
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  char a,b;
  cin >> a >>b;
  
  if(a=='H' && b=='H'){
    cout << "H" << endl;
  }
  
  else if(a=='D'&&b=='D'){
    cout << "H" << endl;
  }
  
  else {
    cout << "D" << endl;
  }
}


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


using namespace std;

int main() {
	int N;
	cin >> N;
	
	long long ans = 0;
	
	for(int i = 1;i <= N; i++) {
		if(i % 3 == 0){
			//Fizz
		} else if(i % 5 == 0) {
			//Buzz
		} else {
			ans += i;
		}
	}
	
	cout << ans << endl;
	


	return 0;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef double D;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
typedef long double ld;

#define rd(x) scanf("%d",&x)
#define rd2(x,y) scanf("%d %d",&x,&y)
#define rl(x) scanf("%lld",&x)
#define rl2(x,y) scanf("%lld %lld",&x,&y)
#define wd(x) printf("%d" ,x)
#define wd2(x,y) printf("%d %d",x,y)
#define wl(x) printf("%lld",x)
#define wl2(x,y) printf("%lld %lld",x,y)
#define PC(x) putchar(x)
#define GC() getchar()
#define NL printf("\n")
#define SP printf(" ")
 
#define SZ(a) (int)a.size()
#define ALL(a) a.begin(), a.end()
#define ITER(it,a) for (__typeof(a.begin()) it = a.begin(); it != a.end(); it++)
#define FILL(a,value) memset(a, value, sizeof(a))

#define F first
#define S second
#define MP make_pair
#define PB push_back

#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL)
#define fr(i,s,e) for(int i=s;i<e;i++)
#define frl(i,s,e) for(ll i=s;i<e;i++)
#define frr(i,s,e) for(int i=s-1;i>=e;i--)
#define frv(i,a) for(int i = 0;i<(int)a.size();i++)
#define frvr(i,a) for(int i = a.size()-1;i>=0;i--)
#define tr(i,a) for(typeof(a.begin()) i = a.begin(); i != a.end();i++)

#define inf 10000000000000
#define mod 1000000007
#define maxn 100009
#define maxr 100009
int main(){
	//sstd::ios::sync_with_stdio(false); cin.tie(NULL);
	string str,apha="abcdefghijklmnopqrstuvwxyz";
	ll n;
	rl(n);
	cin>>str;
	transform(ALL(apha),apha.begin(),::toupper);
	//cout<<apha<<endl;
	fr(i,0,SZ(str))
	{
		ll x=str[i]-'A';
		x+=n;
		x%=26;
		str[i]=apha[x];
	}
	cout<<str<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<map>
#include<iostream>
#include<algorithm>
using namespace std;
bool pd(long long a[]){
	for(int i=0;i<3;i++){
		if(a[i]%2!=0)return false;
	}
	return true;
}
int main(){
	long long a[3],cs=0;
	cin>>a[0]>>a[1]>>a[2];
	while(pd(a)){
		long long t1,t2,t3;
		t1=a[0]/2;
		t2=a[1]/2;
		t3=a[2]/2;
		a[0]=t2+t3;
		a[1]=t1+t3;
		a[2]=t1+t2;
		cs++;
		if(cs>50000){
		cout<<-1<<endl;
		return 0;
		}
	}
	if(!pd(a))cout<<cs<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = a; i < (b); i++)
#define rrep(i, a, b) for (int i = a; i >= (b); i--)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
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;
}
void hr() { cerr << "--------------" << endl; }
const int INF = 2e9;
const int MOD = 1e9 + 7;

int c[10][1005];
int main() {
   int h, w, k;
   cin >> h >> w >> k;
   vector<string> s(h);
   rep(i, 0, h) cin >> s[i];
   int ans = INF;
   rep(i, 0, 1 << (h - 1)) {
      int g = 0;
      vector<int> id(h);
      rep(j, 0, h) {
         id[j] = g;
         if (i >> j & 1) {
            g++;
         }
      }
      g++;
      rep(ii, 0, g) rep(j, 0, w) c[ii][j] = 0;
      rep(ii, 0, h) rep(j, 0, w) c[id[ii]][j] += (s[ii][j] - '0');

      int num = g - 1;
      vector<int> now(g);
      auto add = [&](int j) {
         rep(ii, 0, g) now[ii] += c[ii][j];
         rep(ii, 0, g) if (now[ii] > k) return false;
         return true;
      };
      rep(j, 0, w) {
         if (!add(j)) {
            num++;
            now = vector<int>(g);
            if (!add(j)) {
               num = INF;
               break;
            }
         }
      }
      ans = min(ans, num);
   }
   cout << ans << endl;
   return 0;
}

Measured memory_bytes: 256
from collections import Counter
N=int(input())
D=list(map(int,input().split()))
M=int(input())
T=list(map(int,input().split()))
l1=[]
l2=[]
c1=Counter(D)
c2=Counter(T)
flag=1
val1=list(c1.values())
key1=list(c1.keys())
val2=list(c2.values())
key2=list(c2.keys())

for i in range(len(val1)):
    l1.append([key1[i],val1[i]])
for i in range(len(val2)):
    l2.append([key2[i],val2[i]])

for i in range(len(val2)):
    if c1[l2[i][0]]<l2[i][1]:
        flag=0
if flag==0:
    print("NO")
else:
    print("YES")

Measured memory_bytes: 128332
#include <stdio.h>
#include <math.h>

int min(int a, int b) {
	if (a > b) return b;
	else {
		return a;
	}
}
int main(void) {
  int n, dp[1000101];
  scanf("%d", &n);
  int p[2] = {6, 9};

  for (int i = 0; i < 100010; i++) {
    dp[i] = i;
  }

  dp[0] = 0;
  for (int k = 0; k < 2; k++) {
	  for (int i = p[k]; i <= n; i *= p[k] ) {
		  for (int j = i; j <= n; j++) {
			  dp[j] = min( dp[j], dp[j - i] + 1 );
		  }
	  }
  }

  printf("%ld", dp[n]);

  return 0;
}

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

const ll MAXN = 200000;
const ll INF = 1001001001001001001;

ll N, Q, K, tmp=0;
vector<vector<pair<ll,ll>>> G;
vector<ll> ans;

void dijkstra(ll x) {
    vector<ll> color(N, INF);
    priority_queue<pair<ll,ll>, vector<pair<ll,ll>>, greater<pair<ll,ll>>> PQ;
    color[x] = 0;
    PQ.push(make_pair(color[x],x));
    while(!PQ.empty()) {
        pair<ll,ll> p = PQ.top();
        PQ.pop();
        if (color[p.second] < p.first) {
            continue;
        }
        for(int i=0;i<G[p.second].size();i++) {
            if(color[G[p.second][i].first]>color[p.second]+G[p.second][i].second) {
                color[G[p.second][i].first]=color[p.second]+G[p.second][i].second;
                PQ.push(make_pair(color[G[p.second][i].first],G[p.second][i].first));
            }
        }
    }
    for(int i=0;i<N;i++) {
        ans[i] = color[i];
    }
}

signed main(){
    cin >> N;
    G.resize(N);
    ans.resize(N);
    for(int i=0;i<N-1;i++) {
        ll a, b, c;
        cin >> a >> b >> c;
        a--;
        b--;
        G[a].push_back(make_pair(b,c));
        G[b].push_back(make_pair(a,c));
    }
    cin >> Q >> K;
    K--;
    //cout << "OK" << endl;
    dijkstra(K);
    //cout << "OK" << endl;
    for(int i=0;i<Q;i++) {
        ll x, y;
        cin >> x >> y;
        x--;
        y--;
        cout << ans[x]+ans[y] << endl;
    }
    return 0;
}

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

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

ll lcm(ll a, ll b) {
  ll g = gcd(a, b);
  return a / g * b;
}

int main(void) {
  int N;
  cin >> N;

  ll ans = 1LL;
  for (int i = 0; i < N; ++i) {
    ll T;
    cin >> T;
    ans = lcm(ans, T);
  }

  cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); i++)
#define rep1(i,n) for(int i = 1; i <= (n); i++)
#define all(v) v.begin(),v.end()
#define vi vector<int>
#define vi2 vector<vector<int>>
#define vl vector<long long>
#define vl2 vector<vector<long long>>

template <class T> T maxAny(T a, T b){
    if(a > b) return a;
    else return b;
}

template <class T> T minAny(T a, T b){
    if(a > b) return b;
    else return a;
}

int main(){
    int n, m, x, cost = -1;
    cin >> n >> m >> x;
    vi c(n);
    vi2 a(n,vi(m));
    rep(i,n){
        cin >> c[i];
        rep(j,m) cin >> a[i][j];
    }
    rep(i, 1<<n){
        int tmp = 0;
        vi rikai(m,0);
        rep(j, n){
            if((i>>j)&1){
                tmp += c[j];
                rep(k, m)rikai[k] += a[j][k];
            }
        }
        bool isrikai = true;
        rep(j, m) if(rikai[j] < x) isrikai = false;
        if(isrikai) {
            if(cost<0) cost = tmp;
            else cost = minAny(cost,tmp);
        }
    }
    cout << cost << endl;
}

Measured memory_bytes: 3596
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;

#define SIZE 5000

int Change(int n, int i) {
	return n * 10 + i;
}

int main() {
	string str;
	bool num;
	int count, n;
	int N[SIZE];
	vector<int> P;
	int s;
	int res;

	cin >> s;
	for (int i = 0;i < s;i++) {
		cin >> str;
		count = 0;
		n = 0;
		num = false;
		for (int j = 0;j < str.size();j++) {
			if (str[j] == '[') {
				P.push_back(count);
			}
			else if (str[j] == ']') {
				if (num) {
					N[count] = (n + 1) / 2;
					count++;
					num = false;
					n = 0;
				}
				else {
					sort(N + P.back(), N + count);
					res = 0;
					for (int k = 0;k < (count - P.back() + 1) / 2;k++) {
						res += N[k + P.back()];
					}
					count = P.back();
					N[count] = res;
					count++;
				}
				P.pop_back();
			}
			else {
				num = true;
				n = Change(n, str[j] - 48);
			}

		}
		
		cout << N[0] << endl;
	}

	return 0;
}

Measured memory_bytes: 1272
#include <bits/stdc++.h>
using namespace std;
// type alias
typedef long long LL;
typedef pair<int,int> II;
typedef tuple<int,int,int> III;
typedef vector<int> VI;
typedef vector<string> VS;
typedef unordered_map<int,int> MAPII;
typedef unordered_set<int> SETI;
template<class T> using VV=vector<vector<T>>;
// minmax
template<class T> inline T SMIN(T& a, const T b) { return a=(a>b)?b:a; }
template<class T> inline T SMAX(T& a, const T b) { return a=(a<b)?b:a; }
// repetition
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)
#define REPE(i,n)  for(int i=0;i<=(n);++i)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  for(int i=0;i<(n);++i)
#define FORR(x,arr) for(auto& x:arr)
#define SZ(a) int((a).size())
// collection
#define ALL(c) (c).begin(),(c).end()
// DP
#define MINUS(dp) memset(dp, -1, sizeof(dp))
#define ZERO(dp) memset(dp, 0, sizeof(dp))
// stdout
#define println(args...) fprintf(stdout, ##args),putchar('\n');
// debug cerr
template<class Iter> void __kumaerrc(Iter begin, Iter end) { for(; begin!=end; ++begin) { cerr<<*begin<<','; } cerr<<endl; }
void __kumaerr(istream_iterator<string> it) { (void)it; cerr<<endl; }
template<typename T, typename... Args> void __kumaerr(istream_iterator<string> it, T a, Args... args) { cerr<<*it<<"="<<a<<", ",__kumaerr(++it, args...); }
template<typename S, typename T> std::ostream& operator<<(std::ostream& _os, const std::pair<S,T>& _p) { return _os<<"{"<<_p.first<<','<<_p.second<<"}"; }
#define __KUMATRACE__ true
#ifdef __KUMATRACE__
#define dump(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); __kumaerr(_it, args); }
#define dumpc(ar) { cerr<<#ar<<": "; FORR(x,(ar)) { cerr << x << ','; } cerr << endl; }
#define dumpC(beg,end) { cerr<<"~"<<#end<<": "; __kumaerrc(beg,end); }
#else
#define dump(args...)
#define dumpc(ar)
#define dumpC(beg,end)
#endif

// $ cp-batch YYMMOrMMYY | diff YYMMOrMMYY.out -
// $ g++ -std=c++14 -Wall -O2 -D_GLIBCXX_DEBUG -fsanitize=address YYMMOrMMYY.cpp && ./a.out

/*
 
 5/19/2019
 
 5:03-
 
 */

string S;

bool ism(string s) {
  int x=stoi(s);
  return 1<=x&&x<=12;
}
bool isy(string s) {
  int x=stoi(s);
  return 0<=x&&x<=99;
}
bool ok(string y, string m) {
  return ism(m)&&isy(y);
}
void solve() {
  string a=S.substr(0,2),b=S.substr(2,2);
  string res="NA";
  if(ok(a,b)&&ok(b,a)) res="AMBIGUOUS";
  else if (ok(a,b)) res="YYMM";
  else if(ok(b,a)) res="MMYY";
  cout<<res<<endl;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout<<setprecision(12)<<fixed;
  
  cin>>S;
  solve();
  
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <map>

using namespace std;
typedef long long ll;

#define INF (long long)(10e9+7)
#define REP(i,n) for(ll i = 0; i < n; i++)

map<string, int> s;

int main(void)
{
    int n,m;
    string s1;
    cin >> n;
    REP(i, n) {
        cin >> s1;
        s[s1] ++;
    }
    cin >> m;
    REP(i, m) {
        cin >> s1;
        s[s1] --;
    }
    int res = 0;
    for(auto itr = s.begin(); itr != s.end(); ++itr) {
        if(itr->second > res) res = itr->second;
    }
    cout << res << endl;

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define arep(i,x,n) for(int i=int(x);i<(int)(n);i++)
#define rep(i,n) for(long long i = 0;i < n;++i)
#define pi 3.141592653589793
#define eps 0.00000001
#define INF 1e9+7  
using ll = long long; 
using P=pair<int,int>;
using lP=pair<ll,ll>;
using fP=pair<double,double>;


int main(){
   
    string s;
    cin>>s;
    vector<int>num;
    vector<int>ans(s.size());
    num.push_back(0);
    int b,a,c;
    rep(i,s.size()){
        if(i==0)c=0;
        else c=b;
        while(s[i]=='R'){
            i++;
        }
        a=i;
        while(i<s.size()&&s[i]=='L'){
            i++;
        }
        b=i;
        ans[a-1]=(a-c+1)/2+(b-a)/2;
        ans[a]=(a-c)/2+(b-a+1)/2;

    }
    rep(i,s.size()){
        cout<<ans[i]<<endl;
    }
    
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
using P = pair<int, int>;
using vec = vector<int>;
using mat = vector<vector<int>>;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define endl "\n"

constexpr int MOD = 1000000007;
const int INF = 1 << 30;

int main() {
    int n, k;
    cin >> n >> k;

    int res = INF;

    rep(i, 1 << n) {
        int now = 1;

        rep(j, n) {
            int bt = (i >> j) & 1;
            if (bt) now += k;
            else now *= 2;
        }

        res = min(res, now);
    }

    cout << res << endl;
    return 0;
}

Measured memory_bytes: 3612
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <tuple>
#include <math.h>
#include <deque>
#include <stack>
#include <queue>

using namespace std;

typedef long long ll;


int solve() {
  ll r;
  cin >> r;
  cout << pow(r, 2) << endl;
  return 0;
}


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


Measured memory_bytes: 384
using System;
using System.Collections.Generic;
using System.Linq;

public class Prog
{
    public void run()
    {
        var S = Console.ReadLine();
        int N = int.Parse(S);
        long ans = N * N * N;
        Console.WriteLine(ans);
    }
    public static void Main()
    {
        var prog = new Prog();
        prog.run();
    }
    /*
    最小公倍数
    public static long Lcm(long a, long b)
    {
        return a * b / Gcd(a, b);
    }

    // ユークリッドの互除法 
    public static long Gcd(long a, long b)
    {
        if (a < b)
            // 引数を入替えて自分を呼び出す
            return Gcd(b, a);
        while (b != 0)
        {
            var remainder = a % b;
            a = b;
            b = remainder;
        }
        return a;
    }
    */
    //a<=c, b<=d;
}

//Array.ConvertAll(int.Parse)
//str.IndexOf("Stage",System.StringComparison.CurrentCulture)


Measured memory_bytes: 13140
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define repr(i, n) REPR(i, n, 0)
#define REPR(i, s, e) for(int i=(int)(s-1); i>=(int)(e); i--)
#define pb push_back
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()
#define fi first
#define se second

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

const ll INF = 1e18;
const ll MOD = 1e9 + 7;
const double EPS = 1e-8;

template<typename T> T chmax(T& a, const T& b){return a = (a > b ? a : b);}
template<typename T> T chmin(T& a, const T& b){return a = (a < b ? a : b);}

int main(){
    ll a, b, c;
    cin >> a>> b >> c;
    if(c - a - b < 0) cout << "No" << endl;
    else cout << (4*a*b < (c-a-b) * (c - a - b) ? "Yes" : "No") << endl;
    return 0;
}

Measured memory_bytes: 256
from collections import deque

N,M = (int(a) for a in input().split())
g = [[] for _ in range(N)]
s = [0]*N
for i in range(M) :
    A,B = (int(a) for a in input().split())
    g[A-1].append(B)
    g[B-1].append(A)
visited = {0}
stack = [0]
for i in stack :
    for j in g[i] :
        if j-1 in visited :
            continue
        stack.append(j-1)
        visited.add(j-1)
        s[j-1] = i + 1
if s.count(0) > 1 :
    print("No")
else :
    print("Yes")
    print(*s[1:])









Measured memory_bytes: 49348
a,b,c=map(int,input().split())
d=list(map(int,input().split()))
result1=list(range(0,c+1))
result2=list(range(c,a+1))
ans1=0
ans2=0
for i in result1:
  if i in d:
    ans1+=1
for i in result2:
  if i in d:
    ans2+=1
print(min(ans1,ans2))

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

#define X first
#define Y second
#define pb push_back

using namespace std;

int main() {
    ios_base::sync_with_stdio(false);
    int n;
    cin >> n;
    vector <int> a(n);
    for (int i = 0; i < n; i++)
        cin >> a[i];
    sort(a.begin(), a.end());
    int t = 1;
    int s = 0;
    for (int i = n - 1; i >= 0; i--)
    {
        s += t*a[i];
        t *= -1;
    }
    cout << s;
    return 0;
}


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

using namespace std;

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

    // int N=3;
    // vector<int> d = {1, 2, 1};

    sort(d.begin(), d.end());

    int r_now = d.at(N-1);
    int dan = 1;

    for(int i=N-2 ; i>-1 ; i--){
        if(d.at(i)<r_now){dan++;r_now=d.at(i);}
    }
    cout<< dan << endl;
}


Measured memory_bytes: 256
import Data.List

main = do
	_ <- getLine
	xs <- map read.words <$> getLine :: IO [Int]
	putStrLn.show $ calc (isSolvable $ sort xs) (length xs `div` 2)

isSolvable xs@(v:vs)
	| length xs == 0 = False
	| length xs == 1 = v == 0
	| even (length xs) = v == 1 && third (foldl isCountinuous (v,1,True) vs)
	| odd (length (v:vs)) = v == 0 && head vs == 2 && third (foldl isCountinuous (head vs,1, True) $ tail vs)

isCountinuous (v,i,flag) x 
	| v == x && i == 1 = (x,2,flag)
	| v == x-2 && i == 2 = (x,1,flag)
	| otherwise = (x,0,False)

third (_,_,v) = v

calc False _ = 0
calc True v = 2^v `mod` (10^9+7)

Measured memory_bytes: 37244
#include<iostream>
#include<vector>
#define MAX 1e7
using namespace std;

int main(){
  int n, m;
  while(std::cin >> m >> n){
    vector<bool> isBoring(MAX, false);
    if(n == 0 and m == 0)break;
    int mini = m;
    for (int i = 0; i < n; i++) {
      while(isBoring[mini] == true) mini++;
      for (int j = mini; j < MAX; j+=mini) {
        isBoring[j] = true;
      }
    }
    int ans = 0;
    while(isBoring[ans] == false)ans++;
    while(isBoring[ans] == true)ans++;
    std::cout << ans << std::endl;
  }
  return 0;
}

Measured memory_bytes: 4216
import sys

if __name__ == '__main__':
    n, m = list(map(lambda x: int(x), sys.stdin.readline().split(' ')))
    h = list(map(lambda x: int(x), sys.stdin.readline().split(' ')))
    # matrix = {}
    # matrix = [[0 for i in range(n)] for j in range(n)]
    matrix = [[] for j in range(n)]

    for i in range(m):
        a, b = list(map(lambda x: int(x), sys.stdin.readline().split(' ')))
        a, b = a-1, b-1
        # matrix[a] = matrix.get(a, []) + [b]
        # matrix[b] = matrix.get(b, []) + [a]
        # matrix[a][b] = 1
        # matrix[b][a] = 1
        matrix[a].append(b)
        matrix[b].append(a)

    bads = {}
    good = 0
    # 展望台iが良い展望台か
    for i in range(n):
        if bads.get(i, 0) == 1:
            continue
        # for t in matrix.get(i, []):
        for t in matrix[i]:
            if h[i] <= h[t]:
                break
            else:
                # 展望台tはもはや良い展望台でない
                if t > i:
                    bads[t] = 1
        else:
            good += 1
    print(good)

# matrixを疎行列にする
# 判定順をソートする


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

using namespace std;

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

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

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

const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

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

    const int MX=1201;
    char s[MX]={};
    cin.getline(s,sizeof(s));
    REP(i,MX){
        if(s[i]<97) s[i] = tolower(s[i]);
        else        s[i] = toupper(s[i]);
    }
    cout << s << endl;
    return 0;
}


Measured memory_bytes: 3148
import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] A = new int[N+1];
        for(int i=1;i<=N;i++) A[i] = sc.nextInt();
        long min = 2;
        long max = 2;
        for(int i=N;i>=1;i--){
            if(min%A[i]!=0) min = min/A[i]*A[i]+A[i];
            max = max/A[i]*A[i]+A[i]-1;
            if(min>max){
                System.out.println(-1);
                System.exit(0);
            }
        }
        System.out.println(Long.toString(min)+" "+Long.toString(max));
    }
}


Measured memory_bytes: 51796
#include <iostream>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <algorithm>
#include <set>
#include <string>
#include <queue>

using namespace std;
#define rep(i, N) for(int (i) = 0; (i) < (N); (i) ++)
typedef long long ll;

vector<pair<ll, ll>> pF;


void prime_fact(ll n){
// 素因数分解
for(ll i = 2; i * i <= n; i ++){
ll cnt = 0;
while(n % i == 0){
cnt ++;
n /= i;
}
pair<ll, ll> f = {i, cnt};
pF.push_back(f);
}
if(n != 1){
pF.push_back({n, 1});
}
}


int main(){
    int N, T;
    int ans = 1e9;
    cin >> N >> T;
    rep(i, N){
        int c, t;
        cin >> c >>  t;
        if(t <= T){
            ans = min(ans, c);
        }
    }
    if(ans == 1e9){
        cout << "TLE" << endl;
    }else{
        cout << ans << endl;
    }

    return 0;
}


Measured memory_bytes: 256
/*
    Bismillahir Rahmanir Raheem
    Think Twice Code Once
    author : reaziii
*/
#include<bits/stdc++.h>
#define sc(x)        scanf("%lld",&x)
#define pcase(x)     printf("Case %d: ",x++)
#define pn           printf("\n")
#define fri(f)       for(int i=0;i<f;i++)
#define frj(f)       for(int j=0;j<f;j++)
#define reset(x,e)   memset(x,e,sizeof(x))
#define all(x)       x.begin(),x.end()
#define input        freopen("input.txt","r",stdin);
#define output       freopen("output.txt","w",stdout)
#define infi         INT_MAX
#define m_v          3000000
#define pii          pair<int,int>
#define pch          pair<char,char>
#define pll          pair<ll,ll>
#define mgraph       map<int,set<int> >
#define mp           make_pair
#define pb           push_back
#define clr(x)       memset(x,0,sizeof(x))
#define frx(x,y)     for(int x=0;x<y;x++)
#define deb(x)       cout<<x
#define ideb(i,x)    cout<<i<<" "<<x
#define F            first
#define S            second
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
bool checkbitt(ll num,int pos);
ll setbitt(ll num,ll pos);
ll resetbitt(ll num,int pos);
 //.................___Start from here___.................//
//.................._____________________................//


int bitcount(int n){
    int ans = 0;
    for(int i=0;i<32;i++){
        ans+=(n>>i)&1;
    }

    return ans;
}


void solve(){
    int n;
    cin>>n;
    int mask = 1<<n;
    mask--;

    int a[n+1],x[n+1][n+1],y[n+1][n+1];

    for(int u = 1 ; u <= n ; u++ ){
        cin>>a[u];
        for(int v = 1;v<=a[u];v++){
            cin>>x[u][v]>>y[u][v];
        }
    }

    int ans = 0;

    for(int i=1;i<=mask;i++){
        bool f =true;

        for(int j=1;j<=n;j++){
            if(i & (1<<(j-1))){
                for(int k=1;k<=a[j];k++){
                    if(y[j][k]^checkbitt(i,(x[j][k]-1))) f = false;
                }
            }
        }

        if(f) ans = max(ans,bitcount(i));
    }

    cout<<ans<<endl;

}


int main(){
    // input;
    // output;

    solve();
}






bool checkbitt(ll num,int pos){
    return (num>>pos) & 1;
}

ll setbitt(ll num,ll pos){
    return (1<<pos) | num;
}

ll resetbitt(ll num,int pos){
    if(!checkbitt(num,pos)) {
        return num;
    }
    else{
        return (1<<pos)^num;
    }
}


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


#define rep(s, e) for(int i(s); i < e; ++i)
#define mojinokazu 3

int main() {
    int marble_num(0);
    rep(0, 3) {
        if(cin.get() == '1') {
            marble_num += 1;
        }
    }
    cout << marble_num << "\n";
    return 0;
}

Measured memory_bytes: 256
#include <stdbool.h>
#include <stdio.h>
#include <string.h>

int main()
{
	int n, p, now, initp;
	int pebbles[50];
	while (true) {
		scanf("%d %d", &n, &p);
		now = 0;
		initp = p;
		memset(pebbles, 0, sizeof(pebbles));
		if (!(n || p))
			break;
		while (true) {
			if (p) {
				pebbles[now] += 1;
				if (!--p && pebbles[now] == initp) {
					printf("%d\n", now);
					break;
				}
			} else {
				p += pebbles[now];
				pebbles[now] = 0;
			}
			if (++now == n)
				now = 0;
		}
	}
}



Measured memory_bytes: 2028
#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
//#include <regex>

/* g++ -g -std=c++0x */
/* g++ -g -std=c++11 */

using namespace std;

// freopen("input.txt", "rt", stdin);
// freopen("output.txt", "wt", stdout);

#define ALL(c)          (c).begin(), (c).end()
#define ALLR(c)         (c).rbegin(), (c).rend()
#define FOR(i,a,b)      for (int i=(a); i < (b); ++i)
#define FORR(i,a,b)     for (int i=(a); i > (b); --i)
#define FOR_ALL(i,c)    for (__typeof((c).begin()) i=(c).begin();   \
                             i != (c).end(); ++i)
#define FOR_ALLR(i,c)   for (__typeof((c).rbegin()) i=(c).rbegin(); \
                             i != (c).rend(); ++i)
#define SZ(array)       (sizeof(array)/sizeof(array[0]))
#define lc(x)           (x<<1)     /* 2*x */
#define rc(x)           (x<<1 | 1) /* 2*x+1 */
#define lowbit(x)       (x & (-x)) /* 0b10100 -> 0b100 */

typedef long long       LL;
typedef map<int,int>    MII;
typedef pair<int,int>   PII;
typedef set<int>        SI;
typedef vector<bool>    VB;
typedef vector<double>  VD;
typedef vector<int>     VI;
typedef vector<string>  VS;

/* check if a key is in container C */
template <class C>
inline bool in_(const typename C::key_type& k, const C& A)
{ return A.find(k) != A.end(); }
inline bool in_(const string& s, const string& S)
{ return S.find(s) != string::npos; }

const int inf = 1e9;
const int maxn = 100100;
int n,k;
int h[maxn];
int dp[maxn];

int dfs(const int i)
{
    if (i == 0)
        return 0;
    int& ans = dp[i];
    if (-1 == ans) {
        ans = inf;
        FOR(d,1,k+1) if (i-d >= 0) {
            int j = i-d;
            int result = dfs(j) + abs(h[i]-h[j]);
            ans = min(ans,result);
        }
    }
    return ans;
}
    
int main()
{
/* #ifndef ONLINE_JUDGE */
/*     freopen("foo", "rt", stdin); */
/* #endif */
    std::ios::sync_with_stdio(false);
    while (cin >> n >> k) {
        memset(dp,-1,sizeof(dp));
        FOR(i,0,n) {
            cin >> h[i];
        }
        cout << dfs(n-1) << endl;
    }
    
}


Measured memory_bytes: 4224
from collections import deque
import sys
from operator import itemgetter
N,M = map(int,input().split())
table=[[1]*N for i in range(N)]
for i in range(N):
    table[i][i]=0
for i in range(M):
    a,b=map(int,input().split())
    table[a-1][b-1]=0
    table[b-1][a-1]=0
visit=[False]*N
color =[-1]*N
def f(i):
    q=deque()
    q.append(i)
    color[i]=0
    visit[i]=True
    r=[0,0]
    r[0]+=1
    while q:
        x= q.popleft()
        for j in range(N):
            if table[x][j]==0:
                continue
            if visit[j]:
                if (color[x]==color[j]):
                    print(-1)
                    sys.exit()
                continue
            q.append(j)
            color[j]=(color[x]+1)%2
            r[color[j]]+=1
            visit[j]=True
    return r
ans=[]
for i in range(N):
    if not visit[i]:
        ans.append(f(i))
r=sorted(ans,reverse=True)
#r=sorted(ans,reverse=True,key = itemgetter(1))
for i in range(1,len(ans)):
    if r[0][0]>r[0][1]:
        r[0][0]+=min(r[i][0],r[i][1])
        r[0][1]+=max(r[i][0],r[i][1])
    else:
        r[0][0]+=max(r[i][0],r[i][1])
        r[0][1]+=min(r[i][0],r[i][1])
def dou(k):
    return (k*(k-1))//2
print(dou(r[0][0]) + dou(r[0][1]))



Measured memory_bytes: 9204