akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>

using namespace std;
typedef long long ll;

#define PI 3.141592653

bool cross(double x1,double y1,double x2,double y2,double x3,double y3,double x4,double y4){
    double a,b,c,d;
    
    a=(x3-x4)*(y1-y3)+(y3-y4)*(x3-x1);
    b=(x3-x4)*(y2-y3)+(y3-y4)*(x3-x2);
    c=(x1-x2)*(y3-y1)+(y1-y2)*(x1-x3);
    d=(x1-x2)*(y4-y1)+(y1-y2)*(x1-x4);
    
    if((c<0)^(d<0))
        return true;
    else
        return false;
}

int main(){
    int w;
    
    while(EOF!=scanf("%d",&w)){
        
        bool f = true;
        
        for(int i=0;i<=9;i++){
    
            if(w & (1 << i)){
                printf(f ? "%d" : " %d",(int)pow(2,i));
                f=false;
            }
        }
        
        printf("\n");
    }
    
    return 0;
}

Measured memory_bytes: 1232
n,l=map(int,input().split())
ans=0
if(l>=0):
  ans=(n-1)*(l+1+l+n-1)//2
elif(l<0):
  if(l+n-1>=0):
    ans=n*(l+l+n-1)//2
  else:
    ans=(n-1)*(l+l+n-2)//2
print(ans)

Measured memory_bytes: 3060
#include <iostream>
#include <iomanip>
#include <utility>
#include <cmath>
#include <random>
#include <vector>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <algorithm>
using namespace std;

#define rep(i,n) for(int i = 0; i<n; ++i)
#define REP(i,n) for(int i = 1; i<=n; ++i)
#define all(x) begin(x),end(x)
#define show(obj) {for(auto x:obj)cout<<x<<' ';cout<<endl;}
#define line "----------"
typedef long long ll;
typedef pair<int,int> P;
const int inf = 1001001000;
const ll INF = 1LL<<60;
const ll MOD = 1e9 + 7;

int main(){
	string sa,sb,sc;
	cin>>sa>>sb>>sc;
	vector<queue<int>> player(3);
	rep(i,sa.size()){
		int t = sa[i]-'a';
		player[0].push(t);
	}
	rep(i,sb.size()){
		int t = sb[i]-'a';
		player[1].push(t);
	}
	rep(i,sc.size()){
		int t = sc[i]-'a';
		player[2].push(t);
	}
	bool can = true;
	int p_num = 0;
	char ans;
	while(can){
		if(player[p_num].empty()){
			ans = (char)('A'+p_num);
			can = false;
		}
		// cout<<(char)('A'+p_num)<<endl;
		int nt = player[p_num].front();
		player[p_num].pop();
		p_num = nt;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll v[4];
ll n;
int main() {
  cin >> v[0] >> v[1] >> v[2] >> v[3];
  cin >> n;
  n *= 4;
  vector<vector<ll>> pp;
  pp.push_back({v[0] * 8, 1, v[0]});
  pp.push_back({v[1] * 4, 2, v[1]});
  pp.push_back({v[2] * 2, 4, v[2]});
  pp.push_back({v[3] * 1, 8, v[3]});

  sort(pp.begin(), pp.end());
  ll ret = 0;
  for (int i = 0; i < 4; ++i) {
    ret += n / (pp[i][1]) * pp[i][2];
    n %= pp[i][1];
  }

  cout << ret<< endl;
}

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

int main()
{
    string ans = "";
    string s,t; cin >> s >> t;
    int m = s.length();
    int n = t.length();
    vector<vector<int>> grid(m+1, vector<int> (n+1,0));
    
     for(int i = 1 ; i <= m ; i++){
         for(int j = 1 ; j <= n ; j++){
             if(s[i-1] == t[j-1]){
                 grid[i][j] = 1 + grid[i-1][j-1];
            } else grid[i][j] = max(grid[i-1][j], grid[i][j-1]);
         }
     }

    int i = m, j = n;
    while(i > 0 && j > 0)
    {
        if(s[i-1] == t[j-1])
        {
            ans = ans + s[i-1];
            i--; j--;
        }
        else if(grid[i-1][j] > grid[i][j-1])
        {
            i--;
        }
        else
        {
            j--;
        }
    }
    reverse(ans.begin(), ans.end());

    cout << ans << " ";
}


Measured memory_bytes: 38932
#pragma region
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
#define vi vector<int>
#define vd vector<double>
#define vs vector<string>
#define repi(i, m, n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i, n) repi(i, 0, n)
#define revi(i, m, n) for(int i=(int)(m-1);i>=(int)(n);i--)
#define rev(i, n) revi(i, n, 0)
#define each(i, n) for(auto&& i: n)
#define sz(v) ((int)(v).size()) 
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define uniq(v) (v).erase(unique((v).begin(), (v).end()), (v).end());
#define dump(x) cerr << #x << " = " << x << endl
#define gcd __gcd
int lcm(int a, int b){return a / gcd(a, b) * b;}
const int INF = 1e18;
const int MOD = 1e9 + 7;
const double EPS = 1e-15;
const double PI = acos(-1);
int dig(int n){return (int)(log10(n) + 1);}
int abc(char x){return (int)(x)-(int)('a');} // 0~25
char abc(int x){return (char)(x+(int)('a'));} 
int ABC(char x){return (int)(x)-(int)('A');}
char ABC(int x){return (char)(x+(int)('A'));}
void solve();
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(20);
	solve();
}
#pragma endregion

void solve() {
	string S; cin >> S;
	int ans = 0;
	rep(i, sz(S) / 2) {
		if (S[i] != S[sz(S) - i - 1]) {
			ans++;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var n, m int
	fmt.Scan(&n, &m)

	if n == 1 {
		fmt.Println(m)
		return
	}

	ans := 1
	for i := 2; i*i <= m; i++ {
		if m%i != 0 {
			continue
		}
		if i*n <= m && i > ans {
			ans = i
		}
		if j := m / i; j*n <= m && j > ans {
			ans = j
		}
	}
	fmt.Println(ans)
}


Measured memory_bytes: 512
#include<iostream>
#include<vector>
#include <cmath>
#include <map>
#include <algorithm>
#include <string>
using namespace std;
typedef long long int ll;
ll gcd(ll a , ll b ){
    if(a % b == 0){
        return b ;
    }else{
        return gcd(b , a % b ) ;
    }
}

int main(void){
   ll a,b,c,d,ans,l,g;
  cin >> a >> b >> c >> d;
  g= gcd(c,d);
  l= c*d/g;
 
  ans= b-(b/c)-(b/d)+b/l-((a-1)-((a-1)/c)-((a-1)/d)+(a-1)/l);
  cout << ans;
  
    
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#include<math.h>
#define loop(i, l, r) for(i=l; i<r; i++)/*Instead of function, (for).*/
#define rep(i,r) for(i=0; i<r; i++)
#define Min(a, b) ((a < b)? a : b)
#define Max(a, b) ((a > b)? a : b)
#define Abs(x) ((x>=0)? x : -x)/*Return the absolute value of x.*/
typedef long long int lli;
/*Return Combination ,(nCr)*/
int combi(int n, int r)
{
	if(r==0 || r==n) return 1;
	else return combi(n-1,r) + combi(n-1,r-1);
}
/*Return gcd(a, b)*/
int gcd(int a, int b){
	if(b == 0) return a;
	else return gcd(b, a % b);
}
int main(void)
{
	int i;
	char s[5];
	int a[1000];

	rep(i,1000) a[i]=0;

	scanf("%s", s);
	rep(i,4) a[s[i]]++;
	rep(i,4){
		if(a[s[i]] != 2){
			puts("No");
			return 0;
		}
	}
	puts("Yes");
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#include <iomanip>
#define rep(i,n)for(long long i=0;i<(n);i++)
using namespace std;
typedef long long ll;
 
const int MOD=1000000007;
const int INF=0x3f3f3f3f;
const ll INFL=0x3f3f3f3f3f3f3f3f;

ll gcd(ll x, ll y) {
	return y ? gcd(y, x % y) : x;
}
ll lcm(ll x,ll y){
  ll g=gcd(x,y);
  return x/g*y;
}


int main() {
  int N;
  scanf("%d",&N);
  ll s[N+1];
  s[0] = 0;
  rep(i,N){
    int a;
    scanf("%d",&a);
    s[i+1]=s[i]+a;
  }
  ll ans = 2000000000;
  for(int i=1;i<N;i++){
    ll x = s[i];
    ll y = s[N]-s[i];
    ll sum = max(x-y,y-x);
    if(ans > sum) ans = sum;
  }
  cout << ans << endl;
}

  



Measured memory_bytes: 1792
#include<iostream>
using namespace std;
int main()
{
	int a,b,c,d,i=1;
	cin>>a>>b>>c>>d;//100 10 20 50
	while(a>0||c>0)
	{
		if(i%2!=0)
		{
			c=c-b;//10 0
		}
		else{
			a=a-d;//50
		}
		i++;//1 2 3 4
	}
	if(i%2!=0)
	{
		cout<<"Yes";
	}
	else{
		cout<<"No";
	}
	return 0;
}

Measured memory_bytes: 3608
#include<iostream>
#include<algorithm>
#include<vector>
#include<functional>
#include<numeric>
#include<queue>

using namespace std;

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n, p;
	int ans = 0;
	cin >> n;
	bool mask = false;
	for (int i = 0; i < n; i++) {
		cin >> p;
		if (mask) { mask = false; }
		else if (p-1==i){
			ans++;
			mask = true; 
		}
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
N = int(input())
p = list(map(int, input().split()))

num = [i+1 for i in range(N)]

l = [p[n]-num[n] for n in range(N)]
l2 = [j for j in l if j!=0]
if len(l2) == 2:
    if sum(l2) == 0:
        print('YES')
elif len(l2) == 0:
    print('YES') 
else:
    print('NO')




Measured memory_bytes: 3060
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <math.h>
#include <assert.h>
#include <vector>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <sstream>

using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
static const double EPS = 1e-9;
static const double PI = acos(-1.0);

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, n) for (int i = (s); i < (int)(n); i++)
#define FOREQ(i, s, n) for (int i = (s); i <= (int)(n); i++)
#define FORIT(it, c) for (__typeof((c).begin())it = (c).begin(); it != (c).end(); it++)
#define MEMSET(v, h) memset((v), h, sizeof(v))

struct String {
  string s;
  String() {;}
  String(string s) : s(s) {;}
  int CalcKind() const {
    int exist[300];
    MEMSET(exist, 0);
    FORIT(it, s) { exist[(int)*it] = 1; }
    int ret = 0;
    REP(i, 300) { ret += exist[i]; }
    return ret;
  }
  bool operator<(const String &rhs) const {
    if (CalcKind() != rhs.CalcKind()) { return CalcKind() > rhs.CalcKind(); }
    return s < rhs.s;
  }
};

int cnt;
int n;
int perm[200];
char word[30][100];
char str[1000];
char ans[1000];
vector<String> strs;

int calc(int depth) {
  if (depth == (int)strs.size()) {
    int len = strlen(str);
    REP(i, len) {
      assert(str[i] != -1);
      ans[i] = perm[(int)str[i]];
    }
    ans[len] = 0;
    cnt++;
    return cnt;
  }
  const string s = strs[depth].s;
  REP(i, n) {
    if (strlen(word[i]) != s.size()) { continue; }
    int pperm[200];
    memcpy(pperm, perm, sizeof(perm));
    REP(j, s.size()) {
      int l = s[j];
      int r = word[i][j];
      if (perm[l] == r && perm[r] == l) {
        ;
      } else if (perm[l] == -1 && perm[r] == -1) {
        perm[l] = r;
        perm[r] = l;
      } else {
        goto next;
      }
    }
    calc(depth + 1);
    if (cnt >= 2) { return cnt; }
next:;
     memcpy(perm, pperm, sizeof(perm));
  }
  return cnt;
}

int main() {
  while (scanf("%d", &n), n) {
    cnt = 0;
    strs.clear();
    MEMSET(perm, -1);
    MEMSET(word, 0);
    perm[' '] = ' ';
    perm['.'] = '.';
    REP(i, n) {
      scanf("%s", word[i]);
      REP(j, i) {
        if (strcmp(word[i], word[j]) == 0) { i--; n--; break; }
      }
    }
    fgets(str, 999, stdin);
    fgets(str, 999, stdin);
    str[strlen(str) - 1] = 0;
    memcpy(ans, str, sizeof(ans));
    {
      stringstream sin(str);
      string s;
      while (sin >> s) {
        if (*s.rbegin() == '.') { s = s.substr(0, s.size() - 1); }
        strs.push_back(String(s));
      }
      sort(strs.begin(), strs.end());
    }
    if (calc(0) == 1) {
      printf("%s\n", ans);
    } else {
      printf("-.\n");
    }
  }
}

Measured memory_bytes: 972
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    int even = 1;
    int ans = 1;
    rep(i, N) {
        int t;
        cin >> t;
        if (t % 2 == 0) {
            even *= 2;
        }
        ans *= 3;
    }
    cout << ans - even << endl;

    return 0;
}


Measured memory_bytes: 256
import math
A,B,H,M = map(int,input().split())
 
A_deg = 360*H/12 + 360*M/(60*12)
B_deg = 360*M/60
C_deg = A_deg-B_deg
if C_deg < 0:
    C_deg = -C_deg 
if C_deg > 180:
    C_deg = 360 - C_deg
    
C = (A**2+B**2-2*A*B*math.cos(math.radians(C_deg)))**(1/2)
print(C)

Measured memory_bytes: 9508
import java.util.*;

class Main{
  public static void main(String args[]){
    Scanner sc = new Scanner(System.in);
    int x = sc.nextInt();
    int y = sc.nextInt();
    Integer a[] = {1,3,5,7,8,10,12};
    Integer b[] = {4,6,9,11};

    if(Arrays.asList(a).contains(x) && Arrays.asList(a).contains(y)){
      System.out.println("Yes");
    }else if(Arrays.asList(b).contains(x) && Arrays.asList(b).contains(y)){
      System.out.println("Yes");
    }else System.out.println("No");
  }
}

Measured memory_bytes: 20692
import java.util.Scanner;
import java.util.ArrayList;
import java.util.List;


public class Main {

    public static void main(String[] args) {

        Integer[] input = readInput();

        int W = input[0];
        int H = input[1];
        int x = input[2];
        int y = input[3];
        int r = input[4];

        Circle c = new Circle(x, y, r);
        if (c.isInside(new Rectangle(W, H))) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    }

    protected static class Point {
        private int x;
        private int y;

        Point(int x, int y) {
            this.x = x;
            this.y = y;
        }

        Point(Point p) {
            this(p.x, p.y);
        }

        public boolean greaterThanOrEqual(Point other) {
            return this.x >= other.x && this.y >= other.y;
        }

        public boolean lessThanOrEqual(Point other) {
            return this.x <= other.x && this.y <= other.y;
        }

        public boolean isInside(Rectangle r) {
            return greaterThanOrEqual(r.getLeftBottom()) &&
                lessThanOrEqual(r.getRightTop());
        }
    }

    protected static class Circle {
        private int x;
        private int y;
        private int r;

        Circle(int x, int y, int r) {
            this.x = x;
            this.y = y;
            this.r = r;
        }

        public boolean isInside(Rectangle r) {
            return north().isInside(r) &&
                south().isInside(r) &&
                west().isInside(r) &&
                east().isInside(r);
        }

        protected Point north() {
            return new Point(x, y + r);
        }

        protected Point south() {
            return new Point(x, y - r);
        }

        protected Point west() {
            return new Point(x - r, y);
        }

        protected Point east() {
            return new Point(x + r, y);
        }
    }

    public static class Rectangle {
        Point leftBottom;
        Point rightTop;

        Rectangle(int w, int h) {
            leftBottom = new Point(0, 0);
            rightTop = new Point(w, h);
        }

        public Point getLeftBottom() {
            return new Point(leftBottom);
        }
      
        public Point getRightTop() {
            return new Point(rightTop);
        }
    }

    public static Integer[] readInput() {
        List<Integer> l = new ArrayList<Integer>();

        Scanner sc = new Scanner(System.in);
        while (sc.hasNextInt()) {
            l.add(sc.nextInt());
        }
        return l.toArray(new Integer[l.size()]);
    }
}

Measured memory_bytes: 26400
import java.util.Scanner;
 
public class Main {
 
    public static void main(String[] args) {
 
 
        Scanner sc = new Scanner(System.in);
 
        int a = sc.nextInt();
        int b = sc.nextInt();
 
        String relation;
 
        if(a > b){
            relation = ">";
        }else if(a < b){
            relation = "<";
        }else{
            relation = "==";
        }
 
        System.out.printf("a %s b\n", relation);
    }
}


Measured memory_bytes: 26384
#include <iostream>
#include <algorithm>
#include <string>
#include <functional> 
#include <vector>
#include <numeric>
#include <stack>
#include <queue>
#include <utility>
#include <map>
#include <cstdlib>
 
using namespace std;
 
int main(){
 
 
    int n;
    cin >> n;
    vector<pair<int,int>> red(n),blue(n);
 
    for(int i=0;i<n;i++){
        int a,b;
        cin >> a >> b;
        red[i] = make_pair(a,b);
    }
 
    for(int i=0;i<n;i++){
        int a,b;
        cin >> a >> b;
        blue[i] = make_pair(b,a);
    }
 
    sort(red.begin(),red.end());
    sort(blue.begin(),blue.end());
 
    int cnt = 0;
 
    for(int i=n-1;i>=0;i--){
        int kouho;
        for(int k=0;k<n;k++){
            if(red[i].first < blue[k].second && red[i].second < blue[k].first){
                cnt++;
                blue[k].first = 0;
                blue[k].second = 0;
                break;
            }
        }
    }
 
    cout << cnt;
 
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <iterator>
#include <cmath>
#include <set>
#include <deque> 
#include <string>


using namespace std;

int n, r;

int main()
{
	scanf("%d%d", &n, &r);
	
	
	int ans = 0;
	if (n >= 10)
		ans = r;
	else
		ans = r + 100 * (10 - n);
		
	printf("%d\n", ans);
	
	return 0;
}

Measured memory_bytes: 128
N = int(input())
D , X = map(int, input().split())
A = list(int(input()) for i in range(N))
sum_choco = 0
for a in A:
    if D % a == 0:
        sum_choco += D//a
    else:
        sum_choco += (D//a +1)
print(sum_choco + X)

Measured memory_bytes: 3060
//jinhaonan
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
template<class T>inline void read(T &x){
	x=0;char c=getchar();bool f=0;
	for(;c>'9'||c<'0';f=c=='-',c=getchar());
	for(;c>='0'&&c<='9';x=(x<<1)+(x<<3)+c-'0',c=getchar());
	x=f?-x:x;
}
template<class T>inline void write(T x){
	if(x<0)putchar('-'),x=-x;
	if(x>=10)write(x/10);
	putchar(x%10+48);
}
template<class T>inline bool chkmax(T &a,T const &b){
	return a<b?a=b,1:0;
}
template<class T>inline bool chkmin(T &a,T const &b){
	return a>b?a=b,1:0;
}
int calc(long long x){
	int res=0;
	for(;x;x/=10)
		res+=x%10;
	return res;
}
int main(){
	// freopen("in.txt","r",stdin);
	int n;read(n);
	long long x=0,y=1;
	for(int i=1;i<=n;++i){
		x+=y;
		write(x),putchar('\n');
		while((x+10*y)*calc(x+y)<=(x+y)*calc(x+10*y))
			y*=10;
	}	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define ADD(X, Y) ((X) = ((X) + (Y)%MOD) % MOD)
#define LLINF LLONG_MAX / 3
#define INF 1001001001
#define PI 2*acos(0.0)
#define EPS 1e-10
// #define int long long
#define rep(i, n) for (int i = 0; i < n; ++i)
#define srep(i, s, n) for (int i = s; i < n; ++i)
#define rrep(i, n) for (int i = n-1; i >= 0; --i)
#define all(x) (x).begin(),(x).end() 
#define rall(x) (x).rbegin(),(x).rend() 
#define debug(x) cout<<#x<<" = "<<x<<endl
typedef long long ll; 
typedef unsigned long long ull;
typedef vector<int> ivec;
typedef vector<ll> llvec;
typedef vector<string> svec;
typedef pair<int, int> pii;


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

    int N;
    cin >> N;
    int T[N], A[N];
    int Tflag[N], Aflag[N];
    int mujun = 0;

    rep(i, N) {
        Tflag[i] = 0;
        Aflag[i] = 0;
    }

    rep(i, N) cin >> T[i];
    rep(i, N) cin >> A[i];

    int Ttmp = -1;
    rep(i, N){
        if (Ttmp != T[i]) {
            Tflag[i] = 1;
            Ttmp = T[i];
        }
    }

    int Atmp = -1;
    rrep(i, N){
        if (Atmp != A[i]) {
            Aflag[i] = 1;
            Atmp = A[i];
        }
    }

  

    rep(i, N){
        if (Tflag[i] == 1 && A[i] < T[i]) mujun = 1; 
        if (Aflag[i] == 1 && T[i] < A[i]) mujun = 1; 
    }

    ll ans = 1;

    rep(i, N){
        if (Tflag[i] == 0 && Aflag[i] == 0) ans = (ans * min(T[i], A[i])) % MOD;
    }

    if (mujun == 1) cout << 0 << endl;
    else cout << ans << endl;


   
    return 0;
}

Measured memory_bytes: 1920
#define NDEBUG
NDEBUG


#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cstring>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <memory>
#include <queue>
#include <random>


using namespace std;

template<class T>
using vec = std::vector<T>;


#define FOR(i, n) for (int i = 0; i < (n); ++i)
#define FORA(i, a, n) for (int i = (a); i < (n); ++i)


// TC_REMOVE_BEGIN
/// caide keep
bool __hack = std::ios::sync_with_stdio(false);
/// caide keep
auto __hack1 = cin.tie(nullptr);
// TC_REMOVE_END


// Section with adoption of array and vector algorithms.


//#include <ext/pb_ds/tree_policy.hpp>
//#include <ext/pb_ds/assoc_container.hpp>
//
//template <class T> using StdTree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;


namespace template_util {
    

    constexpr int bytecount(uint64_t x) {
        return x ? 1 + bytecount(x >> 8) : 0;
    }

    template<int N>
    struct bytetype {
        
    };

    
    /// caide keep
    template<uint64_t N>
    struct minimal_uint : bytetype<bytecount(N)> {
    };
}


template<class T>
T next(istream& in) {
    T ret;
    in >> ret;
    return ret;
}


const int MOD = (int)1e9 + 7;

void solve(istream& in, ostream& out) {
  auto n = next<int>(in);
  auto s = next<string>(in);
  vec<int> f(1, 1);

  auto sum = [&] (int a, int b) -> int {
    if (a > b) return 0;
    if (a == 0) return f[b];
    return f[b] - f[a-1] < 0 ? f[b] - f[a-1] + MOD : f[b] - f[a-1];
  };

  FOR(i, n-1) {
    vec<int> f2(f.size() + 1, 0);
    FOR(j, f2.size()) {
      if (s[i] == '>') {
        f2[j] += sum(j, (int)f.size() - 1);
      } else {
        f2[j] += sum(0, j-1);
      }
      if (f2[j] >= MOD) {
        f2[j] -= MOD;
      }
    }
    f = f2;
    FORA(j, 1, f.size()) {
      f[j] += f[j-1];
      if (f[j] >= MOD) {
        f[j] -= MOD;
      }
    }
  }
  out << f.back() << "\n";
}

//#include <fstream>


int main() {
//  ifstream fin("bridges.in");
//  ofstream fout("bridges.out");
    solve(cin, cout);
//  solve(fin, fout);
    return 0;
}



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

using namespace std;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
using ll = long long;
int mod = 1000000000+7;

int main(){

	int n;
	string s;
	cin>>n>>s;
	ll ans=0;
	ll r[n+1]={},g[n+1]={},b[n+1]={};
	for(int i=n-1;i>=0;i--){
		if(s[i]=='R')r[i]+=1;
		else if(s[i]=='G')g[i]+=1;
		else b[i]+=1;
	}

	for(int i=n-1;i>=0;i--){
		r[i]=r[i+1]+r[i];
		g[i]=g[i+1]+g[i];
		b[i]=b[i+1]+b[i];
	}

	char x,y;
	for(int i=0;i<n;i++){
		x=s[i];
		for(int j=i+1;j<n;j++){
			if(s[j]!=x){
				y=s[j];
				if('R'!=x && 'R'!=y){
					ans+=r[j+1];
					if(s[j+(j-i)]=='R' && r[j+1]!=0)ans--;
				}
				else if('G'!=x && 'G'!=y){
					ans+=g[j+1];
					if(s[j+(j-i)]=='G' && g[j+1]!=0)ans--;
				}
				else {
					ans+=b[j+1];
					if(s[j+(j-i)]=='B' && b[j+1]!=0)ans--;
				}
			}

		}
	}

	cout<<ans<<endl;

	return 0;
}


Measured memory_bytes: 3660
a,b,c,d=map(int,input().split())
ans=0
for i in range(1,101):
  if b*i>=c and d*(i-1)<a:
    ans=1
    break
  elif b*i<c and d*i>=a:
    ans=0
    break
if ans==1:
  print('Yes')
elif ans==0:
  print('No')

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

int head, tail;
int Q[100000];
int n, d[110];
bool a[110][110] = {};

void enqueue(int x){
  
  Q[tail] = x;

  if(tail + 1 == 100000) tail = 0;
  else tail++;
}

int dequeue(){
  
  int x = Q[head];

  if(head + 1 == 100000) head = 0;
  else head++;

  return x;
}

void bfs(int u){
  
  // queue<int> Q;
  
  enqueue(u);
  d[u] = 0;
  
  while(head != tail){
    int p = Q[head];
    dequeue();
    
    for(int i = 2;i <= n;i++){
      if(a[p][i] && d[i] == 0){
        enqueue(i);
        d[i] = d[p] + 1;
      }
    }
  }
}

int main(){
  
  int u, k, v;
  
  cin >> n;
  for(int i = 0;i < n;i++){
    cin >> u >> k;
    for(int j = 0;j < k;j++){
      cin >> v;
      a[u][v] = true;
    }
  }
  
  bfs(1);
  
  for(int i = 1;i <= n;i++){
    if(d[i] || i == 1) cout << i << " " << d[i] << endl;
    else cout << i << " " << -1 << endl;
  }
  
  return 0;
}


Measured memory_bytes: 3112
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<vector>
#include<queue>
#include<map>
#include<stack>
using namespace std;
typedef long long ll;
#define N 1000015
int n,a[N],m,st[N],tot;
ll f[N],s[N],g[N],h[N],dp[N];
inline double cal1(int x,int y)
{return 1.0*(f[x]+s[x]+(1ll*x*x-x)/2-f[y]-s[y]-(1ll*y*y-y)/2)/(1.0*(x-y));}
inline double cal2(int x,int y)
{return 1.0*(g[x]+s[x]+(1ll*x*x-x)/2-g[y]-s[y]-(1ll*y*y-y)/2)/(1.0*(x-y));}
inline double cal3(int x,int y)
{return 1.0*(g[x]-s[x-1]+(1ll*x*x+x)/2-g[y]+s[y-1]-(1ll*y*y+y)/2)/(1.0*(x-y));}
void solve(int l,int r)
{
	if(l==r)
	{
		h[l]=max(h[l],f[l-1]+g[l+1]+1-a[l]);
		return;
	}int mid=(l+r)>>1;
	tot=0;
	for(int i=l-1;i<=mid;i++)
	{
		while(tot>1&&cal1(st[tot-1],st[tot])<cal1(st[tot],i))tot--;
		st[++tot]=i;
	}
	for(int i=mid+1;i<=r;i++)
	{
		while(tot>1&&cal1(st[tot-1],st[tot])<i)tot--;
		dp[i]=f[st[tot]]+1ll*(i-st[tot])*(i-st[tot]+1)/2-s[i]+s[st[tot]]+g[i+1];
	}h[r]=max(h[r],dp[r]);
	for(int i=r-1;i>mid;i--)
	{
		dp[i]=max(dp[i],dp[i+1]);
		h[i]=max(h[i],dp[i]);
	}tot=0;
	for(int i=mid+1;i<=r+1;i++)
	{
		while(tot>1&&cal3(st[tot-1],st[tot])<cal3(st[tot],i))tot--;
		st[++tot]=i;
	}
	for(int i=l;i<=mid;i++)
	{
		while(tot>1&&cal3(st[tot-1],st[tot])<i)tot--;
		dp[i]=g[st[tot]]+1ll*(st[tot]-i)*(st[tot]-i+1)/2-s[st[tot]-1]+s[i-1]+f[i-1];
	}h[l]=max(h[l],dp[l]);
	for(int i=l+1;i<=mid;i++)
	{
		dp[i]=max(dp[i],dp[i-1]);
		h[i]=max(h[i],dp[i]);
	}
	solve(l,mid);solve(mid+1,r);
}
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)scanf("%d",&a[i]),s[i]=s[i-1]+a[i],h[i]=-1e18;
	st[++tot]=0;
	for(int i=1;i<=n;i++)
	{
		f[i]=f[i-1];
		while(tot>1&&cal1(st[tot-1],st[tot])<i)tot--;
		f[i]=max(f[i],f[st[tot]]+1ll*(i-st[tot])*(i-st[tot]+1)/2-s[i]+s[st[tot]]);
		while(tot>1&&cal1(st[tot-1],st[tot])<cal1(st[tot],i))tot--;
		st[++tot]=i;
	}
	reverse(a+1,a+1+n);for(int i=1;i<=n;i++)s[i]=s[i-1]+a[i];
	tot=0;st[++tot]=0;
	for(int i=1;i<=n;i++)
	{
		g[i]=g[i-1];
		while(tot>1&&cal2(st[tot-1],st[tot])<i)tot--;
		g[i]=max(g[i],g[st[tot]]+1ll*(i-st[tot])*(i-st[tot]+1)/2-s[i]+s[st[tot]]);
		while(tot>1&&cal2(st[tot-1],st[tot])<cal2(st[tot],i))tot--;
		st[++tot]=i;
	}reverse(a+1,a+1+n);reverse(g+1,g+1+n);
	for(int i=1;i<=n;i++)s[i]=s[i-1]+a[i];
	solve(1,n);
	scanf("%d",&m);
	while(m--)
	{
		int x,y;scanf("%d%d",&x,&y);
		printf("%lld\n",max(f[x-1]+g[x+1],h[x]+a[x]-y));
	}
}


Measured memory_bytes: 29184
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<stack>
#include<queue>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<int > vi;
ll gcd(ll a, ll b) {
	if (a > b)swap(a, b);
	if (b%a == 0)return a;
	return gcd(b, b%a);
}
vl gcd(vl A) {
	ll g = A[0];
	for (int i = 1; i < A.size(); i++) {
		g = gcd(g, A[i]);
	}
	
	for (int i = 0; i < A.size(); i++) {
		A[i] /= g;
	}
	return A;
}
int numofeven(const vl&  A) {
	int n = 0;
	for (int i = 0; i < A.size(); i++) {
		if (A[i] % 2 == 0)n++;
	}
	return n;
}
ostream& operator<<(ostream& os,const vl& A) {
	for (int i = 0; i < A.size(); i++) {
		cout << A[i] << " ";
	}
	cout << endl;
	return os;
}
bool isfirst(vl A) {
//	cout << A;
	int noe = numofeven(A);
	int noo = A.size() - noe;
	if (noe % 2 == 1)return true;
	else if (noo>1)return false;	
	else {
		for (int i = 0; i < A.size(); i++) {
			if (A[i] % 2 == 1) {
				if (A[i] == 1)return false;
				else {
					A[i]--;
					break;
				}
			}
		}
		A=gcd(A);
		return !isfirst(A);
	}
}

int main() {
	int n;
	cin >> n;
	vl A(n);
	for (int i = 0; i < n; i++) {
		cin >> A[i];
	}
	if (isfirst(A)) {
		cout << "First" << endl;
	}
	else {
		cout << "Second" << endl;
	}
	return 0;
}

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

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

long long MOD = 1000000000 + 7;
long long MAX = 1000000000000000000;

// 約数列挙 O(√n)
vector<ll> divisor(ll n){
  vector<ll> res;
  for(ll i = 1; i * i <= n; i++){
    if(n % i == 0){
      res.push_back(i);
      if(i != n / i) res.push_back(n / i);
    }
  }
  return res;
}

int main(){
  cout << setprecision(10);
  ll N;
  cin >> N;

  auto m = divisor(N);

  ll ans = 0;
  for(auto x: m){
    ll tmp =  (N / x) - 1;
    if(tmp == 0) continue;

    if( N % tmp == N / tmp){
      ans += tmp;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 384
extern crate core;

use std::collections::HashSet;
use std::io::{self, Read};

fn main() {
    let mut input = String::new();
    io::stdin().read_to_string(&mut input).unwrap();
    let output = run(input.trim().to_string());
    println!("{}", output);
}

fn run(input: String) -> String {
    let list = input
        .split_whitespace()
        .skip(1)
        .map(|x| x.parse::<i32>().unwrap())
        .collect::<HashSet<_>>();
    list.len().to_string()
}

#[test]
fn test() {
    let tests = vec![("4\n10\n8\n8\n6", "3")];
    for (i, (input, output)) in tests.into_iter().enumerate() {
        println!("test:{}", i);
        assert_eq!(run(input.to_string()), output.to_string());
    }
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define all(v) v.begin(),v.end()
#define P pair<int,int>
#define len(s) (int)s.size()
#define pb push_back

template<class T> inline bool chmin(T &a, T b){
	if(a>b){a=b;return true;}
	return false;
}
template<class T> inline bool chmax(T &a, T b){
	if(a<b){a=b;return true;}
	return false;
}
constexpr int mod = 1e9+7;
constexpr int inf = 3e18;

signed main(){
	int N;cin>>N;
	int ans=0;
	REP(i,N+1){
		ans+=(i+N/i*i)*(N/i)/2;
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 3644
#include <stdio.h>

int main(void)
{
    int n, x;
	
    while (1) {
	scanf("%d %d", &n, &x);
    if (n == 0 && x == 0)
    break;
    int count = 0;
    int i, j, k;
    for (i = 1; i <= n; i++){
        for (j = i+1; j <= n; j++){
            for (k = j+1; k <= n; k++){
            if (i + j + k == x){
            count++;}
            }
        }
    }
    printf("%d\n", count);


    }



    return 0;
}


Measured memory_bytes: 2140
#include <bits/stdc++.h>
////////////////////////////////////////////////////////////
#define all(x) (x).begin(), (x).end() 
const int inf = 1e9;
const long long INF=1e15;
#define endl '\n'
#define forn(i, n) for(int i=0;i<(n);++i)
#define pb push_back
#define eb emplace_back
#define fastio ios::sync_with_stdio(false);cin.tie(0); //cout.tie(0);

using namespace std;

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

typedef long long ll;
typedef pair<int,int> ii;
typedef pair<ll,ll> llll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<ii> vii;

template<class _Tp>
struct segment {
	int size;
	vector<_Tp> v, lazy;
	const vector<_Tp> &input;
	void init(int left, int right, int idx) {
		if(left == right) {
			v[idx] = input[left];
			return;
		}
		int mid = (left+right)/2;
		init(left, mid, idx*2);
		init(mid+1, right, idx*2+1);
		v[idx] = max(v[idx*2], v[idx*2+1]); // <- changeable
	}
	_Tp query(int qleft, int qright, int left, int right, int idx) {
		update_lazy(left, right, idx);
		if(qleft <= left && right <= qright) return v[idx];
		if(qright < left || right < qleft) return -100000000000000000ll; // <- changeable
		int mid = (left+right)/2;
		_Tp retl = query(qleft, qright, left, mid, idx*2);
		_Tp retr = query(qleft, qright, mid+1, right, idx*2+1);
		return max(retl, retr); // <- changeable
	}
	void update(int uleft, int uright, int left, int right, int idx, _Tp vv) {
		update_lazy(left, right, idx);
		if(uleft <= left && right <= uright) {
			v[idx] += vv; // <- changeable
			if(left != right) {
				lazy[idx*2] += vv;
				lazy[idx*2+1] += vv;
			}
			return;
		}
		if(uright < left || right < uleft) return;
		int mid = (left+right)/2;
		update(uleft, uright, left, mid, idx*2, vv);
		update(uleft, uright, mid+1, right, idx*2+1, vv);
		v[idx] = max(v[idx*2], v[idx*2+1]); // <- changeable
		return;
	}
	void update_lazy(int left, int right, int idx) {
		if(lazy[idx] != 0) {
			v[idx] += lazy[idx]; // <- changeable
			if(left != right) {
				lazy[idx*2] += lazy[idx];
				lazy[idx*2+1] += lazy[idx];
			}
			lazy[idx] = 0;
		}
	}
	public:
	segment(vector<_Tp>& input_) : input(input_) {
		size = input.size();
		int capa = 1;
		while(capa < size) capa *= 2;
		v.resize(capa*2);
		lazy.assign(capa*2, 0);
		init(0, size-1, 1);
	}
	_Tp query(int left, int right) {
		return query(left, right, 0, size-1, 1);
	}
	void update(int left, int right, _Tp vv) {
		return update(left, right, 0, size-1, 1, vv);
	}
};

int main() {
	fastio;
	int n; cin >> n;
	vii xd(n);
	forn(i, n) cin >> xd[i].first >> xd[i].second;
	sort(all(xd));
	ll m = 998244353;
	vll dp(n+1); // dp[i] = now, we are at i. activate or not? 
	vll dp2(n+1); // if you activate i, then you can choose starting point at dp2[i]
	segment<ll> rmq(dp2);
	for(int i=n;~i;i--) {
		auto &D = dp[i];
		auto &D2 = dp2[i];
		if(i == n) {
			D = 1;
			D2 = n;
			rmq.update(i, i, D2);
			continue;
		}
		ii t = {xd[i].first+xd[i].second-1, 2*inf};
		int idx = upper_bound(all(xd), t) - xd.begin();
		if(idx == i+1) D2 = i+1;
		else D2 = rmq.query(i+1, idx-1);
		rmq.update(i, i, D2);
		D = dp[i+1] + dp[D2]; D %= m;
	}
	cout << dp[0];
}

Measured memory_bytes: 13184
import java.util.*;
import java.math.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while(true) {
            int n = sc.nextInt();
            if(n == 0) break;
            double[] s = new double[n];
            double sum = 0.0;
            for(int i = 0; i < n; i++) {
                s[i] = sc.nextDouble();
                sum += s[i];
            }
            double ave = sum / (double)n;
            double ans = 0.0;
            for(int i = 0; i < n; i++) {
                ans += (s[i] - ave) * (s[i] - ave);
            }
            ans = Math.sqrt(ans/(double)n);
            System.out.printf("%.8f\n", ans);
        }
    }
}


Measured memory_bytes: 38968
N, Q = map(int, input().split())
S = input()
t = [0] * (N + 1)
for i in range(N):
    t[i + 1] = t[i] + (1 if S[i : i + 2] == 'AC' else 0)
#print(t)
for i in range(Q):
    l, r = map(int, input().split())
    print(t[r-1] - t[l-1])


Measured memory_bytes: 13104
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define SZ(x) ((int)x.size())
#define L(i,u) for (register int i=head[u]; i; i=nxt[i])
#define rep(i,a,b) for (register int i=(a); i<=(b); i++)
#define per(i,a,b) for (register int i=(a); i>=(b); i--)
using namespace std;
typedef long long ll;
typedef unsigned int ui;
typedef pair<int,int> Pii;
typedef vector<int> Vi;
template<class T> inline void read(T &x){
	x=0; char c=getchar(); int f=1;
	while (!isdigit(c)) {if (c=='-') f=-1; c=getchar();}
	while (isdigit(c)) {x=x*10+c-'0'; c=getchar();} x*=f;
}
template<class T> inline void umin(T &x, T y){x=x<y?x:y;}
template<class T> inline void umax(T &x, T y){x=x>y?x:y;}
inline ui R() {
	static ui seed=416;
	return seed^=seed>>5,seed^=seed<<17,seed^=seed>>13;
}
const int N = 666666,mo=998244353;
int n,s[N];char S[N];Vi p[3];
int tp[N],res=1,a[4],b[4];
int find(int i, int j){return 3-i-j;}
int main() {
	read(n);scanf("%s",S+1);
	rep(i,1,3*n)s[i]=S[i]=='R'?0:(S[i]=='G'?1:2);
	rep(i,1,3*n)p[s[i]].pb(i);
	rep(i,0,SZ(p[0])-1){
		int mn=min(min(p[0][i],p[1][i]),p[2][i]);
		int mx=max(max(p[0][i],p[1][i]),p[2][i]);
		tp[mn]=-1;tp[mx]=1;
	}
	rep(i,1,3*n)
		if(tp[i]==-1)a[s[i]]++;
		else if(tp[i]==0){
			rep(j,0,2)if(a[j]&&j!=s[i]){
				res=1LL*res*a[j]%mo;a[j]--;b[find(j,s[i])]++;
				break;
			}
		}
		else{
			res=1LL*res*b[s[i]]%mo;b[s[i]]--;
		}
	rep(i,1,n)res=1LL*res*i%mo;
	cout<<res<<endl;
	return 0;
}


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

vector<int> G[26];
int d[26];
void pre(int k){
	if(G[k].size() == 0)return ;
	printf(" %d", k);
	if(G[k][0] != -1)pre(G[k][0]);
	if(G[k][1] != -1)pre(G[k][1]);
	return ;
}

void in(int k){
	if(G[k].size() == 0)return ;
	if(G[k][0] != -1)in(G[k][0]);
	printf(" %d", k);
	if(G[k][1] != -1)in(G[k][1]);
	return ;
}

void pos(int k){
	if(G[k].size() == 0)return ;
	if(G[k][0] != -1)pos(G[k][0]);
	if(G[k][1] != -1)pos(G[k][1]);
	printf(" %d", k);
	return ;
}

int main(){
	int n, a, b, c, t = 0;
	scanf("%d", &n);
	for(int i = 0;i < n;i++){
		scanf("%d%d%d", &a, &b, &c);
		G[a].push_back(b);
		G[a].push_back(c);
		d[b]++;d[c]++;
	}
	
	for(int i = 0;i < n;i++)if(!d[i])t = i;
	
	printf("Preorder\n");
	pre(t);
	printf("\nInorder\n");
	in(t);
	printf("\nPostorder\n");
	pos(t);
	printf("\n");
	
	return 0;
}


Measured memory_bytes: 3276
import java.util.Scanner;
import java.util.ArrayList;

public class Main {
	Scanner sc;
	public void run(){
		sc = new Scanner(System.in);
		while(sc.hasNext()){
			String n = sc.next();
			if(n.equals(".")){
				break;
			}
			else{
				calc(n);
			}
		}
	}
	public void calc(String line){
		str = line;
		Formula tree = getTree();
		
		int ans = 0;
		for(int p = 0; p < 3; p++){
			for(int q = 0; q < 3; q++){
				for(int r = 0; r < 3; r++){
					int n = tree.calc(p, q, r);
					if(n == 2) ans++;
				}
			}
		}
		System.out.println(ans);
	}
	String str;
	
	public Formula getTree(){
		String s = str.substring(0,1);
		str = str.substring(1);
		
		if(s.equals("0") || s.equals("1") || s.equals("2")){
			return new NumFormula(Integer.valueOf(s));
		}
		else if(s.equals("P") || s.equals("Q") || s.equals("R")){
			return new StringFormula(s);
		}
		else if(s.equals("-")){
			Formula f = getTree();
			return new NotFormula(f);
		}
		else{
			Formula f1 = getTree();
			s = str.substring(0,1);
			str = str.substring(1);
			Formula f2 = getTree();
			Formula f;
			if(s.equals("*")){
				f = new AndFormula(f1, f2);
			}
			else{
				f = new OrFormula(f1, f2);
			}
			str = str.substring(1);
			return f;
		}
	}
	public static void main(String[] args){
		new Main().run();
	}
}

class Formula{
	int calc(int p, int q, int r){
		return 0;
	}
}
class NotFormula extends Formula{
	Formula f1;
	int[] list = new int[]{2,1,0};
	NotFormula(Formula f){
		this.f1 = f;
	}
	int calc(int p, int q, int r){
		int c = f1.calc(p, q, r);
		return list[c];
	}
}
class AndFormula extends Formula{
	Formula f1;
	Formula f2;
	int[][] list = new int[][]{{0,0,0},{0,1,1},{0,1,2}};
	AndFormula(Formula f1, Formula f2){
		this.f1 = f1;
		this.f2 = f2;
	}
	int calc(int p, int q, int r){
		int c1 = f1.calc(p, q, r);
		int c2 = f2.calc(p, q, r);
		return list[c1][c2];
	}
}
class OrFormula extends Formula{
	Formula f1;
	Formula f2;
	int[][] list = new int[][]{{0,1,2},{1,1,2},{2,2,2}};
	OrFormula(Formula f1, Formula f2){
		this.f1 = f1;
		this.f2 = f2;
	}
	int calc(int p, int q, int r){
		int c1 = f1.calc(p,q,r);
		int c2 = f2.calc(p,q,r);
		return list[c1][c2];
	}
}
class NumFormula extends Formula{
	int num;
	NumFormula(int n){
		this.num = n;
	}
	int calc(int p, int q, int r){
		return num;
	}
}
class StringFormula extends Formula{
	String s;
	StringFormula(String s){
		this.s = s;
	}
	int calc(int p, int q, int r){
		if(s.equals("P")) return p;
		else if(s.equals("Q")) return q;
		else return r;
	}
}

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

#define f first
#define s second
#define pb push_back
#define mp make_pair

using namespace std;

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

const int N = (int)2e5 + 123, inf = 1e9, mod = 1e9 + 7;
const ll INF = 1e18;

int n, p[N], pp[N];
ll ans;
set< int> st;

int main()
{                         
	scanf("%d", &n);
	for(int i = 1; i <= n; i++){
		scanf("%d", &p[i]);
		pp[p[i]] = i;
	}            
	st.insert(0);
	st.insert(n + 1);
	for(int i = 1; i <= n; i++){
		int j = pp[i], l, r;
		auto it = st.lower_bound(j);
		r = *it;
		it--;
		l = *it;
		ans += 1ll * (j - l) * (r - j) * i;
		st.insert(j);
	}
	printf("%lld", ans);
	return 0;
}


Measured memory_bytes: 11136
/*
sonu_verma1
*/
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb(a) push_back(a)
#define fast() ios_base::sync_with_stdio(false);cin.tie(NULL)
int main()
{
	ll h,w;
	cin>>h>>w;
	ll m=(h*w)/2;
	if((h*w)%2)
		m++;
  if(h==1||w==1)
    m=1;
	cout<<m<<endl;
 
 
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<queue>
#include<functional>
#include<algorithm>
#include<string>
#include<iomanip>
#include<math.h>

using namespace std;

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


int main(){
  string str;
  cin >> str;

  bool N = false, S = false, W=false, E=false;

  rep(i,str.length()){
    N|=(str[i]=='N');
    S|=(str[i]=='S');
    W|=(str[i]=='W');
    E|=(str[i]=='E');
  }

  if(N==S && W==E){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }

  return 0;
}


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

int main() {
	string S;
	string L = "qwertasdfgzxcvb", R = "yuiophjklnm";
	int C[26] = {};
	for (int i = 0; i < R.size(); i++) C[R[i] - 'a'] = 1;
	while (cin >> S) {
		if (S == "#") return 0;
		int ANS = 0;
		for (int i = 0; i < S.size() - 1; i++) ANS += abs(C[S[i] - 'a'] - C[S[i + 1] - 'a']);
		cout << ANS << endl;
	}
}


Measured memory_bytes: 3140
from heapq import heappush, heappop
from itertools import permutations, accumulate, combinations
import math
import bisect
import numpy as np
from collections import defaultdict, deque
from operator import itemgetter
from bisect import bisect_left, bisect_right
import sys
input = sys.stdin.readline
# sys.setrecursionlimit(10 ** 6)
# MOD = 10 ** 9 + 7
# INF = float("inf")


def main():
    x = int(input())
    a = int(input())
    ans = x -a
    b = int(input())
    ans = ans - (ans // b) * b
    print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 12016
#include <stdio.h>

int main(){
 int a,b,c,d,e,s=0;
 scanf("%d %d %d %d %d",&a,&b,&c,&d,&e);
 if(a<40){
  a=40;
 }
 if(b<40){
  b=40;
 }
 if(c<40){
  c=40;
 }
 if(d<40){
  d=40;
 }
 if(e<40){
  e=40;
 }
 s=(a+b+c+d+e)/5;
 printf("%d\n",s);
 return 0;
}

Measured memory_bytes: 600
mod=10**9+7
n,a,b=map(int,input().split())
Sum=pow(2,n,mod)-1
comba=1
combb=1
a=min(a,n-a)
b=min(b,n-b)
for i in range(1,a+1):
    comba*=(n-i+1)*(pow(i,mod-2,mod))
    comba=comba%mod
comba=comba%mod
for i in range(1,b+1):
    combb*=(n-i+1)*(pow(i,mod-2,mod))
    combb=combb%mod
combb=combb%mod
print((Sum-comba-combb)%mod)

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

int main()
{
    int n, ans=0;
    cin>>n;
    vector<long> a(n), b(n);
    for(int i=0;i<n;++i)
    {
        cin>>a[i];
        if(i==0)
        b[i]=a[i];
        else
        {
            if(a[i]<b[i-1])
            b[i]=a[i];
            else
            b[i]=b[i-1];
        }
    }
    for(int i=0;i<n;++i)
    {
        if(a[i]==b[i])
        ans++;
    }
    cout<<ans<<endl;
	return 0;
}


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

#define fastio 			ios::sync_with_stdio(0);	cin.tie(0); cout.tie(0);  cout<<fixed;  cout<<setprecision(12);	
#define randomINT 		mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
#define	newl 			cout<<"\n"
#define DISP(as)		for(auto it : as) cout<<it<<" ";newl;
#define all(x)         	(x).begin(),(x).end()
#define mset(x,val)    	memset(x,val,sizeof(x))
#define newl           	cout<<"\n"
#define pb             	push_back
#define mp             	make_pair
#define f 				first
#define s 				second
#define dline          cerr<<"///REACHED///\n";
#define deb1(x)        cerr<<#x<<" = "<<x<<'\n';
#define deb2(x,y)      cerr<<'['<<#x<<','<<#y<<"] = "<<'['<<x<<','<<y<<']'<<'\n';
#define deb3(x,y,z)    cerr<<'['<<#x<<','<<#y<<','<<#z<<"] = "<<'['<<x<<','<<y<<','<<z<<']'<<'\n';

typedef long long 				ll;
typedef long double 			ld;
typedef vector<ll> 				vll;
typedef pair<ll ,ll> 			pll;
typedef pair<ld,ld> 			pld;
typedef unordered_map<ll,ll> 	um;
typedef vector<pll> 			vpll;

const ll 	MAX5 	= 	1e+5+7;
const ll 	MAX7 	= 	1e+7+7;
const ll 	MAXN 	= 	MAX7;
const ll   	INF   	=  	0x7f7f7f7f7f7f7f7f;
const ll  	INFi 	=  	0x7f7f7f7f;
const ll 	MOD		=  	1000000007;

/*vll adj[MAXN];ll visit[MAXN]={};
ll dx8[]={0,1,1,1,0,-1,-1,-1}, dy8[]={1,1,0,-1,-1,-1,0,1};
ll dx4[]={0,1,0,-1}, dy4[]={1,0,-1,0};
*/
// <------------- Declare Variables Here ------------> //

ll T=1;
ll n,x,y,m,k,d,w;
string s,t;
//vll a,b;
// <------------- Implement Functions Here ----------> //


// <------------- Start of main() -------------------> //

void MAIN(ll _) {
	cin >> n >> k;
	if(n > k) cout<<n-1;
	else cout<<n;
}

int main() {
	fastio;randomINT;
	//cin>>T;
	for(ll i=1;i<=T;i++) {
		MAIN(i);
	}
	return 0;
}



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

typedef long long int ll;
typedef long long unsigned int ull;
typedef long double ld;
typedef vector<int> vr;
typedef pair<int, int> pr;
#define pb push_back
#define ff first
#define ss second
#define INF 1999999999
#define MODA 1000000007
#define PI 3.1415926535897932384626433
#define endl "\n" 
//cout << fixed << setprecision(2);


int main()
{
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    #ifndef ONLINE_JUDGE 
           freopen("input.txt", "r", stdin); 
           freopen("error.txt", "w", stderr); 
           freopen("output.txt", "w", stdout); 
   #endif 
   
   int n;
   cin >> n;
   if(n >= 30){
     cout << "Yes" << endl;
   }
   else{
     cout << "No" << endl;
   }
   return 0;
}
   

Measured memory_bytes: 3652
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using static System.Math;
 
public class Hello{
    public static void Main(){
        string[] input = ReadLine().Split(' ');
        int n = int.Parse(input[0]);
        int m = int.Parse(input[1]);
        int a = int.Parse(input[2]);
//        int b = int.Parse(input[3]);*/
//        string temp = ReadLine();
//        int a = int.Parse(ReadLine());
//        int b = int.Parse(ReadLine());
//        int c = int.Parse(ReadLine());
//        int d = int.Parse(ReadLine());
//        string a = ReadLine();
//        string b = ReadLine();
//        string c = ReadLine();
        if(n<=a && n+m>=a){
            WriteLine("YES");
        }else{
            WriteLine("NO");
        }
    }
}

Measured memory_bytes: 11092
def solve(N, W, weight_values):
  dp = [0 for _ in range(W + 1)]

  for i in range(N):
    i_weight, i_value = weight_values[i]
    for w in range(W, i_weight - 1, -1):
      # dp[w] = max(dp[w - i_weight] + i_value, dp[w])
      temp = dp[w - i_weight] + i_value
      if temp > dp[w]:
        dp[w] = temp

  print(dp[W])

  
def iln(): return list(map(int, input().split()))


N, W = iln()
w_v = []
for i in range(N):
  w_v.append(iln())
  
solve(N, W, w_v)


Measured memory_bytes: 7832
#ABC145 E
N,T = map(int,input().split())
ab = [list(map(int,input().split())) for _ in range(N)]
ab.sort()

dp = [[0]*T for _ in range(N+1)]
# i番目より前まで注文してT分以内(max T-1)で完食する
def chmax(a,b):
    if a < b:
        return b
    else:
        return a 
    
for i in range(N):
    for t in range(T): #T-1分がmax
        if t+ab[i][0] <= T-1:
        	dp[i+1][t+ab[i][0]] =chmax(dp[i+1][t+ab[i][0]],dp[i][t]+ab[i][1])
        
        dp[i+1][t] = chmax(dp[i+1][t],dp[i][t])

#一番遅いものをラスト(T-1分)に注文
#i番目をラストに注文 = dp[i][t-1] + b[i]
ans = 0
for i in range(N):
    ans = chmax(ans,dp[i][T-1]+ab[i][1])
    
print(ans)

Measured memory_bytes: 117720
from fractions import gcd
import sys
N,M=map(int,input().split())
S=input()
T=input()
a=gcd(M,N)
m=M//a
n=N//a
for i in range(a):
    if S[n*i]!=T[m*i]:
        print(-1)
        sys.exit()
print(m*N)

Measured memory_bytes: 5688
fun main(args: Array<String>) {
    val (n) = readLine()!!.split(' ').map(String::toInt)
    val xs = (1..n).map { readLine()!!.toInt() }
    val ys = xs.sorted()
    val max = ys.last()
    for(i in 0 until n){
        println(if(xs[i] == max) ys[ys.size -2] else max)
    }
}

Measured memory_bytes: 62880