akhauriyash/Code-Regression huggingface dataset:
#define taskname "test"

#include <bits/stdc++.h>

using namespace std;

#define sz(x) (int)x.size()
#define fi first
#define se second

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

const int maxn = 1e6 + 5;

int f[maxn];

int n;
int a[maxn];

int cnt[maxn];

void sieve()
{
    for(int i = 2; i < maxn; ++i)
        if(f[i] == 0)
        {
            for(int j = i; j < maxn; j += i)
                f[j] = i;
        }
}

void read_input()
{
    cin >> n;
    for(int i = 1; i <= n; ++i)
        cin >> a[i];
}

int gcd(int a, int b)
{
    while(b != 0)
    {
        int r = a % b;
        a = b;
        b = r;
    }
    return a;
}

void solve()
{
    bool ok = true;
    for(int i = 1; i <= n; ++i)
    {
        int x = a[i];
        while(x > 1)
        {
            int p = f[x];
            if(cnt[p] > 0)
            {
                ok = false;
                break;
            }
            ++cnt[p];
            while(f[x] == p)
                x /= p;
        }
        if(!ok) break;
    }
    if(ok)
    {
        cout << "pairwise coprime\n";
        return;
    }
    int ans = gcd(a[1], a[2]);
    for(int i = 3; i <= n; ++i)
        ans = gcd(ans, a[i]);
    cout << (ans == 1 ? "setwise coprime\n" : "not coprime\n");
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    sieve();
    read_input();
    solve();
}



Measured memory_bytes: 11744
#include <iostream>
#include <limits>

using namespace std;
using ll = long long;

#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) for(int i=0;i<(n);++i)
#define repi(i,a,b) for(int i=(a);i<(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)

#define in(v) cin>>v;
#define out(v) cout<<v<<"\n"
const ll INF = numeric_limits<ll>::max();

int main() {
  cin.tie(0); ios::sync_with_stdio(false);
  int N, M; in(N); in(M);

  int a[M];
  ll c[M];
  ll can_open = 0;
  rep(i, M) {
    in(a[i]);
    int b; in(b);
    ll key = 0;
    rep(j, b) {
      int c; in(c);
      --c;
      key += 1LL << c;
    }
    c[i] = key;
    can_open |= key;
  }
  if (can_open + 1 != 1LL << N) {
    out(-1);
    return 0;
  }
  ll dp[1<<N];
  fill(dp, dp+(1<<N), INF);
  dp[0] = 0;
  rep(i, M) {
    rep(bit, 1 << N) {
      if (dp[bit] == INF)
        continue;
      dp[bit | c[i]] = min(dp[bit | c[i]], dp[bit] + a[i]);
    }
  }
  out(dp[(1<<N)-1]);

  ll ans = INF;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <set>
#include <list>
#include <utility>
#include <queue>
#include <memory>
#include <cstring>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>

using namespace std; 

int
main(int argc, char const *argv[])
{
    int64_t n, a, b;
    cin >> n >> a >> b;
    if (n * a> b) {
	cout << b << endl;
    } else {
	cout << n * a << endl;
    }
    return 0;
}
 


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

using namespace std;

void __start__() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
#ifdef MY
    freopen("/home/ainur/CLionProjects/wow/input.txt", "r", stdin);
    freopen("/home/ainur/CLionProjects/wow/output.txt", "w", stdout);
#else
    //freopen("search.in", "r", stdin);
   // freopen("search.out", "w", stdout);
#endif
}

#define sz(x) (int)x.size()
#define yes cout<<"Yes\n"
#define  no cout << "No\n"
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define ft first
#define sd second
#define read(a) for(auto &qwqw:a)cin >> qwqw;
#define print(a) for(auto qwqw:a)cout<<qwqw<<' ';
#define print_plus(a) for(auto qwqw:a)cout<<qwqw+1<<' ';
//#define FOR(i, b, n) for(int i=b;i<n;i++) #define FOR(i, n) FOR(i, 0, n) #define FOR(n) FOR(i, 0, n)
mt19937_64 rnd(time(0));
#define int long long
using ll = long long;
using vi = vector<int>;
using ld = long double;
using vb = vector<bool>;
using pii = pair<int, int>;
using vd = vector<long double>;


int log2(int q) {
    int c = 0;
    while (q) {
        q >>= 1;
        c++;
    }
    return c;
}

void test_case() {
    int a[5];
    cin >> a[0] >>a[1] >>a[2] >>a[3] >>a[4];
    for (int i = 0; i < 5; ++i)
        if(!a[i]){
            cout << i+1;
            return;
        }
cout << -1;

}

signed main() {
    __start__();
    int Q = 1;
    //cin >> Q;
    while (Q--) {
        test_case();
    }
}





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


int main()
{
    ll A, B;
    cin >> A >> B;

    ll X = A * B;

    if (A < B) {
    	swap(A, B);
    }

    ll r = A % B;

    while (r != 0) {
    	A = B;
    	B = r;
    	r = A % B;
    }

    ll ans = X / B;

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
from collections import deque
import sys
readline = sys.stdin.readline
write = sys.stdout.write

root = None
def insert(z):
    global root
    y = None
    x = root
    while x is not None:
        y = x
        if z[2] < x[2]:
            x = x[0]
        else:
            x = x[1]
    z[3] = y

    if y is None:
        root = z
    elif z[2] < y[2]:
        y[0] = z
    else:
        y[1] = z

def debug():
    s0 = [""]
    s1 = [""]

    def dfs(nd):
        v = str(nd[2])
        s0.append(v)
        if nd[0] is not None:
            dfs(nd[0])
        s1.append(v)
        if nd[1] is not None:
            dfs(nd[1])
    dfs(root)
    return " ".join(s1), " ".join(s0)


M = int(readline())
ans = []
for m in range(M):
    cmd, *V, = readline().split()
    if cmd == "print":
        ans.extend(debug())
    else:
        insert([None, None, int(V[0]), None])
write("\n".join(ans))
write("\n")




Measured memory_bytes: 124992
n=int(input())
l=[list(map(int,input().split())) for _ in range(n)]
dp=[0]*3
for i in range(n):
    dp[0],dp[1],dp[2]=max(dp[1],dp[2])+l[i][0],max(dp[0],dp[2])+l[i][1],max(dp[0],dp[1])+l[i][2]
    #print(dp)
print(max(dp))

Measured memory_bytes: 30580
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#include <tr1/unordered_map>
using namespace std;
#define ll long long
#define re register
#define pb push_back
#define fi first
#define se second
const int N=1e6+10;
const int mod7=1e9+7;
const int mod=1e9+7;
void read(int &a)
{
    a=0;int d=1;char ch;
    while(ch=getchar(),ch>'9'||ch<'0')
        if(ch=='-')
            d=-1;
    a=ch^48;
    while(ch=getchar(),ch>='0'&&ch<='9')
        a=(a<<3)+(a<<1)+(ch^48);
    a*=d;
}
void read(ll &a)
{
    a=0;int d=1;char ch;
    while(ch=getchar(),ch>'9'||ch<'0')
        if(ch=='-')
            d=-1;
    a=ch^48;
    while(ch=getchar(),ch>='0'&&ch<='9')
        a=(a<<3)+(a<<1)+(ch^48);
    a*=d;
}
ll n;
ll a[N],cnt;
int fen(ll x)
{
    int ans=0;
    for(re ll i=1;i*i<=x;i++)
    {
        if(x%i==0)
        {
            if(i>1) ans++;
            if((n-1)/i!=i) ans++;
        }
    }
    return ans;
}
int main()
{
    read(n);
    int ans=fen(n-1);
    for(re ll i=2;i*i<=n;i++)
    {
        if(n%i==0)
        {
            //cout<<i<<endl;
            ll t=n;
            while(t%i==0) t/=i;
            if(t%i==1) ans++;
            t=n;
            if(i==n/i) continue;
            ll x=n/i;
            while(t%x==0) t/=x;
            if(t%x==1) ans++;
        }
    }
    printf("%d\n",ans+1);
    return 0; 
}

Measured memory_bytes: 256
n = int(input())

l = [100, 10, 1]

n100 =  n // 100
n10 = (n - n100 * 100) // 10
n1 = (n - n100 * 100 - n10 * 10)

if n100 > n10:
    print(int(str(n100) * 3))
elif n100 < n10:
    print(int(str(n100 + 1) * 3))
else:
    if n10 > n1:
        print(int(str(n100) * 3))
    elif n10 < n1:
        print(int(str(n100 + 1) * 3))
    else:
        print(n)



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

typedef long long ll;
typedef unsigned long long ull;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define MAX 9223372036854775807
#define MOD 1000000007

int main(void){

    int a, b;
    cin >> a >> b;

    //ab間に0が入るとき
    if(a<=0 && b >=0){
        cout << "Zero" << endl;
        return 0;
    }

    //以下は両方とも負or正の整数の場合
    int dis = abs(a - b);
    
    //両方正の時
    if(a>=0)cout << "Positive" << endl;

    else if (b <= 0){
        if (dis % 2 == 0)
            cout << "Negative" << endl;
        else
            cout << "Positive" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
M = 100
N = 9
S = 1000

dp = Array.new(M+1) {Array.new(N+1) {Array.new(S+1) {0}}}
dp[0][0][0] = 1
for i in 0..M do
  dp[i+1] = Marshal.load(Marshal.dump(dp[i]))
  for j in 0...N do
    for k in 0...S-i do
      dp[i+1][j+1][k+i] += dp[i][j][k]
    end
  end
end

while (n, s = gets.split.map(&:to_i)).inject(:+) != 0 do
  p dp[M+1][n][s]
end

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

int main(){
  string s; cin >>s;
  int a=0,b=0,c=0;
  rep(i,s.size()){
    if(s[i]=='a') a++;
    else if(s[i]=='b') b++;
    else c++;
  }
  if(a>c+1 or b>c+1 or c>a+1 or c>b+1 or a>b+1 or b>a+1) cout << "NO" << endl;
  else cout << "YES" << endl;
  return 0;
}

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

using namespace std;

int main() {
    int n, m;
    cin >> n >> m;
    vector<vector<int>> e(n);
    for (int i = 0; i < m; ++i) {
        int a, b;
        cin >> a >> b;
        --a; --b;
        e[a].push_back(b);
        e[b].push_back(a);
    }
    queue<int> q;
    q.push(0);
    vector<int> prev(n, -1);
    prev[0] = 0;
    while (!q.empty()) {
        int v = q.front(); q.pop();
        for (int u: e[v]) {
            if (prev[u] >= 0)
                continue;
            prev[u] = v;
            q.push(u);
        }
    }
    if (any_of(prev.begin(), prev.end(), [](int x) {return x < 0;})) {
        cout << "No\n";
    } else {
        cout << "Yes\n";
        for (int i = 1; i < n; ++i) {
            cout << prev[i] + 1 << "\n";
        }
    }
    return 0;
}


Measured memory_bytes: 10236
// I SELL YOU...! 
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<chrono>
#include<iomanip>
#include<map>
#include<set>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
void init_io(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << setprecision(10);
}
using TP = tuple<ll,ll,ll,bool>;
ll ans = 10000000000;
string s[110];
bool tb[110][110]={};
ll d[110][110];
ll h,w;
signed main(){
  init_io();
  cin >> h >> w;
  for(int i=0;i<h;i++){
    cin >> s[i];
    for(int j=0;j<w;j++){
      if(s[i][j]=='#') tb[i][j] = true;
      d[i][j] = 100000000000;
    }
  }
  d[0][0] = 0;
  if(tb[0][0]) d[0][0]++;
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      if(i!=0){
        ll add=0;
        if(tb[i][j]&!tb[i-1][j]){
          add = 1;
        }
        d[i][j] = min(d[i][j],d[i-1][j]+add);
      }
      if(j!=0){
        ll add=0;
        if(tb[i][j]&!tb[i][j-1]){
          add = 1;
        }
        d[i][j] = min(d[i][j],d[i][j-1]+add);
      }
    }
  }
  ll ans = d[h-1][w-1];
  cout << ans<<endl;
}


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

int main() {
  int N;

  cin >> N;
  vector<int> vec(N);
  for(int i=0;i<N;++i){
    int s; cin >> s;
    vec.at(s-1) = i+1;
  }

  for(int i=0;i<N-1;++i){
    cout << vec.at(i) << " ";
  }
  cout << vec.at(N-1) << endl;
  return 0;
}


Measured memory_bytes: 3744
#include<bits/stdc++.h>
using namespace std;
long long n, k;
long long ans(long long n,long long k)
{
    if (n<=k) 
        return min(n,k-n);
    return ans(n%k,k);
}
int main()
{
    cin>>n>>k;
    cout<<ans(n,k);
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstring>
#include<queue>
using namespace std;
#define N 120
typedef struct node
{
    int x;
    int y;
    int sum;
    friend bool operator<(node x,node y)
    {
        return x.sum>y.sum;
    }
} node;
int ans[N][N]= {{0}};
int ch[N][N]= {{0}};
int Judge[N][N]= {{0}};
int n;
int BFS(int x,int y);
int  main()
{
    int K,i,all,j,x1;
    cin>>n>>K;
    for(i=1; i<=n; i++)
    {
        cin>>x1;
        ans[x1][i]=1;
        ch[0][i]=2;
        ch[K][i]=3;
    }
    all=0;
    for(i=0; i<=N; i++)
    {
        for(j=0; j<=N; j++)
        {
            if(ans[i][j]==1)
            {
                all=all+BFS(i,j);
            }
        }
    }
    cout<<all<<endl;
    return 0;
}
int BFS(int i,int j)
{
    int ii;
    node a;
    priority_queue<node>que;
    for(ii=i; ii>=0; ii--)
    {
        if(ch[ii][j]==2)
        {
            a.x=ii;
            a.y=j;
            a.sum=2*(i-ii);
            que.push(a);
        }
    }
    for(ii=i+1; ii<=N; ii++)
    {
        if(ch[ii][j]==2)
        {
            a.x=ii;
            a.y=j;
            a.sum=2*(ii-i);
            que.push(a);
        }
    }
    for(ii=i; ii>=0; ii--)
    {
        if(ch[ii][j]==3)
        {
            a.x=ii;
            a.y=j;
            a.sum=2*(i-ii);
            que.push(a);
        }
    }
    for(ii=i+1; ii<=N; ii++)
    {
        if(ch[ii][j]==3)
        {
            a.x=ii;
            a.y=j;
            a.sum=2*(ii-i);
            que.push(a);
        }
    }
    a=que.top();
    ch[a.x][a.y]=0;
    return a.sum;
}


Measured memory_bytes: 256
#ifdef LOCAL
#include <cstdio>
#include <vector>
#include <algorithm>
#include <iostream>
#include <cstring>
#else
#include <bits/stdc++.h>
#endif
using namespace std ;

typedef long long ll ;
#define rep(i , n ) for ( int i =0; i < n ; i++)
#define _sort(arg) sort(begin(arg), end(arg))
#define MOD 1000000007
#define pb push_back
#define DEBUG(x) cout << #x << ": " << x << endl;

/*
__attribute__((constructor))
void initial()
{
	cin.tie(NULL);
	ios::sync_with_stdio(false);
}
*/

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

	string s;
	
	cin >> s;
	int k = 15;
	int total = k - s.size();
	for(int i=0; i < s.size(); i++)
	{
		if (s[i] == 'o')
		{
			total++;
		}
	}
	if (total >= 8)
	{
		cout << "YES" << endl;
	}
	else
	{
		cout << "NO" << endl;
	}
	


	
	return 0;
}


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

bool judge(int x){
    int ans3 = 0,ans5 = 0,ans7 = 0,num=0;
    do{
       if(x % 10 == 3) ans3++;
       if(x % 10 == 5) ans5++;
       if(x % 10 == 7) ans7++;
       num++;
       x = x/10;

    }while(x != 0);
    if(ans3 > 0 && ans5 > 0 && ans7 > 0 && ans3+ans5+ans7 == num){
        return true;
    }else{
        return false;
    }
}

int main(){
    int t;
    cin>>t;
    int ans = 0;
    for(int i = 1;i <= t;){
        if(judge(i)){
            ans++;
            i+=18;
        }else{
            i++;
        }
    }
    cout<<ans;
}
*/
#include<cstdio>
int count = 0;
int t;

void DFS(long long x,bool three,bool five,bool seven){
    if(x > t) return;
        if(three && five && seven) count++;
    DFS(x*10+3,true,five,seven);
    DFS(x*10+5,three,true,seven);
    DFS(x*10+7,three,five,true);

}

int main(){
    scanf("%d",&t);
    DFS(0,false,false,false);
    printf("%d",count);
}

























Measured memory_bytes: 128
#include <iostream>
static void e(int *a) {
    int t = a[1];
    a[1] = a[4];
    a[4] = a[6];
    a[6] = a[3];
    a[3] = t;
}
static void n(int *a) {
    int t = a[1];
    a[1] = a[2];
    a[2] = a[6];
    a[6] = a[5];
    a[5] = t;
}
static void s(int *a) {
    int t = a[1];
    a[1] = a[5];
    a[5] = a[6];
    a[6] = a[2];
    a[2] = t;
}
static void w(int *a) {
    int t = a[1];
    a[1] = a[3];
    a[3] = a[6];
    a[6] = a[4];
    a[4] = t;
}
int main() {
    int a[7], b[7];
    for (int i = 1; i <= 6; ++i) {
        std::cin >> a[i];
    }
    for (int i = 1; i <= 6; ++i) {
        std::cin >> b[i];
    }
    bool f = false;
    std::string m;
    for (int i = 0; i < 4 && !f; ++i) {
        s(b);
        for (int j = 0; j < 4 && !f; ++j) {
            w(b);
            for (int k = 0; k < 4 && !f; ++k) {
                s(b);
                e(b);
                n(b);
                f = true;
                for (int x = 1; x <= 6; ++x) {
                    if (a[x] != b[x]) {
                        f = false;
                        break;
                    }
                }
            }
        }
    }
    std::cout << (f ? "Yes" : "No") << std::endl;
}



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

struct Node{
    int key;
    Node *parent, *left, *right;
};

Node *root, *NIL;

void insert(int k){
    Node *y = NIL;
    Node *x = root;
    Node *z;

    z = (Node *)malloc(sizeof(Node));
    z->key = k;
    z->left = NIL;
    z->right = NIL;

    while(x != NIL){
        y = x;
        if(z->key < x->key) x = x->left;
        else x = x->right;
    }

    z->parent = y;

    if(y == NIL){
        root = z;
    }else{
        if(z->key < y->key) y->left = z;
        else y-> right = z;
    }

}

int find(int k){
    Node *x = root;
    while(x != NIL && x->key != k){
        if(k < x->key) x = x->left;
        else x = x->right;
    }
    if(x == NIL) return 0;
    else return 1;
}

void inorder(Node *u){
    if(u == NIL) return;
    inorder(u->left);
    printf(" %d", u->key);
    inorder(u->right);
}

void preorder(Node *u){
    if(u == NIL) return;
    printf(" %d", u->key);
    preorder(u->left);
    preorder(u->right);
}

void print(Node *u){
    inorder(u);
    printf("\n");
    preorder(u);
    printf("\n");
}

int main(){
    int n;
    scanf("%d", &n);

    int k;
    char com[10];

    rep(i,n){
        scanf("%s", com);
        if(com[0] == 'i'){
            scanf("%d", &k);
            insert(k);
        }else if(com[0] == 'f'){
            scanf("%d", &k);
            if(find(k)) printf("yes\n");
            else printf("no\n");
        }else if(com[0] == 'p'){
            print(root);
        }
    }
    
    return 0;
}


Measured memory_bytes: 21960
#include <stdio.h>
int main(void)
{
    int a,b,c,d,i,s,g,t=0;
    
    scanf("%d%d%d%d",&a,&b,&c,&d);
    if(a<c) s=a;
    else s=c;
    if(b>d) g=b;
    else g=d;
    for(i=s;i<=g;i++)
        if(((a<=i)&&(i<b))&&((c<=i)&&(i<d)))
            t++;
    printf("%d\n",t);
    return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define maxn 1000
int num[maxn+5];
int main(){
//	freopen("1.in","r",stdin);
	int h,w,a,b,c=0,d=0;scanf("%d%d%d%d",&h,&w,&a,&b);
	c=b,d=a;
	for(int i=0;i<h;i++){
		int w1=((i<c)?a:w-a);
		for(int j=0;j<w;j++){
			if(w1&&num[j]<((j<d)?b:h-b))num[j]++,putchar('1'),w1--;
			else putchar('0');
		}
		puts("");
	}
	return 0;
} 

Measured memory_bytes: 1280
//#pragma GCC optimize("Ofast,no-stack-protector")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")
//#pragma GCC target("avx,tune=native")
#include<bits/stdc++.h>
//#include<ext/pb_ds/assoc_container.hpp>
using namespace std;
//using namespace __gnu_pbds;
const int inf=0x3f3f3f3f;
const double eps=1e-6;
const int mod=1000000007;
typedef long long ll;
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
inline string getstr(string &s,int l,int r){string ret="";for(int i=l;i<=r;i++)ret.push_back(s[i]);return ret;}
int modpow(int x,int y,int md=mod){if(y==0)return 1;int ret=modpow(x,y>>1,md);ret=(ll)ret*ret%md;if(y&1)ret=(ll)ret*x%md;return ret;}
int n,m;
struct edge{
    int to,flow,rev;
};
vector<edge>g[401];
void add_edge(int u,int v,int c){
    g[u].push_back((edge){v,c,(int)g[v].size()});
    g[v].push_back((edge){u,0,(int)g[u].size()-1});
}
int q[401];
int dist[401];
bool bfs(int s,int t){
    memset(dist,0x3f3f3f3f,sizeof(dist));
    dist[s]=0;
    int b=0,e=1;q[0]=s;
    while(b<e){
        int x=q[b++];
        for(int i=0;i<g[x].size();i++){
            if(dist[g[x][i].to]==0x3f3f3f3f&&g[x][i].flow>0){
                q[e++]=g[x][i].to;
                dist[g[x][i].to]=dist[x]+1;
            }
        }
    }
    return dist[t]!=0x3f3f3f3f;
}
int dfs(int x,int to,int f){
    if(x==to)return f;
    int ret=0;
    for(int i=0;i<g[x].size();i++){
        if(g[x][i].flow>0 && dist[g[x][i].to]==dist[x]+1){
            int tmp=dfs(g[x][i].to,to,min(g[x][i].flow,f-ret));
            g[x][i].flow-=tmp;
            g[g[x][i].to][g[x][i].rev].flow+=tmp;
            ret+=tmp;
            if(ret>=f)break;
        }
    }
    return ret;
}
int max_flow(int s,int t){
    int ret=0;
    while(bfs(s,t)){
        ret+=dfs(s,t,INT_MAX);
    }
    return ret;
}
int a[105][105];
int b[105][105];
int c[105][105];
set<int>need[105];
vector<int>data[105][105];
int level(int x){
	return (x-1)/m;
}
void solve(int col){
	for(int i=0;i<=400;i++)g[i].clear();
	int S=400,T=399;
	for(int i=1;i<=n;i++){
		add_edge(S,i,1);
	}
	for(int i=1;i<=n;i++){
		for(int lvl=0;lvl<n;lvl++){
			add_edge(i,lvl+101,data[i][lvl].size());
		}
	}
	for(int i=0;i<n;i++){
		add_edge(i+101,T,1);
	}
	int x=max_flow(S,T);//cerr<<x<<endl;
	vector<int>use(105,-1);
	for(int i=1;i<=n;i++){
		for(auto e:g[i]){
			int to=e.to,flow=e.flow;
			if(to!=S&&flow!=data[i][to-101].size()){
				use[i]=to-101;
			}
		}
	}
	for(int i=1;i<=n;i++){
//		cerr<<i<<" "<<use[i]<<" "<<data[i][use[i]].size()<<endl;
		b[i][col]=data[i][use[i]].back();
		data[i][use[i]].pop_back();
	}
}

int main(){
	cin>>n>>m;
	for(int i=1;i<=m;i++)for(int j=1;j<=n;j++)need[i].insert(j-1);
	for(int i=1;i<=n;i++)for(int j=1;j<=m;j++){
		cin>>a[i][j];
		data[i][level(a[i][j])].push_back(a[i][j]);
	}
	for(int j=1;j<=m;j++){
		solve(j);
	}
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			cout<<b[i][j]<<" ";
		}
		cout<<endl;
	}
	for(int j=1;j<=m;j++){
		for(int i=1;i<=n;i++){
			for(int k=i+1;k<=n;k++){
				if(b[i][j]>b[k][j]){
					swap(b[i][j],b[k][j]);
				}
			}
		}
	}
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			cout<<b[i][j]<<" ";
		}
		cout<<endl;
	}
	return 0;
}

Measured memory_bytes: 1792
import math
A, B, H, M = map(int, input().split())
a = math.pi/360 * (H*60 + M)
b = math.pi/30 * M
# if abs(a - b) > math.pi:
#     theta = 2 * math.pi - abs(a-b)
# else:
theta = abs(a-b)
L = math.sqrt(A**2 + B**2 - 2*A*B*math.cos(theta))
print(L)

Measured memory_bytes: 62424
package main

import (
	"fmt"
)

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

	n := 1
	var m int
	for i := 2; i <= N; i++ {
		for j := 1; ; j++ {
			if i%(pow(2, j)) != 0 {
				if j > m {
					n, m = i, j-1
				}
				break
			}
		}
	}
	fmt.Println(n)
}

func pow(n int, p int) int {
	r := n
	for i := 1; i < p; i++ {
		r = r * n
	}
	return r
}


Measured memory_bytes: 512
#include<iostream>
#include<algorithm>
#include<stdio.h>
#include<stdlib.h>
#include<string>
#include<vector>
#include<math.h>
#include<stack>
#include<queue>
#include<map>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
const long long mod = 1e9 + 7;
typedef long long ll;
 
int main(){
    int n, t;
    cin >> n >> t;
    int c, time, ans = 1001;
    rep(i,n){
        cin >> c >> time;
        if(time > t) continue;
        if(c <= ans) ans = c;
    }
    if(ans == 1001) cout << "TLE" << endl;
    else cout << ans << endl;
} 

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using P=pair<int,int>;
using G=vector<vector<int>>;

int main(){
    int n; cin>>n;
    set<string> s;
    for(int i=0;i<n;i++){
        string si;
        cin>>si;
        s.insert(si);
    }

    cout<<s.size()<<endl;
}

Measured memory_bytes: 19228
#include <iostream>
#include <fstream>
#include <cmath>  
#include <cstdlib>
#include <ctime>
#include <algorithm>
#include <numeric>
#include <functional>
#include <string> 
#include <vector>
#include <bitset>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>

using namespace std;
using ll = long long;

template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;

#define REP(i,n) for(int i = 0; i < int(n); i++)
#define FOR(i, m, n) for(int i = int(m);i < int(n);i++)
#define ALL(obj) (obj).begin(),(obj).end()

const ll MOD = (ll)1e9 + 7;
const ll HINF = (ll)1e18;
const ll LINF = (ll)1e9;
const long double PI = 3.1415926535897932384626433;

vector<int> dy = { 0,0,1,-1 };
vector<int> dx = { 1,-1,0,0 };

template<class T> void corner(bool flg, T hoge) {
	if (flg) {
		cout << hoge << endl;
		exit(0);
	}
	else return;
}

template <class T, class U>ostream &operator<<(ostream &o, const map<T, U>&obj) {
	o << "{"; for (auto &x : obj) o << " {" << x.first << " : " << x.second << "}" << ","; o << " }"; return o;
}

template <class T>ostream &operator<<(ostream &o, const set<T>&obj) {
	o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;
}

template <class T>ostream &operator<<(ostream &o, const vector<T>&obj) {
	o << "{"; for (int i = 0; i < (int)obj.size(); ++i)o << (i > 0 ? ", " : "") << obj[i]; o << "}"; return o;
}

template <class T, class U>ostream &operator<<(ostream &o, const pair<T, U>&obj) {
	o << "{" << obj.first << ", " << obj.second << "}"; return o;
}

template <template <class tmp>  class T, class U> ostream &operator<<(ostream &o, const T<U> &obj) {
	o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr)o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;
}

void print(void) {
	cout << endl;
}

template <class Head> void print(Head&& head) {
	cout << head;
	print();
}

template <class Head, class... Tail> void print(Head&& head, Tail&&... tail) {
	cout << head << " ";
	print(forward<Tail>(tail)...);
}

void YN(bool flg) {
	cout << ((flg) ? "YES" : "NO") << endl;
}

void Yn(bool flg) {
	cout << ((flg) ? "Yes" : "No") << endl;
}

void yn(bool flg) {
	cout << ((flg) ? "yes" : "no") << endl;
}

int main() {
	ll N, K; cin >> N >> K;
	V<ll> a(N + 1, 0); REP(i, N) cin >> a[i + 1];
	FOR(i, 1, N + 1) a[i] += a[i - 1];
	ll M = (N * (N + 1)) / 2;
	V<ll> b(M, 0);
	ll idx = 0;
	REP(i, N) {
		FOR(j, i + 1, N + 1) {
			b[idx] = a[j] - a[i];
			idx++;
		}
	}
	//idx = 0;
	//REP(i, N) {
	//	FOR(j, i + 1, N + 1) {
	//		print(b[idx]);
	//		idx++;
	//	}
	//}

	for (int k = 59; 0 <= k; --k) {
		ll cnt = 0;
		REP(i, M) cnt += bool(b[i] & (1LL << k));
		if (cnt >= K) {
			REP(i, M) if (!(b[i] & (1LL << k))) b[i] = 0;
		}
	}

	idx = 0;
	ll ans = (1LL << 60) - 1;
	REP(i, M) {
		if (b[i] != 0) {
			ans &= b[i];
			idx++;
		}
	}
	if (idx >= K) cout << ans << endl;
	else cout << 0 << endl;

	return 0;
}




Measured memory_bytes: 4224
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

n = inp()
s = input()
ss = [0] * n
for i,t in enumerate(s):
    if t == 'R':
        ss[i] = 0
    elif t == 'G':
        ss[i] = 1
    else:
        ss[i] = 2
color = [[0] * 3 for _ in range(n)] 
color[0][ss[0]] = 1
for i,t in enumerate(ss):
    if i == 0:
        continue
    for j in range(3):
        if t == j:
            color[i][j] = color[i-1][j] + 1
        else:
            color[i][j] = color[i-1][j]
res = 0
for i in range(n-1):
    for j in range(i+1,n):
        if ss[i] == ss[j]:
            continue
        c = j-i
        yet = -1
        for _ in range(3):
            if ss[i] == _ or ss[j] == _ :
                continue
            yet = _
        res += color[-1][yet] - color[j][yet]
        if j+c < n and ss[j+c] == yet:
            res -= 1
print(res)


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

int cnt;

void print(vector<int> &a, int n)
{
	rep(i, n)
		cout << a[i] << endl;
}

void insert_sort(vector<int> &a, int n, int g)
{
	for (int i = g; i < n; i++) {
		int v = a[i];
		int j = i - g;
		while (j >= 0 && a[j] > v) {
			a[j+g] = a[j];
			j -= g;
			cnt++;
		}
		a[j+g] = v;
	}
}

void shell_sort(vector<int> &a, int n)
{
	vector<int> g;
	for (int h = 1; h <= n; h = 3*h + 1)
		g.push_back(h);
	cout << g.size() << endl;
	for (int i = g.size()-1; i >= 0; i--) {
		cout << g[i];
		if (i) cout << " ";
	}
	cout << endl;

	for (int i = g.size()-1; i >= 0; i--)
		insert_sort(a, n, g[i]);
}

int main()
{
	int n;
	cin >> n;
	vector<int> a(n);
	rep(i, n) cin >> a[i];

	shell_sort(a, n);
	cout << cnt << endl;
	print(a, n);
}



Measured memory_bytes: 6752
import sys
import bisect
input = sys.stdin.readline
ins = lambda: input().rstrip()
ini = lambda: int(input().rstrip())
inm = lambda: map(int, input().split())
inl = lambda: list(map(int, input().split()))
out = lambda x: print('\n'.join(map(str, x)))

n, m, k = inm()
a = inl()
b = [0] + inl()
count = 0
prev = 0
for i in range(n-1):
    a[i+1] += a[i]
for i in range(m+1):
    if b[i]+prev > k:
        break
    j = bisect.bisect(a, (k - b[i] - prev))
    count = max(count, i + j)
    prev += b[i]
print(count)

Measured memory_bytes: 40996
import java.util.Scanner;

public class Main {

	public static void main (String[] args) {
		Scanner scan = new Scanner(System.in);
		long a = scan.nextLong(),b = scan.nextLong();
		long x = scan.nextLong();
		long result = (b/x) - (a/x);
		if(a%x==0)result++;
		System.out.println(result);
	}

}

Measured memory_bytes: 22996
N, M = [int(_) for _ in input().split()]

mod = 10 ** 9 + 7
def comb(x, y):
    if y * 2 > x:
        y = x - y
    result = 1
    for j in range(1, y + 1):
        result *= (x + j - y)
        result //= j
    return result
def homoprod(x, y):
    return comb(x + y - 1, y)

ans = 1
i = 2
for i in range(2, int(M ** 0.5) + 2):
    count = 0
    while M % i == 0:
        count += 1 
        M //= i
    if count > 0:
        ans *= homoprod(N, count)
        ans %= mod
if M > 1:
    ans *= homoprod(N, 1)
    ans %= mod
print(ans)

Measured memory_bytes: 3188
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]

def main():
    r,g,b=MI()
    if (g*10+b)%4:print("NO")
    else:print("YES")
main()

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

using namespace std;
using namespace __gnu_pbds;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key

typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<int> vi;
typedef long double ld;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0);
    ll a,b,c,k;
    cin>>a>>b>>c>>k;
    if(a>=k){
        cout<<k;
    }
    else if(a+b>=k){
        cout<<a;
    }
    else{
        cout<<a-(k-a-b);
    }
    return 0;
}


Measured memory_bytes: 3652
#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long
#define pii std::pair<int,int>
#define pli std::pair<ll,int>
#define pil std::pair<int,ll>
#define psi std::pair<string,int>
#define pll std::pair<ll,ll>
#define pci std::pair<char,int>
#define sll(x) scanf("%lld",&x)
#define prll(x) printf("%lld ",x)
#define pri(x) printf("%d ",x)
#define si(x) scanf("%d",&x)
#define pb push_back
#define vll std::vector<ll>
#define vpi std::vector<std::pair<int,int>>
#define vi std::vector<int>
#define vvi std::vector<std::vector<int>>
#define vvpil std::vector<std::vector<std::pair<int,ll>>>
#define vlpii std::vector<std::list<pii>>
#define vlpil std::vector<std::list<pil>>
#define li std::list<int>
#define lpil std::list<pil>
#define Endl printf("\n")
#define vli vector<list<int>>
#define vvll vector<vector<ll>>
#define mp make_pair
#define x first
#define y second
#define ull uint64_t
#define ma 100000000
#define imie(...) "[" << #__VA_ARGS__": " << (__VA_ARGS__) << "] "
const ll  INF=10000000000000;
const ll mod =  1e9 + 7;
using namespace std;
void add(ll& a , ll b){
	a += b;
	if(a >= mod) a -= mod;
}
ll mul(ll a , ll b){
	return (a * b) % mod;
}
ull Pow(ull a , ull b){
	if(b == 0) return 1 ;
	ull c = Pow(a , b / 2) ;
	if(b % 2) return (a * ((c * c) % mod)) % mod;
	return (c * c) % mod ;
}


int main(){
	IOS;
	cout.precision(30) ;
	int n , k; cin >> n >> k ;
	vll x(n);for(int i = 0 ;  i< n ; i++) cin >> x[i] ;
	ll ans = 1e18 ;
	for(int i = k - 1 ; i < n ; i++) {
		ans = min( ans , min(abs(x[i]) , abs(x[i -(k - 1)])) + x[i] - x[i - (k - 1)]) ;
	}
	cout << ans << endl ;
	return 0;
}


Measured memory_bytes: 1024
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <cstdlib>
using namespace std;
typedef long long LL;
const int Maxn = 1e5 + 5;
int main ()
{
	int n,m;
	scanf("%d%d",&n,&m);
	int k = 1;
	for (int i = 1; i <= m; i++)
		k = 2*k;
	printf("%d",1900*m*k+(n-m)*100*k);
	return 0;
}

Measured memory_bytes: 128
// AtCoder.cpp : このファイルには 'main' 関数が含まれています。プログラム実行の開始と終了がそこで行われます。
//

// AtCoder.cpp : このファイルには 'main' 関数が含まれています。プログラム実行の開始と終了がそこで行われます。
//


#define _USE_MATH_DEFINES
#include<math.h>

//#include<cmath>

#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<array>
#include<map>
#include<iomanip>
#include<assert.h>
#include<bitset>
#include<stack>
#include<memory>



//#include "Ants.h"
using namespace std;
typedef long long ll;
#define rad_to_deg(rad) (((rad)/2/M_PI)*360)
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define rep(i,n) for(int i=0;i<n;i++)
#define show(s) cout<<s<<endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define LINF (1000000000000000000ll)
#define MOD (1e9+7)
typedef pair < ll, ll> P;
ll gcd(ll a, ll b) {//最大公約数を求める///最大公倍数a*b/gcd(a,b)
	if (b == 0) return a;
	return gcd(b, a % b);
}
ll lcd(ll a, ll b) {//最小公倍数を求める　b=0のときaを返す
	if (b == 0) return a;
	return (a / gcd(a, b)) * b;
}
vector<int> divnum(ll num) {
	int dig;
	vector<int>p;
	while (num) {
		dig = num % 10;
		p.push_back(dig);
		num /= 10;
	}
	return p;
}
int digiter(ll num) {
	int dig;
	vector<int>p;
	while (num) {
		dig = num % 10;
		p.push_back(dig);
		num /= 10;
	}
	return p.size();
}
vector<int> convertstring(string s) {
	vector<int> d;
	ll n = s.size();
	rep(i, n) {
		d.push_back(s[i] - '0');
	}
	return d;
}
map< int64_t, int > prime_factor(int64_t n) {
	map< int64_t, int > ret;
	for (int64_t i = 2; i * i <= n; i++) {
		while (n % i == 0) {
			ret[i]++;
			n /= i;
		}
	}
	if (n != 1) ret[n] = 1;
	return ret;
}
vector<ll> divisor(ll n) {
	vector<ll>res;
	for (ll i = 1; i * i <= n; i++) {
		if (n % i != 0)continue;
		res.push_back(i);
		if (i * i != n)res.push_back(n / i);
	}
	return res;
}


ll myPow(ll x, ll n, ll m) {
	if (n == 0)
		return 1;
	if (n % 2 == 0)
		return myPow(x * x % m, n / 2, m);
	else
		return x * myPow(x, n - 1, m) % m;
}
std::vector<int> Eratosthenes(const int N)
{
	std::vector<bool> is_prime(N + 1);
	for (int i = 0; i <= N; i++)
	{
		is_prime[i] = true;
	}
	std::vector<int> P;
	for (int i = 2; i <= N; i++)
	{
		if (is_prime[i])
		{
			for (int j = 2 * i; j <= N; j += i)
			{
				is_prime[j] = false;
			}
			P.emplace_back(i);
		}
	}
	return P;
}

int N, C, D[35][35], c[505][505]; int sz[3][35];
int coster(int mpos, int y) {
	int res = 0;
	rep(x, C) {
		res+=D[x][y] * sz[mpos][x];
	}
	return res;
}
int main()
{
	cin >> N >> C;
	rep(x, C)rep(y, C)cin >> D[x][y];
	rep(i, N)rep(j, N)cin >> c[i][j];
	rep(i, N)rep(j, N) {
		sz[(i + j) % 3][--c[i][j]]++;
	}
	
	vector<int>d[3];
	rep(i, 3) {
		rep(j, C) {
			d[i].push_back(coster(i, j));
		}
		
	}
	int ans = INF;
	rep(i, C) {
		rep(j, C) {
			if (i == j)continue;
			rep(k, C) {
				if (i == k || j == k)continue;
				chmin(ans, d[0][i] + d[1][j] + d[2][k]);
			}
		}
	}
	cout << ans << endl;
}

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

void fnInput(vector<vector<int>>& rvvnAdjcy)
{
  int nMaxSiz;
  cin >> nMaxSiz;

  rvvnAdjcy.resize(nMaxSiz + 1, vector<int>(nMaxSiz + 1, 0));
  for (int i = 0; i < nMaxSiz; i++)
  {
    int nx, nSecSiz;
    cin >> nx >> nSecSiz;
    for (int j = 0; j < nSecSiz; j++)
    {
      int ny;
      cin >> ny;
      rvvnAdjcy[nx][ny] = 1;
    }
  }
}

void fnResult(const vector<vector<int>>& cnrvvnAdjcy)
{
  for (int i = 1; i < cnrvvnAdjcy.size(); i++)
  {
    for (int j = 1; j < cnrvvnAdjcy[i].size(); j++)
    {
      if (j != 1) cout << " ";
      cout << cnrvvnAdjcy[i][j];
    }
    cout << endl;
  }
}

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  vector<vector<int>> vvnAdjcy;

  fnInput(vvnAdjcy);
  fnResult(vvnAdjcy);

  return 0;
}

Measured memory_bytes: 3160
#include <iostream>
#include <string>
#include <regex>
#include <algorithm>

using namespace std;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string raw_text;
    string pattern;
    int count = 0;
    cin >> pattern;
    while(true){
        cin >> raw_text;
        if(raw_text == "END_OF_TEXT") break;
        transform(raw_text.begin(), raw_text.end(), raw_text.begin(), ::tolower);
        if(regex_match(raw_text, regex(pattern))) count++;
    }
    cout << count << endl;
}



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

using namespace std;

int main() {
    string S, T;
    cin >> S >> T;

    bool translatable = true;

    vector<char>  c1_to(26, -1);
    vector<char>  c2_to(26, -1);

    for(int i=0; i<S.size(); i++) {
        char c1 = S[i] - 97;
        char c2 = T[i] - 97;

        if(c1_to[c1] >= 0) {
            if(c1_to[c1] != c2) {
                translatable = false;
                break;
            }
        } else {
            c1_to[c1] = c2;
        }

        if(c2_to[c2] >= 0) {
            if(c2_to[c2] != c1) {
                translatable = false;
                break;
            }
        } else {
            c2_to[c2] = c1;
        }
    }

    cout << (translatable ? "Yes" : "No") << endl;
}


Measured memory_bytes: 1020
#include <bits/stdc++.h>
using namespace std;
int main(){
   int s;
  cin>>s;
  vector<int> x(1000000);
  int ans=1;
  int ansh=0;
  x[0]=s;
  for(int i=1;i<1000000;i++){
    if(s%2==0){
      s/=2;
    }
    else{
      s=3*s+1;
    }
    x[i]=s;
    for(int j=0;j<i-1;j++){
      if(s==x[j]){
        ansh++;
        break;
      }
    }
    ans++;
    if(ansh==1){
      break;
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 4096
fun main(arr: Array<String>) {
    println(getAns()?:-1)
}


fun getAns():Int? {
    val n = readLine()!!.toInt()
    val list = (1..n).map { readLine()!!.toInt() }
    val dic = mutableMapOf<Int,Boolean>()
    var current = 1
    var ans = 0
    while (current != 2) {
        dic[current]?.let { return null }
        dic[current] = true
        ans++
        current = list[current-1]
    }
    return ans
}

Measured memory_bytes: 63404
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < int(n); i++)
using namespace std;
using ll = long long;
const int INF = (1<<30)-1;
const long long LINF = (1LL<<62)-1;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

template<int Mod> class ModInt {
  int v;
public:
  constexpr ModInt(const long long x = 0) noexcept : v((x % Mod + Mod) % Mod) {}
  constexpr ModInt &operator+=(const ModInt rhs) noexcept {
    v += rhs.v;
    if (v >= Mod)
      v -= Mod;
    return *this;
  }
  constexpr ModInt &operator-=(const ModInt rhs) noexcept {
    if (v < rhs.v)
      v += Mod;
    v -= rhs.v;
    return *this;
  }
  constexpr ModInt &operator*=(const ModInt rhs) noexcept {
    v = int(1LL * v * rhs.v % Mod);
    return *this;
  }
  constexpr ModInt &operator/=(ModInt rhs) noexcept {
    long long exp = Mod - 2;
    while (exp) {
      if (exp & 1)
        *this *= rhs;
      rhs *= rhs;
      exp >>= 1;
    }
    return *this;
  }
  constexpr ModInt operator-() const noexcept { return ModInt(-v); }
  constexpr ModInt operator+(const ModInt rhs) const noexcept {
    return ModInt(*this) += rhs;
  }
  constexpr ModInt operator-(const ModInt rhs) const noexcept {
    return ModInt(*this) -= rhs;
  }
  constexpr ModInt operator*(const ModInt rhs) const noexcept {
    return ModInt(*this) *= rhs;
  }
  constexpr ModInt operator/(const ModInt rhs) const noexcept {
    return ModInt(*this) /= rhs;
  }
  constexpr bool operator==(const ModInt rhs) const noexcept {
    return v == rhs.v;
  }
  constexpr bool operator!=(const ModInt rhs) const noexcept {
    return v != rhs.v;
  }
  constexpr ModInt pow(long long exp) const noexcept {
    ModInt res(1), mul(v);
    while (exp) {
      if (exp & 1)
        res *= mul;
      mul *= mul;
      exp >>= 1;
    }
    return res;
  }
  friend ostream &operator<<(ostream &os, const ModInt obj) noexcept {
    return os << obj.v;
  }
  friend istream &operator>>(istream &is, ModInt &obj) noexcept {
    long long tmp;
    is >> tmp;
    obj = ModInt<Mod>(tmp);
    return is;
  }
};
constexpr int MOD = 998244353;
using mint = ModInt<MOD>;

using P = pair<int, int>;

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, k;
  cin >> n >> k;
  --n;
  vector<P> d(k);
  rep(i, k) {
    cin >> d[i].first >> d[i].second;
    d[i].second++;
  }
  sort(d.begin(), d.end());
  vector<mint> dp(n+1), sum(n+2);
  dp[0] = sum[1] = 1;
  for (int i = 1; i <= n; i++) {
    rep(j, k) {
      dp[i] += sum[max(i+1-d[j].first, 0)]-sum[max(i+1-d[j].second, 0)];
      if (i+1-d[j].second <= 0)
        break;
    }
    sum[i+1] = sum[i]+dp[i];
  }
  cout << dp[n] << endl;
  return 0;
}

Measured memory_bytes: 4792
function main()
	lines=readlines()
	H,W=map(x->parse(Int,x),split(shift!(lines)))
	S=Array{Int}(H,W)
	for i=1:H
		s=shift!(lines)
		for j=1:W
			S[i,j]=s[j]=='.'
		end
	end
	dp1=copy(S)
	dp2=copy(S)
	dp3=copy(S)
	dp4=copy(S)
	for i=1:H,j=1:W
		if i>1
			dp1[i,j]=dp1[i,j]*(dp1[i-1,j]+1)
			dp2[H-i+1,j]=dp2[H-i+1,j]*(dp2[H-i+2,j]+1)
		end
		if j>1
			dp3[i,j]=dp3[i,j]*(dp3[i,j-1]+1)
			dp4[i,W-j+1]=dp4[i,W-j+1]*(dp4[i,W-j+2]+1)
		end
	end
	println(maximum(dp1+dp2+dp3+dp4)-3)
end
main()


Measured memory_bytes: 367220
#include <bits/stdc++.h>
#include <cstdlib>
#include <cmath>
#include <algorithm>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using Graph= vector<vector<ll>>;
struct edge{ll to ; ll cost ;} ;
using graph =vector<vector<edge>> ;
#define rep(i,n) for (ll i=0; i < (n); ++i)
#define rep2(i,n,m) for(ll i=n;i<=m;i++)
#define rep3(i,n,m) for(ll i=n;i>=m;i--)
#define pb push_back
#define eb emplace_back
#define ppb pop_back
#define mpa make_pair
#define fi first
#define se second 
#define set20 cout<<fixed<<setprecision(20) ;
const ll INF=1e18 ;
inline void chmax(ll& a,ll b){a=max(a,b);}
inline void chmin(ll& a,ll b){a=min(a,b);}
double pi=acos(-1) ;
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;}

 int main(){
  ll n ; cin>> n ;
  vector<ll> A(n) ;
  rep(i,n) cin>>A[i] ;
  vector<ll> sum(n+1) ;
  sum[0]=0 ;
  rep(i,n) sum[i+1]=sum[i]+A[i] ;
  vector<ll> sumd(n+1) ;
  rep(i,n+1) sumd[i]=sum[i]*2 ;
  ll ans=INF ;
  rep2(i,2,n-2){// iは前にある個数
    ll k= sum[i] ;
    ll now = lower_bound(sumd.begin(),sumd.end(),k)-sumd.begin() ;
    ll a=sum[now] ;
    ll b= k-a ;
    ll c= sum[now-1] ;
    ll d= k-c ;
    if(abs(c-d)<abs(a-b)){
      a=c ;
      b= d ;
    }
    /////
    ll kk= sum[n]-k ;
    ll mow= lower_bound(sumd.begin(),sumd.end(),k*2+kk) 
    -sumd.begin() ;
    ll e= sum[mow]-k ;
    ll f= kk- e ;
    ll g= sum[mow-1]-k ;
    ll h= kk- g ;
    if(abs(g-h)<abs(e-f)){
      e=g ;
      f=h ;
    }
    /////
    ll xx = max(max(a,b),max(e,f)) ;
    ll yy=  min(min(a,b),min(e,f)) ;
    chmin(ans,abs(yy-xx)) ;
  }
  cout<<ans<<endl ;
   return 0 ;
 }



Measured memory_bytes: 7992
#include<iostream>
#include<sstream>
#include<vector>
#include<algorithm>
#include<string>
#include<stdexcept>
#include<stdio.h>
using namespace std;

int main(){
  int a,b; cin >> a >> b;
  int ans = max(max(a+b,a+a-1),b+b-1);
  cout << ans <<endl;
  return 0;
}

Measured memory_bytes: 256
import scala.io.StdIn

object Main extends App {
  val N = StdIn.readInt()
  val Ws = StdIn.readLine().split(" ").map(_.toInt)

  val abss =
  for (t <- 1 to N) yield {
    val sum1 = Ws.take(t).sum
    val sum2 = Ws.drop(t).sum
    Math.abs(sum1 - sum2)
  }

  println(abss.min)

}

Measured memory_bytes: 25560
//ALDS1_1C
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>

using namespace std;

bool isPrime(int x){
 if(x==2) return true;
 if(x<2 || x%2==0) return false;
 int n=static_cast<int>(sqrt(x));
 for(int i=3;i<=n;i+=2){
  if(x%i==0) return false;
 }
 return true;
}

int main(){
 int n;
 cin>>n;
 vector<int>data(n);
 for(int i=0;i<n;i++){
  cin>>data.at(i);
 }
 int res=0;
 for(int i=0;i<n;i++){
  if(isPrime(data.at(i))) res++;
 }

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

Measured memory_bytes: 1232
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < int(n); i++)
using namespace std;
using ll = long long;
const int INF = (1<<30)-1;
const long long LINF = (1LL<<62)-1;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int x;
  cin >> x;
  if (x >= 30)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}

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

int main(int argc, const char * argv[]) {
    
    int nyuuryoku[5];
    int oturi[5];
    int maisuu[5];
    int data;
    
    for(int i=0;i<5;i++){
        maisuu[i]=0;
    }
    
    for(int i=0;;i++){
        cin >> nyuuryoku[i];
        if(nyuuryoku[i]==0){
            data=i;
            break;
        }
    }
    
    
    for(int i=0;i<data;i++){
        oturi[i]=1000-nyuuryoku[i];
    }
    
    
    for(int i=0;i<data;i++){
        
        for(;;){  //500???
            if(oturi[i]<500){
                break;
            }
            oturi[i]=oturi[i]-500;
            maisuu[i]++;
        }
        
        for(;;){  //100???
            if(oturi[i]<100){
                break;
            }
            oturi[i]=oturi[i]-100;
            maisuu[i]++;
        }
        
        
        for(;;){  //50???
            if(oturi[i]<50){
                break;
            }
            oturi[i]=oturi[i]-50;
            maisuu[i]++;
        }
        
        
        for(;;){  //10???
            if(oturi[i]<10){
                break;
            }
            oturi[i]=oturi[i]-10;
            maisuu[i]++;
        }
        
        
        for(;;){  //5???
            if(oturi[i]<5){
                break;
            }
            oturi[i]=oturi[i]-5;
            maisuu[i]++;
        }
        
        
        for(;;){  //1???
            if(oturi[i]<1){
                break;
            }
            oturi[i]=oturi[i]-1;
            maisuu[i]++;
        }
        
    }
    
    
    
    for(int i=0;i<data;i++){
        cout << maisuu[i] << endl;
    }
    
    
    return 0;
}

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

int main()
{
  int n;
  cin >>  n;
  float a[n],s=0;
  rep(i,n){
    cin >> a[i];
	s+=1/a[i];
}
 
 cout << 1/s;

return 0;
}

Measured memory_bytes: 256