akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections.Generic;
using System.Linq;

class Program
{
    static void Main(string[] args)
    {
        string[] input = Console.ReadLine().Split();
        int N = int.Parse(input[0]);
        int M = int.Parse(input[1]);
        var list = new List<int>[M];
        for (int i = 0; i < M; i++)
        {
            list[i] = new List<int>();
            input = Console.ReadLine().Split();
            int K = int.Parse(input[0]);
            for(int j = 0; j < K; j++)
            {
                list[i].Add(int.Parse(input[j + 1]));
            }
        }
        input = Console.ReadLine().Split();
        int[] p = new int[M];
        for(int i = 0; i < M; i++)
        {
            p[i] = int.Parse(input[i]);
        }
        int all_pattern = (int)Math.Pow(2, N);
        int[] pattern = new int[11];
        pattern[0] = 1;
        for(int i = 1; i < 11; i++)
        {
            pattern[i] = pattern[i - 1] * 2;
        }
        int ans = 0;
        for(int i = 0; i < all_pattern; i++)
        {
            bool flag = true;
            for(int j = 0; j < M; j++)
            {
                int ct = 0;
                for(int k = 0; k < list[j].Count; k++)
                {
                    if (i / pattern[list[j][k] - 1] % 2 == 1)
                    {
                        ct++;
                    }
                }
                if (ct % 2 != p[j])
                {
                    flag = false;
                }
            }
            if (flag)
            {
                ans++;
            }
        }
        Console.WriteLine(ans);
    }
}


Measured memory_bytes: 11220
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <map>
using namespace std;
typedef long long ll;
#define rep(i,n) for (int i=0;i < (int)(n);i++)

int main(){
  int a,b,c;
  string s;
  cin >> a >> b >> c;
  cout << b/c - (a-1)/c << endl;

  return 0;
}


Measured memory_bytes: 3620
import sys
from collections import Counter

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    n = int(readline())
    S = [readline().strip() for _ in range(n)]

    vec = [INF] * 26
    for s in S:
        counter = Counter(s)
        for i in range(26):
            c = chr(i + ord('a'))
            if vec[i] > counter[c]:
                vec[i] = counter[c]

    ans = []
    for i, n in enumerate(vec):
        ans.extend([chr(i + ord('a'))] * n)

    print(''.join(ans))
    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 9188
#include <bits/stdc++.h>
using namespace std;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    int a,b,c,k;
    cin>>a>>b>>c>>k;
    if(a>=k) cout<<k<<endl;
    else if(a+b>=k) cout<<a<<endl;
    else cout<<(2*a+b-k)<<endl;
    return 0;
}

Measured memory_bytes: 3656
#include<bits/stdc++.h>
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long
using namespace std;
void solve()
{
    ll n;
    cin>>n;
    ll z=(n%1000);
    if(z) cout<<1000-z;
    else cout<<z;
}

int main()
{
    fast;
    int t;
    solve();
}


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

using namespace std;
typedef long long lint;

#define RPT(i, b, e) for (int i = ((int)b); i <= ((int)e); i++)
#define RPT0(i, n) RPT(i, 0, ((int)n) - 1)
#define RPT1(i, n) RPT(i, 1, (n))
#define EACH(it, v) for (const auto& it : v)
#define ALL(v) v.begin(), v.end()

void resolve()
{
    int X, N;
    cin >> X >> N;
    vector<int> p(N);
    RPT0(i, N) cin >> p[i];

    set<int> s;
    RPT(i, -1, 101) s.insert(i);
    RPT0(i, N) s.erase(p[i]);

    int mind = 1000;
    int ans = 1000;
    EACH(it, s)
    {
        int diff = abs(it - X);
        if (diff < mind || (diff == mind && it < ans)) {
            ans = it;
            mind = diff;
        }
    }
    cout << ans << endl;
}

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


Measured memory_bytes: 3648
#include "bits/stdc++.h"
using namespace std;
#define max(a, b) (a < b ? b : a)
#define min(a, b) ((a > b) ? b : a)
#define mod 1e9 + 7
#define FOR(a, c) for (int(a) = 0; (a) < (c); (a)++)
#define FORL(a, b, c) for (int(a) = (b); (a) <= (c); (a)++)
#define FORR(a, b, c) for (int(a) = (b); (a) >= (c); (a)--)
#define INF 1000000000000000003
typedef long long int ll;
typedef vector<int> vi;
typedef pair<int, int> pi;
#define F first
#define S second
#define PB push_back
#define POB pop_back
#define MP make_pair
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
     int n;
     cin>>n;
     n=n%10;
     if(n==3)
     cout<<"bon";
     if(n<2 || (n==6 || n==8))
     cout<<"pon";
     else if(n==2 || (n==4 || (n==5 ||(n==7 || n==9))))
     cout<<"hon";
    return 0;
}


Measured memory_bytes: 3664
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
const ll INF = 1LL << 60;

//dp動的計画法の問題
//dp[i]=dp[i+1]+dp[i+2]という漸化式で表せる
int main(){
    int n, m;
    cin >> n >> m;
    //壊れた段に1、壊れてない段は0
    vector<int> broken(n+1);
    rep(i,m){
        int a;
        cin >> a;
        broken[a]=1;
    }
    vector<int> dp(n+2);
    const int mod=1000000007;
    dp[n]=1; //初期値
    for(int i=n-1; i>=0; i--){
        if(broken[i]){
            dp[i]=0;
            continue;
        }
        dp[i]=(dp[i+1]+dp[i+2]) %mod;
    }
    cout << dp[0] << endl;
    return 0;

}

Measured memory_bytes: 4060
import java.util.*;

public class Main{
	
	public static void main(String[] args){
      Scanner sc = new Scanner(System.in);
      int a = sc.nextInt();
      int b = sc.nextInt();
      int c = sc.nextInt();
      int d = sc.nextInt();
      
      long tmp1 = (long)a*(long)c;
      long tmp2 = (long)a*(long)d;
      long tmp3 = (long)b*(long)c;
      long tmp4 = (long)b*(long)d;

      // tmp1のチェック
      if(((tmp1>tmp2)|| (tmp1==tmp2)) &&((tmp1>tmp3) || (tmp1==tmp3)) && ((tmp1>tmp4) || (tmp1==tmp4))){

            System.out.println(tmp1);
      // tmp2のチェック
      }else if (((tmp2>tmp1) || (tmp2==tmp1)) && ((tmp2>tmp3) || (tmp2==tmp3)) && ((tmp2>tmp4) || (tmp2==tmp4))){

            System.out.println(tmp2);
      // tmp3のチェック  
      }else if (((tmp3>tmp1) || (tmp3==tmp1)) && ((tmp3>tmp2) || (tmp3==tmp2)) && ((tmp3>tmp4) || (tmp3==tmp4))){

            System.out.println(tmp3);
      }else if (((tmp4>tmp1) || (tmp4==tmp1)) && ((tmp4>tmp2) || (tmp4==tmp2)) && ((tmp4>tmp3) || (tmp4==tmp3))){

            System.out.println(tmp4);
      }
    }
}

Measured memory_bytes: 27068
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N=1005;
int n,m;
LL x[N],y[N],d[N];
char ch[2];
int t[N],s=0;
int f1=0,f2=0;
void solve(LL x,LL y){
	for (int i=1;i<=m;i++){
		if (y>=abs(x))
			putchar('U'),y-=d[i];
		else if (y<=-abs(x))
			putchar('D'),y+=d[i];
		else if (x>=abs(y))
			putchar('R'),x-=d[i];
		else
			putchar('L'),x+=d[i];
	}
	if (x!=0||y!=0)
		puts("ERROR");
	puts("");
}
int main(){
	scanf("%d",&n);
	for (int i=1;i<=n;i++){
		scanf("%lld%lld",&x[i],&y[i]);
		if ((x[i]+y[i])%2==0)
			f1=1;
		else
			f2=1;
	}
	if (f1&&f2)
		return puts("-1"),0;
	m=40;
	d[m]=d[m-1]=d[m-2]=d[m-3]=1;
	for (int i=m-4;i>=1;i--)
		d[i]=d[i+1]*2;
	if (f2)
		m--;
	printf("%d\n",m);
	for (int i=1;i<=m;i++)
		printf("%lld ",d[i]);
	puts("");
	for (int i=1;i<=n;i++)
		solve(x[i],y[i]);
	return 0;
}

Measured memory_bytes: 256
import Control.Monad
import Control.Applicative
import Data.List




getBysplit = map read . words <$> getLine

main :: IO()
main = do
  [a, b, c] <- getBysplit :: IO [Int]
  let [a1, b1] = sort [a, b]
  let ans = if a1 <= c && c <= b1
            then "Yes"
            else "No"
  putStrLn ans


Measured memory_bytes: 508
ND = list(map(int,input().split()))
N = ND[0]
D = ND[1]
input_list = []
for n in range(N):
  input_list.append(list(map(int,input().split())))
  
import math

count = 0
for i in range(N):
  if math.sqrt(input_list[i][0]**2+input_list[i][1]**2) <= D:
    count += 1
print(count)

Measured memory_bytes: 45464
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <set>
#include <map>
#include <numeric>
#include <regex>
#include <tuple>
#include <iomanip>
#include <math.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
#define MOD 1000000007 // 10^9 + 7
#define INF 1000000000 // 10^9
#define LLINF 1LL<<60
const double PI = 3.14159265358979323846;

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

	int A[3][3];
	bool B[3][3];
	for (int i = 0; i < 3; i++) {
		for (int j = 0; j < 3; j++) B[i][j] = false;
	}

	for (int i = 0; i < 3; i++) {
		for (int j = 0; j < 3; j++) {
			cin >> A[i][j];
		}
	}
	int N; cin >> N;

	for (int i = 0; i < N; i++) {
		int num; cin >> num;
		for(int j = 0; j < 3; j++) {
			for (int k = 0; k < 3; k++) {
				if (A[j][k] == num) B[j][k] = true;
			}
		}
	}

	bool flag = false;
	// 縦
	for(int i = 0; i < 3; i++) {
		bool check = true;
		for (int j = 0; j < 3; j++) {
			check *= B[i][j];
		}
		if (check) flag = true;
	}
	// 横
	for(int i = 0; i < 3; i++) {
		bool check = true;
		for (int j = 0; j < 3; j++) {
			check *= B[j][i];
		}
		if (check) flag = true;
	}
	// 斜め
	if (B[0][0] * B[1][1] * B[2][2]) flag = true;
	if (B[0][2] * B[1][1] * B[2][0]) flag = true;

	if (flag) cout << "Yes" << endl;
	else cout << "No" << endl;

	return 0;
}

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

int main(void){
  int n,result=0,i=0;
  char c;

  while(1){
    if(i%2==0){
      scanf("%d",&n);
      getchar();

      if(i==0){ result=n; }
      else{
        switch(c){
          case '+':
            result+=n;
            break;
          case '-':
            result-=n;
            break;
          case '*':
            result*=n;
            break;
          case '/':
            result/=n;
            break;
          default:
            break;
        }
      }
    }
    else{
      scanf("%c",&c);
      getchar();

      if(c=='='){ printf("%d\n",result); break; }
    }
    i++;
  }

  return 0;
}



Measured memory_bytes: 2080
#define MOD 1000000007;
#define input ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define  ll long long

#include <bits/stdc++.h>

using namespace std;
const int N = 2e1 + 5;

int main() {

    ll  n,k;
    cin>>n>>k;
    vector<pair<int,int>> vec;
    for(int i=0;i<n;i++)
    {
        int a,b;
        cin>>a>>b;
        vec.push_back({a,b});
    }
    sort(vec.begin(),vec.end());


    int ans;
    for(int i=0;i<n;i++)
    {
        if(vec[i].second>=k)
        {ans=vec[i].first;
            break;}
        else
            k-=vec[i].second;

    }
    cout<<ans;

}

Measured memory_bytes: 1400
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define off ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define pi 3.141592653589793116
#define mod 1e9+7
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
int main() {
    off;
    int t;
    //cin>>t;
    t=1;
    while(t--){  
        string s,temp1,temp2;
        cin>>s;
        for(int i=0;i<s.size();i++)
          { 
             temp1+=char('0'+i%2);
             temp2+=char('0'+(i+1)%2);
          }  
         int count=0,count2=0; 
        for(int i=0;i<s.size();i++)
          {
             if(s[i]!=temp1[i])
                ++count;
             if(s[i]!=temp2[i])
                 ++count2;
          }
       cout<<min(count,count2)<<'\n';   
    }
      return 0;
}

Measured memory_bytes: 720
#include<stdio.h>

int main(){
    int a,b;

    scanf("%d %d",&a,&b);
    if(a > b){
    	printf("a > b\n");
    }
    else if(a<b){
    	printf("a < b\n");
    }
    else
    	printf("a == b\n");
return 0;
}

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

bool check(string s) {
    if (s[0] != 'A') return false;
    int c_idx = -1;
    for (int i = 2; i + 1 < s.size(); i++) {
        if (s[i] == 'C') {
            if (c_idx != -1) return false;
            c_idx = i;
            break;
        }
    }
    if (c_idx == -1) return false;
    for (int i = 1; i < s.size(); i++) {
        if (i == c_idx) continue;
        if (s[i] >= 'A' && s[i] <= 'Z') return false;
    }
    return true;
}

void solve() {
    string s;
    cin >> s;
    cout << (check(s) ? "AC" : "WA") << endl;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    solve();
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int H, W;
  cin >> H >> W;
  vector<vector<char>> grid(H, vector<char>(W));
  vector<bool> blank_rows(H, false);
  vector<bool> blank_columns(W, false);
  for (int i = 0; i < H; i++) {
    int count = 0;
    for (int j = 0; j < W; j++) {
      char input;
      cin >> input;
      if (input == '.') { count++; }
      grid.at(i).at(j) = input;
      if (j == W - 1 && count == W) { blank_rows.at(i) = true; }
    }
  }
  for (int i = 0; i < W; i++) {
    int count = 0;
    for (int j = 0; j < H; j++) {
      if (grid.at(j).at(i) == '.') { count++; }
      if (j == H - 1 && count == H) { blank_columns.at(i) = true; }
    }
  }
  for (int i = 0; i < H; i++) {
    if (blank_rows.at(i) == true) { continue; }
    for (int j = 0; j < W; j++) {
      if (blank_columns.at(j) == true) {
        if (j == W - 1) { cout << endl; }
        continue;
      }
      else if (j == W - 1) { cout << grid.at(i).at(j) << endl; }
      else { cout << grid.at(i).at(j); }
    }
  }
}

Measured memory_bytes: 764
#include <stdio.h>

int main(void) {
  int a, b, c, d, e, f, result;
  scanf("%d %d %d %d %d %d", &a, &b, &c, &d, &e, &f);
  if (a * 1 + b * 5 + c * 10 + d * 50 + e * 100 + f * 500 >= 1000) {
    printf("%d\n", 1);
  } else {
    printf("%d\n", 0);
  }
  return 0;
}



Measured memory_bytes: 2104
#include <iostream>

using namespace std;

int main()
{
  long long int a, b, c;
  
  cin >> a >> b >> c;
  
  if (a <= b) {
    cout << 1 << endl;
    return (0);
  }
  if (b <= c) {
    cout << -1 << endl;
    return (0);
  }
  long long int div;
  
  if ((a-b) % (b-c) == 0) {
    div = (a-b) / (b-c);
  }
  else {
    div = 1 + (a-b) / (b-c);
  }
  
  cout << div*2 + 1 << endl;
}

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

using namespace std;
using ll = long long;
const double pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
	REP(i, v.size()) { if (i)os << " "; os << v[i]; }return os;
}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
	REP(i, v.size()) { if (i)os << endl; os << v[i]; }return os;
}

const ll V = 200000;
const ll INF = 1LL << 60;
using P = pair<ll, ll>;
vector<P> G[V];	//pair<辺の距離, 行き先の頂点>
vector<ll> dist(V); //dist[i]はsから頂点iへの最短距離が入る
vector<bool> used(V);
void dijkstra(ll s) {	//s : 始点
	//初期化
	fill(dist.begin(), dist.end(), INF);
	fill(used.begin(), used.end(), false);

	priority_queue<P, vector<P>, greater<P>> q;
	q.push(P(0, s));
	while (!q.empty()) {
		ll d;	//d : sからの距離
		ll t;	//t ; 行き先
		tie(d, t) = q.top();
		q.pop();
		if (used[t]) {	//もう探索済みか
			continue;
		}
		used[t] = true;
		dist[t] = d;
		for (P e : G[t]) {
			if (dist[e.second] <= d + e.first) {	//枝刈り
				continue;
			}
			q.push(P(d + e.first, e.second));
		}
	}
}

int main() {
	ll n, m;

	cin >> n >> m;

	REP(i, m) {
		ll a, b;
		cin >> a >> b;
		G[a - 1].push_back(make_pair(1, b - 1));
	}

	dijkstra(0);

	if (dist[n - 1] == 2) {
		cout << "POSSIBLE" << endl;
	}
	else {
		cout << "IMPOSSIBLE" << endl;
	}
}

Measured memory_bytes: 14320
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<cstring>
#include<math.h>
#include<bitset>
#include<queue>
#include<set>
#include<iomanip>
#include<math.h>
// #include<bits/stdc++.h>
using namespace std;
#define ll long long
constexpr long long int INFLL = 1001001001001001LL;
constexpr int INFI = 1000000007;

int main(){
  int N;
  cin >> N;
  map<int,int> mp;
  for(int i=0; i<N; i++){
    int a;
    cin >> a;
    mp[a]++;
  }
  int sum=0;
  for(auto x:mp){
    if(x.first < x.second){
      sum += x.second-x.first;
    }else if(x.first > x.second){
      sum += x.second;
    }
  }
  cout << sum << endl;
  return 0;
}


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

#define ul unsigned long int
#define ull unsigned long long
#define li long long int


int main()
{
  long long int a,b;
  string op;
  cin >> a;
  cin >> op;
  cin >>b;
  while (op!="?") {
    switch (op.c_str()[0]) {
    case '+':
      cout << a + b << endl;
      break;
    case '-':
      cout << a - b << endl;
      break;
    case '*':
      cout << a * b << endl;
      break;
    case '/':
      cout << a / b << endl;
      break;
    }

      cin >> a >> op >> b;
  }

  return 0;
}



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

typedef long long ll;
typedef pair<ll,ll> pi;
typedef vector <ll> vi;
typedef vector <pi> vpi;
#define f first
#define s second
#define FOR(i,s,e) for(ll i=s;i<=ll(e);++i)
#define DEC(i,s,e) for(ll i=s;i>=ll(e);--i)
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define lbd(x, y) lower_bound(all(x), y)
#define ubd(x, y) upper_bound(all(x), y)
#define aFOR(i,x) for (auto i: x)
#define mem(x,i) memset(x,i,sizeof x)
#define fast ios_base::sync_with_stdio(false),cin.tie(0)
int S,W;
int main(){
	fast;
   cin>>S>>W;
  
  if (S > W){
	cout<<"safe";
  }else cout<<"unsafe";
	
}


Measured memory_bytes: 3588
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < int(n); i++)
#define rep1(i,n) for (int i = 1; i <= int(n); i++)
#define repR(i,n) for (int i = int(n)-1; i >= 0; i--)
#define rep1R(i,n) for (int i = int(n); i >= 1; i--)
#define loop(i,a,B) for (int i = a; i B; i++)
#define loopR(i,a,B) for (int i = a; i B; i--)
#define all(x) (x).begin(), (x).end()
#define mp make_pair
#define fst first
#define snd second
#define cauto const auto
#ifdef LOCAL
#define dump(...) cerr << "[" << __LINE__ << ":" << __FUNCTION__ << "] ", _dmp_(#__VA_ARGS__, __VA_ARGS__)
void _dmp_(const char*) { cerr << endl; }
template <class T, class... U>
void _dmp_(const char *s, T const& x, U const& ...y) { const char *o = "({[", *e = "]})"; for (int i = 0; *s != '\0'; cerr << *s++) { if (count(o,o+3,*s)) i++; if (count(e,e+3,*s)) i--; if (!i && *s == ',') break; } cerr << " = " << x; if (*s == ',') cerr << ", ", s++; _dmp_(s, y...); }
#else
#define dump(...)
#endif
using ll = long long;
#define int ll
template <class T> using pque_max = priority_queue<T>;
template <class T> using pque_min = priority_queue<T, vector<T>, greater<T> >;
#define CONAINER_OUTPUT os << "{"; for (auto const& x : v) os << " " << x; return os << " }";
template <class T> ostream& operator<<(ostream& os, vector<T> const& v) { CONAINER_OUTPUT }
template <class T> ostream& operator<<(ostream& os, deque<T> const& v) { CONAINER_OUTPUT }
template <class T> ostream& operator<<(ostream& os, set<T> const& v) { CONAINER_OUTPUT }
template <class T> ostream& operator<<(ostream& os, multiset<T> const& v) { CONAINER_OUTPUT }
template <class T, class U> ostream& operator<<(ostream& os, map<T,U> const& v) { CONAINER_OUTPUT }
#undef CONAINER_OUTPUT
template <class T> istream& operator>>(istream& is, vector<T>& v) { for (auto& x : v) is >> x; return is; }
template <class T, class S> ostream& operator<<(ostream& os, pair<T,S> const& p) { return os << "(" << p.first << ", " << p.second << ")"; }
template <class T, class S> istream& operator>>(istream& is, pair<T,S>& p) { return is >> p.first >> p.second; }
struct Init_ { Init_() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(20); } } init_;

template <class T> void quit(T const& x) { cout << x << endl; exit(0); }
template <class T> bool chmin(T& x, T const& y) { if (x > y) { x = y; return true; } return false; }
template <class T> bool chmax(T& x, T const& y) { if (x < y) { x = y; return true; } return false; }
template <class It> auto sumof(It b, It e) { return accumulate(b,e,typename iterator_traits<It>::value_type{}); }
////////////////////////////////

int32_t main() {
    int n; cin >> n;
    vector<int> a(n),pos(n+1); cin >> a;
    rep (i,n) pos[a[i]] = i;
    set<int> s;
    s.insert(-1);
    s.insert(+n);

    int sum = 0;
    rep1 (x,n) {
        int m = pos[x];
        auto it = s.lower_bound(m);
        int r = *it;
        int l = *--it;
        sum += x*(m-l)*(r-m);
        s.insert(m);
    }
    cout << sum << "\n";
}


Measured memory_bytes: 12800
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <utility>
#include <cmath>
#include <climits>

#define ll long long int
#define pb push_back
#define mk make_pair
#define pq priority_queue

using namespace std;
typedef pair<int, int> P;
typedef pair<ll, int> Pl;
typedef pair<ll, ll> Pll;
const int inf = 1e9;
const ll linf = 1LL << 50;
const double EPS = 1e-10;
vector<int> at[26];

int main(int argc, char const* argv[])
{
  string s;
  cin >> s;
  for(int i = 0; i < s.size(); i++){
    at[int(s[i] - 'a')].pb(i);
  }
  for(int i = 0; i < 26; i++){
    int ld = 0;
    int rd = at[i].size() - 1;
    while(rd - ld >= 1){
      int cnum = rd - ld + 1;
      int snum = at[i][rd] - at[i][ld] + 1;
      if(2 * cnum > snum){
        cout << at[i][ld] + 1 << " " << at[i][rd] + 1 << endl;
        return 0;
      }
      int left = ld + 1;
      int right = rd - 1;
      while(right - left >= 1 && at[i][left] - at[i][ld] == at[i][rd] - at[i][right]){
        left++;
        right--;
      }
      if(at[i][left] - at[i][ld] > at[i][rd] - at[i][right])ld++;
      else rd--;
    }
  }
  cout << -1 << " " << -1 << endl;
	return 0;
}


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

using namespace std;

int main(void){
  ll n, m;
  cin >> n >> m;
  
  if (n == m)
    cout << n + m << endl;
  else
    cout << 2*max(n, m) - 1 << endl;

  return 0;
}


Measured memory_bytes: 256
#!/usr/bin/python

import math
import sys

def main(argv):
    for line in sys.stdin:
        n = int(line)

        answer = 737935835
        if n < 50000:
            answer = math.factorial(n)
        elif n > 50000:
            for i in xrange(50001, n + 1):
                answer = (answer * i) % (10**9 + 7)
        print answer % (10**9 + 7)

if __name__ == "__main__":
    main(sys.argv)

Measured memory_bytes: 2568
#include <bits/stdc++.h>
#define rep(a, b, c) for(int a = (b); a <= (c); ++ a)
#define per(a, b, c) for(int a = (b); a >= (c); -- a)
using namespace std;

const int maxn = 2e5 + 5;
int n;
char s[maxn];

struct automaton{
  int son[maxn][26], lst[maxn];
  int dp[maxn], nxt[maxn];

  void build(){
	per(i, n, 0){
	  rep(j, 0, 25) son[i][j] = lst[j];
	  lst[s[i] - 'a'] = i;
	}
  }

  void dfs(int u){
	printf("%c", 'a' + nxt[u]);
	if(dp[u] == 0) return ;
	dfs(son[u][nxt[u]]);
  }

  void sol(){
	per(i, n, 0){
	  dp[i] = n;
	  rep(j, 0, 25){
		if(son[i][j] == 0){
		  dp[i] = 0;
		  nxt[i] = j;
		  break;
		}
		else{
		  if(dp[son[i][j]] + 1 < dp[i]){
			dp[i] = dp[son[i][j]] + 1;
			nxt[i] = j;
		  }
		}
	  }
	}
	dfs(0);
	puts("");
  }
}am;

int main(){
  scanf("%s", s + 1);
  n = strlen(s + 1);
  am.build();
  am.sol();
  return 0;
}


Measured memory_bytes: 23040
from itertools import combinations as comb
def cube_dist(a,b):
	return sum([(a[i]-b[i])**2 for i in range(3)])
def cal_total_dist(t):
	if len(t) == 1:
		return 0
	return sum([cube_dist(ca,cb) for ca, cb in comb(t,2)])

N, M = map(int,raw_input().split())
color = [tuple(map(float,raw_input().split())) for i in range(N)]
print max([cal_total_dist(ctuple) for ctuple in comb(color,M)])

Measured memory_bytes: 10120
lst=[]
n = int(input())
for i in range(n) :
    ope = list(map(int, input().split()))
    if ope[0] == 0 :
        lst.append(ope[1])
    elif ope[0] == 1 :
        print(lst[ope[1]])
    elif ope[0] == 2 :
        del lst[-1]


Measured memory_bytes: 13360
#include<bits/stdc++.h>
using namespace std;
#define int long
#define mod (long)(1e9+7)
string str;
int d;

void manupulate(string &str)
{
    for(auto &x:str)
    x-=48;
}

int dp[10001][2][101];

int rec(int idx,int tight,int sum)
{
    if(idx>=str.size())
    {
        if(sum%d==0)
            return 1;
        else
            return 0;
    }
    
    if(dp[idx][tight][sum]!=-1)
        return dp[idx][tight][sum];
    
    int n;
    if(tight)
        n=str[idx];
    else
        n=9;
    
    int ans=0;
    for(int i=0;i<=n;++i)
        ans=(rec(idx+1,tight&&i==n?true:false,(i+sum)%d)+ans)%mod;
    
    dp[idx][tight][sum]=ans;
    return ans;
}

signed main()
{
    cin>>str>>d;
    manupulate(str);
    memset(dp,-1,sizeof dp);
    cout<<(rec(0,true,0)-1+mod)%mod;
}

Measured memory_bytes: 16896
import sys
sys.setrecursionlimit(2147483647)
INF = 1 << 60
MOD = 10**9 + 7 # 998244353
input = lambda:sys.stdin.readline().rstrip()
from collections import Counter
def resolve():
    n, p = map(int, input().split())
    S = input()

    if p == 2 or p == 5:
        res = 0
        for i, c in enumerate(S, 1):
            if int(c) % p == 0:
                res += i
        print(res)
        return

    res = 0
    now = 0
    counter = Counter()
    counter[0] = 1
    for i in range(n):
        now = (10 * now + int(S[i])) % p
        k = now * pow(10, (p - 2) * i, p) % p
        res += counter[k]
        counter[k] += 1
    print(res)
resolve()

Measured memory_bytes: 42828
#include <iostream>

using namespace std;

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

  int K, A, B, found = 0;
  int K_value = 0;
  cin >> K >> A >> B;

  while (K_value <= B) {
    if (K_value >= A) {
      found = 1;
      cout << "OK" << endl;
      break;
    }
    K_value += K;
  }

  if (!found)
    cout << "NG" << endl;

return 0;
}


Measured memory_bytes: 3132
#include <iostream>

int
main(int argc, char** argv) {
    int a, b;
    std::cin >> a >> b;

    if (0 != ((a + b) & 0x01)) {
        std::puts("IMPOSSIBLE");
    } else {
        std::printf("%d\n", (a+b)/2);
    }
    return 0;
}

Measured memory_bytes: 888
#include<bits/stdc++.h>
using namespace std;
int n,a,b,k[200005];
bool vis[20];
void dfs(int x,int y,int l,int r)
{
    k[l]=x;
    k[r]=y;
    if(l>=r-1) return;
    int t;
    for(int i=0;i<n;i++)
    {
        if(vis[i]) continue;
        if((1<<i&x)!=(1<<i&y)) {t=i;break;}
    }
    vis[t]=true;
    int p=0,q=0;
    bool flag=true;
    for(int i=0;i<n;i++)
    {
        if(vis[i])
        {
            p^=(1<<i)&x;
            q^=(1<<i)&y;
        }
        else if(flag)
        {
            p^=((1<<i)&x)^(1<<i);
            q^=((1<<i)&x)^(1<<i);
            flag=false;
        }
        else
        {
            p^=(1<<i)&x;
            q^=(1<<i)&x;
        }
    }
    dfs(x,p,l,(l+r)/2);
    dfs(q,y,(l+r)/2+1,r);
    vis[t]=false;
}
int main()
{
    scanf("%d%d%d",&n,&a,&b);
    if(__builtin_popcount(a)%2==__builtin_popcount(b)%2)
    {
        printf("NO\n");return 0;
    }
    printf("YES\n");
    int t=1<<n;
    dfs(a,b,0,t-1);
    for(int i=0;i<t;i++)
        printf(i==t-1?"%d\n":"%d ",k[i]);
}


Measured memory_bytes: 1536
n=int(input())
v=list(map(int,input().split()))

judge_2n_1={}
judge_2n={}

for i in range(n):
    if i%2==0:
        if v[i] not in judge_2n_1.keys():
            judge_2n_1[v[i]]=1
        else:
            judge_2n_1[v[i]]+=1
    else:
        if v[i] not in judge_2n.keys():
            judge_2n[v[i]]=1
        else:
            judge_2n[v[i]]+=1

#print(max(judge_2n))
#print(max(judge_2n_1))

judge_2n=sorted(judge_2n.items(),key=lambda x:x[1],reverse=True)
judge_2n_1=sorted(judge_2n_1.items(),key=lambda x:x[1],reverse=True)
answer=n-1

for i in judge_2n[:2]:
    for j in judge_2n_1[:2]:
        if i[0]!=j[0]:
            answer=min(answer,n-i[1]-j[1])
        else:
            answer=min(answer,n-max(i[1],j[1]))
print(answer)



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

using namespace std;
typedef long long ll;
typedef pair<ll, ll> p_ll;

template<class T>
void debug(T itr1, T itr2) { auto now = itr1; while(now<itr2) { cout << *now << " "; now++; } cout << endl; }
#define repr(i,from,to) for (int i=(int)from; i<(int)to; i++)
#define all(vec) vec.begin(), vec.end()
#define rep(i,N) repr(i,0,N)
#define per(i,N) for (int i=(int)N-1; i>=0; i--)

const ll MOD = pow(10,9)+7;
const ll LLINF = pow(2,61)-1;
const int INF = pow(2,30)-1;

vector<ll> fac;
void c_fac(int x=pow(10,6)+10) { fac.resize(x,true); rep(i,x) fac[i] = i ? (fac[i-1]*i)%MOD : 1; }
ll inv(ll a, ll m=MOD) { ll b = m, x = 1, y = 0; while (b!=0) { int d = a/b; a -= b*d; swap(a,b); x -= y*d; swap(x,y); } return (x+m)%m; }
ll nck(ll n, ll k) { return fac[n]*inv(fac[k]*fac[n-k]%MOD)%MOD; }
ll gcd(ll a, ll b) { if (a<b) swap(a,b); return b==0 ? a : gcd(b, a%b); }
ll lcm(ll a, ll b) { return a/gcd(a,b)*b; }

vector<vector<int>> d;
vector<string> S;

struct coord {int h; int w;};

void bfs(int h, int w) {
  coord dic[4] = {{1,0}, {0,1}, {0,-1}, {-1,0}};
  queue<coord> q; q.push({h,w});
  while (q.size()) {
    coord c = q.front(); q.pop();
    rep(i,4) {
      int nh = c.h+dic[i].h, nw = c.w+dic[i].w;
      if (d[nh][nw]==-1&&S[nh][nw]=='.') {
        d[nh][nw] = d[c.h][c.w] + 1;
        q.push({nh,nw});
      }
    }
  }
}

int main() {
  int H, W; cin >> H >> W; H+=2; W+=2;
  S.resize(H); rep(i,W) { S[0] += "#"; S[H-1] += "#"; }
  rep(i,H-2) { string tmp; cin >> tmp; S[i+1] = "#" + tmp + "#"; }
  // rep(i,H) cout << S[i] << endl;

  int result = 0;
  rep(i,H) rep(j,W) {
    if (S[i][j]=='#') continue;
    d.assign(H,vector<int>(W,-1)); d[i][j] = 0;
    bfs(i,j);
    int res = 0;
    rep(x,H) rep(y,W) res = max(res, d[x][y]);
    result = max(result, res);
    // rep(i,H) debug(all(d[i])); cout << endl;
  }
  cout << result << endl;
  return 0;
}

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

#define FAST ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define REP(i,a,n) for (int i=a;i<n;i++)
#define ALL(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define UM unordered_map
#define PB push_back
#define V vector
#define EPS 1e-8
typedef long long int LL;
typedef string STR;
/*FIN*/

int main()
{
	FAST;
	int n;
	cin>>n;
	V<LL> a(n+1), s(n+1);
	for(auto &i:a) cin>>i;
	LL _t = 1LL;
	bool f=1;
	for(int i=0;i<=n;i++) {
        if(_t < 1e18) s[i] = _t - a[i], _t = 2LL*s[i] ;
        else s[i] = 1e18 ;
		if(s[i]<0) {
			f=0;
			break;
		}
	}
	if(a[n]==0) f=0;
	LL ans=0;
	if(f) {
		ans += a[n];
		for(int d = n-1; d>=0; d--) {
			if(a[d+1] > 2*s[d]) {
				f=0;
				break;
			}
			ans += min(a[d+1], s[d]) + a[d];
			a[d] += min(a[d+1],s[d]);
		}
	}
	if(f) cout<<ans<<endl;
	else cout<<"-1\n";
	return 0;
}


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

typedef struct {
	int parent;
	long long total;
	int visit;
}node_t;

node_t node[200030] = { 0 };

int root(int node_n) {
	if (node_n == 1) return 1;
	else if (node_n == 0)return 0;
	else 
	return root(node[node_n].parent);
}
void joint(int upper, int lower){
	int temp = node[lower].parent;

	node[lower].parent = upper;
	if (temp != 0)
		joint(lower, temp);
}
long long ans(int i) {
	if (node[i].visit)return node[i].total;
	else {
		node[i].visit = 1;
		node[i].total += ans(node[i].parent);
		return node[i].total;
	}
}
int main(void) {
	int n, q;
	int a, b;
	int p, x;

	scanf("%d %d", &n, &q);
	node[1].parent = 1;
	node[1].visit = 1;
	for (int i = 0; i < n - 1; i++) {
		scanf("%d %d", &a, &b);
		if (a != 1 && root(b)) joint(b, a);
		else joint(a, b);
	}
	for (int i = 0; i < q; i++) {
		scanf("%d %d", &p, &x);
		node[p].total += x;
	}
	for (int i = 1; i <= n; i++) {
		printf("%lld ", ans(i));
	}
}

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


int main(){
    int x,y;
    cin >> x >> y;
    if( ((y-2*x)%2==0 && y-2*x>=0) && ((4*x-y)%2==0 && 4*x-y>=0) )
        cout << "Yes" << endl;
    else cout << "No" << endl; 
    return 0;
}

Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
struct fast_ios { fast_ios(){cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20);} } fast_ios_;

int main()
{
    int N, M;
    cin >> N >> M;

    cout << (M==N?"Yes":"No") << endl;
    
    return 0;
}

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

struct UnionFind {
  std::vector<int32_t> parent;
  std::vector<int32_t> rank;

  UnionFind(uint32_t N) : parent(N, -1), rank(N, 0) {}

  int root(uint32_t n) {
    if(parent[n] < 0) return n;
    return parent[n] = root(parent[n]);
  }

  void unite(uint32_t x, uint32_t y) {
    x = root(x), y = root(y);
    if(x == y) return;
    if(rank[x] > rank[y]){
      parent[x] += parent[y];
      parent[y] = x;
    }else{
      parent[y] += parent[x];
      parent[x] = y;
      if(rank[x] == rank[y]) rank[y]++;
    }
  }
};

int main() {
  uint32_t N = 0, M = 0;
  std::cin >> N >> M;

  UnionFind uf(N);

  for (size_t i = 0; i < M; i++)
  {
    uint32_t A = 0, B = 0;
    std::cin >> A >> B;
    uf.unite(A-1, B-1);
  }
  
  uint32_t max_size = 0;
  for (size_t i = 0; i < N; i++)
  {
    if(uf.parent[i] < 0){
      uint32_t size = static_cast<uint32_t>(-uf.parent[i]);
      if(max_size < size){
        max_size = size;
      }
    }
  }
  
  std::cout << max_size << std::endl;

  return 0;
}

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


using ll=long long;
int main(){
    ll n;
    ll m;
    cin>>n>>m;
    string s,t;
    cin>>s>>t;
    ll g=__gcd(n,m);
    ll l=n*m/g;
    for(int i=0;i<n;i++){
        ll x=i*n/g;
        ll y=i*m/g;
        if(x<n && y<m){
            if(s[x]!=t[y]){
                cout<<-1<<endl;
                return 0;
            }
        }
        else{
            break;
        }
    }
    cout<<l<<endl;
    return 0;
}

Measured memory_bytes: 512
#include<iostream>
#include<fstream>
#include<string>
#include<algorithm>
using namespace std;
struct island{
	int c,d;
};
bool myComp(const island&a,const island&b){
	if(a.d!=b.d)   return a.d<b.d;
	else           return a.c<b.c;
}
island a[26];
int main(){
	//ifstream cin("input.txt");
	//ofstream cout("output.txt");
	for(int n;cin>>n&&n;){
		for(int i=0;i<n;i++)
			cin>>a[i].c>>a[i].d;
		sort(&a[0],&a[n],myComp);
		int sum=0,flag=0;
		for(int i=0;i<n;i++){
			sum+=a[i].c;
			if(sum>a[i].d)   flag=1;
		}
		cout<<(flag==0?"Yes\n":"No\n");
	}
}
		
			

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

int main(){
    int h, w;
    cin >> h >> w;
    vector<string> s(h);
    for(size_t i = 0; i < h; i++)
    {
        cin >> s[i];
    }
    vector<int> xh = {-1, 0, 0, 1};
    vector<int> xw = { 0,-1, 1, 0};
    for(size_t i = 0; i < h; i++)
    {
        for(size_t j = 0; j < w; j++)
        {
            if(s[i][j] == '#') { 
                bool isOK = false;
                for(size_t k = 0; k < 4; k++)
                {
                    int hind = i+xh[k];
                    int wind = j+xw[k];
                    if (hind >= 0 && hind <= h-1 && wind >= 0 && wind <= w-1 && s[hind][wind] == '#')
                    {
                        isOK = true;
                        break;
                    }
                }
                if(!isOK){
                    cout << "No" << endl;
                    return 0;
                }
            }
        }
    }
    cout << "Yes" << endl;
    
    return 0;
}

Measured memory_bytes: 256
A,B,C,K=map(int,input().split())
a=A;b=B;c=C;p=0

if K<=a:
  p=p+K
  print(p)
else:
  p=p+a
  if (K-a)<=b:
    p=p+(K-a)*0
    print(p)
  else:
    p=p+b*0
    if (K-a-b)<=c:
      p=p+(K-a-b)*-1
      print(p)
    else:
      p=p+c*-1

Measured memory_bytes: 9200
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

ans = B[A[0]-1]
for i in range(1, N):
    ans += B[A[i]-1]
    if(A[i-1]+1 == A[i]):
        ans += C[A[i-1]-1]

print(ans)

Measured memory_bytes: 3064
// https://atcoder.jp/contests/abc102/tasks/arc100_a

#include <algorithm>
#include <cmath>
#include <iostream>
#include <tuple>
#include <vector>
using namespace std;

typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;

#define EPS (1e-7)
#define INF (1e9)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()

ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a * b / gcd(a, b); }

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n, m, sum = 0;
    cin >> n;
    vector<int> v, w;

    for (int i = 0; i < n; i++) {
        cin >> m;
        v.push_back(m);
        w.push_back(m - i - 1);
    }
    sort(ALL(w));

    int mid = w[n / 2];
    for (int i = 0; i < n; i++) {
        sum += abs(v[i] - mid - i - 1);
    }
    cout << sum << endl;

    return 0;
}


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

int main() {
  int k, a, b, c;
  std::cin >> k;
  
  long ans = 0;
  for (a = 1; a <= k; a++) {
  	for (b = 1; b <= k; b++) {
  		for (c = 1; c <= k; c++) {
  			ans += std::__gcd(std::__gcd(a, b), c);
  		}
  	}
  }
  
  std::cout << ans << std::endl;
  
  return 0;
}

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

int		main(void)
{
	int A, B;
	int i;
	int N, M;
	int ct = 0;

	cin >> N >> M;
	vector<int> goodpeak(N, true);
	vector<int> Hs(N);
	for (i = 0; i < N; i++)
	{
		cin >> Hs[i];
	}
	for (i = 0; i < M; i++)
	{
		cin >> A >> B;
		if (Hs[A - 1] <= Hs[B - 1])
		{
			goodpeak[A - 1] = false;
		}
		if (Hs[B - 1] <= Hs[A - 1])
		{
			goodpeak[B - 1] = false;
		}
	}

	for (i = 0; i < N; i++)
	{
		if (goodpeak[i] == true)
		{
			ct++;
		}
	}
	cout << ct;
	return (0);
}

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

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

	int nn[3];
	nn[0] = n % 10;
	nn[1] = (n % 100)/10;
	nn[2] = n /100;

	if (nn[0] == 7 || nn[1] == 7 || nn[2] == 7)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;


}


Measured memory_bytes: 3580
#include <bits/stdc++.h>
using namespace std;
#define long long long
#define read cin >>
#define echo cout <<
#define fin << endl
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = (0); i < (n); ++i)

// for debug macro
bool global_debug_flag = false;
#define DEBUG(val) \
  if (global_debug_flag) cout << #val << " = " << val << endl

int main() {
  int n;
  read n;
  vector<int> data(n);
  REP(i, n) {
    int x;
    read x;
    data[i] = x;
  }
  // sort(data.begin(), data.end());
  int now_renga = 1;
  int idx = 0;
  bool flag = false;
  REP(i, n) {
    if (data[i] == now_renga) {
      flag = true;
      now_renga++;
    }
  }

  if (flag) {
    cout << n - (now_renga - 1) << endl;
  } else {
    cout << -1 << endl;
  }
}


Measured memory_bytes: 1152
N = int(input())
S = list(input())
for i in range(len(S)):
  if ord(S[i])+N <= 90:
    S[i] = chr(ord(S[i])+N)
  else:
    S[i] = chr(ord(S[i])+N-26)
for j in S:
  print(j,end = "")

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

using namespace std;
using ll = long long;
using ull = unsigned long long;
using P = pair<int,int>;
#define rep(i,n) for(ll i = 0;i < (ll)n;i++)
#define ALL(x) (x).begin(),(x).end()
#define MOD 1000000007



int main(){
  
  ll n,c;
  cin >> n >> c;
  vector<ll> x(n),v(n);
  rep(i,n)cin >> x[i] >> v[i];
  ll res = 0;
  {
    vector<ll> s(n+1,0);
    rep(i,n)s[i+1] = s[i]+v[i]-x[i]+(i != 0 ? x[i-1] : 0);
    rep(i,n)s[i+1] = max(s[i+1],s[i]);
    ll k = 0;
    res = max(res,s[n]);
    for(int i = n-1;i >= 0;i--){
      k += v[i]-(c-x[i])*2;
      if(i != n-1)k += (c-x[i+1])*2;
      res = max(res,k+s[i]);
    }
  }
  {
    vector<ll> s(n+1,0);
    for(int i = n;i > 0;i--)s[i-1] = s[i]+v[i-1]-(c-x[i-1])+(i != n ? (c-x[i]) : 0);
    for(int i = n;i > 0;i--)s[i-1] = max(s[i-1],s[i]);
    ll k = 0;
    res = max(res,s[0]);
    rep(i,n){
      k += v[i]-x[i]*2;
      if(i != 0)k += x[i-1]*2;
      res = max(res,k+s[i+1]);
    }
  }
  cout << res << endl;



  return 0;
}


Measured memory_bytes: 5632
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<cmath>
#include<cstdio>
#include<queue>
#include<deque>
#include<map>
#include<stack>
#include<set>
#include<tuple>
using namespace std;
typedef pair<int,int> ii;
typedef long long ll;
typedef pair<ll,ll> pll;
const int INF=1e9;
const ll MOD=1e9+7;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};

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

int dis2(int x1,int y1,int x2,int y2){
    return (x1-x2)*(x1-x2)+(y1-y2)*(y1-y2);
}
ll power(ll a,ll x){
    ll res=1;
    while(x>0){
        if(x&1) res=res*a%MOD;
        a=a*a%MOD;
        x>>=1;
    }
    return res;
}
string s;
int g(int i){
    if(i<0) return 0;
    if(i==0) return 1;
    if(i==1&&s[1]==s[0]) return 1;

}
int main(){
    int x,n;cin>>x>>n;
    vector<bool> used(102,false); 
    for(int i=0;i<n;i++){
        int p;cin>>p;
        used[p]=true;
    }
    int ans=0;
    int s=x;
    for(int i=1;i<=101;i++)if(!used[i]){
        if(s>abs(i-x)){
            ans=i;
            s=abs(i-x);
        }
    }
    cout<<ans<<endl;
    return 0;
}

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

int main(){
  long long n;
  cin >> n;
  vector<long long> vec;
  for(long long i=0; i<n; i++){
    long long num;
    cin >> num;
    vec.push_back(num);
  }
  vector<long long> resVec = vec;
  sort(vec.begin(), vec.end(), greater<long long>());
  long long max = vec[0];
  bool maxOverTwo = (vec[1] == max) ? true : false;
  long long second = -1;
  for(long long i=0; i<n; i++){
    if(vec[i] != max){
      second = vec[i];
      break;
    }
  }
  for(long long i=0; i<n; i++){
    if(second == -1){
      if(i != n-1){
        cout << max << endl;
      }else{
      	cout << max;
      }
    }else{
      if(resVec[i] == max){
        if(i != n-1){
          if(maxOverTwo){
            cout << max << endl;
          }else{
            cout << second << endl;
          }
        }else{
          if(maxOverTwo){
            cout << max;
          }else{
          	cout << second;
          }
        }
      }else{
        if(i != n-1){
          cout << max << endl;
        }else{
          cout << max;
        }
      }
    }
  }
  return 0;
}

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

int main(){
  int nin;
  while(1){ 
    scanf("%d",&nin);
    if(!nin)break;

    long long int human[4002]={0};
    long long int no[4002],tanka,kazu,outflag=0;;
    
    for(int i=0;i<nin;i++){
      scanf("%d %d %d",&no[i],&tanka,&kazu);
      human[no[i]]+=tanka*kazu;
    }
    
    for(int i=0;i<nin;i++){
      if(human[no[i]]>=1000000 && human[no[i]]!=-1){
	printf("%d\n",no[i]);
	human[no[i]]=-1;
	outflag=1;
      }
    }
    
    if(outflag==0)printf("NA\n");
    
  }
}

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

using namespace std ;

const int MAX = 3e5 + 10 ;

int arr[MAX] , freq[MAX] , suff[MAX] ;
vector<int>er[MAX] ;
int n ;

int main()
{
	ios_base::sync_with_stdio(0) ;
	cin.tie(0) ;
	cin>>n ;
	vector<int>v ;
	for(int i = 0 ; i < n ; ++i)
	{
		cin>>arr[i] ;
		freq[arr[i]]++ ;
	}
	for(int i = 0 ; i < n ; ++i)
	{
		if(freq[arr[i]])
			v.push_back(freq[arr[i]]) ;
		freq[arr[i]] = 0 ;
	}
	sort(v.rbegin() , v.rend()) ;
	int sz = v.size() ;
	for(int i = sz-1 ; i >= 0 ; --i)
		suff[i] = suff[i+1] + v[i] ;
	int idx = sz-1 ;
	for(int i = 1 ; i <= n ; ++i)
	{
		while(idx >= 0 && v[idx] < i)
			idx-- ;
		int k = idx+1 + suff[idx+1] / i ;
		er[k].push_back(i) ;
	}
	set<int>s ;
	for(int i = 0 ; i <= n ; ++i)
		s.insert(i) ;
	for(int i = 1 ; i <= n ; ++i)
	{
		cout<<*s.rbegin()<<"\n" ;
		for(auto &j : er[i])
			s.erase(j) ;
	}
	return 0 ;
}		

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


def read_values():
    return map(int, input().split())


def read_list():
    return list(read_values())


def func(N, mod):
    F = [1]
    for i in range(1, N + 1):
        F.append(F[-1] * i % mod)
    return F


def inv(a, mod):
    return pow(a, mod - 2, mod)


def C(F, a, b, mod):
    return F[a] * inv(F[b], mod) * inv(F[a - b], mod) % mod


def f(V, L, R):
    import bisect
    N = len(V)
    
    res = 0
    for r in range(min(N - L, R) + 1):
        LL = sorted(V[:L] + V[-r:] if r != 0 else V[:L])
        k = min(R - r, bisect.bisect_left(LL, 0))
        res = max(res, sum(LL[k:]))
    return res


def main():
    N, K = read_values()
    V = read_list()
    
    res = 0
    for L in range(K + 1):
        res = max(res, f(V, L, K - L))
    print(res)


if __name__ == "__main__":
    main()



Measured memory_bytes: 3188
import math
N,D = map(int,input().split())
x = [0] * N
y = [0] * N
cnt=0
for i in range(N):
    x[i], y[i] = map(int, input().split())
    if math.sqrt(x[i]**2 + y[i]**2) <= D:
        cnt +=1
print(cnt)

Measured memory_bytes: 73104
#include <algorithm>
#include <climits>
#include <cmath>
#include <deque>
#include <iostream>
#include <map>
#include <memory>
#include <numeric>
#include <set>
#include <string>
#include <utility>
#include <vector>

using namespace std;

#define all(collection) (collection).begin(), (collection).end()
#define loop(i, times) for(int i = 0; i < times; i++)
#define seloop(i, start_index, end_index) for(int i = start_index; i < end_index; i++)
#define eqseloop(i, start_index, end_index) for(int i = start_index; i <= end_index; i++)

char Search5000(string s, int k)
{
	loop(i, s.size() - 1)
	{
		if (i == k-1)
			return s[k-1];

		if (s[i] != '1')
			return s[i];
	}

	return s[s.size() - 1];
}

int main()
{
	string s; cin >> s;
	long long k; cin >> k;

	cout << Search5000(s, k);

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ui = uint32_t;
const int MOD = 1e+9+7;

int a[21][21] = {};
int dp[21][1 << 21] = {};

ui popcnt(ui n){
    ui c = 0;
    c = (n & 0x55555555) + ((n>>1) & 0x55555555);
    c = (c & 0x33333333) + ((c>>2) & 0x33333333);
    c = (c & 0x0f0f0f0f) + ((c>>4) & 0x0f0f0f0f);
    c = (c & 0x00ff00ff) + ((c>>8) & 0x00ff00ff);
    c = (c & 0x0000ffff) + ((c>>16) & 0x0000ffff);
    return(c);
}

int main(){
    int n;
    cin >> n;
    int lim = 1 << n;
    for(int i = 0; i < n; i++){
        for(int j = 0; j < n; j++){
            cin >> a[i][j];
            if(i == 0) dp[0][1 << j] = a[i][j]; // 最初の一人目だけはaの値と同値
        }
    }
    for(int i = 1; i < n; i++){
        for(ui b = 1; b < lim; b++){
            if(i != popcnt(b)) continue; // i人決まってる状態の場合のみ処理でよい
            for(int j = 0; j < n; j++){
                if(b & (1 << j) || !a[i][j]) continue; // 既にペアになってる奴や相性の良くないのは無視
                dp[i][b | 1 << j] += dp[i-1][b];
                dp[i][b | 1 << j] %= MOD;
            }
        }
    }
    cout << dp[n-1][lim-1] << endl;
}

Measured memory_bytes: 160128
from pprint import pprint

def solve(a, b, c):
    nums = set()
    nums.add(a)
    nums.add(b)
    nums.add(c)
    print("Yes" if len(nums) == 2 else "No")


if __name__ == "__main__":
    a, b, c = map(int, input().split(" "))
    solve(a, b, c)

Measured memory_bytes: 3700