akhauriyash/Code-Regression huggingface dataset:
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii =  pair<int, int>;
using pll =  pair<long long, long long>;
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
constexpr long long INF = 1000000009LL;
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main() {
    int n; cin >> n;
    int cnt = 0;
    for(int i=1; i<=1000100; i++){
        int j = n-i;
        if(i<j && j>0 && i!=j) cnt++;
    }
    cout << cnt << ln;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, e) for (int i = (int)(s); i <= (int)(e); i++)
#define printYesNo(is_ok) puts(is_ok ? "Yes" : "No");
#define SORT(v) sort(v.begin(), v.end());
#define RSORT(v) sort(v.rbegin(), v.rend());
#define REVERSE(v) reverse(v.begin(), v.end());

template <typename T>
void printlnVector(T v)
{
  rep(i, v.size())
  {
    cout << v[i] << endl;
  }
}

template <typename T>
void printVector(T v)
{
  rep(i, v.size())
  {
    cout << v[i] << " ";
  }
  cout << endl;
}

int main()
{
  string S, T;
  cin >> S >> T;
  if (S == T.substr(0, S.size()))
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = s; i < (int)(n); i++)
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

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

int		main(void)
{
	int a, b;
	cin >> a >> b;
	cout << 6 - a - b << endl;
}


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

int h, w, mx, c[2005][2005];
char a[2005][2005];
int main() {
	int i, j, x, y;
	cin >> h >> w;
	for(i=0; i<h; i++) scanf("%s", a[i]);
	for(i=0; i<h; i++) {
		x = y = 0;
		for(j=0; j<w; j++) {
			c[i][j] += (a[i][j]=='.' ? ++x : x=0);
			c[i][w-1-j] += (a[i][w-1-j]=='.' ? ++y : y=0);
		}
	}
	for(j=0; j<w; j++) {
		x = y = 0;
		for(i=0; i<h; i++) {
			c[i][j] += (a[i][j]=='.' ? ++x : x=0);
			c[h-1-i][j] += (a[h-1-i][j]=='.' ? ++y : y=0);
		}
	}
	for(i=0; i<h; i++) for(j=0; j<w; j++) {
		mx = max(mx, c[i][j]);
	}
	cout << mx - 3;
	return 0;
}

Measured memory_bytes: 19840
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,q;
  string s;
  cin>>n>>q>>s;
  vector<int> c(n+1,0);
  for(int i=2;i<=n;i++)
    c.at(i)=c.at(i-1)+(s.at(i-2)=='A'&&s.at(i-1)=='C'?1:0);
  for(int i=0;i<q;i++){
    int l,r;
    cin>>l>>r;
    l--;
    cout<<c.at(r)-c.at(l)-(l-1>=0&&s.at(l-1)=='A'&&s.at(l)=='C'?1:0)<<endl;
  }
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
int main() {
	int r; cin >> r;
	if(r<1200){
		cout << "ABC" << endl;
	}
	else if(r<2800){
		cout << "ARC" << endl;
	}else{
		cout << "AGC" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <map>
#include <iomanip>
typedef long long ll;
#define rep(i,a,b) for(int i=a;i<b;++i)
#define rrep(i,a,b) for(int i=a;i>=b;--i)
using namespace std;
ll mod = 1e9 + 7;

using namespace std;
using Graph = vector<vector<int>>;
Graph G;


int main()
{
	ll S;
	cin >> S;
	int value = 0;
	int ans = 0;
	for (int i = 1; i <= S; i++)
	{
		value += i;
		if (value >= S)
		{
			ans = i;
			break;
		}

	}
	
		cout << ans << endl;

	
	return 0;
}


Measured memory_bytes: 256
import java.util.*;
import java.awt.geom.*;
import java.io.*;
public class Main{
	
	private void doit(){
		Scanner sc = new Scanner(System.in);
		int [] data = new int[3];
		for(int i = 0 ; i < 3; i++){
			data[i] = i;
		}
		while(sc.hasNext()){
			String [] input = sc.next().split(",");
			int change1 = input[0].charAt(0) - 'A';
			int change2 = input[1].charAt(0) - 'A';
			int temp = data[change1];
			data[change1] = data[change2];
			data[change2] = temp;
		}
		int ind = -1;
		for(int i = 0; i < 3; i++){
			if(data[i] == 0){
				ind = i;
				break;
			}
		}
		System.out.println((char) (ind + 'A'));
	}

	public static void main(String [] args){
		new Main().doit();
	}
}

Measured memory_bytes: 12000
#include<bits/stdc++.h>
using namespace std;
inline void rd(int &x){
  int k, m=0;
  x=0;
  for(;;){
    k = getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
inline void wt_L(char a){
  putchar_unlocked(a);
}
inline void wt_L(int x){
  char f[10];
  int m=0, s=0;
  if(x<0){
    m=1;
    x=-x;
  }
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    putchar_unlocked('-');
  }
  while(s--){
    putchar_unlocked(f[s]+'0');
  }
}
inline void wt_L(const char c[]){
  int i=0;
  for(i=0;c[i]!='\0';i++){
    putchar_unlocked(c[i]);
  }
}
int M;
int K;
int res[300000];
int main(){
  int i, j;
  rd(M);
  rd(K);
  if(K >= (1<<M)){
    wt_L(-1);
    wt_L('\n');
    return 0;
  }
  if(M==1){
    if(K==0){
      wt_L("0 0 1 1");
      wt_L('\n');
    }
    else{
      wt_L("-1");
      wt_L('\n');
    }
    return 0;
  }
  j = 0;
  for(i=0;i<1<<M;i++){
    if(i!=K){
      res[j++] = i;
    }
  }
  res[j++] = K;
  for(i=(1<<M)-1;i>=0;i--){
    if(i!=K){
      res[j++] = i;
    }
  }
  res[j++] = K;
  {
    int Lj4PdHRW;
    if(j==0){
      putchar_unlocked('\n');
    }
    else{
      for(Lj4PdHRW=0;Lj4PdHRW<j-1;Lj4PdHRW++){
        wt_L(res[Lj4PdHRW]);
        wt_L(' ');
      }
      wt_L(res[Lj4PdHRW]);
      wt_L('\n');
    }
  }
  return 0;
}
// cLay varsion 20190706-1

// --- original code ---
// int M, K;
// int res[3d5];
// {
//   int i, j;
// 
//   rd(M,K);
//   if(K >= (1<<M)){
//     wt(-1);
//     return 0;
//   }
// 
//   if(M==1){
//     wt( if[K==0, "0 0 1 1", "-1"] );
//     return 0;
//   }
//   
//   j = 0;
//   rep(i,1<<M) if(i!=K) res[j++] = i;
//   res[j++] = K;
//   for(i=(1<<M)-1;i>=0;i--) if(i!=K) res[j++] = i;
//   res[j++] = K;
// 
//   wt(res(j));
// }


Measured memory_bytes: 2816
#include <iostream>
#include <vector>
#include <cstdio>
#include <cmath>
using namespace std;
int n,k;
vector<int> v,dp;
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cin>>n>>k;
    v.resize(n);
    for(int i=0;i<n;++i)  cin>>v[i];
    dp.resize(n,0);
    dp[0]=0;dp[1]=abs(v[1]-v[0]);
    for(int i=2;i<n;++i)
    {
        dp[i]=abs(v[i]-v[i-1])+dp[i-1];
        for(int j=2;j<=min(k,i);++j)
            dp[i]=min(dp[i],(int)abs(v[i]-v[i-j])+dp[i-j]);
    }
    printf("%d",dp[n-1]);
    return 0;
}


Measured memory_bytes: 1024
N,M = map(int,input().split())
L=[]
R=[]
Nlist = list(range(1,N+1))
for i in range(M):
  L_n,R_n = map(int,input().split())
  L.append(L_n)
  R.append(R_n)

Lmax=max(L)
Rmin=min(R)
if Rmin < Lmax:
  print(0)
else:
  print(Rmin-Lmax+1)


Measured memory_bytes: 14980
#include <cstdio>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <queue>
#include <set>
#include <cmath>
#include <iomanip>
#include <tuple>
#include <map>
using namespace std;
typedef long long ll;
const int mod = 1e9 + 7;

typedef pair<int,int> P;

int main() {
    int n; cin >> n;
    vector<ll> a(n);
    map<ll,ll> mp;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        mp[a[i]]++;
    }
    ll ans = 0;
    for (const auto& p : mp) {
        ans += p.second * (p.second - 1) / 2;
    }
    for (int i = 0; i < n; i++) {
        cout << ans - mp[a[i]] + 1 << "\n";
    }
}

Measured memory_bytes: 11008
#include<bits/stdc++.h>
#define ll long long int
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
static const ll MAX = 1000000000000000;
static const int NIL = -1;
using namespace std;
const long double EPS = 0.0000000001;
const long double PI = (acos(-1));
const ll MOD = 1e9 + 7;

#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")


int main(){
    ll n; cin >> n;
    vector<pair<ll,ll>> p(n),d;
    map<pair<ll,ll>,ll> mp;
    ll ans = 1;

    if(n == 1){
        cout << 1;
        return 0;
    }
    
    rep(i,n){
        cin >> p[i].first >> p[i].second;
    }

    rep(i,n){
        for(int j = i+1; j < n; j ++){
            d.push_back(make_pair(p[i].first - p[j].first, p[i].second - p[j].second));
            d.push_back(make_pair(p[j].first - p[i].first, p[j].second - p[i].second));
        }
    }

    rep(i,d.size()){
        if(mp.count(d[i]) == 0) mp[d[i]] = 1;
        else mp[d[i]] ++;
    }

    rep(i,d.size()) ans = max(ans,mp[d[i]]);

    cout << n - ans;




}

Measured memory_bytes: 3744
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <map>
#include <deque>
#include <string.h>
using namespace std;

#define REP(i,n) for(int i = 0; i < n; i++)
#define ALL(v) v.begin(),v.end()
typedef long long ll;
typedef pair<int,int> pi;
typedef pair<ll,ll> pll;
typedef pair<string,string> pss;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pi> vpi;
typedef vector<ll> vll;
typedef vector<vll> vvll;

double EPS = 1e-9;
int INFi = 1000000005;
long long INFll = 1000000000000000005ll;
double PI = acos(-1);
int dirx[8] = {-1,0,0,1,-1,-1,1,1};
int diry[8] = {0,1,-1,0,-1,1,-1,1};
ll MOD = 1000000007;

int N;
const int MAX_N = 300;
string S[MAX_N];

bool check(int s) {
  string SS[N];
  REP(i, N) {
    SS[i] = S[(s + i) % N];
  }
  REP(i, N) {
    REP(j, N) {
      if(SS[i][j] != SS[j][i]) {
        return false;
      }
    }
  }
  return true;
}

int main(){
  cin >> N;
  REP(i, N) cin >> S[i];
  int ans = 0;
  REP(i, N) {
    if(check(i)) ans += N;
  }

  cout << ans << endl;
  
  return 0;

}



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

int arr[100000];

vector< pair<int,int> >vec[100000];
bool visited[100000];
int col[100000];
int colour;
int nc = 0;
int ager = 0;

void dfs(int u,int ager)
{
    stack<pair<int,int> >st;
    st.push(make_pair(u,ager));
    visited[u]=true;
    while(!st.empty())
    {
        /*for(int i=0; i<vec[u].size(); i++)
        {
            int v = vec[u][i].first;
            if(visited[v])
            {
                ager = col[vec[u][i].second];
                break;
            }
        }*/
        u=st.top().first;
        ager=st.top().second;
        st.pop();
        //cout<<ager<<endl;
        for(int i=0; i<vec[u].size(); i++)
        {
            int v = vec[u][i].first;
            if(!visited[v])
            {
                int temp = nc%colour+1;
                if(temp!=ager)
                {
                    col[vec[u][i].second]=temp;
                }
                else
                {
                    nc++;
                    temp = nc%colour+1;
                    col[vec[u][i].second]=temp;

                }
                nc++;
                //cout<<v<<" "<<ager<<endl;
                st.push(make_pair(v,temp));
            }
        }
        visited[u]=true;
    }
}

int main()
{

    cin>>n;
    memset(visited,false,sizeof(visited));
    memset(arr,0,sizeof(arr));

    for(int i=0; i<n-1; i++)
    {
        int a,b;
        cin>>a>>b;
        a--;
        b--;
        arr[a]++;
        arr[b]++;
        vec[a].push_back(make_pair(b,i));
        vec[b].push_back(make_pair(a,i));

    }
    colour  = *max_element(arr,arr+n);
    cout<<colour<<endl;
    dfs(0,0);
    for(int i=0; i<n-1; i++)
    {
        cout<<col[i]<<endl;

    }

}


Measured memory_bytes: 7424
//http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ITP1_8_C
#include <iostream>
#include <string>
#include <array>

using namespace std;

int main(){
    std::array<int, 26> counter;
    for(int i=0; i<26; i++){
        counter[i] = 0;
    }
    //couter????????????

    char ch;
    while(cin >> ch){

        int num = tolower(ch) - 'a';
        counter[num]++;
    }

    int num = 'a';
    for(int i=0; i<26; i++){
        cout << (char)(num+i) << " : " << counter[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 3096
#include <iostream>
#include <cmath>
using namespace std;
const double eps = 1e-9;

int main() {
    double n;
    while (cin >> n, 0 <= n) {
        if (abs(n*16 - round(n*16)) < eps && n < 256 + eps) {
            for (int i=7; i>=-4; --i) {
                double d = pow(2, i);
                if (d < n + eps) {
                    n -= d;
                    cout << "1";
                } else {
                    cout << "0";
                }
                if (i == 0) cout << ".";
            }
            cout << endl;
        } else {
            cout << "NA" << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 1260
import java.util.*;

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int mod = 1_000_000_007;
		String L = sc.next();
		int n = L.length();
		long[][] dp = new long[n+1][2];
		dp[0][0] = 1;
		for (int i=0;i<n;i++) {
			if (L.charAt(i)=='1') {
				dp[i+1][1]=(dp[i][1]*3+dp[i][0]) % mod;
				dp[i+1][0]=dp[i][0]*2 % mod;
			} else {
				dp[i+1][1]=dp[i][1]*3 % mod;
				dp[i+1][0]=dp[i][0] % mod;

			}
		}
		long ans = (dp[n][0]+dp[n][1]) % mod;
		System.out.println(ans);
	}

}

Measured memory_bytes: 29524
n = gets.to_i
a = gets.split.map(&:to_i)

ans = a == a.sort
n.times do |i|
  (i+1).upto(n-1) do |j|
    t = a.dup
    k = t[i]
    t[i] = t[j]
    t[j] = k
    ans = true if t == t.sort
  end
end
puts ans ? "YES" : "NO"

Measured memory_bytes: 2684
import java.util.*;
import java.io.*;
import static java.lang.System.*;

class FastScanner {
  private final InputStream in = System.in;
  private final byte[] buffer = new byte[1024];
  private int ptr = 0;
  private int buflen = 0;
  private boolean hasNextByte() {
      if (ptr < buflen) {
          return true;
      }else{
          ptr = 0;
          try {
              buflen = in.read(buffer);
          } catch (IOException e) {
              e.printStackTrace();
          }
          if (buflen <= 0) {
              return false;
          }
      }
      return true;
  }
  private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
  private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
  public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
  public String next() {
      if (!hasNext()) throw new NoSuchElementException();
      StringBuilder sb = new StringBuilder();
      int b = readByte();
      while(isPrintableChar(b)) {
          sb.appendCodePoint(b);
          b = readByte();
      }
      return sb.toString();
  }
  public long nextLong() {
      if (!hasNext()) throw new NoSuchElementException();
      long n = 0;
      boolean minus = false;
      int b = readByte();
      if (b == '-') {
          minus = true;
          b = readByte();
      }
      if (b < '0' || '9' < b) {
          throw new NumberFormatException();
      }
      while(true){
          if ('0' <= b && b <= '9') {
              n *= 10;
              n += b - '0';
          }else if(b == -1 || !isPrintableChar(b)){
              return minus ? -n : n;
          }else{
              throw new NumberFormatException();
          }
          b = readByte();
      }
  }
  public int nextInt() {
      long nl = nextLong();
      if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
      return (int) nl;
  }
  public double nextDouble() { return Double.parseDouble(next());}
}

class Main {
  public static final int MOD = 1000000007;
  public static final int INF = 1000000000;
  public static void main(String[] args) {
    FastScanner sc = new FastScanner();
    int D = sc.nextInt();
    int G = sc.nextInt();
    int p[] = new int[D];
    int c[] = new int[D];
    for(int i=0; i<D; i++){
      p[i] = sc.nextInt();
      c[i] = sc.nextInt();
    }
    int ans = INF;
    for(int n=0; n<(1<<D); n++){
      int point = 0;
      int maxindex = 0;
      int cnt = 0;
      for(int i=0; i<D; i++){
        if((n>>i & 1) == 1){
          point += 100 * (i+1) * p[i] + c[i];
          cnt += p[i];
        }else{
          maxindex = i;
        }
      }
      if(G > point){
        int need = (G - point + (maxindex+1) * 100 - 1) / ((maxindex+1) * 100);
        if(need >= p[maxindex]) continue;
        cnt += need;
      }
      ans = Math.min(ans, cnt);
    }
    out.println(ans);
  }

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

Measured memory_bytes: 21332
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using VI = vector<int>;
using VL = vector<ll>;
#define FOR(i,a,n) for(int (i)=(a);(i)<(n);++(i))
#define eFOR(i,a,n) for(int (i)=(a);(i)<=(n);++(i))
#define rFOR(i,a,n) for(int (i)=(n)-1;(i)>=(a);--(i))
#define erFOR(i,a,n) for(int (i)=(n);(i)>=(a);--(i))
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i,a) sort((i).begin(),(i).end(),(a))
#define all(i) (i).begin(),(i).end()
#define out(y,x,h,w) (y) < 0 || (h) <= (y) || (x) < 0 || (w) <= (x)
#define line cout << "------------------------\n" 
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
const long double pi = acos(-1);
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; }return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; }return 0; }
inline void init() { cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }
template<class T>inline istream& operator>>(istream& input, vector<T>& v) { for (auto& elemnt : v)input >> elemnt; return input; }

int main() {
    init();

    int h, w; cin >> h >> w;
    FOR(i, 0, h)FOR(j, 0, w) {
        string s; cin >> s;
        if (s == "snuke") {
            cout << char('A' + j) << i + 1 << "\n";
        }
    }
}


Measured memory_bytes: 256
#include<stdio.h>

int main()
{
    int m,n,i,sum=0;
    scanf("%d %d",&m,&n);
    while(n>0)
    {
        scanf("%d",&i);
        sum+=i;
        n--;
    }
    if(sum>=m)
       printf("Yes");
   else
       printf("No");

}


Measured memory_bytes: 128
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;

namespace AtCoder.C
{
    public class Program
    {
        public static void Main() { var r = GetResult(); Debug.WriteLine(r); Console.Write(r); }

        private static object GetResult()
        {
            var (N, M) = Read2Longs();
            var H = ReadLongs();

            var otherMaxes = new long[N];
            for (long i = 0; i < M; i++)
            {
                var (a, b) = Read2Longs();
                var ia = (int)a - 1;
                var ib = (int)b - 1;
                otherMaxes[ia] = Math.Max(H[ib], otherMaxes[ia]);
                otherMaxes[ib] = Math.Max(H[ia], otherMaxes[ib]);
            }

            return otherMaxes.Select((x, i) => new { Val = x, Index = i })
                .Count(x => x.Val < H[x.Index]);
        }
        private static object _GetResult()
        {
            var (N, M) = Read2Longs();
            var H = ReadLongs();

            var roadMap = new HashSet<string>();
            for (long i = 0; i < M; i++)
            {
                var (a, b) = Read2Longs();
                if (a > b)
                {
                    var temp = a;
                    a = b;
                    b = temp;
                }
                roadMap.Add($"{a - 1}.{b - 1}");
            }

            var count = 0L;
            for (long i = 0; i < N - 1; i++)//from
            {
                var max = 0L;
                for (long j = i + 1; j < N; j++)//to
                {
                    if (roadMap.Contains($"{i}.{j}"))
                    {
                        max = Math.Max(max, H[(int)j]);
                    }
                }

                if (max < H[(int)i])
                {
                    count++;
                }
            }

            return count;
        }
        #region Console.Read

        public static string ReadText() { return Console.ReadLine(); }
        public static List<string> ReadTexts() { return Console.ReadLine().Split(' ').ToList(); }
        public static long ReadLong() { return long.Parse(Console.ReadLine()); }
        public static (long, long) Read2Longs() { var ls = ReadLongs(); return (ls[0], ls[1]); }
        public static (long, long, long) Read3Longs() { var ls = ReadLongs(); return (ls[0], ls[1], ls[2]); }
        public static (long, long, long, long) Read4Longs() { var ls = ReadLongs(); return (ls[0], ls[1], ls[2], ls[3]); }
        public static (long, long, long, long, long) Read5Longs() { var ls = ReadLongs(); return (ls[0], ls[1], ls[2], ls[3], ls[4]); }
        public static List<long> ReadLongs() { return Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToList(); }

        #endregion
    }
}


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

int main(){
  while(true){
    int n;
    cin>>n;
    if(n==0)break;
    vector<int> a(n);
    for(int i=0;i<n;i++){
      string s;
      cin>>s;
      a[i]=s.size();
    }
    int flag=0;
    int sum=0;
    int i;
    int j;
    for(j=0;j<n;j++){
      for(i=j;i<n;i++){
        sum+=a[i];
        if(flag==0&&sum==5){
          flag++;
          sum=0;
        }else if(flag==1&&sum==7){
          flag++;
          sum=0;
        }else if(flag==2&&sum==5){
          flag++;
          sum=0;
        }else if(flag==3&&sum==7){
          flag++;
          sum=0;
        }else if(flag==4&&sum==7){
          flag++;
          sum=0;
        }else if((flag==0||flag==2)&&sum>5){
          flag=0;
          sum=0;
          break;
        }else if((flag==1||flag==3||flag==4)&&sum>7){
          flag=0;
          sum=0;
          break;
        }
        if(flag==5)break;
      }
      if(flag==5)break;
    }
    cout<<j+1<<endl;
  }
}



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

#define rep(i,n) for(int i = 0; i < ((int)(n)); i++)   //0-origin昇順
#define rep1(i,n) for(int i = 1; i <= ((int)(n)); i++) //1-origin昇順
#define rrep(i,n) for(int i = ((int)(n)-1); i >= 0; i--)  //0-origin降順
#define rrep1(i,n) for(int i = ((int)(n)); i >= 1; i--)   //1-origin降順
//rep2 -> 第二引数 m から n 回繰り返し ex) m=5 n=3 なら i=5,i=6,i=7 まで
#define rep2(i,m,n) for(int i = ((int)(m)); i < ((int)(n))+((int)(m)); i++)
#define SIZE(x) ((int)((x).size()))
#define all(x) (x).begin(),(x).end()
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vi> vii; //2次元配列
typedef vector<ll> vll;
typedef vector<string> vs;
template<typename T> bool chmax(T &a, const T &b){ if(a<b){ a=b; return 1;} return 0;}
template<typename T> bool chmin(T &a, const T &b){ if(a>b){ a=b; return 1;} return 0;}


/*FUNCs=================================================*/
//nの素因数とその個数のpairのmapを返す
template<typename T_n>
map<T_n, ll> prime_factor(T_n n) { 
    map<T_n, ll> ret;
    for(T_n i = 2; i*i <= n; i++){
        while(n % i == 0){
            ret[i]++;
            n /= i;
        }
    }
    if(n != 1) ret[n] = 1;
    return ret;
}

/*MAIN==================================================*/
int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);   //cin cout 高速化

    ll n, p; cin >> n >> p;
    map<ll,ll> prime = prime_factor<ll>(p);

    ll answer = 1;
    for(auto num : prime){
        if(num.second>=n){
            int times = num.second/n;
            for(int i = 0; i < times; i++) answer *= num.first;
        }
    }
    cout << answer << '\n';
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
	int a,b,c,n;	cin>>a>>b>>c>>n;
	int ans=a+b+c;
	int k=max(a , max(b, c));
	ans-=k;
	for(int i=1;i<=n;i++)
		k*=2;
	ans+=k;
	cout<<ans<<endl;
}

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

int main(void) {
    long n;
    cin >> n;
    vector<long> a(n);
    for(auto &e: a) cin >> e;

    if(n==1) {
        cout << "YES" << endl;
        return 0;
    }

    long sum = 0;
    for(auto &e: a) sum += e;
    long cnt = sum / (n * (n+1) /2);

    if(cnt * (n*(n+1)/2) != sum) {
        cout << "NO" << endl;
        return 0;
    }

    vector<long> k(n);
    {
        long t = 0;
        for(long i=0; i<n; i++) {
            // a[i+1] - a[i] == x - (n-1)*(cnt-x)
            // a[i+1] - a[i] == x - (n-1)*cnt + (n-1)x
            // nx == a[i+1] - a[i] + (n-1)*cnt
            long nx = a[(i+1)%n] - a[i] + (n-1)*cnt;
            long x = nx / n;
            if (x*n != nx) {
                cout << "NO" << endl;
                return 0;
            }
            if(!(0 <= x && x <= cnt)) {
                cout << "NO" << endl;
                return 0;
            }
            k[i] = x;
            t += cnt - x;
        }

        if(t != cnt) {
            cout << "NO" << endl;
            return 0;
        }
    }

    long s = cnt - k[n-1];
    for(long i=1; i<n; i++)
        s += (n+1-i)*(cnt - k[i-1]);

    a[0] -= s;
    for(long i=1; i<n; i++) {
        s += cnt;
        s -= n * (cnt - k[i-1]);
        a[i] -= s;
    }
    for(auto &e: a) {
        if(e) {
            cout << "NO" << endl;
            return 0;
        }
    }

    cout << "YES" << endl;
    return 0;
}


Measured memory_bytes: 1792
#!/usr/bin/env python
# -*- coding: utf-8 -*-

var = raw_input().split()

var = map(int, var)

if var[0] > var[1]:
	tmp = var[0]
	var[0] = var[1]
	var[1] = tmp
	
if var[0] > var[2]:
	tmp = var[0]
	var[0] = var[2]
	var[2] = tmp
	
if var[1] > var[2]:
	tmp = var[1]
	var[1] = var[2]
	var[2] = tmp

print var[0],var[1],var[2]

Measured memory_bytes: 6340
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <set>
#include <map>
#include <queue>
using namespace std;
#define rep(i,n) for(int i = 0;i<n;i++)
const long long MOD = 1000000007LL;
const string alpha = "abcdefghijklmnopqrstuvwxyz";
int main(){
    long n;
    cin >> n;
    long a[n];
    long maxa[2] = {0,0};
    rep(i,n){
        cin >> a[i];
        if(a[i]>=maxa[0]){
            maxa[1] = maxa[0];
            maxa[0] = a[i];
        }
        else if(a[i] >= maxa[1]) maxa[1]=a[i];
    }
    vector<long> ans;
    rep(i,n){
        if(maxa[0]==a[i]) ans.push_back(maxa[1]);
        else ans.push_back(maxa[0]);
    }
    rep(i,n){
        cout << ans[i] << endl;
    }
}

Measured memory_bytes: 4848
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i < (n+1); ++i)
using namespace std;
using ll = long long;
const int INF = +100100100;
typedef pair<int,int> P;
const ll MO = 1000000007;


int main(){
    int n,k,r,s,p;
    string t;
    cin >> n >> k >> r >> s >> p >> t;
    ll ans=0; 
    rep(i,t.size()){
        if(t[i]=='r')ans+=p;
        if(t[i]=='s')ans+=r;
        if(t[i]=='p')ans+=s;
    } 
    
    rep(fir,k){
        stack<char> st;
        vector<char> minus;
        // cout << "hi"<< endl;
        st.push(t[fir]);
        // cout << fir<<": " << st.top() << endl;
        
        for(int i = fir+k; i<t.size(); i+=k){
            // if(st.top()=='x'){
            //     st.pop();
            //     st.push(t[i]);
            // }
            // cout << "i:"<<i<<endl;
            if(!st.empty() && st.top()==t[i]){
                st.pop();
                st.push('x');
                minus.push_back(t[i]);
            }else{
                st.pop();
                st.push(t[i]);
            }
        }
        // cout << endl;
        for(auto ele : minus){
            if(ele=='r')ans-=p;
            if(ele=='s')ans-=r;
            if(ele=='p')ans-=s;
        }
    }
    
    cout << ans << endl;
    return 0;

}

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

int main() {
	int a, b, c;
	cin >> a >> b >> c;
	if (a > b) swap(a, b);
	if (a <= c && c <= b) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

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

int main(){
    char S[11];
    char T[12];
    int i, f = 0;

    scanf("%s", S);
    scanf("%s", T);

    for(i=0; i<strlen(S); i++){
        if(S[i] != T[i])f = 1;
    }

    if(f == 1){
        printf("No\n");
    }else{
        printf("Yes\n");
    }

    return 0;
}

Measured memory_bytes: 1660
//#pragma GCC optimize ("Ofast")
//#pragma GCC optimize ("unroll-loops")
//#pragma GCC target("avx,avx2,fma")

#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//#include <ext/rope>
#define pb push_back
#define F first
#define S second
#define ins insert
#define mp make_pair
#define fo(i, n1, n, x) for(int i = n1; i <= n; i += x)
#define foo(i, n, n1, x) for(int i = n; i >= n1; i -= x)
#define bit __builtin_popcount
#define md (l + ((r - l) / 2))
#define all(x) x.begin(),x.end()
#define eb emplace_back
#define ub upper_bound
#define lb lower_bound
#define ios ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define file(s) if (fopen(s".in", "r")) freopen(s".in", "r", stdin), freopen(s".out", "w", stdout)

using namespace std;
//using namespace __gnu_pbds;
//using namespace __gnu_cxx;


using ll = long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vi = vector<int>;

//#define int ll


const int N = 5e5 + 11, mod = 1e9 + 7, mod2 = 998244353;
const int MAX = 1e5 + 11;
const int INF1 = 2e9 + 11;
const ll INF2 = 2e18 + 11;
const double INF3 = 1e8 + 11;
const int base = 500;
const int P = 31;
const int dx[] = {1, -1, 0, 0, 1, 1, -1, -1};
const int dy[] = {0, 0, 1, -1, 1, -1, 1, -1};
const double EPS = 1e-4;
const double PI = acos(-1.0);


//template<typename T> using ordered_set = tree <T, null_type, less <T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename T1, typename T2> inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }


mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int n,q,t[N][33];
string s;
void upd(int pos, int x, int val) {
  for (int i = pos; i <= N; i = (i | (i + 1))) t[i][x]+=val;
}
int get(int pos, int x) {
  int res=0;
  for (int i = pos; i >= 0; i = (i & (i + 1)) - 1) res += t[i][x];
  return res;
}
main() {
  file("threesum");
  //ios;
  cin>>n>>s;
  s='#'+s;
  fo(i,1,n,1) {
    int nom=s[i]-'a';
    upd(i,nom,1);
  }
  cin>>q;
  while (q--) {
    int type,l,r;
    char d;
    cin>>type>>l;
    if (type==1) {
      cin>>d;
      int nom=d-'a';
      upd(l,s[l]-'a',-1);
      upd(l,nom,1);
      s[l]=d;
    } else {
      cin>>r;
      int ans=0;
      fo(i,0,25,1) ans+=(get(r,i)-get(l-1,i) > 0 ? 1 : 0);
      cout<<ans<<'\n';
    }
  }
  cerr << "\nTime elapsed: " << (clock() + 0.0) / CLOCKS_PER_SEC;
  return 0;
}
/**

*/


Measured memory_bytes: 65432
#include<bits/stdc++.h>
int m, k;

int main(){
    scanf("%d%d", &m, &k);
    if((1<<m) <= k) return puts("-1")*0;
    if(m < 2) return puts(m == 0 ? "0 0" : k == 1 ? "-1" : "0 0 1 1")*0;
    for(int i = 0; i < (1<<m); i++){
        if(i == k) continue;
        printf("%d ", i);
    }
    printf("%d ", k);
    for(int i = (1<<m)-1; i >= 0; i--){
        if(i == k) continue;
        printf("%d ", i);
    }
    printf("%d\n", k);
}

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

int main(){
    int64_t n;
    cin >> n;
    int64_t ans = 0;
    for(int64_t i=1; i<=n; i++){
        int64_t a;
        cin >> a;
        while(a%2==0){
            a /= 2;
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#ABC127B-Algae.py

from sys import stdin

r, D, x_2000 = list(map(int, stdin.readline().split()))

def x(i):
    if i == 0:
        return x_2000
    else:
        return r * x(i-1) - D

for i in range(1, 11):
    print(x(i))


Measured memory_bytes: 2940
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
l=[0]*(n+1)
c=0
for i in range(n):
    aa=a[i]
    c+=min(a[i],b[i])
    a[i]=max(0,a[i]-b[i])
    if a[i]==0:
        c+=min(a[i+1],b[i]-aa)
        a[i+1]=max(0,a[i+1]+aa-b[i])
print(c)


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

string jud="0+++",s;
bool endjud=false;

void saiki(int n,int sum){
	if(n==4){
		//cout<<sum<<"\n";
		if(sum==7&&endjud==false){
			cout<<s[0];
			for (int i = 1; i < 4; i++) {
				cout<<jud[i]<<s[i];
			}
			cout<<"=7\n";
			endjud=true;
		}
		return;
	}
	saiki(n+1,sum+s[n]-'0');
	jud[n]='-';
	saiki(n+1,sum-s[n]+'0');
	jud[n]='+';
}

int main(void) {
	cin>>s;
	saiki(1,s[0]-'0');


	return 0;
}


Measured memory_bytes: 256
//g++でビルド

#include "bits/stdc++.h"

using namespace std;
const int inf = 1000000000;

int abs(int a){
    if(a < 0) return -a;
    return a;
}

int main(){
    int n; 
    cin >> n;
    vector<int> a(n), b(n), c(n);
    for(int i = 0; i < n; i++){
        cin >> a[i] >> b[i] >> c[i];
    }
    int dp[3][n];
    for(int i = 0; i < 3; i++){
        for(int j = 0; j < n; j++){
            dp[i][j] = inf;
        }
    }

    for(int i = 0; i < 3; i++){
        for(int j = 0; j < n; j++){
            if(j == 0){
                dp[0][0] = a[0];
                dp[1][0] = b[0];
                dp[2][0] = c[0];
            }else{
                dp[0][j] = a[j] + max(dp[1][j-1], dp[2][j-1]);
                dp[1][j] = b[j] + max(dp[0][j-1], dp[2][j-1]);
                dp[2][j] = c[j] + max(dp[0][j-1], dp[1][j-1]);
            }
        }
    }
    

    cout << max(dp[0][n-1], max(dp[1][n-1], dp[2][n-1])) << endl;
    return 0;
}

Measured memory_bytes: 2560
#include<iostream>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
#include<limits>
#include<sstream> 
#include<unordered_map>      

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef int itn;
typedef vector<int> vi;
typedef vector<ll> vl;

const int inf = numeric_limits<int>::max() >> 2;
const ll linf = numeric_limits<ll>::max() >> 2;
const ull ulinf = numeric_limits<ull>::max() >> 2;
const double pi = acos(-1);
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
const int dx8[8]={-1,0,1,-1,1,-1,0,1};
const int dy8[8]={-1,-1,-1,0,0,1,1,1};

#define p_queue(i) priority_queue<i> 
#define rp_queue(i) priority_queue<i, vector<i>, greater<i>> 
#define umap(i,j) unordered_map<i,j>
#define P(p) cout<<(p)<<endl
#define PS(p) cout<<(p)<< " "
#define IN cin >> 
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define rrep(i,m,n) for(int i = (m-1); i >= (int)(n); i--)
#define inrep(n,a) for(int i = 0; i < (int)(n); i++)cin >> a[i];
#define mod(i) ((i)%(ll)(1e9 + 7))
#define divm(a,b) (mod(a * modpow((ll)b,(ll)(1e9+5))))
#define rsort(a,b,c) sort(a, b, greater<c>())
#define vsort(v) sort(v.begin(), v.end())
#define rvsort(v,c) sort(v.begin(), v.end(), greater<c>()) 
#define ft first
#define sd second
#define pb push_back
#define it insert
#define sz(x) ((int)(x).size())
#define lb(a,n,k) (lower_bound(a,a+n,k) - a) 
#define vlb(a,k)  (lower_bound(a.begin(),a.end(),k) - a.begin())
#define ub(a,n,k) (upper_bound(a,a+n,k) - a) 
#define vub(a,k)  (upper_bound(a.begin(),a.end(),k) - a.begin())
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return

ll modpow(ll i,ll j){ ll tmp=1; while(j){ if(j%2)tmp=mod(tmp*i);i=mod(i*i);j/=2;}return tmp;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

vector<string> split(const string &str, char sep){
    vector<string> v;
    stringstream ss(str);
    string buffer;
    while( getline(ss, buffer, sep) ) {
        v.push_back(buffer);
    }
    return v;
}

//ll ncr[100][100];
//ll nCr(int n, int r){if(n==r) ret ncr[n][r] = 1; if(r==0) ret ncr[n][r] = 1; if(r==1) ret ncr[n][r] = n;if(ncr[n][r]) ret ncr[n][r]; ret ncr[n][r] = nCr(n-1,r) + nCr(n-1,r-1);}

//ll npr[100][100]={};
//ll nPr(int n,int r){if(npr[n][r])ret npr[n][r];if(r==0)ret npr[n][r] = 1;if(r==1)ret npr[n][r] = n;ret npr[n][r] = n * nPr(n-1,r-1);}

//ll nHr(int n,int r){ret nCr(n+r-1,r);}

///////////////////////////////////////////////////////////////////////////


int main(){
    
    ll n,m;
    cin >> n >> m;
    p_queue(ll) a;

    rep(i,0,n){
	ll b;
	cin >> b;
	a.push(b);
    }

    rep(i,0,m){
	ll t = a.top();
	a.pop();
	a.push(t/2);
    }
    ll ans = 0;
    rep(i,0,n){
	ans += a.top();
	a.pop();
    }
    P(ans);
    return  0;
}


Measured memory_bytes: 1400
#include <iostream>

using namespace std;

void divide(char[],int,int);
int combine(char[],int);
void sort(char[],int,bool);
int power(int);

int main(void){
	int	in=-1,L,a[21];
	char	val[6];

GET:	cin >> in >> L;
	if(in!=0||L!=0){
		a[0]=in;
		for(int i=1;i<=20;i++){
			divide(val,L,in);
			sort(val,L,true);
			int lrg=combine(val,L);
			sort(val,L,false);
			in=(a[i]=lrg-combine(val,L));

			for(int j=0;j<i;j++)
				if(a[i]==a[j]){
					cout << j << " " << a[j]<< " "  << i-j << endl;
					goto GET;
				}
		}
	}

	return 0;
}

void divide(char val[],int L,int num){
	for(int i=0;i<L;i++){
		val[i]=num/power(L-i-1);
		num-=val[i]*power(L-i-1);
	}
}

int combine(char val[],int L){
	int num=0;
	for(int i=0;i<L;i++)
		num += val[i]*power(L-i-1);

	return num;
}

void sort(char val[],int L,bool down){
	for(int i=0;i<L-1;i++)
		for(int j=0;j<L-i-1;j++)
			if((down&&val[j]<val[j+1])||!down&&val[j]>val[j+1]){
				int tmp=val[j];
				val[j]=val[j+1];
				val[j+1]=tmp;
			}
}

int power(int n){
	int num=1;
	for(int i=0;i<n;i++)
		num*=10;

	return num;
}

Measured memory_bytes: 1164
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cassert>
#include <functional>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
using namespace std;
using llong = long long;

const llong mod = (1e9) + 7;
llong h, w;
char mp[1005][1005];
llong dp[1005][1005];

int main() {
    cin >> h >> w;
    for (int i = 1; i <= h; i++) {
        for (int j = 1; j <= w; j++) {
            cin >> mp[i][j];
        }
    }

    dp[0][1] = 1;
    for (int i = 1; i <= h; i++) {
        for (int j = 1; j <= w; j++) {
            if (mp[i][j] == '#') continue;
            dp[i][j] = dp[i - 1][j] + dp[i][j - 1];
            if (dp[i][j] >= mod) dp[i][j] -= mod;
        }
    }

    cout << dp[h][w] << endl;

    return 0;
}


Measured memory_bytes: 9088
use proconio::input;
use std::cmp::{max, min};

const MAX_L: usize = 100_000;
const BASE_SIZE: usize = 1 << 10;

fn main() {
    input! {
        n: usize,
        vw: [(u32, u32); n],
        q: usize,
        vl: [(usize, u32); q],
    }
    let dp = make_dp(&vw);
    for vlq in vl {
        println!("{}", calc(&vw, vlq.0 - 1, vlq.1, &dp));
    }
}

fn make_dp(vw: &Vec<(u32, u32)>) -> Vec<Vec<u32>> {
    let mut dp = Vec::<Vec<u32>>::new();

    dp.push(
        (0..=MAX_L)
        .map(|i| if (i as u32) < vw[0].1 { 0 } else { vw[0].0 })
        .collect()
    );

    let n = min(vw.len(), BASE_SIZE - 1);
    for c in 1..n {
        let p = (c - 1) / 2;
        dp.push(
            (0..=MAX_L)
            .map(|i| {
                let w = vw[c].1;
                let v = if (i as u32) < w { 0 } else { dp[p][i - w as usize] + vw[c].0 };
                max(dp[p][i], v)
            })
            .collect()
        );
    }

    dp
}

fn calc(
    vw: &Vec<(u32, u32)>,
    u: usize, 
    l: u32,
    dp: &Vec<Vec<u32>>
) -> u32 {
    if u < dp.len() {
        dp[u][l as usize]
    } else {
        let p = (u - 1) / 2;
        let w = vw[u].1;
        let pv1 = calc(vw, p, l, dp);
        let pv2 = if l < w { 0 } else { calc(vw, p, l - w, dp) + vw[u].0 };
        max(pv1, pv2)
    }
}


Measured memory_bytes: 410964
w,h,n=map(int,input().split())
x=[]
y=[]
a=[]
for i in range(n):
    xya=list(map(int,input().split()))
    x.append(xya[0])
    y.append(xya[1])
    a.append(xya[2])

top,bottom,left,right=h,0,0,w

for i in range(n):
    if a[i]==1:
        left=max(left, x[i])
    elif a[i]==2:
        right=min(right,x[i])
    elif a[i]==3:
        bottom=max(bottom,y[i])
    else:
        top=min(top,y[i])

if (top-bottom)<=0 or (right-left)<=0:
    ans=0
else:
    ans=(right-left)*(top-bottom)
print(ans)

Measured memory_bytes: 62888
#include<iostream>
#include<stdio.h>
//#include <bits/stdc++.h>
#include<vector>
#include<float.h>
#include<iomanip>
#include<algorithm>
#include<string>
#include<cstring>
#include<math.h>
#include<cmath>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include <cassert>
#include <cmath>
#include<cstdint>

#define INF 1e9
#define rep(i,n)for(int i=0;(i)<(int)(n);i++)
#define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)
#define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
#define vec(type,n) vector<type>(n)
#define vvec(m,n) vector<vector<int>> (int(m),vector<int>(n))
#define ALL(a)  (a).begin(),(a).end()


using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using P = pair<ll, ll>;

ll MOD = INF + 7;
ll dp[100100][2];

int main(){
    string s;
    cin >> s;
    dp[0][0] = 1;
    for(int i = 0; i < s.size(); i++){
        for(int f = 0; f < 2; f++){
        for(int j = 0; j < 2; j++){     //aのiビット
            for(int k = 0; k < 2; k++){ //bのiビット
                if(j == 1 && k == 1)continue;
                if(f == 0 && j + k > s[i] - '0')continue;
                dp[i + 1][f || (j + k < s[i] - '0')] += dp[i][f] % MOD;
                dp[i + 1][0] %= MOD;
                dp[i + 1][1] %= MOD;
            }
        }
        }
    }
  	
    //rep(i, s.size() + 1){rep(j, 2)cout << dp[i][j] << " ";cout << endl;}
    ll res = dp[s.size()][0] + dp[s.size()][1] % MOD;
  res %= MOD;
    cout << res << endl;
}


Measured memory_bytes: 2048
#ABC047.B

w,h,n = map(int,input().split())
#座標を作る
right = w
left = 0
upper = h
under = 0

for _ in range(n):
    x,y,a = map(int,input().split())

    if a ==1:
        left = max(x,left)
    elif a ==2:
        right = min(x,right)
    elif a ==3:
        under = max(y,under)
    else:
        upper = min(y,upper)

if(upper-under)>0 and (right-left)>0:
    c = (upper-under)*(right-left)
    print(c)
else:
    print(0)

Measured memory_bytes: 3064
def gcd(a, b):
    if a < b:
        return gcd(b, a)
    if b == 0:
        return a
    else:
        return gcd(b, a % b)


def main():
    N, M = map(int, input().split())
    S = input()
    T = input()

    g = gcd(N, M)
    for i in range(g):
        if S[i * N // g] != T[i * M // g]:
            print("-1")
            exit()
    print(N * M // g)

main()

Measured memory_bytes: 3316
#include<stdio.h>

int main(void){
    double N, Sum = 0.0;

    scanf("%lf",&N);

    for(int i = 1; i <= N; i++){
        if(i%3 != 0 && i%5 != 0){
            Sum += i;
        }
    }
    printf("%.0f\n",Sum);
    return 0;
}

Measured memory_bytes: 1716
using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;

namespace atcoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var cij = new int[10, 10];
            var n = int.Parse(Console.ReadLine());
            for (var i = 1; i <= n; i++)
            {
                var str = i.ToString();
                cij[int.Parse(str.Substring(0, 1)), int.Parse(str.Substring(str.Length - 1))]++;
            }

            var result = 0;
            for (var i = 0; i <= 9; i++)
            {
                for (var j = 0; j <= 9; j++)
                {
                    result += cij[i, j] * cij[j, i];
                }
            }
            Console.WriteLine(result);
        }
    }
}

Measured memory_bytes: 43932
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<math.h>
#include<vector>
using namespace std;
int main()
{
	int n, x = 0, y = 0, ans = 0;
	string s;
	cin >> n >> s;
	for (int i = 0; i < n / 2; i++)
	{
		if (s.at(0 + y) == s.at(n / 2 + y))
		{
			ans++;
			y++;
		}
	}
	if (ans * 2 == n)
	{
		cout << "Yes" << endl;
	}
	else
	{
		cout << "No" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
program mixjuice

 implicit none
 integer::n,k,temp,i,j,ans
 integer,allocatable::p(:)

 read*,n,k
 allocate(p(n))
 read*,p
! print*,p

!sort

 do i=1,n-1
  do j=1,n-i
   if(p(i)>=p(j+i)) then
    temp=p(j+i)
    p(j+i)=p(i)
    p(i)=temp
   end if
  end do
 end do
!print*,p

ans=0
 do i=1,k
  ans=ans+p(i)
 end do

print*,ans

end program mixjuice
    


Measured memory_bytes: 2812
#include <iostream>
#include <vector>
#include <bitset>
#include <utility>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
 
using namespace std;
typedef long long ll;
 
int main(){
  ll N;
  cin >> N;
  ll ans=0;
  ll n=0;
  for (n = 2; n*n < N; n++){
    if(N%n!=0) continue;
    ll N0=N;
    while(N0%n==0) N0/=n;
    if(N0%n==1) ans++;
    N0=N;
    ll m=N/n;
    while(N0%m==0) N0/=m;
    if(N0%m==1) ans++;
  }
  if (N==n*n) ans++;
  ans++;
  //cout << ans << endl;

  N--;
  n=2;
  ll a0=1;
  ll n0;
  for (n = 2; n*n <= N; n++){
    if(N%n!=0) continue;
    n0=1;
    while(N%n==0){
      N/=n; n0++;
    }
    a0*=n0;
  }
  if(N!=1) a0*=2;
  a0--;
  ans+=a0;

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;int main(){int n,i,j,k;string s,t;cin>>n;getline(cin,s);while(n--){getline(cin,s);t=s;for(i=99;i;i--)for(j=0;j<26;j++){for(k=0;k<s.size();k++)if(t[k]-32)t[k]=97+(i*s[k]+j)%26;if(t.find("this")+1||t.find("that")+1)goto p;}p:cout<<t<<endl;}return 0;}

Measured memory_bytes: 3180
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
int main(){
    int n,a,b,kokunai=0,kaigai=0;
    string s;
    cin >> n >> a >> b >> s;
    rep(i,n){
        if(s[i]=='a'){
            if(kokunai+kaigai<a+b){
                cout << "Yes" << endl;
                kokunai++;
            }
            else{
                cout << "No" << endl;
            }
        }
        else if(s[i]=='b'){
            if(kokunai+kaigai<a+b){
                if(kaigai<b){
                  cout << "Yes" << endl;
                  kaigai++;
                }
                else cout << "No" << endl;
            }
            else cout << "No" << endl;
        }
      	else cout << "No" << endl;
    }
}


Measured memory_bytes: 896
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func main() {
	sc.Split(bufio.ScanWords)

	n := nextInt()

	h := make([]int, n+1)
	for i := 0; i < n; i++ {
		h[i] = nextInt()
	}
	dp := make([]int, n)
	for i := 0; i < n; i++ {
		dp[i] = -1
	}

	ans := dfs(0, n, h, dp)
	fmt.Println(ans)
}

// posからゴールまでの最小コストを返す関数
func dfs(pos int, n int, h []int, dp []int) int {
	// オーバーしていた場合は十分に大きいコストを返す
	if pos >= n {
		return 99999999
	}
	// ゴールしていたらこれ以上コストは掛からないので0
	if pos == n-1 {
		return 0
	}
	// すでにdfsの結果を計算済みであればそれを返す
	if dp[pos] != -1 {
		return dp[pos]
	}
	// 1つ進む場合と2つ進む場合を比較して小さい方を採用
	step1 := dfs(pos+1, n, h, dp) + int(math.Abs(float64(h[pos+1]-h[pos])))
	step2 := dfs(pos+2, n, h, dp) + int(math.Abs(float64(h[pos+2]-h[pos])))
	// 答えをメモしておく
	dp[pos] = int(math.Min(float64(step1), float64(step2)))
	return dp[pos]
}


Measured memory_bytes: 29696