akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

long int a[3005],dp[3005][3005][2];
/*
long int brute(int i,int j,int k)
{
	//cout<<i<<" "<<j<<" "<<k<<endl;
	if(i == j)
	{
		if(k == 0)
		return a[i];
		return -a[i];
	}
	if(dp[i][j][k] == -1)
	{
		if(k == 0)
		dp[i][j][k] = max(brute(i+1,j,1)+a[i],brute(i,j-1,1)+a[j]);
		else 	
		dp[i][j][k] = min(brute(i+1,j,0)-a[i],brute(i,j-1,0)-a[j]);
	}
	return dp[i][j][k];
}*/
int main()
{
	int n;
	scanf("%d",&n);
	for(int i=0;i<n;++i)
	scanf("%ld",a+i);
	for(int i=n-1;i>=0;--i)
	{
		for(int j=i;j<n;++j)
		{
			if(i == j)
			{
				dp[i][j][0] = a[i];
				dp[i][j][1] = -a[i];
			}
			else 
			{
				//0
				dp[i][j][0] = max(dp[i+1][j][1]+a[i],dp[i][j-1][1]+a[j]);
				dp[i][j][1] = min(dp[i+1][j][0]-a[i],dp[i][j-1][0]-a[j]);
			}
		}
	}
	//memset(dp,-1,sizeof dp);
	printf("%ld\n",dp[0][n-1][0]);
	return 0;
}


Measured memory_bytes: 139648
import java.util.Scanner;

class Main {
	public static void main(String[] args) {
    	Scanner sc = new Scanner(System.in);
      
      	int ab = sc.nextInt();
      	int bc = sc.nextInt();
      	int ca = sc.nextInt();
      
      	System.out.println(ab * bc / 2);
    }
}

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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcount

#define INF INT_MAX/3
#define MAX_V 5005

struct edge{ int to,cap,rev; bool flag; };
vector<edge> G[MAX_V];
int level[MAX_V];
int iter[MAX_V];

void add_edge(int from,int to,int cap){
  G[from].push_back((edge){to,cap,(int)G[to].size(),cap==1});
  G[to].push_back((edge){from,0,(int)G[from].size()-1,false});
}

void bfs(int s){
  memset(level,-1,sizeof(level));
  queue<int> que;
  level[s]=0;
  que.push(s);
  while(!que.empty()){
    int v=que.front(); que.pop();
    for(int i=0;i<G[v].size();i++){
      edge &e=G[v][i];
      if(e.cap>0&&level[e.to]<0){
        level[e.to]=level[v]+1;
        que.push(e.to);
      }
    }
  }
}

int dfs(int v,int t,int f){
  if(v==t)return f;
  for(int &i=iter[v];i<G[v].size();i++){
    edge &e=G[v][i];
    if(e.cap>0&&level[v]<level[e.to]){
      int d=dfs(e.to,t,min(f,e.cap));
      if(d>0){
        e.cap-=d;
        G[e.to][e.rev].cap+=d;
        return d;
      }
    }
  }
  return 0;
}

int max_flow(int s,int t){
  int flow=0;
  while(1){
    bfs(s);
    if(level[t]<0)return flow;
    memset(iter,0,sizeof(iter));
    int f;
    while((f=dfs(s,t,INF))>0){
      flow+=f;
    }
  }
}

int V,E;
bool vis[MAX_V];

void vble(int v){
  vis[v]=true;
  for(edge e : G[v]){
    if(e.cap>0&&!vis[e.to]){
      vble(e.to);
    }
  }
}

int main(){
	cin>>V>>E;
  rep(i,E){
    int s,t,c;
    cin>>s>>t>>c;
    add_edge(s,t,c);
    add_edge(t,s,c);
  }
  int mf=max_flow(V-1,0);
  bool heru=false;
  rep(v,V){
    memset(vis,0,sizeof(vis));
    vble(v);
    for(edge e : G[v]){
      if(e.flag&&!vis[e.to])heru=true;
    }
  }
  if(mf-heru>10000)cout<<-1<<endl;
  else cout<<mf-heru<<endl;
	return 0;
}

Measured memory_bytes: 3872
import java.util.Scanner;
public class Main {
	public static void main(String[] args) throws java.io.IOException {
		Scanner scan = new Scanner(System.in);
		int s[] = new int[10];
		int sam = 0;
		for(int i = 0; i<10 ;i++){
			s[i] = scan.nextInt();
			sam += s[i];
		}
		System.out.println(sam);
	}
}

Measured memory_bytes: 17168
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
from bisect import bisect_left,bisect_right 
import sys,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()))

mod = 998244353
class Combination:
    """
    comb = Combination(1000000)
    print(comb(5, 3))  # 10
    """
    def __init__(self, n_max, mod=998244353):
        self.mod = mod
        self.modinv = self.make_modinv_list(n_max)
        self.fac, self.facinv = self.make_factorial_list(n_max)

    def __call__(self, n, r):
        return self.fac[n] * self.facinv[r] % self.mod * self.facinv[n-r] % self.mod

    def make_factorial_list(self, n):
        # 階乗のリストと階乗のmod逆元のリストを返す O(n)
        # self.make_modinv_list()が先に実行されている必要がある
        fac = [1]
        facinv = [1]
        for i in range(1, n+1):
            fac.append(fac[i-1] * i % self.mod)
            facinv.append(facinv[i-1] * self.modinv[i] % self.mod)
        return fac, facinv

    def make_modinv_list(self, n):
        # 0からnまでのmod逆元のリストを返す O(n)
        modinv = [0] * (n+1)
        modinv[1] = 1
        for i in range(2, n+1):
            modinv[i] = self.mod - self.mod//i * modinv[self.mod%i] % self.mod
        return modinv

n,m,k = inpl()
conb = Combination(300010)
res = 0
for i in range(k+1):
    x = n - i - 1
    res += conb(n-1,x) * m * pow(m-1,x,mod)
    res %= mod
print(res)

Measured memory_bytes: 118812
//bottom up solution
//same S.C but no recc overhead
#include <bits/stdc++.h>
using namespace std;

vector<vector<int >> memo;

int main(){
	string s,t;
	string ans;
	cin>>s>>t;
	memo.assign(s.size()+1, vector<int>(t.size()+1, 0));
	for(int i=1; i<=s.size(); i++){
		for(int j=1; j<=t.size(); j++){
			if(s[i-1] == t[j-1]){
				memo[i][j] = memo[i-1][j-1] + 1;
			}
			else{
				memo[i][j] = std::max(memo[i-1][j], memo[i][j-1]);
			}
		}
	}
	for(int i=s.size(), j=t.size(); i>0 and j>0 ;){
		if(s[i-1] == t[j-1]){
			ans = s[i-1] + ans;
			i--;
			j--;
		}
		else{
			if(memo[i-1][j] > memo[i][j-1]){
				i--;
			}
			else{
				j--;
			}
		}
	}
	cout<<ans<<"\n";
	// for(auto v : memo){
	// 	for(auto u : v){
	// 		cout<<u<<" ";
	// 	}
	// 	cout<<"\n";
	// }
	return 0;
}

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


int main()
{
	int X;
	cin>>X;
	int t=360;
	while(t%X!=0)
	{
		t+=360;
	}
	cout<<t/X<<endl;
	return 0;
}


Measured memory_bytes: 3544
#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,sqrt,factorial,hypot,log #log2ないｙｐ
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from fractions import gcd
from random import randint
def ceil(a,b): return (a+b-1)//b
inf=float('inf')
mod = 10**9+7
def pprint(*A): 
    for a in A:     print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    N,M,X=MI()
    A=[[] for _ in range(N)]
    C=[0]*N
    for i in range(N):
        c,*a = MI()
        A[i] = a
        C[i] = c

    def f(mask):
        B = [0]*M
        cost = 0

        for i in range(N):
            if mask >> i & 1:
                cost += C[i]
                for j,a in enumerate(A[i]):
                    B[j] += a

        ok = True
        for b in B:
            if(b<X):
                ok = False
        return ok,cost

    ans = inf
    for mask in range(1<<N):
        ok,cost = f(mask)
        if(ok):
            ans = min(ans, cost)
    if(ans == inf):
        print(-1)
    else:
        print(ans)
if __name__ == '__main__':
    main()

Measured memory_bytes: 79212
#include<bits/stdc++.h>
using namespace std;
long long dp[200010],ar[20010];
int main()
{
	long long j,n,i,k;
	scanf("%lld%lld",&n,&k);
	for(i=0;i<n;i++)
		scanf("%lld",ar+i);
	dp[n-1]=0;
	dp[n-2]=abs(ar[n-1]-ar[n-2]);
	for(i=n-3;i>=0;i--)
	{
		dp[i]=dp[i+1]+abs(ar[i]-ar[i+1]);
		for(j=1;j<=k;j++)
        {
            if((i+j) >=n )
              break;
			dp[i]=min(dp[i+j]+abs(ar[i]-ar[i+j]),dp[i]);
        }
	}
	printf("%lld\n",dp[0]);
}


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

using namespace std;

#define all(x) (x).begin(), (x).end()

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long long ll;

const int N = 5200;
const int MOD = 1e9 + 7;

int dp[N][2];
int dp1[N][2];

int main()
{
    int n, a, b;
    cin >> n >> a >> b;
    if (a > b) swap(a, b);
    dp1[0][0] = 1;
    for (int i = 1; i < b; i++)
    {
        for (int j = a; j <= i; j++)
        {
            dp1[i][0] = (dp1[i][0] + dp1[i - j][1]) % MOD;
        }
        dp1[i][1] = (dp1[i - 1][0] + dp1[i - 1][1]) % MOD;
    }

    dp[0][1] = 1;
    for (int i = 1; i <= n; i++)
    {
        for (int j = 1; j < a && j <= i; j++)
        {
            dp[i][0] = (dp[i][0] + dp[i - j][1]) % MOD;
        }
        for (int j = 1; j < b && j <= i; j++)
        {
            dp[i][1] = (dp[i][1] + 1ll * dp[i - j][0] * dp1[j][1]) % MOD;
        }
        //cout << i << " " << dp[i][0] << " " << dp[i][1] << "\n";
    }
    int ans = 1;
    for (int i = 0; i < n; i++) ans = (ans + ans) % MOD;

    for (int p = 0; p < b; p++)
    {
        for (int s = 0; s < b && s + p < n; s++)
        {
            ans = (ans - 1ll * (dp1[p][1] + dp1[p][0]) * (dp1[s][1] + dp1[s][0]) % MOD * dp[n - p - s][0]) % MOD;
            ans = (ans + MOD) % MOD;
        }
    }

    cout << ans;
}

/*

*/


Measured memory_bytes: 3684
n = int(input())
li = list(map(int,input().split()))	
if n == 1:
  print("0")
else:
  ans_li =[]
  ans_1 = 0
  for i in range(n-1):
    if li[i] >= li[i+1]:
       ans_1 = ans_1 + 1
    elif li[i]<li[i+1]:
      ans_li.append(ans_1)
      ans_1 = 0
    if i == n-2:
      ans_li.append(ans_1)
  print(max(ans_li))

Measured memory_bytes: 14224
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include<stdio.h>
#include<queue>
const int mod = 1e9 + 7;
const int INF = 1e9;
using namespace std;
typedef long long ll;


int main()
{
    int n,T;
    cin >> n >> T;
    int t[n];
    int dif[n-1];
    int ans = 0;
    for(int i = 0; i < n; i++){
        cin >> t[i];
    }
    for(int i = 0; i < n-1; i++){
        dif[i] = t[i+1] - t[i];
    }
    for(int i = 0; i < n-1; i++){
        ans += min(T,dif[i]);
    }
    cout << ans + T << endl;
}

Measured memory_bytes: 1792
#include <iostream>
#include <vector>
using namespace std;
int N, M;

int dp[1000001];
vector<vector<int> > G;

int rec(int i){
    if(dp[i] != -1) return dp[i];
    int res = 0;
    for(int e = 0; e < G[i].size(); e++){
        res = max(res, rec(G[i][e])+1);
    }
    return dp[i] = res;
}

int main(void){
    cin >> N >> M;
    int x, y;
    G.resize(N);
    for(int i = 0; i < M; i++){
        cin >> x >> y;
        x--, y--;
        G[x].push_back(y);
    }
    
    for(int i = 0; i < N; i++) dp[i]= -1;
    
    int res = 0;
    for(int v = 0; v < N; v++){
        res = max(res, rec(v));
    }
    cout << res << endl;
}


Measured memory_bytes: 8192
#include<bits/stdc++.h>
#include<cmath>
#define SZ(x) ((int)x.size())
#include<vector>
#include<set>
#include<map>
#define ll long long
#define lli long long int
#define REP(i,a,b) for(ll i=a;i<b;i++)
#define pb push_back
#include<string>
#include<cctype>
#include<queue>
#define ii pair<int,int>
#include <sstream>
#define lli long long int
#define pairs pair<int,int>
#define mod 1000000007
const double PI = 3.141592653589793238460;
typedef std::complex<double> Complex;
typedef std::valarray<Complex> CArray;
using namespace std;
ll pows(ll a,ll n,ll m)
{
	ll res=1;
	while(n)
	{
	if(n%2!=0)
	{
		res=(res*a)%m;
		n--;
		}
		else
		{
			a=(a*a)%m;
			n=n/2;
			}	
	}
	return res%m;
}
ll  gcd(ll a,ll b)
{
	if(b==0)
	return a;
	else 
	return gcd(b,a%b);
}
bool isprime(ll n)
{
	if(n==1)
	{
		return false;
	}
	for(ll i=2;i*i<=n;i++)
	{
		if(n%i==0)
		{
			return false;
		}
	}
	return true;
}
bool istrue(string s)
{
	int i=0;
	int j=s.size()-1;
	while(i<j)
	{
	if(s[i]==s[j])
	{
		i++;
		j--;
		}
		else
		{
			return false;
			}	
	}
	return true;
}
ll n,m;
ll dp[1001][1001];
char a[1001][1001];
ll getans(int i,int j)
{
	if(i>=n||j>=m)
	{
		return 0;
	}
	if(i==n-1&&j==m-1)
	{
		return 1;
	}
	if(a[i][j]=='#')
	{
		return 0;
	}
	if(dp[i][j]!=-1)
	{
		return dp[i][j];
	}
	int ans=0;
	ans=(getans(i+1,j))%mod+(getans(i,j+1))%mod;
	return dp[i][j]=ans%mod;
}
int main()
{
ios::sync_with_stdio(false);
	 cin.tie(0);
    cout.tie(0);
memset(dp,-1,sizeof(dp));
cin>>n>>m;
for(int i=0;i<n;i++)
{
	for(int j=0;j<m;j++)
	{
		cin>>a[i][j];
	}
}
cout<<getans(0,0);
}





Measured memory_bytes: 12536
#include <algorithm>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
#include <list>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
//#define cerr if(false) cerr
#ifdef DEBUG
#define show(...) cerr << #__VA_ARGS__ << " = ", debug(__VA_ARGS__);
#else
#define show(...) 42
#endif
using namespace std;
using ll = long long;
using pii = pair<int, int>;
template <typename T, typename S>
ostream& operator<<(ostream& os, pair<T, S> a) {
    os << '(' << a.first << ',' << a.second << ')';
    return os;
}
template <typename T>
ostream& operator<<(ostream& os, vector<T> v) {
    for (auto x : v) os << x << ' ';
    return os;
}
void debug() {
    cerr << '\n';
}
template <typename H, typename... T>
void debug(H a, T... b) {
    cerr << a;
    if (sizeof...(b)) cerr << ", ";
    debug(b...);
}
int main(){
    string s;
    cin >> s;
    if(s[0] == '>')s = '<' + s;
    if(s.back() == '<')s += '>';
    ll ans = 0;
    int id = 0;
    show(s);
    while(id < s.size()){
        ll cnt = 0, cnt2 = 0;
        while(id < s.size() and s[id] == '<'){
            id++;
            cnt++;
        }
        while(id < s.size() and s[id] == '>'){
            id++;
            cnt2++;
        }
        show(cnt,cnt2);
        ans += cnt*(cnt+1)/2+cnt2*(cnt2+1)/2 -min(cnt,cnt2);
    }
    cout << ans << endl;
}


Measured memory_bytes: 1412
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		String t = sc.next();
		sc.nextLine();
		int a = sc.nextInt();
		int b = sc.nextInt();
		sc.nextLine();
		String u = sc.nextLine();
		if(u.equals(s)) {
			a--;
		}
		else {
			b--;
		}
		System.out.print(a+" "+b);
	}
}

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

int main(){
    int N,A,B;
    cin>>N>>A>>B;
    bool ans=false;

for(int i=A;i<=B;i++){
    if(i%N==0){
        cout<<"OK"<<endl;
        ans=true;
        break;
    }
}
if(ans==false){
    cout<<"NG"<<endl;
}
}  

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

#define ll long long
#define sc(n) long long int n; scanf("%d",&n);
#define mod 10000007
#define N 100001
#define MX 1000000001
#define log(n) (int)log2(n)
#define pb(x) push_back(x);
#define T int t, q=0; scanf("%d", &t); while(q++<t)
#define scArr(n) int n; scanf("%d", &n); int a[n]; for(int i=0; i<n; i++) scanf("%d", &a[i]);

int main()
{
    int n;
    scanf("%d", &n);
    int a[n];
    for(int i=0;i<n;i++)
        scanf("%d", &a[i]);
    sort(a, a+n);
    n/=2;
    printf("%d", a[n]-a[n-1]);
}


Measured memory_bytes: 640
import scala.io.StdIn

object Main{
  def main(args: Array[String]): Unit = {

    val input = scala.io.Source.stdin.getLines().toList.map(_.split(" ").map(_.toInt))
    val buildingTable = List.tabulate(4, 3, 10) { (i, j, k) =>
      input.collect {case Array(b, f, r, v) if b - 1 == i && f - 1 == j && r - 1 == k => v}.sum
    }

    for{
      (building, bidx) <- buildingTable.zipWithIndex
      } {
        println(building.map(" " + _.mkString(" ")).mkString("\n"))
        if(bidx != 4 - 1){
          println("####################")
        }
      }
  }
}

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


using namespace std;

#define endl '\n'
#define PB push_back
#define MP make_pair
#define LL long long
#define FOR(i,a,b) for(int i = (a); i <= (b); i++)
#define RE(i,n) FOR(i,1,n)
#define REP(i,n) FOR(i,0,(int)(n)-1)
#define R(i,n) REP(i,n)
#define VI vector<int>
#define PII pair<int,int>
#define LD long double
#define FI first
#define SE second
#define st FI
#define nd SE
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())

typedef long long ll;

bool file=0,rt=1;
clock_t tStart ;
void FAST_IO();
////////////////////////

int main() {

    //FAST_IO();
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cout << setprecision(5);
    cout << fixed;

    int n, q;
    string s;

    cin >> n >> q;
    cin >> s;

    int print[n];
    print[0] = 0;
    for(int i = 1; i < n; i++) {

        if(s[i-1] == 'A' && s[i] == 'C') {

            print[i] = print[i-1] + 1;
        }
        else print[i] = print[i-1];
    }

    while(q--) {

        int l, r;

        cin >> l >> r;



        cout << print[r-1] - print[l-1] << endl;
    }


    return 0;
}

void FAST_IO()
{
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    //cout.tie(NULL);
    //cout.setf(ios::fixed);
    //cout.precision(2);
    if(rt && file){ tStart = clock(); }
    if(file){
    #ifndef _offline
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    }
}




Measured memory_bytes: 1488
import sys
input = sys.stdin.readline
#import math #python 3.5~
import fractions #fractions.gcd() python~3.4
sys.setrecursionlimit(1000000)

def main(): 

    N = int(input())
    A = list(map(int, input().split()))
    sum=0
    minus=0
    for i in range(N):
        if A[i] < 0:
            minus+=1
            A[i]=-A[i]
        sum+=A[i]
        
    if minus%2==0:
        print(sum)
    else:
        print(sum-2*min(A))

if __name__ == "__main__":
    main()
    

Measured memory_bytes: 16400
#include <bits/stdc++.h>
#include <stdio.h>
using namespace std;
int main(){
char a,b;
cin >>a>>b;
if (a=='H'){
    if (b=='H')
        cout<<"H"<<endl;
    else if(b=='D')
        cout<<"D"<<endl;
      
}else if (a=='D'){
    if (b=='D')
        cout<<"H"<<endl;
    else if(b=='H')
        cout<<"D"<<endl;
}

return 0;
}


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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}

int nextInt() { int x; scanf("%d", &x); return x;}

const int MAX_N = 1004;
vector<int> g[MAX_N], h[MAX_N];

int pre[MAX_N];
vector<int> cycle;
int inCycle[MAX_N];

void dfs(int cur, int prev) {
  if (pre[cur] >= 0) {
    pre[cur] = prev + 1;
    int i = cur;
    do {
      cycle.push_back(i);
      i = pre[i] - 1;
    } while (i != cur);
    throw 1;
  }
  pre[cur] = prev + 1;
  for (int nxt : g[cur]) {
    dfs(nxt, cur);
  }
  pre[cur] = -2;
}

int main2() {
  REP(i, MAX_N) g[i].clear();
  REP(i, MAX_N) h[i].clear();

  int N = nextInt();
  int M = nextInt();
  REP(i, M) {
    int a = nextInt() - 1;
    int b = nextInt() - 1;
    g[a].push_back(b);
  }

  for (;;) {
    try {
      cycle.clear();
      CLR(pre, -1);
      REP(i, N) if (pre[i] == -1) {
        dfs(i, -1);
      }
    } catch (int e) {

    }
    if (cycle.empty()) {
      cout << -1 << endl;
      return 0;
    }

    reverse(ALL(cycle));

    CLR(inCycle, -1);
    REP(i, cycle.size()) {
      inCycle[ cycle[i] ] = i;
    }

    vector<int> prune;
    REP(i, cycle.size()) {
      const int x = cycle[i];
      for (int j : g[x]) if (inCycle[j] >= 0) {
        if (j != cycle[(i + 1) % cycle.size()]) {
          // 使用しない辺を見つける
          prune.push_back(x);
          prune.push_back(cycle[(i + 1) % cycle.size()]);
        }
      }
    }

    if (prune.empty()) {
      cout << cycle.size() << endl;
      for (int x : cycle) cout << (x+1) << endl;
      break;
    }

    REP(i, MAX_N) h[i].clear();
    REP(i, cycle.size()) {
      const int x = cycle[i];
      for (int j : g[x]) if (inCycle[j] >= 0) {
        if (prune[0] == x && prune[1] == j) continue;
        h[x].push_back(j);
      }
    }
    REP(i, N) g[i] = h[i];
  }

  return 0;
}

int main() {

#ifdef LOCAL
  for (;!cin.eof();cin>>ws)
#endif
    main2();
  return 0;
}


Measured memory_bytes: 384
N = int(input())
MOD = int(1e+9) +7 
prime = [2]

for i in range(2,1001):
    for j in range(2, i-1):
        if i % j == 0:
            break
    else:
        prime.append(i)

factor = [1] * 1000

for i in range(1, N+1):
    for p in prime:
        if i == 1:
            break
        while i % p == 0:
            i /= p 
            factor[p] += 1

ans = 1
for fact in factor:
    ans *= fact
    ans %= MOD
print(int(ans))



Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <utility>
#include <numeric>
#include <functional>
#include <stdio.h>
#include <math.h>
#include <string>
#include <algorithm>
#include <deque>
#include <queue>
#include <map>

#define rep(i, m, n) for (int (i)(m); (i)<(n); ++(i))
#define repr(i, m, n) for (int (i)(m - 1); (i)>=(n); --(i))
#define repv(i, v) for (unsigned (i)(0); (i)<(v.size()); ++(i))
#define all(v) (v).begin(), (v).end()
#define sortv(v) sort(all(v))
#define sortgi(v) sort(all(v), greater<int>())
#define sortgd(v) sort(all(v), greater<double>())
#define sortgll(v) sort(all(v), greater<ll>())
#define debug(x) cerr << #x << ": " << x << '\n'

using namespace std;
using pii = pair<int, int>;
using pss = pair<string, string>;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vd = vector<double>;
using vvd = vector<vd>;
using vs = vector<string>;
using ll = long long;
using pllll = pair<ll, ll>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvvb = vector<vvb>;
using vpii = vector<pii>;
using pqi = priority_queue<int>;
using pqd = priority_queue<double>;
using pqll = priority_queue<ll>;
using pqvi = priority_queue<vi>;
using pqvll = priority_queue<vll>;

int main() {
	int n;
	cin >> n;
	vs w;
	rep(i, 0, n) {
		string s;
		cin >> s;
		w.push_back(s);
	}
	string s0(w[0]);
	repv(i, w) {
		repv(j, w) {
			if (w[i] == w[j] && i != j) {
				cout << "No" << endl;
				return 0;
			}
		}
	}
	rep(i, 1, n) {
		string s1 = w[i];
		if (s0[s0.size() - 1] != s1[0]) {
			cout << "No" << endl;
			return 0;
		}
		s0 = s1;
	}
	cout << "Yes" << endl;
}


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

#define REP(i, n) for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n) for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define REP_REV(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (int (i) = (int)(n) - 1 ; (i) >= m ; --(i))

#define INF 2e9
#define INF_LL 1LL<<60
#define ll long long
#define MOD 1e9+7

#define print2D(h, w, arr) REP(i, h) { REP(j, w) cout << arr[i][j] << " "; cout << endl; }
#define print_line(vec, n) {for(int i=0;i<(n-1);i++) cout << (vec)[i] << " "; cout << (vec)[(n)-1] << endl;}
template<class T> void print(const T& x){cout << x << endl;}
template<class T, class... A> void print(const T& first, const A&... rest) { cout << first << " "; print(rest...); }
struct PreMain {PreMain(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20);}} premain; 

/* dp[i][j]: i日目に行動jをしたときの幸福度の最大値 */ 
int dp[100001][3];

int main(){
    int n;
    cin >> n;
    vector<int> a(n), b(n), c(n);
    REP(i, n) cin >> a[i] >> b[i] >> c[i];
    dp[0][0] = a[0];
    dp[0][1] = b[0];
    dp[0][2] = c[0];

    REPN(i, 1, n)  {
        dp[i][0] = max(dp[i-1][1]+a[i], dp[i-1][2]+a[i]); 
        dp[i][1] = max(dp[i-1][0]+b[i], dp[i-1][2]+b[i]);
        dp[i][2] = max(dp[i-1][0]+c[i], dp[i-1][1]+c[i]);
    }

    int ans = max(dp[n-1][0], dp[n-1][1]);
    ans = max(ans, dp[n-1][2]);

    cout << ans << endl;

    return 0;
}

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

#define rep(i, n) for(int i = 0; i<(n); i++)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;

const int MOD = 1000000007;

bool cmp(pair<int, int> a, pair<int, int> b) { return a.second < b.second; }

int main() {
    int N, M;
    cin >> N >> M;
    vector<pair<int, int>> A(M);
    rep(i, M) cin >> A[i].first >> A[i].second;
    sort(A.begin(), A.end(), cmp);

    int ans = 0;
    int end_time = 0;
    rep(i, M) {
        if (A[i].first >= end_time) {
            end_time = A[i].second;
            ans++;
        }
    }

    cout << ans << endl;
}

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

int n;
int a[500001];
int ans;

int main(){
  cin>>n;
  for(int i=0;i<n;i++){
    int b;
    cin>>b;
    a[b]++;
  }

  for(int i=0;i<500001;i++){
    if(a[i]!=1&&a[i]!=0)
      ans+=a[i]-1;
  }
  if(ans%2) ans++;

  cout<<n-ans<<endl;

  return 0;
}


Measured memory_bytes: 640
import copy

S = [int(x) for x in input()]
N = len(S)

com = [0] * N
com_01 = copy.deepcopy(com)
com_10 = copy.deepcopy(com)

dif_01 = 0
dif_10 = 0
for n in range(N):
    
    if n % 2 == 0:
        com_10[n] = 1
    else:
        com_01[n] = 1

    dif_01 += abs(S[n] - com_01[n])
    dif_10 += abs(S[n] - com_10[n])

print(min(dif_01, dif_10))

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

struct V{
    vector<int> nexts;

    void add(int n){
        nexts.push_back(n);
    }
};

int main() {
    int N, M;
    cin >> N >> M;
    vector<int> H(N);
    for(int i=0;i<N;i++){
        cin >> H.at(i);
    }
    vector<V> Vs(N, V());
    for(int i=0;i<M;i++){
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        Vs[a].add(b);
        Vs[b].add(a);
    }
    int count = 0;
    for(int i=0;i<N;i++){
        V v = Vs[i];
        bool ok = true;
        for(int n:v.nexts){
            if(H[i] <= H[n]){
                ok = false;
                break;
            }
        }
        if(ok) count++;
    }
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 8800
use std::io::{self, Stdin};
use std::str::{self, FromStr};
use std::error::Error;

const MOD: i64 = 1000000007;
fn exec() {
    let mut sc = Scanner::new();
    let (n, m): (usize, usize) = (sc.ne(), sc.ne());
    let tate: Vec<i64> = (0..n).map(|_| sc.ne()).collect();
    let yoko: Vec<i64> = (0..m).map(|_| sc.ne()).collect();
    let mut tate1 = vec![0i64; n - 1];
    for i in 0..n - 1 {
        let l = i as i64 + 1;
        let r = (n - i - 1) as i64;
        tate1[i] = (l * r) % MOD;
        // println!("{} {} {}", l, r, tate1[i]);
    }
    let mut yoko1 = vec![0i64; m - 1];
    for i in 0..m - 1 {
        let l = i as i64 + 1;
        let r = (m - i - 1) as i64;
        yoko1[i] = (l * r) % MOD;
    }
    let mut tsum = 0i64;
    for i in 0..n - 1 {
        let haba = (tate[i + 1] - tate[i]) % MOD;
        tsum += haba * tate1[i];
        tsum %= MOD;
    }
    // println!("{}", tsum);
    let mut sum = 0i64;
    for i in 0..m - 1 {
        let haba = (yoko[i + 1] - yoko[i]) % MOD;
        sum += (tsum * haba) % MOD * yoko1[i];
        sum %= MOD;
    }
    println!("{}", sum);
}

fn main() {
    const STACK: usize = 16 * 1024 * 1024;
    let _ = std::thread::Builder::new()
        .stack_size(STACK)
        .spawn(|| { exec(); })
        .unwrap()
        .join()
        .unwrap();
}

#[allow(dead_code)]
struct Scanner {
    stdin: Stdin,
    id: usize,
    buf: Vec<u8>,
}

#[allow(dead_code)]
impl Scanner {
    fn new() -> Scanner {
        Scanner {
            stdin: io::stdin(),
            id: 0,
            buf: Vec::new(),
        }
    }
    fn next_line(&mut self) -> Option<String> {
        let mut res = String::new();
        match self.stdin.read_line(&mut res) {
            Ok(0) => None,
            Ok(_) => Some(res),
            Err(why) => panic!("error in read_line: {}", why.description()),
        }
    }
    fn next<T: FromStr>(&mut self) -> Option<T> {
        while self.buf.len() == 0 {
            self.buf = match self.next_line() {
                Some(r) => {
                    self.id = 0;
                    r.trim().as_bytes().to_owned()
                }
                None => return None,
            };
        }
        let l = self.id;
        assert!(self.buf[l] != b' ');
        let n = self.buf.len();
        let mut r = l;
        while r < n && self.buf[r] != b' ' {
            r += 1;
        }
        let res = match str::from_utf8(&self.buf[l..r]).ok().unwrap().parse::<T>() {
            Ok(s) => Some(s),
            Err(_) => {
                panic!("parse error, {:?}",
                       String::from_utf8(self.buf[l..r].to_owned()))
            }
        };
        while r < n && self.buf[r] == b' ' {
            r += 1;
        }
        if r == n {
            self.buf.clear();
        } else {
            self.id = r;
        }
        res
    }
    fn ne<T: FromStr>(&mut self) -> T {
        self.next::<T>().unwrap()
    }
}


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

int main() {
	int n,k=0,l=0;
	cin>>n;
	int a[n],b[8];
	for(int i=0;i<n;i++)cin>>a[i];
	sort(a,a +n);
	for(int i=0;i<8;i++)b[i]=0;
	for(int i=0;i<n;i++){
		if(a[i]<400)b[0]++;
		else if(a[i]<800)b[1]++;
		else if(a[i]<1200)b[2]++;
		else if(a[i]<1600)b[3]++;
		else if(a[i]<2000)b[4]++;
		else if(a[i]<2400)b[5]++;
		else if(a[i]<2800)b[6]++;
		else if(a[i]<3200)b[7]++;
		else{
			k++;
		}
	
	}
	for(int i=0;i<8;i++){
		if(b[i]!=0)l++;
	}
	if(l>0){
	cout<<l<<" "<<l+k<<endl;
	}
	else{
		cout<<1<<" "<<k<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
n = int(input())
xs = [int(c) for c in input().strip().split()]

def try_inc(i):
    while i < n:
        if i+1 == n or xs[i+1] < xs[i]:
            return i+1
        i += 1
    return i

def try_dec(i):
    while i < n:
        if i+1 == n or xs[i+1] > xs[i]:
            return i+1
        i += 1
    return i

i = 0
ans = 0
while i < n:
    i = max(try_inc(i), try_dec(i))
    ans += 1
print(ans)


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

int main() {
  int a, b;
  cin >> a >> b;
  cout << a*b << endl;
  return 0;
}


Measured memory_bytes: 3640
#include <stdio.h>
#include <iostream>
#include <string>
using namespace std;
 
int main(){
    string s;
    int flag = 0;
    string ans[] = {"Sunny", "Cloudy", "Rainy"};
	cin>>s;
    for (int i = 0; i < 3; i++){
        if (ans[i] == s){
            if (i != 2){
                flag = i + 1;
            }else{
                flag = 0;
            }
        }
    }
	cout<<ans[flag]<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
/* typedef */
typedef long long ll;
typedef pair<int, int> pii;
/* constant */
const int INF = 1 << 30;
const ll LINF = 1LL << 50;
const int NIL = -1;
const int MAX = 10000;
const int mod = 1000000007;
const double pi = 3.141592653589;
/* global variables */
/* function */
/* main */
int main(){
    string S;
    cin >> S;
    cout << S.substr(0, 3) << '\n';
}


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

int main () 
{
    int S, s, m, h;
    cin >> S;
    
    h = S / 3600;
    m = (S % 3600) / 60;
    s = (S % 3600) % 60;
    
    cout << h << ":" << m << ":" << s << endl;
    
    return 0;
}


Measured memory_bytes: 3116
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
using namespace std;

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

  int a[3] = {};
  int b[3] = {};

  a[0] = 0;
  b[0] = c[0][0] - a[0];
  b[1] = c[0][1] - a[0];
  b[2] = c[0][2] - a[0];
  a[1] = c[1][0] - b[0];
  a[2] = c[2][0] - b[0];

  if(a[1] + b[1] == c[1][1] && a[1] + b[2] == c[1][2] && a[2] + b[1] == c[2][1] && a[2] + b[2] == c[2][2]){
    cout << "Yes" << "\n";

    /*
    for(int i=0;i<3;i++){
      cout << a[i] << " ";
    }
    cout << "\n";
    for(int i=0;i<3;i++){
      cout << b[i] << " ";
    }
    cout << "\n";
    */

  }else{
    cout << "No" << "\n";
  }


  return 0;
}


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

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

int main() {
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	int N,A,B; cin>>N>>A>>B; cout<<min(A,B)<<" "<<max(0,A+B-N)<<"\n";
	return 0;
}

Measured memory_bytes: 256
/// __Macro's__
#include <bits/stdc++.h>
using namespace std;
#define ll                   long long
#define II                   pair<int,int>
#define III                  pair<int, II>
#define VL                   vector<ll>
#define VI                   vector<int>
#define VII                  vector<II>
#define VIII                 vector<III>
#define VVI                  vector<vector<int>>
#define VVII                 vector<vector<II>>
#define fr                   first
#define sc                   second
#define mkpr                 make_pair
#define PQ                   priority_queue
#define pb                   push_back
#define eb                   emplace_back
#define all(v)               v.begin(), v.end()
#define LINE                 putc('\n', stdout)
#define SPACE                putc(' ' , stdout)
#define TAB                  putc('\t', stdout)
#define fillarr(arr, val)    fill((int*)arr, (int*)arr+(sizeof(arr)/sizeof(int)), val)
#define Log2(x)              (31^__builtin_clz(x))
#define INF                  1000000007 
#define MOD                  1000000007 
#define getint ReadInt()
const char IO_MODE = 0; // in-->00<--out (MSB-->LSB) | 0: Norm, 1: Fast 
inline ll ReadInt(){ll x=0,s=1;char c=getchar();while(c<'0'||c>'9'){if(c=='-')s=-1;c=getchar();}while(c>='0'&&c<='9'){x=x*10+c-'0';
c=getchar();}return s*x;}inline void WriteInt(ll x){char c[20];if(!x){putchar('0');return;}if(x<0)putchar('-'),x=-x;int i=0;while(x>0)
c[++i]=x%10,x/=10;while(i)putchar(c[i--]+48);}template <typename T>inline void out(T x){if(IO_MODE&1)WriteInt(x);else if(typeid(x)==typeid(int))
printf("%i", x);else printf("%lld", (ll)x);}template<typename T, typename... Args>inline void out(T x,Args...args){out(x);SPACE;out(args...);}
template <typename T>inline void in(T &x){if(IO_MODE&2) x=ReadInt();else if(typeid(x)==typeid(int))scanf("%i",&x);else if(typeid(x)==typeid(ll))
scanf("%lld",&x);}template<typename T, typename... Args>inline void in(T &x,Args&...args){in(x);in(args...);}
int aa,bb,cc,dd,ee,ff,gg,hh,ii,jj,kk,mm,nn,oo,pp,qq,rr,ss,tt,uu,vv,ww,xx,yy,zz;
int tc;
///
int n;
int cnt[3];
double Dp[303][303][303];
// int vis[303][303][303];
// double dp(int a, int b, int c)
// {
//   if(!a && !b && !c) return 0;
//   if(vis[a][b][c]++) return memo[a][b][c];
//   int x = n-a-b-c;
//   double r = (double) (n-x) / n;
//   double ret = 1;
//   if(a) ret += (double)a/n * dp(a-1, b, c);
//   if(b) ret += (double)b/n * dp(a+1, b-1, c);
//   if(c) ret += (double)c/n * dp(a, b+1, c-1);
//   ret/=r;
//   return memo[a][b][c]=ret;
// }

int main()
{
  in(n);
  for(int i=0 ; i<n ; i++) cnt[getint-1]++;
  // cout << dp(cnt[0], cnt[1], cnt[2]) << endl;

  for(int k=0 ; k<=n ; k++)
    for(int j=0 ; j<=n ; j++)
      for(int i=0 ; i<=n ; i++)
      {
        if(i) Dp[i][j][k] += (double)i/n * Dp[i-1][j][k];
        if(j) Dp[i][j][k] += (double)j/n * Dp[i+1][j-1][k];
        if(k) Dp[i][j][k] += (double)k/n * Dp[i][j+1][k-1];
        if(i|j|k) Dp[i][j][k]+=1.0;
        if(i|j|k) Dp[i][j][k]/= (double)(i+j+k)/n;
      }
  cout<<fixed<<setprecision(11)<<Dp[cnt[0]][cnt[1]][cnt[2]]<<endl;
  return 0;
}

Measured memory_bytes: 217344
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<set>
#include<map>

#define INF 1000000007
#define LINF 1000000000000000007

using namespace std;

typedef long long Int;
typedef pair<Int, Int> P;

Int gcd(Int x, Int y){
	if(y == 0)
		return x;
	return gcd(y, x % y);
}

Int lcm(Int x, Int y){
	return x * y / gcd(x, y);
}

bool sosuu(int x){
	bool b = 1;
	if(x == 1) b = 0;
	for(int i = 2; i * i <= x; i++){
		if(x % i == 0) {
			b = 0;
			break;
		}
	}
	return b;
}

Int n, h, a[100001], b[100001];
P p[100001];

int main(){
	cin >> n >> h;
	for(int i = 0; i < n; i++){
		cin >> a[i] >> b[i];
	}
	sort(a, a+ n);
	sort(b, b+n);
	Int c = 0, cnt = 1;
	while(h > 0){
		if(b[n-cnt] > a[n-1] && cnt <= n){
			h -= b[n-cnt];
			cnt++;
			c++;
		}
		else{
			c += h / a[n-1] + !(h%a[n-1] == 0);
			h = 0;
		}
	}
	cout << c << endl;
	
	return 0;
}

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

bool flag[8];
int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    int c=0;

    rep(i, n) {
        int t = a[i] / 400;
        flag[t] = true;
        if (t >= 8) c++;
    }

    int cc=0;
    rep(i, 8) if (flag[i]) cc++;

    cout << (cc ? cc : 1) << " " << cc+c << endl;

}


Measured memory_bytes: 256
N = int(input())
As = list(map(int,input().split()))
sum_a = [0]
for i in range(N):
  sum_a.append(As[i]+sum_a[i])
ans = float('inf')
p,q = 0,2
for cut in range(2,N-1):
  while p < cut-1:
    if abs(sum_a[cut]-sum_a[p]*2) >= abs(sum_a[cut]-sum_a[p+1]*2):
      p += 1
    else:
      break
      
  while q < N-1:
    if abs(sum_a[N]-sum_a[q]-(sum_a[q]-sum_a[cut])) >= abs(sum_a[N]-sum_a[q+1]-(sum_a[q+1]-sum_a[cut])):
      q += 1
    else:
      break
      
  ls = [sum_a[N]-sum_a[q],sum_a[q]-sum_a[cut],sum_a[cut]-sum_a[p],sum_a[p]]
  ans = min(ans,max(ls)-min(ls))
print(ans)
  
  
  
 

Measured memory_bytes: 24684
parseInt(x) = parse(Int, x)
parseArray(x::Array{SubString{String}, 1}) = map(parseInt, x)

function main()
  N = readline() |> parseInt

  result=0
  # for i in 1:N
  #   N÷i!=N%i&&continue
  #   result+=i
  # end
  for i in 1:floor(Int, sqrt(N))
    (N-i)%i!=0 && continue
    m = (N-i)÷i
    i>=m && continue
    result+=m
  end
  println(result)
end

main()


Measured memory_bytes: 111520
import math
from itertools import combinations as com


k = int(input())
num = [i for i in range(1, k+1)]
cnt = sum(num)

for a,b in com(num, 2):
    cnt += 6 * math.gcd(a, b)

for a,b,c in com(num, 3):
    cnt += 6*math.gcd(c,math.gcd(a, b))

print(cnt)


Measured memory_bytes: 9180
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> P;
int INF = 1e9+7;
int mod = 1e9+7;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0 , -1};
struct mint {
  int x;
  mint(int x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(int t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }
 
  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}
struct UnionFind {
    vector<int> par, size;
    UnionFind(int x) {
        par.resize(x);
        size.resize(x, 1);
        for(int i = 0; i < x; i++) {
            par[i] = i;
        }
    }
    int find(int x) {
        if (par[x] == x)
            return x;
        return par[x] = find(par[x]);
    }
    bool same(int x, int y) {
        return find(x) == find(y);
    }
    int consize(int x) {
        return size[find(x)];
    }
    void unite(int x, int y) {
        x = find(x);
        y = find(y);
        if (x == y)
            return;
        if (size[x] < size[y]) {
            par[x] = y;
            size[y] += size[x];
        } else {
            par[y] = x;
            size[x] += size[y];
        }
    }
};
signed main() {
    vector<int>ans(3);
    cin >> ans[0] >> ans[1] >> ans[2];
    sort(ans.begin(),ans.end());
    for(int i = 0; i < 3; i++) {
        if(i) cout << " ";
        cout << ans[i];
    }
    cout << endl;
}



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

int main(){
    int n;
    scanf("%d",&n);
    int p[n];
    for(int i=0;i<n;i++) scanf("%d",&p[i]);
    int count=0;
    for(int i=0;i<n-2;i++){
        if((p[i]-p[i+1]>0 && p[i+1]-p[i+2]>0)||(p[i+2]-p[i+1]>0 && p[i+1]-p[i]>0)) count++;
    }
    printf("%d\n",count);
}

Measured memory_bytes: 256
#include <stdio.h>
int a[100010];
char c[100010];
int main(){
    int i,j,k,l,n;
    scanf("%d%s",&n,c+1);
    for(i=0;i<2;++i){
        a[1]=i;
        for(j=0;j<2;++j){
            a[2]=j;
            for(k=0;k<2;++k){
                a[3]=k;
                for(l=3;l<n;++l){
                    if(a[l]){
                        if(c[l]=='o')a[l+1]=a[l-1];
                        else a[l+1]=!a[l-1];
                    }
                    else{
                        if(c[l]=='o')a[l+1]=!a[l-1];
                        else a[l+1]=a[l-1];
                    }
                }
                a[0]=a[n],a[n+1]=a[1];
                for(l=1;l<=n;++l){
                    if(a[l]){
                        if(c[l]=='o'&&a[l-1]!=a[l+1])break;
                        if(c[l]=='x'&&a[l-1]==a[l+1])break;
                    }
                    else{
                        if(c[l]=='o'&&a[l-1]==a[l+1])break;
                        if(c[l]=='x'&&a[l-1]!=a[l+1])break;
                    }
                }
                if(l>n){
                    for(l=1;l<=n;++l)printf(a[l]?"S":"W");
                    return 0;
                }
            }
        }
    }
    puts("-1");
    return 0;
}


Measured memory_bytes: 768
#include<bits/stdc++.h>
//#define ll long long
#define fast ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
using namespace std;
int main()
{
    fast;
    long long k,n,i,j,l,t=0;
    cin>>k>>n;
    long long a[n],b[n];

    for (i=0;i<n;i++)
    {
        cin>>a[i];
    }
    for(i=0;i<n-1;i++)
    {
        b[i]=a[i+1]-a[i];
    }

  if (a[0] ==0) b[n-1]=k-a[n-1];
  else b[n-1]=k-a[n-1]+a[0];
//cout<<b[n-1];
    sort(b,b+n);

    for(l=0;l<n-1;l++)
    {
       // cout<<b[l];
      t+=b[l] ;
    }
    cout<<t;
}


Measured memory_bytes: 3328
#!/usr/bin/env python3
from collections import deque, Counter
from heapq import heappop, heappush
from bisect import bisect_right

def main():
    N = int(input())
    A = list(map(int, input().split()))
    l = Counter(A)
    ans = N - sum(l.values()) + len(l)
    if ans % 2 == 0: ans -= 1
    print(ans)

if __name__ == "__main__":
    main()


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

int main()
{
  int N;
  cin >> N;
  char s[N];
  scanf("%s", s);
  auto cntR=0, cntB=0;
  for (auto i=0; i<N; ++i) {
    if (s[i] == 'R') {
      ++cntR;
    } else {
      ++cntB;
    }
  }
  if (cntR>cntB) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define FORR(i,a,b) for (int i=(a);i>=(b);i--)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define pcnt __builtin_popcount
#define sz(x) (int)(x).size()
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define show(x) cout<<#x<<" = "<<x<<endl;
#define rng(a) (a.begin()),(a.end())
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)

using namespace std;
typedef long long ll;
typedef __int128_t lll;
template <class T> using V = vector<T>;
template <class T> using VV = V<V<T>>;
template<typename T>string join(V<T>&v){stringstream s;FOR(i,0,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename A,size_t N,typename T>void Fill(A (&array)[N],const T&v){fill((T*)array,(T*)(array+N),v);}
lll gcd(lll a,lll b,lll &x,lll &y){if(!b){x=1;y=0;return a;}lll d=gcd(b,a%b,y,x);y-=a/b*x;return d;}
ll gcd(ll a,ll b){lll x=0,y=0;return gcd(a,b,x,y);}
ll modpow(lll a,lll n,ll m){if(!a)return a;lll p=1;for(;n>0;n>>=1,a=a*a%m)if(n&1)p=p*a%m;return(ll)p;}
bool isprime(ll n){if(n<2)return 0;if(!(n%2))return !(n-2);lll d=n-1,t,y;while(!(d%2))d>>=1;V<ll> al={2,325,9375,28178,450775,9780504,1795265022};for(ll a:al){if(n<=a)break;t=d,y=modpow(a,t,n);while(t!=n-1&&y!=1&&y!=n-1)y=y*y%n,t<<=1;if(y!=n-1&&!(t%2))return 0;}return 1;}
void dout(double d){printf("%.12f\n",d);}
void YN(bool z){cout<<(z?"YES\n":"NO\n");}
void Yn(bool z){cout<<(z?"Yes\n":"No\n");}
void yn(bool z){cout<<(z?"yes\n":"no\n");}
mt19937 rnd; void set_rnd(){random_device r;rnd=mt19937(r());}
V<ll> fact, rfact; void set_fact(int n, ll m){fact.pb(1);rfact.pb(1);FOR(i,1,n+1)fact.pb(fact[i-1]*i%m),rfact.pb(modpow(fact[i],m,m-2));}
const int iinf = 1e9+6;
const ll linf = 1e18;
const int mod = 1e9+7;
const double pi = acos(-1);
const double eps = 1e-10;
const int N = 2e5;
void init(){
  set_rnd();
//  set_fact(N);
}

ll p[2][N+1], n, a[N];
main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  init();
  cin >> n;
  FOR(i, 0, n) cin >> a[i];
  FOR(j, 0, 2){
    stack<pair<int, int> > st;
    st.push(mp(n-1, iinf));
    FORR(i, n-2, 0){
      ll aa = a[i], an = a[i+1];
      int d = 0;
      if(aa <= an){
        while(aa<=an) aa<<=2, d++;
        if(d-1) st.push(mp(i, d-1));
        p[j][i] = p[j][i+1];
      }else{
        while(aa>an) an<<=2, d++;
        int s = (n-i)*d;
        while(true){
          pair<int, int> t = st.top();
          st.pop();
          if(t.se >= d){
            s -= (n-t.fi) * d;
            if(t.se > d){
              t.se -= d;
              st.push(t);
            }
            break;
          }else{
            s -= (n-t.fi) * t.se;
            d -= t.se;
          }
        }
        p[j][i] = p[j][i+1]+s;
      }
    }
    reverse(a, a+n);
  }
  ll ans = linf;
  FOR(i, 0, n+1) mins(ans, (p[0][i]+p[1][n-i])*2+i);
  cout << ans << endl;
  return 0;
}

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

using namespace std;

int main(){
  int n = 0;
  vector<int> sequence;
  cin >> n;
  for(int i = 0; i < n; i++){
    int x = 0;
    cin >> x;
    sequence.push_back(x);
  }
  sort(sequence.begin(), sequence.end());
  
  cout << sequence[sequence.size() - 1] - sequence[0] << "\n";
 
  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);


		int s = sc.nextInt();
		int w = sc.nextInt();

		System.out.println(w >= s?"unsafe" : "safe");
	}

}


Measured memory_bytes: 27088