akhauriyash/Code-Regression huggingface dataset:
#include <cmath>
#include <string>
#include <vector>
#include <iomanip>
#include <iostream>
#include <algorithm>
#include <functional>
#pragma warning(disable : 4996)
using namespace std;
int n, a[100009];
int main() {
	scanf("%d", &n);
	for (int i = 0; i < n; i++) scanf("%d", &a[i]);
	sort(a, a + n);
	int ret = 0; long long sum = 0;
	for (int i = 1; i < n; i++) {
		sum += a[i - 1];
		if (sum * 2 < a[i]) ret = i;
	}
	printf("%d\n", n - ret);
	return 0;
}

Measured memory_bytes: 640
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		int S=sc.nextInt(),W=sc.nextInt();
		if (S<=W) {
			System.out.println("unsafe");
		}else {
			System.out.println("safe");
		}

	}

}


Measured memory_bytes: 35724
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define pll pair<ll,ll>
#define x first
#define y second
#define mod 1e9+7
#define f(i,a,b) for(ll i=a;i<b;i++)
#define rof(i,a,b) for(ll i=a;i>b;i--)

ll power_mod(ll x,ll n,ll m) // x^n %mod // O(Log Power n)
{ll ans=1;
while(n!=0)
{
    if(n&1==1)
    {
        ans=(ans%m * x%m)%m;
    }
    x=(x%m * x%m)%m;
    n=n>>1;
}
    return ans;
}
ll lcm(ll a, ll b){
    return a / __gcd(a, b) * b;
}
//memset can initialize to 0 or -1 ONLY
// memset(a,0,sizeof(a[0][0])*n*n); //2D array
//memset(a, 0, sizeof(a));  //1D array
//memset(str, 't', sizeof(str)); // string
void solve()
{
ll n,p;cin>>n>>p;
string s;cin>>s;


if(p==2||p==5)
{
	ll ans=0;
if(p==2)
{
f(i,0,n)
{
	if((s[i]-'0')%2==0)
		ans+=i+1;
}}
else
{
	f(i,0,n)
{
	if((s[i]-'0')%5==0)
		ans+=i+1;
}

}

cout<<ans;
	return;

}
unordered_map<ll,ll> m;

m[0]++; ll a=0; n=s.length()-1;
f(i,0,s.length())
{
a= a%p + (((s[i]-'0')%p)*power_mod(10,n,p))%p;
a=a%p;
m[a]++;
n--;
}

ll ans=0;
for(auto i=m.begin();i!=m.end();i++)
{
	ans+= ((i->second)*(i->second -1))/2;
}

cout<<ans;

}


int main()
{

ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    ll t=1;
   // cin>>t;
    while(t--)
    {
    
    solve();
    
    }

}

Measured memory_bytes: 916
#include<iostream>
#include <string>
#include <stdio.h>
#define rb(a,b,c) for(int a=b;a<=c;++a)
#define rl(a,b,c) for(int a=b;a>=c;--a)
#define niv vector<int>
#define LL long long
#define IT iterator
#define PB(a) push_back(a)
#define II(a,b) make_pair(a,b)
#define FIR first
#define SEC second
#define FREO freopen("check.out","w",stdout)
#define rep(a,b) for(int a=0;a<b;++a)
#define KEEP while(1)
#define SRAND mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define random(a) rng()%a
using namespace std;
const int INF=0x3f3f3f3f;
typedef pair<int,int> mp;
typedef pair<mp,mp> superpair;
int  n;
int res[505][505];
void dfs(int start,int to,int index){
	if(to-start+1<=1) return;
	for(int i=start;i<to;i++)
		for(int j=i+1;j<=to;j++) {res[i][j]=index;
		}
	int mid=(start+to)>>1;
	dfs(start,mid,index+1),dfs(mid+1,to,index+1);
}
int main(){
	cin>>n;
	dfs(1,n,1);
 
	for(int i=1;i<n;i++)
        for(int j=i+1;j<=n;j++)
	cout<<res[i][j]<<" ";
}


Measured memory_bytes: 1536
import Data.Char
import Data.List
import qualified Data.ByteString.Char8 as B
import qualified Data.Map as M
main=print.solve.map(unfoldr$B.readInt.B.dropWhile isSpace).B.lines=<<B.getContents
solve([n,c]:stcs)=M.foldr(+)0.foldl f M.empty.sort$map(\[s,t,c]->(t,s,c))stcs
f m(t,s,c)=M.insertWith(+)(t,c)1$case M.lookup(s,c)m of
  Just _ -> g(s,c)m
  Nothing -> case M.lookupLT(s,0)m of
    Just(k,v) -> g k m
    Nothing -> m
g k m=M.update(\i->if i>1 then Just(i-1) else Nothing)k m

Measured memory_bytes: 32436
#include <bits/stdc++.h>
using namespace std;
int dis[100005];
vector<int>v[100005];
int n, m;
int dfs(int x){
	if(dis[x] != -1)return dis[x];
	int ret = 0;
	for(int i = 0; i < v[x].size(); i++){
		ret = max(ret, dfs(v[x][i]) + 1);
	}
	return dis[x] = ret;
}
int main(){
	cin >> n >> m;
	for(int i = 0; i <= n; i++)dis[i] = -1;
	for(int i = 0; i < m; i++){
		int x, y;
		cin >> x >> y;
		v[x].push_back(y);
	}
	int ans = 0;
	for(int i = 1; i <= n; i++){
		ans = max(ans, dfs(i));
	}
	cout << ans;
}

Measured memory_bytes: 8192
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int n, id[2*100000+10];
bool visited[2*100000+10];
void initSets() {
    for (int i = 1; i <= n; i++) id[i]=i;
}
int find(int x) {
    if (x == id[x]) 
        return x;
    return id[x] = find(id[x]);
}
void unionSets(int x, int y) {
    x = find(x);
    y = find(y);
    if (id[x]!=id[y]) {
        id[y]=x;
    }
}
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);

    int m; cin >> n >> m;
    initSets();
    while (m--) {
        int x,y; cin >> x >> y;
        visited[x]=true;
        visited[y]=true;
        if (find(x) != find(y)) {
            unionSets(x,y);
        }
    }
    map<int,int> s;
    for (int i = 1; i <= n; i++) {
        find(i);
        s[id[i]]++;
    }
    int mSz = 0;
    for (auto it : s) {
        mSz = max(it.second, mSz);
    }
    cout << mSz << endl;

    return 0;
}


Measured memory_bytes: 13776
#include<iostream>
#include<math.h>

#define ll long long

using namespace std;

ll dp[2001][2001]={};

int main(){
  int N;
  cin >> N;
  ll a[N];
  int index[N];
  for(int i=0;i<N;i++){
    cin >> a[i];
    index[i]=i;
  }

  /* sort with index*/

  for(int i=0;i<N;i++){
    for(int j=0; j<N-i-1;j++){
      if(a[j]<a[j+1]){
        swap(a[j],a[j+1]);
        swap(index[j],index[j+1]);
      }
    }
  }
/*
  for(int i=0;i<N;i++)
    cout << a[i] << " ";
  cout <<endl;

  for(int i=0;i<N;i++)
    cout << index[i] << " ";
  cout <<endl;
*/

  //ll dp[N+1][N+1] = {};
  for(int i=1;i<N+1;i++){
    for(int j=0; j<i+1;j++){
      if(j==0)
        dp[i-j][j] = dp[i-j-1][j] + a[i-1]*abs(index[i-1]-i+j+1);
      else if(i==j)
        dp[i-j][j] = dp[i-j][j-1] + a[i-1]*abs(N-index[i-1]-j);
      else
        dp[i-j][j] = max(dp[i-j-1][j] + a[i-1]*abs(index[i-1]-i+j+1), dp[i-j][j-1] + a[i-1]*abs(N-index[i-1]-j));
    }
  }

  ll max=0;
  for(int i=0;i<N+1;i++)
    if(dp[N-i][i] > max) max = dp[N-i][i];


  cout << max << endl;
/*
  for(int i=0;i<N+1;i++){
    for(int j=0; j<N-i+1;j++){
      cout << dp[i][j] << "\t";
      }
    cout << endl;
  }
*/
  return 0;
}

Measured memory_bytes: 26156
import sys

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

s = ns()
for i in range(3):
    if s[i] == s[i+1]:
        print("Bad")
        sys.exit(0)
print("Good")


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

#define x first
#define y second
#define ndl '\n'
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define up_b upper_bound
#define low_b lower_bound
#define sz(x) (int)x.size()
#define bit __builtin_popcount
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()

using namespace std;
using namespace __gnu_pbds;

template<typename T> using indexed_set = tree <T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

typedef long long ll;
typedef long double ld;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef pair<int, ll> pil;
typedef pair<ll, int> pli;
typedef pair<int, ull> piu;
typedef vector<vector<int>> matrix;

const ll INF = 1e18 + 123;
const ld EPS = 1e-9;
const int inf = 1e9 + 123;
const int MOD = 1e9 + 7;
const int N = 5e5 + 123;
const int M = 1e6 + 123;
const double pi = acos(-1.0);
const int dx[] = {0, 0, 1, -1};
const int dy[] = {1, -1, 0, 0};

int a[M];

void solve(){
    int k, n;
    cin >> k >> n;
    for (int i = 1; i <= n; i++) cin >> a[i];
    int mx = 0;
    for (int i = 1; i < n; i++){
        mx = max(mx, a[i+1] - a[i]);
    }
    cout << min(k-mx, a[n]-a[1]);
}

int main(){
    #ifdef KAZAKH
        freopen("input.txt", "r", stdin);
    #endif
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int t = 1;
    //cin >> t;
    for (int i = 1; i <= t; i++){
        //cout << "case #" << i << ": ";
        solve();
    }
    return 0;
}


Measured memory_bytes: 1024
import java.util.Scanner;

class Main{
	public static void main(String[] args) {
		try(Scanner sc = new Scanner(System.in)){
			Dice dice = new Dice(sc.nextLine().split(" "));
			int num = sc.nextInt();
			for(int i=0;i<num;i++) {
				dice.toTop(sc.nextInt());
				dice.toFront(sc.nextInt());
				System.out.println(dice.showN(2));
			}
		}
	}
	static class Dice{

		private int[] face;

		public Dice(int[] face) {
			this.face = face;
		}
		public Dice(String[] face) {
			this.face = new int[6];
			for(int i=0;i<this.face.length;i++) {
				this.face[i] = Integer.parseInt(face[i]);
			}
		}

		//東西南北EWSN+右左RLでさいころを回転

		public void rotate(char to){
			int buf;
			switch(to) {
			case 'E':
				buf = this.face[0];
				this.face[0] = this.face[3];
				this.face[3] = this.face[5];
				this.face[5] = this.face[2];
				this.face[2] = buf;
				break;
			case 'W':
				buf = this.face[0];
				this.face[0] = this.face[2];
				this.face[2] = this.face[5];
				this.face[5] = this.face[3];
				this.face[3] = buf;
				break;
			case 'S':
				buf = this.face[0];
				this.face[0] = this.face[4];
				this.face[4] = this.face[5];
				this.face[5] = this.face[1];
				this.face[1] = buf;
				break;
			case 'N':
				buf = this.face[0];
				this.face[0] = this.face[1];
				this.face[1] = this.face[5];
				this.face[5] = this.face[4];
				this.face[4] = buf;
				break;
			case 'R':
				buf = this.face[1];
				this.face[1] = this.face[2];
				this.face[2] = this.face[4];
				this.face[4] = this.face[3];
				this.face[3] = buf;
				break;
			case 'L':
				buf = this.face[1];
				this.face[1] = this.face[3];
				this.face[3] = this.face[5];
				this.face[5] = this.face[2];
				this.face[2] = buf;
				break;
			}
		}


		//指定した数字を上面に持ってきます
		public void toTop(int num) {
			if(this.showTop()==num) return;
			int i;
			for(i=0;i<4;i++) {
				this.rotate('N');
				if(this.showTop() == num) {
					return;
				}
			}
			for(i=0;i<4;i++) {
				this.rotate('W');
				if(this.showTop() == num) {
					return;
				}
			}
		}

		 //指定した数字を手前に持ってきます
		 // 水平方向のみ可
		public void toFront(int num) {
			if(this.showN(1)==num) return;
			for(int i=0;i<4;i++) {
				this.rotate('R');
				if(this.showN(1) == num) {
					return;
				}
			}
		}
		public int showTop() {
			return this.face[0];
		}
		public int showN(int n) {
			return this.face[n];
		}
	}
}


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

using namespace std;
typedef long long ll;
typedef pair <int, int> pp;
#define MAXN 51
#define MAXM 1005
#define MAXP 25
#define INF 2000000000
#define A first
#define B second
#define MP make_pair
#define PB push_back

const ll MOD = 1e9+7;
int N;
set <pp> adj[MAXN];
int a[MAXN], b[MAXN];
vector <int> good;
ll p2[MAXN];
int vis[MAXN];
bool can(int u, int v, int cant)
{
	memset(vis, 0, sizeof(vis));
	queue <int> q;
	q.push(u);
	while(!q.empty()) {
		int c = q.front();
		q.pop();
		if(vis[c]) continue;
		vis[c] = 1;
		if(c == v) return true;
		for(auto e : adj[c]) {
			if(vis[e.A]) continue;
			if(e.B == cant) continue;
			q.push(e.A);
			
		}
	}
	return false;
}
bool chk(int x)
{
	for(int i=0; i<N; i++) if(!can(a[i], b[i], x)) return true;
	return false;
}
int main(void)
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cin >> N;
	for(int i=0; i<N; i++) cin >> a[i];
	for(int i=0; i<N; i++) cin >> b[i];
	for(int i=0; i<N; i++) {
		if(b[i] * 2 >= a[i]) if(b[i] != a[i]) {
			cout << -1 << endl;
			return 0;
		}
	}
	for(int i=1; i<=50; i++) good.PB(i);
	for(int i=1; i<=50; i++) for(auto v : good) if(v <= i) adj[i].insert({i%v, v});
	p2[0] = 1LL;
	for(int i=1; i<=50; i++) p2[i] = p2[i-1] * 2LL;
	ll ans = 0;
	for(int i=good.size()-1; i>=0; i--) {
		if(chk(good[i])) ans += p2[good[i]];
		else {
			for(int j=1; j<=50; j++) for(auto e : adj[j]) if(e.B == good[i]) adj[j].erase(e);
		}
	}
	cout << ans << endl;			
	
	
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1e9 + 7;
const int inf = 1e9;
const ll INF = 1e18;
const double pi = 3.14159265358979323846;

int isPrime(int i){
	bool ok=1;
	if(i==1) return 0;
	else if(i==2||i==3) return 1;
	else{
		for(int k=2;k*k<=i;k++) if(i%k==0) ok=0;
		if(ok) return 1;
		else return 0; 
	}
}

int main(){
	int q;cin>>q;int s[100005]={0};
	for(int i=1;i<=100000;i++){
		if(i%2==1&&isPrime(i)&&isPrime((i+1)/2)) s[i+1]=s[i]+1;
		else s[i+1]=s[i];
	}
	int r,l;
	while(q){
		cin>>l>>r;
		int ans=s[r+1]-s[l];
		cout<<ans<<endl;
		q--;
	}
}

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

int main() {
  int S,W;
  cin >> S >> W;
  if(S>W){
    cout << "safe" << endl;
  }
  else{
    cout << "unsafe" << endl;
  }
}

Measured memory_bytes: 3620
import java.awt.geom.Point2D;
import java.util.Scanner;
public class Main {
	Scanner in = new Scanner(System.in);
	public static void main(String[] args) {
		new Main();
	}
	public Main() {
		int n = in.nextInt();
		for(int i=0;i<n;i++)new AOJ0143().doIt();
		
	}
	class AOJ0143{
		void doIt(){
			Point2D ps[] = new Point2D[3];
			for(int i=0;i<3;i++)ps[i] = new Point2D.Double(in.nextInt(),in.nextInt());;
			Point2D a = new Point2D.Double(in.nextInt(),in.nextInt());
			Point2D b = new Point2D.Double(in.nextInt(),in.nextInt());
			int c = contains(ps, a);
			int d = contains(ps, b);
//			System.out.println(c+" "+d);
			if(c==d)System.out.println("NG");
			else System.out.println("OK");
		}
		Point2D sub(Point2D p1,Point2D p2){
			return new Point2D.Double(p1.getX()-p2.getX(),p1.getY()-p2.getY());
		}
		double cross(Point2D p1,Point2D p2){
			return p1.getX()*p2.getY()-p1.getY()*p2.getX();
		}
		double dot(Point2D p1,Point2D p2){
			return p1.getX()*p2.getX()+p1.getY()*p2.getY();
		}
		private int contains(Point2D[] plist,Point2D p) {
			boolean isin = false;
			int n = plist.length;
			for(int i=0;i<n;i++){
				Point2D a = sub(plist[i], p);
				Point2D b = sub(plist[(i+1) % n], p);
				if(a.getY() > b.getY()){
					Point2D temp = (Point2D) a.clone();
					a = b;
					b = temp;
				}
				if(a.getY() <= 0 && 0 < b.getY()){
					if(cross(a,b) < 0) isin = ! isin;
				}
				if(cross(a,b) == 0 && dot(a, b) <= 0) return 0;
			}
			return isin ? 1 : -1;
		}
	}
}

Measured memory_bytes: 62528
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.*;
import java.util.stream.Collectors;
 
public class Main {
    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter out = new PrintWriter(System.out);
        String[] line = br.readLine().split(" ");
        int X = Integer.parseInt(line[1]);
        int D = 1;

        List<Integer> list = Arrays.stream(br.readLine().split(" "))
            .map(Integer::parseInt)
            .map(x -> Math.abs(x - X))
            .distinct()
            .sorted()
            .collect(Collectors.toList());
            
        int smallest = list.get(0);
        int listSize = list.size();

        PARENT:
        for (int i = smallest; i > 1; i--) {
            for (int j = 0; j < listSize; j++) {
                if (list.get(j) % i != 0) {
                    break;
                }
                if (j == listSize - 1) {
                    D = i;
                    break PARENT;
                }
            }
        }
        out.println(D);
        out.close();
    }
}

Measured memory_bytes: 48268
n,m= map(int,input().split())
r = 0
p = 0
li = [0]*n
for i in range(m):
    a,b = input().split()
    if li[int(a)-1]==-1:
        pass
    elif b=='WA':
        li[int(a)-1]+=1
    elif b=='AC':
        r += 1
        p += li[int(a)-1]
        li[int(a)-1]=-1
print(r,p)


Measured memory_bytes: 3828
#include<bits/stdc++.h>
using namespace std;
int n,ans;
bool b;
string s;
int main()
{
	cin>>s;
	for(int i=0;i<s.size();i++)
	{
		bool t;
		b=!b;
		if(s[i]=='g') t=1;
		else if(s[i]=='p') t=0;
		if(t==b) continue;
		else if(t==1&&b==0) ans++;
		else ans--;
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 512
import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop, std.bitmanip;

void main() {
    auto N = readln.chomp.to!int;
    auto A = readln.split.map!(to!long).array;

    auto tmp = 0;
    foreach (i; 0..N) {
        tmp += i % 2 ? -A[i] : A[i];
    }

    auto ans = new long[](N);
    ans[0] = tmp;

    foreach (i; 1..N) {
        ans[i] = (A[i-1] - ans[i-1] / 2) * 2;
    }

    ans.map!(to!string).join(" ").writeln;
}

Measured memory_bytes: 9496
from fractions import gcd
N = int(input())
A = list(map(int, input().split()))

param = [[0, 0, 0]]
while True:
    if len(param) <= 0:
        break
    addr, Li, Lv = param.pop()
    if addr == 0:
        if Li == N-1:
            Rv = 0
            M = Lv
            continue            
        param += [[addr+1, Li, Lv], [0, Li+1, gcd(Lv, A[Li])]]
        continue 
    elif addr == 1:
        Rv = gcd(A[Li+1], Rv)
        M = max(M, gcd(Lv, Rv))
        continue

print(M)


Measured memory_bytes: 22756
#include<iostream>
#include<stdio.h>
using namespace std;
int main()
{
    int counter=1,x;
    while(scanf("%d",&x)==1)
    {
        if(x==0)
            break;
        else
        cout<<"Case "<<counter<<": "<<x<<endl;
        counter++;
    }
    return 0;
}


Measured memory_bytes: 3120
#include<stdio.h>
#include<string.h>
int main(){
char s[10010];
int i,a,ans=0,ans1=0;
while(fgets(s,10005,stdin)!=NULL){
a=strlen(s);
for(i=0;i<a-2;i++){
if(s[i]=='J' && s[i+1]=='O' && s[i+2]=='I'){
ans++;
}
if(s[i]=='I' && s[i+1]=='O' && s[i+2]=='I'){
ans1++;
}
}
printf("%d\n%d\n",ans,ans1);
ans=0,ans1=0;
}
return 0;
}


Measured memory_bytes: 2076
package main

import "fmt"

func main() {
	var w, h, n int
	fmt.Scan(&w, &h, &n)
	xs := make([]int, n)
	ys := make([]int, n)
	as := make([]int, n)
	for i := range xs {
		fmt.Scan(&xs[i])
		fmt.Scan(&ys[i])
		fmt.Scan(&as[i])
	}

	xl := 0
	yl := 0
	xu := w
	yu := h
	for i, a := range as {
		x := xs[i]
		y := ys[i]
		switch a {
		case 1:
			if xl < x {
				xl = x
			}
		case 2:
			if xu > x {
				xu = x
			}
		case 3:
			if yl < y {
				yl = y
			}
		case 4:
			if yu > y {
				yu = y
			}
		}
	}
	if xl >= xu || yl >= yu {
		fmt.Println(0)
	} else {
		fmt.Println((xu - xl) * (yu - yl))
	}
}


Measured memory_bytes: 512
#include<algorithm>
#include<vector>
#include<iostream>
using namespace std;
int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    for(int i = 0;i < n;i++){
        cin >> a[i];
    }
    sort(a.begin(), a.end());
    cout << a[n-1]-a[0] << "\n";
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main() {
	int N[5];
	int i;
	for(i = 0; i <5; i++) {
		cin>>N[i];
	}
	for(i = 0; i < 5; i++) {
		if(N[i] == 0) {
			cout<<(i+1);
		}
	}
	return 0;
}


Measured memory_bytes: 3632
using System;

namespace AtCoder.ABC118
{
    class A
    {
        public static void Solve()
        {
            int a, b;
            string[] str = Console.ReadLine().Split(' ');
            a = int.Parse(str[0]);
            b = int.Parse(str[1]);
            if ((b % a) == 0) { Console.WriteLine("{0}", a + b); }
            else { Console.WriteLine("{0}", b - a); }
        }
    }
}


namespace AtCoder
{
    class Program
    {
        public static void Main(string[] args)
        {
            ABC118.A.Solve();
        }
    }
}

Measured memory_bytes: 13140
from copy import deepcopy
import math
import string
import collections
from collections import Counter
from collections import deque
from decimal import Decimal
import sys
import fractions
from operator import itemgetter
import itertools
import copy


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


def nCr(n, r):
    return math.factorial(n)//(math.factorial(n-r)*math.factorial(r))


def has_duplicates2(seq):
    seen = []
    for item in seq:
        if not(item in seen):
            seen.append(item)
    return len(seq) != len(seen)


def divisor(n):
    divisor = []
    for i in range(1, n+1):
        if n % i == 0:
            divisor.append(i)
    return divisor


def gcd(a, b):
    while(b != 0):
        a, b = b, a % b
    return a


# coordinates
dx = [-1, -1, -1, 0, 0, 1, 1, 1]
dy = [-1, 0, 1, -1, 1, -1, 0, 1]
a = int(input())
ans = a+a**2+a**3
print(ans)


Measured memory_bytes: 72876
#include <stdio.h>
int main(){
  int a, b;
  scanf("%d %d", &a, &b);
  if(a < b){
    printf("a < b\n");
  }else if(a > b){
    printf("a > b\n");
  }else{
    printf("a == b\n");
  }
  return 0;
}

Measured memory_bytes: 1756
#include <stdio.h>

int main(){
  int n,i,f=0;
  char s[105];
  scanf("%d",&n);
  if(n%2==0){
    scanf("%s",&s);
    f=1;
    for(i=0;i<n/2;i++){
      if(s[i]!=s[i+n/2]){
        f=0;
        break;
      }
    }
  }
  if(f){
    printf("Yes");
  }else{
    printf("No");
  }
  return(0);
}

Measured memory_bytes: 128
//by yjz
#include<bits/stdc++.h>
using namespace std;
#define FF first
#define SS second
#define PB push_back
#define MP make_pair
typedef long long ll;
const int Imx=2147483647;
const int mod=1000000007;
const ll Lbig=2e18;
//My own input/output stream
#define geti(x) x=getnum()
#define getii(x,y) geti(x),geti(y)
#define getiii(x,y,z) getii(x,y),geti(z)
#define puti(x) putnum(x),putsp()
#define putii(x,y) puti(x),putnum(y),putsp()
#define putiii(x,y,z) putii(x,y),putnum(z),putsp()
#define putsi(x) putnum(x),putendl()
#define putsii(x,y) puti(x),putnum(y),putendl()
#define putsiii(x,y,z) putii(x,y),putnum(z),putendl()
inline ll getnum()
{
	register ll r=0;register bool ng=0;register char c;c=getchar();
	while(c!='-'&&(c<'0'||c>'9'))c=getchar();
	if(c=='-')ng=1,c=getchar();
	while(c>='0'&&c<='9')r=r*10+c-'0',c=getchar();
	if(ng)r=-r;return r;
}
template <class T> inline void putnum(T x)
{
	if(x<0)putchar('-'),x=-x;
	register short a[20]={},sz=0;
	while(x>0)a[sz++]=x%10,x/=10;
	if(sz==0)putchar('0');
	for(int i=sz-1;i>=0;i--)putchar('0'+a[i]);
}
inline void putsp(){putchar(' ');}
inline void putendl(){putchar('\n');}
inline char mygetchar(){register char c=getchar();while(c==' '||c=='\n')c=getchar();return c;}
int n,a[100111];
ll A,B;
bool check(ll x)
{
	ll cnt=0;
//	cout<<"check:"<<x<<endl;
	for(int i=1;i<=n;i++)
	{
		ll c=max(0ll,a[i]-B*x);
		if(c==0)continue;
		cnt+=(c-1)/(A-B)+1;
	}
	return cnt<=x;
}
int main()
{
	geti(n);
	getii(A,B);
	for(int i=1;i<=n;i++)geti(a[i]);
	int l=0,r=1000000000;
	while(l<=r)
	{
		int m=l+r>>1;
		if(check(m))r=m-1;
		else l=m+1;
	}
	cout<<l<<endl;
	return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
#define endl '\n'
#define ll long long
#define pi pair<int, int>
#define f first
#define s second

const int mod = 1000000007;
const int mxn = 10000001;
int n, m;
ll iv[mxn], f[mxn], rf[mxn];

void init(){
	iv[1] = f[0] = f[1] = rf[0] = rf[1] = 1;
	for(int i = 2; i < mxn; i++){
		iv[i] = mod - mod / i * iv[mod % i] % mod;
		f[i] = i * f[i - 1] % mod;
		rf[i] = iv[i] * rf[i - 1] % mod;
	}
}

ll C(int x, int y){
	return f[x] * rf[y] % mod * rf[x - y] % mod;
}

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	init();
	
	cin >> n >> m;
	
	ll ret = 0;
	for(int i = 1; i <= m; i++)
	for(int j = 0; j <= i; j++){
		(ret += (j & 1 ? mod - 1 : 1) * C(i, j) % mod * (i - j) % mod *
			iv[i - j + n - m] % mod * f[n - j - (i < m)]) %= mod;
	}

	cout << ret << endl;

	return 0;
}

Measured memory_bytes: 237964
#include <bits/stdc++.h>
#define ll long long
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a,b) for(int i=a;i<=b;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define vi vector<int>
#define vv vector<vi>
#define pb push_back
#define pi pair<int,int>
#define vp vector<pair<int,int> >
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define INF 100000000000
#define eps 1e-7
#define mod 998244353
#define itn int
#define int ll
using namespace std;

int N; string S;
int ruiseki_white[2*100000 + 10];

signed main(void) {
    cin>>N>>S;
    int black=0;
    for(int i=0; i<S.size(); i++) {
        if (i==0) {
            ruiseki_white[i]=(S[0]=='.')?1:0;
        } else {
            ruiseki_white[i]=ruiseki_white[i-1]+((S[i]=='.')?1:0);
        }
        if (S[i]=='#') black++;
    }
//    for(int i=0; i<N; i++) {
//        cerr<<ruiseki_white[i]<<"\t";
//    }
//    cerr<<endl;
    int ans=INF;
    Rep(i,0,S.size()) {
        int black_left = i+1-ruiseki_white[i];
        int white_right = (ruiseki_white[N-1] - ruiseki_white[i]);
//        cerr<<black_left<<","<<white_right<<endl;
        ans = min(ans, black_left+white_right);
    }
    cout<<min(ans, min(black, ruiseki_white[N-1]))<<endl;
    return 0;
}

Measured memory_bytes: 2688
#include<string>
#include<vector>
std::string minus2(long long n, int i = 40, bool padding = false) {
  static std::vector<long long> power = {1}, sum = {0, 1};
  while(int(power.size()) <= i) power.emplace_back(power.back() << 1);
  while(int(sum.size()) < i) sum.emplace_back(sum[sum.size() - 2] + power[sum.size() - 1]);
  if(i < 0) return "";
  if(n == 0) return (padding ? std::string(i + 1, '0') : "0");
  if(i & 1) {
    if(n + power[i] <= sum[i]) return "1" + minus2(n + power[i], i - 1, true);
    return (padding ? "0" : "") + minus2(n, i - 1, padding);
  } else {
    if(-sum[i] <= n - power[i]) return "1" + minus2(n - power[i], i - 1, true);
    return (padding ? "0" : "") + minus2(n, i - 1, padding);
  }
}

#include<bits/stdc++.h>
using namespace std;

int main() {
  int N;
  cin >> N;
  cout << minus2(N) << endl;
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0;i < n; ++i)
using namespace std;
const int INF = 2147483647;
using ll = long long;

int main() {
    int n;
    cin >> n;
    vector<int> x(n);
    for (int i=0;i<n;i++){
        cin >> x.at(i);
    }
    vector<int> b = x;
    sort(b.begin(),b.end());
    int l,r;
    l = b.at(n/2-1);
    r = b.at(n/2);
    vector<int> ans(n);
    for (int i=0;i<n;i++){
        if(x.at(i)<=l) ans.at(i) = r;
        else ans.at(i) = l;
    }
    for (int i=0;i<n;i++){
        cout << ans.at(i) << endl;
    }
    return 0;
}



Measured memory_bytes: 4480
#include<iostream>
#include<vector>
#include<map>
#include<string>
#include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std;
#define rep(i,x,n) for(int i=x;i<n;i++)
using ll=long long;

int n,m;
vector<bool> I(200000,false);

ll gcl(ll x,ll y){
    if(x<y) swap(x,y);
    while(y>0){
        ll t=x%y;
        x=y;
        y=t;
    }
    return x;
}

int main(){
    cin>>n>>m;
    bool ok=false;
    rep(i,0,m){
        int a,b;
        cin>>a>>b;
        if(a==1){
            if(!I[b-1]) I[b-1]=true;
            else{
                ok=true;
                break;
            }
        }
        if(b==n){
            if(!I[a-1]) I[a-1]=true;
            else{
                ok=true;
                break;
            }
        }
    }
    if(ok) cout<<"POSSIBLE"<<endl;
    else cout<<"IMPOSSIBLE"<<endl;
}

Measured memory_bytes: 256
// I am Nothing, You Are Nothing!
// Krishna is Everything ...
// Jai Shree Krishna

#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N = 3e3 + 5, mod = 1e9 + 7;

double prob[N], dp[N][N];
int n;

double solve(int i, int heads) {
	if (heads < 1)
		return 1;
	if (i < 1)
		return 0;

	if (dp[i][heads] > -0.9)
		return dp[i][heads];

	return dp[i][heads] = solve(i - 1, heads) * (1 - prob[i]) + solve(i - 1, heads - 1) * prob[i];
}

int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> prob[i];
	}
	int heads = (n + 1) / 2;

	memset(dp, -1, sizeof dp);

	cout << fixed << setprecision(10) << solve(n, heads);

	return 0;
}


Measured memory_bytes: 74556
#include<stdio.h>
#include<string.h>
int n,x,f[30],i,j,k,r;
int dp[1000005],p[1000005]={1,1};

int main()
{
	for(i=0;i<1000005;i++)
		if(!p[i])
			for(j=2;i*j<1000005;j++)
				p[i*j]=1;
	for(;scanf("%d%d",&n,&x),n;)
	{
		for(i=0;i<n;i++)
			scanf("%d",&f[i]);
		memset(dp,-1,sizeof(dp));
		dp[0]=0;
		for(i=0;i<n;i++)
			for(j=0;j<=x;j++)
			{
				if(dp[j]>=0)
					dp[j]=x/f[i];
				else if(j<f[i]||dp[j-f[i]]<=0)
					dp[j]=-1;
				else
					dp[j]=dp[j-f[i]]-1;
			}
		for(i=x,r=-1;i>0;i--)
			if(!p[i]&&dp[i]>=0)
			{
				r=i;
				break;
			}
		if(r==-1)
			puts("NA");
		else
			printf("%d\n",r);
	}
	return 0;
}

Measured memory_bytes: 8432
n = int(input())
S = []
H = []
C = []
D = []

for _ in range(n):
    raw = input().split(" ")
    if str(raw[0]) == "S":
        S.append(int(raw[1]))
    elif str(raw[0]) == "H":
        H.append(int(raw[1]))
    elif str(raw[0]) == "C":
        C.append(int(raw[1]))
    elif str(raw[0]) == "D":
        D.append(int(raw[1]))

M = [S, H, C, D]
M_name = ["S", "H", "C", "D"]

for m, m_name in zip(M, M_name):
    for i in range(1,14):
        if i not in m:
            print ("%s %d"%(m_name, i))    

Measured memory_bytes: 7704
#include <cstdio>
#include <string>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <iterator>
#include <cassert>
#include <numeric>
#include <functional>
#include <cassert>
//#include <numeric>
#pragma warning(disable:4996) 
 
typedef long long ll;
typedef unsigned long long ull;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF  9223300000000000000
#define LINF2 1223300000000000000
#define INF 2140000000
const long long MOD = 1000000007;
//const long long MOD = 998244353;

using namespace std;

char str0[200005];
char str1[200005];

void solve()
{
    scanf("%s%s", str0, str1);
    int n = strlen(str0);
    vector<int> v(26, -1);
    int i;
    for (i = 0; i < n; i++) {
        int tmp0 = str0[i] - 'a';
        int tmp1 = str1[i] - 'a';

        if (v[tmp0] >= 0) {
            if (v[tmp0] != tmp1) {
                printf("No\n"); return;
            }
        }
        else {
            v[tmp0] = tmp1;
        }
    }
    set<int> z;
    for (i = 0; i < 26; i++) {
        if (v[i] >= 0) {
            if (!z.insert(v[i]).second) {
                printf("No\n"); return;
            }
        }
    }
    printf("Yes\n");
    return;
}

int main(int argc, char* argv[])
{
#if 1
    solve();
#else
    int T;
    scanf("%d", &T);
    int t;
    for(t=0; t<T; t++) {
        //printf("Case #%d: ", t+1);
        solve();
    }
#endif
    return 0;
}



Measured memory_bytes: 640
#include<map>
#include<iostream>
#include<deque>
#include<algorithm>
#include<string>
#include<cctype>
#include<iomanip>
#include<vector>
#include<queue>
 
using namespace std;
#define REP(i,b,e) for(int i=(int)b;i<(int)e;i++)
#define rep0(i,n) REP(i,0,n)
#define rep1(i,n) REP(i,1,n+1)
 
#define shosu setprecision(10)
 
typedef long long ll;
ll longinf=1ll<<60;
int inf=1<<29;

ll MOD=1e9+7;

int main(){
    string s;
    cin>>s;
    int n=s.size();
    ll dp[n+1][13];
    rep0(i,n+1)rep0(j,13) dp[i][j]=0;
    dp[0][0]=1;
    rep0(i,n){
        rep0(j,13){
            if(s[i]=='?'){
                rep0(k,10) dp[i+1][(j*10+k)%13] = (dp[i+1][(j*10+k)%13] + dp[i][j]) % MOD;
            }
            else{
                dp[i+1][(j*10+s[i]+4)%13] = (dp[i+1][(j*10+s[i]+4)%13] + dp[i][j]) % MOD;
            }
        }
    }
    /* rep0(i,n+1){
        rep0(j,13){
            cout<<dp[i][j]<<" ";
        }
        cout<<endl;
    }*/
    cout<<dp[n][5]<<endl;
    return 0;
}


Measured memory_bytes: 10624
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int a = scan.nextInt();
		int b = scan.nextInt();
		int c = scan.nextInt();
		scan.close();
		int count = 0;
		if (1 <= a && a <= 10000 && 1 <= b && b <= 10000 && 1 <= c && c <= 10000) {
			if (a <= b) {
				for (int i = a; i <= b; i++) {
					if (c % i == 0) {
						count++;
					}

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

	}

}

Measured memory_bytes: 26072
n = int(input())
c = input()

lft = 0
rht = 0

ans = 0

flag = False

for i in range(n):
    #print(i,rht)
    if flag == True:
        break
    if n-1-rht <= i:
        break
    if c[i] == 'W':
        for j in range(n-i):
            if n-1-j-rht == i:
                flag = True
                break
            if c[n-1-j-rht] == 'R':
                ans += 1
                rht += j+1
                break

print(ans)

Measured memory_bytes: 9488
#1 
mylist = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
k = int(input())
print(mylist[k-1])

Measured memory_bytes: 3060
S = str(input())
if S == "SUN":
    print(7)
elif S == "MON":
    print(6)
elif S == "TUE":
    print(5)
elif S == "WED":
    print(4)
elif S == "THU":
    print(3)
elif S == "FRI":
    print(2)
else :
    print(1)


Measured memory_bytes: 2940
import java.util.*;
public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        // 整数の入力                                                                                                  
        int N = sc.nextInt();
	int a[] = new int[N];
	int i,j;
	int res=0;
        for(i=0;i<N;i++){
	    a[i] = sc.nextInt();
	}
	Arrays.sort(a);
        j=1;
        for(i=0;i<N-1;i++){
	    if(a[i]==a[i+1]) j++;
	    else{
                if(j%2 == 1) res++;
                j=1;
            }
        }
	if(j%2==1) res++;
        // 出力                                                                                                        
        System.out.println(res);
    }
}




Measured memory_bytes: 50880
#include <bits/stdc++.h>
using namespace std;
//FILE *fi=freopen("1.txt","r",stdin);
int n,m,k;
struct p{
    int x,y;
};
p a[3001];
const long long mod=1e9+7;
long long d[3001];
long long giaithua[200002];
long long ndgiaithua[200002];
long long power(long long x,long long n)
{
    if(n==0)
        return 1;
    if(n%2==0)
        return power(x*x%mod,n/2);
    else
        return x*power(x*x%mod,n/2)%mod;
}
long long nck(int n,int k)
{
    if(n<0||k<0||k>n)
        return 0;
    return giaithua[n]*ndgiaithua[k]%mod*ndgiaithua[n-k]%mod;
}
long long cal(int a,int b)
{
    return nck(a+b,a);
}
bool cmp(p a,p b)
{
    return a.x+a.y<b.x+b.y;
}
int main()
{
    scanf("%d%d%d",&n,&m,&k);
    for(int i=1;i<=k;i++)
    {
        scanf("%d%d",&a[i].x,&a[i].y);
    }
    giaithua[0]=1;
    for(int i=1;i<=n+m;i++)
    {
        giaithua[i]=giaithua[i-1]*i%mod;
    }
    ndgiaithua[n+m]=power(giaithua[n+m],mod-2);
    for(int i=n+m-1;i>=0;i--)
    {
        ndgiaithua[i]=ndgiaithua[i+1]*(i+1) % mod;
    }
    sort(a+1,a+k+1,cmp);
    a[k+1]={n,m};
    for(int i=1;i<=k+1;i++)
    {
        long long tmp=cal(a[i].x-1,a[i].y-1);
        for(int j=1;j<i;j++)
        {
            if(a[j].x<=a[i].x&&a[j].y<=a[i].y)
                tmp=(tmp-(d[j]*cal(a[i].x-a[j].x,a[i].y-a[j].y)%mod)+mod*mod)%mod;
        }
        d[i]=tmp;
    }
    cout<<d[k+1];
    return 0;
}


Measured memory_bytes: 3456
#include<stdio.h>
int main()
{
    int n,b;
    scanf("%d",&n);
    int a[n];
    for(b=0;b<n;b++)
    scanf("%d",&a[b]);
    for(b=n-1;b>0;b--)
    {
     printf("%d ",a[b]);
     }
     printf("%d\n",a[0]);
     return 0;
}



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

int main() {
  ll h1,h2,m1,m2,k;
  cin >> h1 >> m1 >> h2 >> m2 >> k;
  
  ll ji=h2-h1;
  ll hun=m2-m1;
  ji*=60;
  
  cout << ji+hun-k << endl;
  
  
  
  
  
}


Measured memory_bytes: 3592
n, m = map(int, input().split())
broken = [int(input()) for _ in range(m)]

ways = [1] * (n+1)
for i in broken:
  ways[i] = 0
  
keep = 1
for i in range(1, n+1):
  if ways[i]:
    if keep == 2:
      ways[i] = ways[i-1] + ways[i-2]
    elif keep == 1:
      ways[i] = ways[i-1]
      keep += 1
    else:
      ways[i] = ways[i-2]
      keep += 1
  else:
    keep = 0
      
print(ways[-1] % 1000000007)

Measured memory_bytes: 470392
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
typedef long long ll;
typedef pair<int, int> pii;
const int INF = 1e9;
const int MOD = 1000000007;
const double PI = acos(-1);
int dx[4] = {0,1,0,-1};
int dy[4] = {1,0,-1,0};

void solve() {
  ll q, h, s, d;
  cin >> q >> h >> s >> d;
  ll n;
  cin >> n;
  ll t = min(q*4,h*2);
  t = min(t, s);
  if (t * 2 <= d) cout << t * n << endl;
  else {
    if (n%2 == 0) cout << n / 2 * d << endl;
    else cout << n / 2 * d + t << endl;
  }
}

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

Measured memory_bytes: 3684
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=2e3+7;
const int mod=1e9+7;
vector<int> g[maxn];
int n,x,y,a[maxn],b[maxn],vis[maxn];
int main()
{
   scanf("%d%d%d",&n,&x,&y);
   for(int i=1;i<=n-1;i++)
   {
  g[i].push_back(i+1);
  g[i+1].push_back(i);
   }
   g[x].push_back(y);
   g[y].push_back(x);
  for(int i=1;i<=n;i++)
  {
   queue<int> p;
   p.push(i);
   memset(b,0,sizeof(b));
   memset(vis,0,sizeof(vis));
   b[i]=0,vis[i]=1;
  while(!p.empty())	
  {
  int m=p.front();
  p.pop();
  for(int j=0;j<g[m].size();j++)
  {
  	int d=g[m][j];
  if(!vis[d])
  {
  b[d]=b[m]+1;
  a[b[d]]++;
  p.push(d);
  vis[d]=1;
  }
	  }	
	
}	
  	while(!p.empty()) p.pop();
  	
  }
 for(int i=1;i<=n-1;i++)
 	printf("%d\n",a[i]/2);
	
	
	
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll dp[102][100004];
ll prefix[102][100004];
ll m=1e9+7;
int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
	ll n,k;
	cin>>n>>k;
	ll a[n+1];
	for (ll i=1;i<=n;i++)
		cin>>a[i];
	memset(dp,0,sizeof(dp));
	dp[0][0]=1;
	memset(prefix,0,sizeof(prefix));
	for (ll i=1;i<=k;i++)
		dp[0][i]=0;
	for (ll i=1;i<=n;i++)
	{
		for (ll r=0;r<=k;r++)
			{
				if (r==0)
					prefix[i-1][r]=(dp[i-1][0])%m;
				else
					prefix[i-1][r]=(prefix[i-1][r-1]%m+dp[i-1][r]%m)%m;
			}
		for (ll j=0;j<=k;j++)
		{
			if (j-a[i]-1>=0)
			dp[i][j]=(dp[i][j]%m+(prefix[i-1][j]%m-prefix[i-1][j-a[i]-1]%m+m))%m;
			else
				dp[i][j]=(dp[i][j]%m+prefix[i-1][j]%m)%m;

			//prefix[i][j]=prefix[i][j-1]+dp[i][j];
		}
	}
	cout<<dp[n][k]%m;
}

Measured memory_bytes: 159616
#include <algorithm>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <map>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <list>
#define INF 10000000000ll
#define MOD 1000000007ll
#define EPS 1e-10
#define REP(i,m) for(long long i=0; i<m; i++)
#define FOR(i,n,m) for(long long i=n; i<m; i++)
#define DUMP(a) for(long long dump=0; dump<(ll)a.size(); dump++) { cout<<a[dump]; if(dump!=(ll)a.size()-1) cout<<" "; else cout<<endl; }
#define ALL(v) v.begin(),v.end()
#define pb push_back
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
typedef long double ld;
using namespace std;

int main(){
	int n;
	cin >> n;
	int a[n];
	REP(i, n) cin >> a[i];
	vector<int> b;
	int tmp = n-1;
	int i = 0;
	while(tmp >= 0){
		b.pb(a[tmp]);
		tmp -= 2;
		i++;
	}
	tmp = -1 - tmp;
	while(i != n){
		b.pb(a[tmp]);
		tmp += 2;
		i++;
	}
	DUMP(b);
	return 0;
}


Measured memory_bytes: 3828
import Data.List.Split
import Data.List

main = do
    a <- getContents
    let aa = head $ splitOn "\n" a
    putStr $ getStr2 aa



getStr2 :: String -> String
getStr2 [] = []
getStr2 (s:[]) = [s]
getStr2 (s:ss:[]) = [s]
getStr2 (s:ss:sx) = (s : getStr2 sx)


Measured memory_bytes: 1020
n = int(input())
dp = [[0,0,0]]*n
a,b,c = map(int, input().split())
dp[0]=[a,b,c]

for i in range(1,n):
    abc = list(map(int, input().split()))
    #dp[i][0]=abc[0]+max(dp[i-1][1], dp[i-1][2])
    #dp[i][1]=abc[1]+max(dp[i-1][2], dp[i-1][0])
    #dp[i][2]=abc[2]+max(dp[i-1][0], dp[i-1][1])
    dp0= abc[0]+max(dp[i-1][1], dp[i-1][2])
    dp1= abc[1]+max(dp[i-1][2], dp[i-1][0])
    dp2= abc[2]+max(dp[i-1][0], dp[i-1][1])
    dp[i]=[dp0,dp1,dp2]
ans = dp[-1]
print(max(ans)) 


Measured memory_bytes: 58072
using System;

namespace ABC101_a
{
    class Program
    {
        static void Main(string[] args)
        {
            double a = 0;
            double b = 0;
            double c = 0;
            
            string array = Console.ReadLine();
            for (int i = 0; i < array.Length; i++)
            {
                char ch = array[i];
                if(ch == '+')
                {
                    a++;
                }
            }
            
            for(int i = 0; i < array.Length; i++)
            {
                char ch = array[i];
                if(ch == '-')
                {
                    b++;
                    
                }
            }
             c = 0 + a - b;
            Console.WriteLine(c);
            
        }
    }
}


Measured memory_bytes: 11220
#include <bits/stdc++.h>
 #define f first
 #define s second
 #define endl '\n'
 #define LL long long
 #define pb push_back
 #define sz(a) (int)a.size()
 #define all(a) a.begin(),a.end()
 #define rall(a) a.rbegin(),a.rend()
 #define debug(x) cerr << #x << " is " << x << endl;
 using namespace std;
 int const MAXN = 2e6 + 9;
int n, k;
 int main(){
    ios_base::sync_with_stdio (0),cin.tie(0);
    cin >> n >> k;
    LL ans = 0;
    for (int i = 1; i <= n; i++){
         if (i  + k  - 1<= n) ans++;
    }
     cout << ans;
 }


Measured memory_bytes: 256
import sys
input=sys.stdin.readline
import math

N,A,B = map(int,input().split())
H = [int(input()) for _ in range(N)]

def check(T):
    t = 0
    for h in H:
        h -= B*T
        if h > 0:
            t += math.ceil(h/(A-B))
    return T >= t

def main():
    lb = ub = 0
    for h in H:
        ub += h//B + 1

    while ub - lb > 1:
        mid = (lb + ub)//2
        if check(mid):
            ub = mid
        else:
            lb = mid

    print(ub)

if __name__ == '__main__':
    main()


Measured memory_bytes: 7068
#include<iostream>
#include<cstdio>
#include<cmath>

using namespace std;

int main() {
    int a, b, C;
    double S, L, h, r, c;
    cin >> a >> b >> C;
    r = C*M_PI/180;
    S = a*b*sin(r)/2;
    c = sqrt(a*a + b*b -2*a*b*cos(r));
    L = a + b + c;
    h = S*2/a;
    printf("%.5lf\n",S);
    printf("%.5lf\n",L);
    printf("%.5lf\n",h);
    return 0;
}


Measured memory_bytes: 3504
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main() {
	int n;
	cin >> n;
	vector<int> num(n);
	int min_num = 100000001;
	bool i_iscd;
	for (int i = 0; i < n; i++)
	{
		cin >> num[i];
		min_num = min(min_num, num[i]);
	}
	for (int i = 1; i <= min_num; i++)
	{
		i_iscd = true;
		for (int j = 0; j < n; j++)
		{
			i_iscd &= (num[j] % i == 0);
			if (i_iscd == false) break;
		}
		if (i_iscd == true) cout << i << endl;
	}
	return 0;
}


Measured memory_bytes: 3132
# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: print('Yes' if b else 'No')
YESNO=lambda b: print('YES' if b else 'NO')

def main():
    Q=int(input())
    for _ in range(Q):
        S=tuple(input())
        T=tuple(input())
        dp=[0]*(len(T)+1)
        for s in S:
            pre=dp[:]
            for i,t in enumerate(T):
                if s==t:
                    dp[i+1]=max(dp[i+1],pre[i]+1)
                elif dp[i+1]<dp[i]:
                    dp[i+1]=dp[i]
        print(dp[-1])

if __name__ == '__main__':
    main()



Measured memory_bytes: 5648
#include <bits/stdc++.h>
using namespace std;
 
int main(){
    string s;
    int k;
    cin >> s >> k;
 
    int n = s.length();
    vector<string> substrings;
    for(int i=1; i<=5; i++){
        for(int j=0; j<=n-i; j++){
            substrings.push_back(s.substr(j,i));
        }
    }
    sort(substrings.begin(), substrings.end());
    
    int count = 0;
    for(int i=0; i<n*(n+1)/2; i++){
        if(i >= 1 && substrings[i] == substrings[i-1]) continue;
 
        count += 1;
        if(count == k){
            cout << substrings[i] << endl;
            return 0;
        }
    }
    return 0;
}

Measured memory_bytes: 1660
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>

#define int long long
 
#define rep(i, n) for (int i = 0; i < (n); i++)
#define itrep(i, a) for (auto i = (a).begin(); i != (a).end(); i++)
#define REP(i, a, n) for (int i = (a); i <= (n); i++)
#define all(a) (a).begin(), (a).end()
 
using namespace std;

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

	vector<int> A(N), B(N), C(N);
	rep(i, N) cin >> A[i];
	rep(i, N) cin >> B[i];
	rep(i, N) cin >> C[i];

	A.push_back(0);
	C.push_back(10000000000);
	sort(all(A));
	sort(all(B));
	sort(all(C));
	reverse(all(C));

	int ret = 0;
	rep(i, N) {
		int base = B[i];

		int tmp = 1;
		{
			int low = 0;
			int high = N + 1;
			int mid = (low + high) / 2;
			while (high - low > 1) {
				if (A[mid] >= base) {
					high = mid;
				} else {
					low = mid;
				}
				mid = (low + high) / 2;
			}
			tmp *= mid;
		}
		{
			int low = 0;
			int high = N + 1;
			int mid = (low + high) / 2;
			while (high - low > 1) {
				if (C[mid] <= base) {
					high = mid;
				} else {
					low = mid;
				}
				mid = (low + high) / 2;
			}
			tmp *= mid;
		}
		ret += tmp;
	}

	cout << ret << endl;

	return 0;
}


Measured memory_bytes: 3456
ABCD = input()
A = int(ABCD[0])
B = int(ABCD[1])
C = int(ABCD[2])
D = int(ABCD[3])
if (A==B and B==C and C==D and D==A) or (A==B and B==C and C==A) or (B==C and C==D and D==B) :
  print("Yes")
else:
  print("No")

Measured memory_bytes: 9204
#include<stdio.h>

int main()
{
	int n,i,j,k;
	int b,f,r,v;
	int house[4*3*10];
	for(i=0;i<4*3*10;i++)house[i]=0;
	
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		scanf("%d %d %d %d",&b,&f,&r,&v);
		house[30*(b-1)+10*(f-1)+(r-1)]+=v;
	}
	for(i=0;i<4;i++)
	{
		for(j=0;j<3;j++)
		{
			for(k=0;k<10;k++)
			{
				printf(" %d",house[30*i+10*j+k]);
			}
			printf("\n");
		}
		if(i!=3)printf("####################\n");
	}
	return 0;
}

Measured memory_bytes: 612
import sys
sys.setrecursionlimit(10 ** 9)
input = sys.stdin.readline
from itertools import permutations,  combinations, accumulate
from functools import *
from collections import deque, defaultdict, Counter
from heapq import heapify, heappop, heappush, heappushpop

INF = float('inf')
NIL = - 1


N = int(input())
P = list(map(int, input().split()))
counter = 0
for i in range(1, len(P) - 1):
    if (P[i - 1] < P[i] < P[i + 1]) or (P[i - 1] > P[i] > P[i + 1]):
        counter += 1

print(counter)


Measured memory_bytes: 3568
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef pair<int,int> P;
 
const int INF = 1e9;
const int mod = 1e9+7;
const double EPS = 1e-10;
const double PI = acos(-1.0);

int main()
{
    double t,x;
    cin >> t >> x;
    cout << t/x << endl;
    return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env ruby
# coding: utf-8

class Integer
  def bit_length
    Math.log2(self < 0 ? -self : self+1).ceil
  end
end

class PrioQ

  def initialize(base = 0)
    @table = []
    @base = base
    @size = 0
  end

  attr_reader :size

  def add(prio, val)
    @size += 1
    bitlen = prio.bit_length
    if bitlen < 2
      if @table[bitlen] == nil
        @table[bitlen] = []
      end
      @table[bitlen] << val
    else
      base = 2 ** (bitlen - 1)
      if @table[bitlen] == nil
        @table[bitlen] = PrioQ.new(base)
      end
      @table[bitlen].add(prio - base, val)
    end
  end

  def to_s
    s = @table.map(&:to_s).join(' ')
    s[0,1] = ""
    s
  end

  def pop
    if @size > 0
      @size -= 1
    end
    while @table.size > 0
      if @table.last
        x = @table.last.pop
        return x if x
      end
      @table.pop
    end
    nil
  end
end

n, m = ARGF.gets.split.map(&:to_i)
tbl = Array.new(m+1) { [] }
pq = PrioQ.new

n.times do
  a, b = ARGF.gets.split.map(&:to_i)
  tbl[a] << [a, b] if a <= m
end

# 残り日数の少ないものから順に

sum = (m+1).times.reduce(0) do |s, day|
  tbl[day].each {|job| pq.add(job[1], job[1])}
  job = pq.pop
  s + (job || 0)
end

puts sum


Measured memory_bytes: 23316