akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1;} return 0;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1;} return 0;}
const long long INFLL = 1LL<<60;
const int INF = 1<<28;
const long long MOD =1000000000+7;

int main(){
    string s,t;
    cin >>s;
    cin >>t;
    string ans="";
    vector<vector<int>>dp(s.size()+3,vector<int>(t.size()+3,0));
    //s[i],t[i]->longest string

    for(int i=1;i<=s.size();i++){
        for(int j=1;j<=t.size();j++){
            if(s[i-1]==t[j-1]){
                chmax(dp[i][j],dp[i-1][j-1]+1);
            }else{
                chmax(dp[i][j],dp[i-1][j]);
                chmax(dp[i][j], dp[i][j-1]);
            }
        //    cout <<dp[i][j]<<" ";
        }
      //  cout<<endl;
    }
    bool down[2]={false,false};//first,second
    pair<int,int>p={s.size(),t.size()};
    while(p.first != 0 and p.second!=0){
        down[0] = dp[p.first][p.second] - 1 == dp[p.first - 1][p.second];
        down[1] = dp[p.first][p.second] - 1 == dp[p.first ][p.second-1];
        if (down[0] and down[1])
        {
            ans=s[p.first-1]+ans;
            p.first--;
            p.second--;
        }else if(down[0]==true){
            p.second--;
        }else{
            p.first--;
        }
    }
    cout<<ans;
}


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

int main() {
  int N;
  cin >> N;
  int A = 0 , B = 0 , MAX = 0 , unkomann = 0 ,hinkomann = 0;
  vector<int> v(N);
  for (int i = 0; i < N; i++){
    cin >> v.at(i);
  }
  for (int i = 0; i < N; i++){
    MAX = 0;
//    hinkomann += 1;
//    unkomann = 0;
    for (int m = 0; m < N; m++){
      if (v.at(m) > MAX){
        MAX = v.at(m);
        unkomann = m;
      }
    }
    if (i % 2 == 0){
      A += MAX;
    }else{
      B += MAX;
    }
    v.at(unkomann) = -1;
  }
  cout << A - B<< endl;
}

Measured memory_bytes: 256
#include<iomanip>
#include<limits>
#include<thread>
#include<utility>
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<numeric>
#include<cassert>
#include<random>
#include<chrono>
#include<unordered_set>
#include<unordered_map>
#include<fstream>
#include<list>
#include<functional>
#include<bitset>
#include<complex>
#include<tuple>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef long double D;
#define F first
#define S second
const ll E=1e18+7;
const ll MOD=1000000007;



int main(){
    ll n;
    cin>>n;
    vector<ll> T(n);
    ll sum=0;
    for(auto &I:T){cin>>I; sum+=I; I=sum;}
    vector<ll> A(sum);
    ll l=0;
    for(int i=0;i<n;i++){
        ll v;
        cin>>v;
        while(l<T[i]){A[l]=v; l++;}
    }
    ll mi=0;
    vector<ll> dp1(sum,0);
    vector<ll> dp2(sum,0);
    for(int i=0;i+1<sum;i++){
        mi++;
        mi=min(mi,A[i]);
        dp1[i+1]=mi;
    }
    mi=0;
    for(ll i=sum-1;i>0;i--){
        mi++;
        mi=min(mi,A[i]);
        dp2[i-1]=mi;
    }
    mi=0;
    double ans=0;
    for(int i=0;i+1<sum;i++){dp2[i]=min(dp2[i],dp1[i+1]);}
    ll s=0;
    for(int i=0;i<sum;i++){
        //cout<<i<<" "<<dp2[i]<<endl;
        if(s<dp2[i]){
            ans+=s+1.0/2;
            s++;
        }
        else if(s>dp2[i]){
            ans+=s-1.0/2;
            s--;
        }
        else{
            if(A[i]>s){ans+=s+1.0/4;}
            else{ans+=s;}
        }
    }
    cout<<fixed<<setprecision(12)<<ans<<endl;
    
    
    return 0;
}


Measured memory_bytes: 768
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()



def main():
    x,a,b = LI()
    if a >= b:
        return 'delicious'
    if a+x >= b:
        return 'safe'
    return 'dangerous'


print(main())








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

int fun(string &s1,string &s2,int i,int j,vector<vector<int>>& dp){
   if(i<=0||j<=0){
        return 0;
   }
   if(dp[i][j]!=-1){
       return dp[i][j];
   }
   if(s1[i-1]==s2[j-1]){
       dp[i][j]=1+fun(s1,s2,i-1,j-1,dp);
       return dp[i][j];
   }
   dp[i][j]=max(fun(s1,s2,i-1,j,dp),fun(s1,s2,i,j-1,dp));
   return dp[i][j];
}

int main(){

  string s1,s2;
  cin>>s1>>s2;
  int n=s1.size();
  int m=s2.size();
  vector<vector<int>> dp(n+1,vector<int>(m+1,-1));
  fun(s1,s2,n,m,dp);
  /*for(int i=0;i<=n;i++){
     for(int j=0;j<=m;j++){
       cout<<dp[i][j]<<" ";
    }
    cout<<"\n";
  } */
  int len=dp[n-1][m-1];  
  int i=n;
  int j=m;
  string res;
  while(i>0&&j>0){
     if(s1[i-1]==s2[j-1]){
        res.push_back(s1[i-1]); 
        i--;
        j--;
     }else if(dp[i-1][j]>dp[i][j-1]){
        i--;
     }else{
        j--;
     }
  }
  reverse(res.begin(),res.end());
  cout<<res<<"\n";
  
}

Measured memory_bytes: 36096
import java.util.*;

public class Main{
    public static void main(String args[]){

        Scanner sc = new Scanner(System.in);


        long s = sc.nextLong();


        long x1 = 0;
        long y1 = 0;

        List<Integer> num = new ArrayList<>();

//        for (int i=(int)Math.sqrt(s); i>=0; i--){
//            if (s%i==0){
//                num.add(i);
//                break;
//            }
//        }


//        int sqr = 0;
//        if (Math.sqrt(s)==(int)Math.sqrt(s)){
//            sqr=(int)Math.sqrt(s);
//        }else{
//            sqr=(int)Math.sqrt(s)+1;
//        }



//        int y2 = 1;
//        int x3 = Math.abs((int)diff/1);

//        for (int i=(int)Math.sqrt(s); i>=0; i--){
//            if (s%i==0){
//                num.add(i);
//                break;
//            }
//        }

        long x2 = (long)1e9;
        long y2 = 1;

//        long x2 = (long)sqr;
//        long y3 = (long)sqr;

        long x3=0;
        long y3=0;
//        long diff = Math.abs(x2*y3-s);

        if ((long)s%(long)1e9==0){
            y3 = (long)s/(long)(1e9);
        }else{
            y3 = (long)s/(long)(1e9)+1;
        }
        x3 = (long)1e9*y3-s;



//        long x2 = num.get(num.size()-1);
//        long y2 = 0;
//
//        long x3 = x2;
//        long y3 = s/x2;


        System.out.println(x1+" "+y1+" "+x2+" "+y2+" "+x3+" "+y3);

    }
}

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

using namespace std;
using ll = long long;
constexpr int mod = 1e9+7;
constexpr int md = mod;
constexpr ll inf = 1e15;
int main(){
    int n,m;
    cin>>n>>m;
    vector<ll> a(m);
    for(auto & b : a) cin>>b;
    for(int i=1;i<m;++i)if(a[i] == a[i-1] + 1) {
        cout << 0 << endl;
        return 0;
    }
    vector<ll> dp(n+1);
    for(int i=0;i<m;++i){
        dp[a[i]] = inf;
    }
    dp[0] = 1;
    for(int i=0;i<=n;++i){
            if(dp[i] == inf) continue;
            if(i+1 <= n && dp[i+1] != inf) {dp[i+1] += dp[i]; dp[i+1] %= mod;}
            if(i+2 <= n && dp[i+2] != inf) {dp[i+2] += dp[i]; dp[i+2] %= mod;}
    }
    cout << dp[n] << endl;
    return 0;
}



Measured memory_bytes: 1408
#入力（後でいじる）
def pin(type=int):
    return map(type,input().split())

"""
"""

#solution:

#input
N,=pin()
A=list(pin())
S=sum(A)
s=A[0]
m=abs(S-s*2)
#print(m)
for i in range(1,N-1):
    s=s+A[i]
    t=abs(S-s*2)
    #print(t)
    m=min(t,m)
print(m)

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

using namespace std;

int main(){
  
  int a, b, c;
  cin>>a>>b>>c;

  int k;
  cin>>k;
  
  for(int i=1; i<=k; i++){
    
    if(c<=b){
      c=c*2;
    }else if(b<=a){
      b=b*2;
    }
  }

  if(c>b and b>a) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;

}


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

#define SORT(x) sort((x).begin(),(x).end())
#define RSORT(x) sort((x).begin(),(x).end(),greater<int>())
#define SZ(x) ((int)(x).size())
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) " (L" << __LINE__ << ") " << __FILE__ << endl;

typedef long long ll;
const int mod = 1e9+7;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const int inf = 0x3f3f3f3f;

void solve()
{
  string s;cin>>s;
  string yy = s.substr(0,2);
  string mm = s.substr(2,2);
  if ("01" <= mm && mm <= "12" && "01" <= yy && yy <= "12") {
    cout << "AMBIGUOUS" << endl;
    return;
  }
  if ("01" <= mm && mm <= "12") {
    cout << "YYMM" << endl;
    return;
  }
  if ("01" <= yy && yy <= "12") {
    cout << "MMYY" << endl;
    return;
  }
  cout << "NA" << endl;
}

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


Measured memory_bytes: 256
import java.util.Random;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        Dice dice = new Dice(new int[]{sc.nextInt(), sc.nextInt(), sc.nextInt(),
                                       sc.nextInt(), sc.nextInt(), sc.nextInt()});

        int count = sc.nextInt();
        char[] choice = new char[]{'N', 'E', 'S', 'W'};
        Random rand = new Random();
        for (int i = 0; i < count; i++) {
            int[] a = new int[]{sc.nextInt(), sc.nextInt()};
            while (dice.eyes[dice.now[0]] != a[0]) {
                int idx = dice.find(a[0]);
                if (idx == 2 || idx == 4) {
                    dice.move('E');
                } else {
                    dice.move('N');
                }
            }
            while (dice.eyes[dice.now[3]] != a[1]) {
                dice.spin('R');
            }
            System.out.println(dice.eyes[dice.now[2]]);
        }
    }

    static class Dice {

        int[] eyes;
        int[/*TOP N E S W BOT*/] now;

        public Dice(int[] eyes) {
            this.eyes = eyes;
            this.now = new int[]{0, 4, 2, 1, 3, 5};
        }

        int find(int eye) {
            for (int i = 0; i < now.length; i++) {
                if (eyes[now[i]] == eye) {
                    return i;
                }
            }
            return -1; // never comes
        }

        void move(char way) {
            int tmp;
            switch (way) {
                case 'N':
                    tmp = now[0];
                    now[0] = now[3];
                    now[3] = now[5];
                    now[5] = now[1];
                    now[1] = tmp;
                    break;
                case 'E':
                    tmp = now[0];
                    now[0] = now[4];
                    now[4] = now[5];
                    now[5] = now[2];
                    now[2] = tmp;
                    break;
                case 'S':
                    tmp = now[0];
                    now[0] = now[1];
                    now[1] = now[5];
                    now[5] = now[3];
                    now[3] = tmp;
                    break;
                case 'W':
                    tmp = now[0];
                    now[0] = now[2];
                    now[2] = now[5];
                    now[5] = now[4];
                    now[4] = tmp;
                    break;
            }
        }

        void spin(char way) {
            int tmp;
            switch (way) {
                case 'R':
                    tmp = now[1];
                    now[1] = now[4];
                    now[4] = now[3];
                    now[3] = now[2];
                    now[2] = tmp;
                    break;
                case 'L':
                    tmp = now[1];
                    now[1] = now[2];
                    now[2] = now[3];
                    now[3] = now[4];
                    now[4] = tmp;
                    break;
            }
        }
    }
}

Measured memory_bytes: 26156
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <vector>
using namespace std;
typedef long long ll;
ll const INF = 1LL << 60;

int main() {
  ll X, Y;
  cin >> X >> Y;
  if (X % Y == 0) {
    cout << -1 << endl;
  } else {
    cout << X << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>                                                                              
using namespace std;                                                                                  
using ll = long long;                                                                                 
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }               
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }               
                                                                                                      
int main() {                                                                                          
  string s;                                                                                           
  cin >> s;                                                                                           
  for (int i=0; i<(int)s.size(); i++) {                                                               
    cout << 'x';                                                                                      
  }                                                                                                   
  cout << endl;                                                                                       
  return 0;                                                                                           
}                                                                                                     
                               

Measured memory_bytes: 256
#include<bits/stdc++.h>
//ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
//clock_t start=clock();clock_t end=clock();cout<<(double)(end-start)/CLOCKS_PER_SEC<<endl;
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef pair<int,int> pii;
typedef pair<pii,int> ppii;
typedef pair<int,pii> pipi;
typedef pair<ll,ll> pll;
typedef pair<pll,ll> ppll;
typedef pair<ll,pll> plpl;
typedef tuple<ll,ll,ll> tl;
typedef pair<double,double> pdd;
typedef vector<vector<ll>> mat;
ll mod=1000000007;
ll mod2=998244353;
ll mod3=1000003;
ll mod4=998244853;
ll mod5=1000000009;
ll inf=1LL<<60;
double pi=3.141592653589793238462643383279L;
double eps=1e-9;
#define rep(i,m,n) for(ll i=m;i<n;i++)
#define rrep(i,n,m) for(ll i=n;i>=m;i--)
#define srep(itr,st) for(auto itr=st.begin();itr!=st.end();itr++)
#define mrep(itr,mp) for(auto itr=mp.begin();itr!=mp.end();itr++)
#define Max(a,b) a=max(a,b)
#define Min(a,b) a=min(a,b)
int dh[4]={1,-1,0,0};
int dw[4]={0,0,1,-1};
int ddh[8]={-1,-1,-1,0,0,1,1,1};
int ddw[8]={-1,0,1,-1,1,-1,0,1};
ll gcd(ll a,ll b){
    if(a<b)swap(a,b);
    if(b==0)return a;
    if(a%b==0)return b;
    return gcd(b,a%b);
}
ll Pow(ll n,ll k){
    ll ret=1;
    ll now=n;
    while(k>0){
        if(k&1)ret*=now;
        now*=now;
        k/=2;
    }
    return ret;
}
ll beki(ll n,ll k,ll md){
  ll ret=1;
  ll now=n;
  while(k>0){
    if(k%2==1){
      ret*=now;
      ret%=md;
    }
    now*=now;
    now%=md;
    k/=2;
  }
  return ret;
}
ll gyaku(ll n,ll md){
  return beki(n,md-2,md);
}
ll popcount(ll n){
    ll ret=0;
    ll u=n;
    while(u>0){
        ret+=u%2;
        u/=2;
        
    }
    return ret;
}
int main(){
    ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    ll x,y;cin>>x>>y;
    if(abs(x-y)<=1)cout<<"Brown"<<endl;
    else cout<<"Alice"<<endl;
}










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

using namespace std;
#define rep(i, n) for(int i=0;i<n;i++)
#define REP(i, n) for(int i=1;i<=n;i++)
typedef long long ll;

vector<ll> a;
vector<ll> p;

ll solve(ll n, ll x) {
	if (n == 0 && x >= 1) {
		return 1;
	} else if (x == 1) {
		return 0;
	} else if (1 <= x && x <= 1 + a[n - 1]) {
		return solve(n - 1, x - 1);
	} else if (x == a[n - 1] + 2) {
		return p[n - 1] + 1;
	} else if (2 + a[n - 1] < x <= 2 + 2 * a[n - 1]) {
		return p[n - 1] + 1 + solve(n - 1, x - 2 - a[n - 1]);
	} else if (x == a[n - 1] + 3) {
		return 2 * p[n - 1] + 1;
	}
}

int main() {
	ll n, x;
	cin >> n >> x;
	a.resize(n + 1, 0);
	p.resize(n + 1, 0);
	a[0] = 1;
	p[0] = 1;
	REP(i, n) {
		a[i] = 2 * a[i - 1] + 3;
		p[i] = 2 * p[i - 1] + 1;
	}
	ll ans = solve(n, x);
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
#include<string>
#include<algorithm>//sort()
using namespace std;
bool UDid(char a) {
    if ((a >= 'a') && (a <= 'z')) {
        return true;
    }
    else if ((a >= 'A') && (a <= 'Z')) {
        return false;
    }
}
int main() {
    int p[5];
    for (int i = 0; i < 5; i++) {
        cin >> p[i];
    }
    for (int i = 0; i < 5; i++) {   
        if (p[i] == 0) {
            cout << i + 1;
            return 0;
        }
    }
}

Measured memory_bytes: 3156
package main

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

// input scanner
var sc = bufio.NewScanner(os.Stdin)

const (
	initialBufSize = 10e4
	maxBufSize     = 10e6
)

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	a, _ := strconv.Atoi(next())
	return a
}

func nextInt64() int64 {
	a, _ := strconv.ParseInt(next(), 10, 64)
	return a
}

func nextFloat64() float64 {
	a, _ := strconv.ParseFloat(next(), 64)
	return a
}

func nextInts(n int) []int {
	ret := make([]int, n)
	for i := 0; i < n; i++ {
		ret[i] = nextInt()
	}
	return ret
}
func nextFloats(n int) []float64 {
	ret := make([]float64, n)
	for i := 0; i < n; i++ {
		ret[i] = nextFloat64()
	}
	return ret
}
func nextStrings(n int) []string {
	ret := make([]string, n)
	for i := 0; i < n; i++ {
		ret[i] = next()
	}
	return ret
}

// util
func max(l []int) (int, int) {
	idx := 0
	ans := l[idx]
	for i, n := range l {
		if n > ans {
			idx = i
			ans = n
		}
	}
	return idx, ans
}

func min(l []int) (int, int) {
	idx := 0
	ans := l[idx]
	for i, n := range l {
		if n < ans {
			idx = i
			ans = n
		}
	}
	return idx, ans
}

// main
func main() {
	buf := make([]byte, initialBufSize)
	sc.Buffer(buf, maxBufSize)
	sc.Split(bufio.ScanWords)
	n := nextInt()
	a := nextInts(n)
	for i := 0; i < n; i++ {
		if a[i]%2 == 0 {
			if a[i]%3 != 0 && a[i]%5 != 0 {
				fmt.Println("DENIED")
				return
			}
		}
	}
	fmt.Println("APPROVED")
}


Measured memory_bytes: 640
import math
A, B, H, M = map(int, input().split(" "))

argH = 30 * (H + M / 60)
argM = 6 * M
arg = abs(argH - argM - 180)
length = math.sqrt( A**2 + B**2 - 2*A*B*math.cos(math.radians(argH - argM)))
print(length)

Measured memory_bytes: 9504
import sys

input = sys.stdin.readline
N,M=map(int,input().rstrip().split())
G=[[0 for _ in range(N)] for __ in range(N)]
used=[0 for _ in range(N)]
used[0]=True

for i in range(M):
    a,b=map(int,input().rstrip().split())
    G[a-1][b-1]=True
    G[b-1][a-1]=True

def resolve():
    print(dfs(0,used))


def dfs(v,used):
    if not False in used:
        return 1
    ans=0
    for i in range(N):
        if G[v][i]==False:
            continue
        if used[i]==True:
            continue

        used[i]=True
        ans+=dfs(i,used)
        used[i]=False
    return ans

    



from io import StringIO
import unittest

class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)
    def test_入力例_1(self):
        input = """3 3
1 2
1 3
2 3"""
        output = """2"""
        self.assertIO(input, output)
    def test_入力例_2(self):
        input = """7 7
1 3
2 7
3 4
4 5
4 6
5 6
6 7"""
        output = """1"""
        self.assertIO(input, output)

if __name__ == "__main__":
    #unittest.main()
    resolve()

Measured memory_bytes: 5700
#include <cstdio>
#include <cstring>
#include <vector>
#include <queue>
#include <string>
#include <algorithm>
#include <iostream>
#include <map>
#include <set>
#include <functional>
#include <iostream>
#define INF 2000000000LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int n,k;
int a[100001];
int cnt[100001];
int res;
bool used[100001];
vector<int> G[100001];

int dfs(int v,int p){
	used[v]=true;
	int len=0;
	for(int i=0;i<G[v].size();i++){
		if(!used[G[v][i]])len=max(len,dfs(G[v][i],v));
	}
	if(len+1==k && p!=0){
		res++;
		return 0;
	}
	return len+1;
}
int main(void){
	scanf("%d%d",&n,&k);
	for(int i=0;i<n;i++){
		scanf("%d",&a[i]);
		a[i]--;
	}
	if(k==1){
		for(int i=0;i<n;i++){
			if(a[i]!=0)res++;
		}
		printf("%d\n",res);
		return 0;
	}
	if(a[0]!=0){
		a[0]=0;
		res++;
	}
	for(int i=1;i<n;i++){
		G[a[i]].push_back(i);
	}
	dfs(0,0);
	printf("%d\n",res);
	return 0;
}

Measured memory_bytes: 12416
N = int(input())
cnt = 0
for i in range(1,int(N**0.5)+1):
    if N%i==0:
        q = N//i
        m = i-1
        if q<m:
            cnt += m
        m = N//i-1
        q = i
        if q<m:
            cnt += m
print(cnt)

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

int data[6];

void syokika();
void north();
void east();
void south();
void west();

main(){
  int n;
  while(1){
    cin >> n;
    if(n==0) break;

    syokika();
    string in;
    for(int i=0;i<n;i++){
      cin >> in;
      if(in=="north"){
	north();
      }
      else if(in=="east"){
	east();
      }
      else if(in=="south"){
	south();
      }
      else if(in=="west"){
	west();
      }
    }
    cout << data[1] << endl;
  }
  return 0;
}

void syokika(){
  data[0]=2;
  data[1]=1;
  data[2]=5;
  data[3]=6;
  data[4]=4;
  data[5]=3;
}

void north(){
  int tmp[6];
  for(int i=0;i<6;i++){
    tmp[i]=data[i];
  }

  data[0]=tmp[1];
  data[1]=tmp[2];
  data[2]=tmp[3];
  data[3]=tmp[0];
}

void east(){
  int tmp[6];
  for(int i=0;i<6;i++){
    tmp[i]=data[i];
  }

  data[1]=tmp[5];
  data[3]=tmp[4];
  data[4]=tmp[1];
  data[5]=tmp[3];
}

void south(){
  int tmp[6];
  for(int i=0;i<6;i++){
    tmp[i]=data[i];
  }

  data[0]=tmp[3];
  data[1]=tmp[0];
  data[2]=tmp[1];
  data[3]=tmp[2];
}

void west(){
  int tmp[6];
  for(int i=0;i<6;i++){
    tmp[i]=data[i];
  }

  data[1]=tmp[4];
  data[3]=tmp[5];
  data[4]=tmp[3];
  data[5]=tmp[1];
}

Measured memory_bytes: 0
import sys

input = sys.stdin.readline


def main():
    s = input().rstrip()
    t = input().rstrip()

    ss = "".join(sorted(s))
    tt = "".join(sorted(t, reverse=True))

    ans = "Yes" if ss < tt else "No"
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 2940
while True:
    n=int(input())
    if n==0:
        break
    else:
        if n==1:
            print(1)
        elif n==2:
            print(1)
        else:
            A=[0]*(n+1)
            A[0]=1
            A[1]=1
            A[2]=2
            for i in range(3,n+1):
                A[i]=A[i-1]+A[i-2]+A[i-3]
            print(A[n]//3650+1)


Measured memory_bytes: 5592
A=list(map(int,input().split()))

if A[0]==A[1] and not A[0]==A[2]:
    print(2)
elif not A[0]==A[1] and not A[1]==A[2] and not A[0]==A[2]:
    print(3)
elif A[0]==A[2] and not A[0]==A[1]:
    print(2)
elif A[1]==A[2] and not A[1]==A[0]:
    print(2)
else:
    print(1)


Measured memory_bytes: 3064
#include<bits/stdc++.h>
#include<vector>
#include<string>
#include<stack>
#include<iostream>
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long
#define MOD 1000000007
#define vec(a) vector<int>a
using namespace std;


int main()
{
#ifndef ONLINE_JUDGE
	freopen("output.txt", "w", stdout);
	freopen("input.txt", "r", stdin);
#endif
		ll n,m,i,j,k,l;
		cin>>n>>m;
		n=n*(n-1)/2;
		m=m*(m-1)/2;
		cout<<n+m<<"\n";
		return 0;
}
	

Measured memory_bytes: 3596
#include<cstdio>
#include<cstring>
#define maxn 3005
int n,a[maxn],ans[maxn],cnt;
bool f[maxn];
struct node { int v; node *nxt; } edge[maxn*2],*head[maxn],*ncnt;
void addedge(int u,int v)
{
	ncnt++;
	ncnt->v=v,ncnt->nxt=head[u];
	head[u]=ncnt;
}
bool dfs(int u,int fa)
{
	for(node *p=head[u];p;p=p->nxt)
	{
		int v=p->v;
		if(a[v]<a[u]&&!dfs(v,u)) return f[u]=true;
	}
	return f[u]=false;
}
int main()
{
	ncnt=&edge[0];
	scanf("%d",&n);
	for(int i=1;i<=n;i++) scanf("%d",&a[i]);
	for(int i=1;i<n;i++)
	{
		int u,v;
		scanf("%d%d",&u,&v);
		addedge(u,v); addedge(v,u);
	}
	for(int i=1;i<=n;i++)
	{
		memset(f,0,sizeof(f));
		if(dfs(i,0)) ans[++cnt]=i;
	}
	for(int i=1;i<=cnt;i++) printf("%d ",ans[i]);
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define Rint register int
using namespace std;
typedef long long LL;
const int N = 1003, K = 10003, d[2][4] = {{0, 1, 0, -1}, {1, 0, -1, 0}};
int n, pri[N << 1], tot;
bool notp[K];
LL a[N][N];
inline void init(int m){
	notp[0] = notp[1] = 1;
	for(Rint i = 2;;i ++){
		if(!notp[i]){pri[++ tot] = i; if(tot == m) break;}
		for(Rint j = 1;j <= tot && i * pri[j] <= 10000;j ++){
			notp[i * pri[j]] = true;
			if(!(i % pri[j])) break;
		}
	}
}
inline LL gcd(LL a, LL b){return b ? gcd(b, a % b) : a;}
inline LL lcm(LL a, LL b){return a / gcd(a, b) * b;}
int main(){
	scanf("%d", &n);
	if(n == 2){
		puts("2 3"); puts("5 4"); return 0;
	} init(2 * n);
	for(Rint i = 1;i <= n;i ++)
		for(Rint j = 1;j <= n;j ++) if(!(i + j & 1))
			a[i][j] = pri[i + j >> 1] * pri[n + (n + i - j + 1 >> 1)];
	for(Rint i = 1;i <= n;i ++){
		for(Rint j = 1;j <= n;j ++){
			if(!a[i][j]){
				a[i][j] = 1;
				for(Rint k = 0;k < 4;k ++){
					int dx = i + d[0][k], dy = j + d[1][k];
					if(dx >= 1 && dx <= n && dy >= 1 && dy <= n)
						a[i][j] = lcm(a[i][j], a[dx][dy]);
				}
				++ a[i][j];
			}
			printf("%lld ", a[i][j]);
		}
		putchar('\n');
	}
}

Measured memory_bytes: 7296
#include <stdio.h>

int main(void) {
	int l[10],v1,v2;
	double point;
	int i;
	while(1) {
		if(scanf("%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d",
			&l[0],&l[1],&l[2],&l[3],&l[4],
			&l[5],&l[6],&l[7],&l[8],&l[9],&v1,&v2)==-1)break;
		for(i=1;i<10;i++)l[i]+=l[i-1];
		point=(double)l[9]*v1/(v1+v2);
		for(i=0;i<10;i++) {
			if(l[i]>=point)break;
		}
		printf("%d\n",i+1);
	}
	return 0;
}

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

int main() {
  int N, M;
  cin >> N >> M;
  
  vector<int> roads(N,0);
  
  for(int i=0; i<M; i++)
  {
    int a, b;
    cin >> a >> b;
    
    roads[a-1]++;
    roads[b-1]++;
    
  }
  
  for(int i=0; i<N; i++)
  {
    cout << roads[i] << endl;
  }
}


Measured memory_bytes: 256
#include <stdio.h>
#include <cstdio>
#include <iostream>
#include <queue>
#include <set>
#include <vector>
#include <cstring>
#include <algorithm>

int main(){
  long long int N, L;
  scanf("%lld%lld", &N, &L);
  
  long long int sum_taste = 0, smallest_taste = 10000;
  
  for(long long int i = 0; i < N; i++){
    sum_taste += L+i;
    if(std::abs(L+i) < std::abs(smallest_taste)){
      smallest_taste = L+i;
    }
  }
  
  std::cerr << "Answer:" << std::endl;
  std::cout << sum_taste - smallest_taste << std::endl;
  
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
using ll = long long;

void ins() {}
template<class T,class... Rest>void ins(T& v,Rest&... rest){cin>>v;ins(rest...);}
#define _overload3(_1,_2,_3,name,...) name
#define _rep2(i,n) for(int i=0,_i=(n);i<_i;++i)
#define _rep3(i,a,b) for(int i=(a),_i=(b),_ii=(b)>(a)?1:-1;abs(_i-i)>0;i+=_ii)
#define rep(...) _overload3(__VA_ARGS__,_rep3,_rep2)(__VA_ARGS__)
#define all(f,c,...) (([&](decltype((c)) cccc) { return (f)(begin(cccc), end(cccc), ## __VA_ARGS__); })(c))

signed main() {
  ll N, M, V, P;
  ins(N, M, V, P);

  vector<ll> A(N);
  rep(i, N)
    cin >> A[i];
  all(sort, A); all(reverse, A);

  int ok = -1, ng = N;
  auto f = [&](int mid) {
    if (mid < P) return true;
    if (A[P-1] > A[mid]+M) return false;

    ll tmp = 1LL * ((N-mid)+P-1) * M;
    rep(i, P-1, mid)
      tmp += min(1LL*M, max(0LL, A[mid]+M-A[i]));
    return tmp >= M*V;
  };
  while (abs(ok - ng) > 1) {
    int mid = ok + (ng-ok) / 2;
    (f(mid) ? ok : ng) = mid;
  }
  cout << ok+1 << endl;
  return 0;
}


Measured memory_bytes: 1024
import sys

sys.setrecursionlimit(10**4)

N=int(input())
S=input()
edge=[[] for i in range(N)]
for i in range(N-1):
    a,b=map(int,input().split())
    edge[a-1].append(b-1)
    edge[b-1].append(a-1)

depth=[0]*N
num=[0]*N
sd=[0]*N
def dfs(v,pv):
    res=depth[v]*(S[v]=="1")
    n=int(S[v])
    for nv in edge[v]:
        if nv!=pv:
            depth[nv]=depth[v]+1
            dfs(nv,v)
            res+=sd[nv]
            n+=num[nv]
    sd[v]=res
    num[v]=n

def dfs2(v,pv):
    hosei=depth[v]
    S=sd[v]-num[v]*hosei
    if S%2==0:
        check=0
        node=-1
        for nv in edge[v]:
            if nv!=pv:
                if sd[nv]-num[nv]*hosei>S//2:
                    check=sd[nv]-num[nv]*hosei
                    node=nv
        if not check:
            return S//2
        else:
            minus=dfs2(node,v)
            if check-2*minus<=S-check:
                return S//2
            else:
                return S-check+minus
    else:
        check=0
        node=-1
        k=S//2
        for nv in edge[v]:
            if nv!=pv:
                if sd[nv]-num[nv]*hosei>k+1:
                    check=sd[nv]-num[nv]*hosei
                    node=nv
        if not check:
            return k
        else:
            minus=dfs2(node,v)
            if check-2*minus<=S-check:
                return k
            else:
                return S-check+minus


ans=10**18

for i in range(N):
    depth[i]=0
    dfs(i,-1)
    #print(i,depth)
    test=dfs2(i,-1)
    if test*2==sd[i]:
        ans=min(ans,test)

if ans==10**18:
    print(-1)
else:
    print(ans)


Measured memory_bytes: 239812
// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
//#define int ll
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
//#define mt make_tuple
//typedef tuple<pii,int,int> tp;
//typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
//template<class C>constexpr int size(const C &c){return (int)c.size();}
//template<class T,size_t N> constexpr int size(const T (&xs)[N])noexcept{return (int)N;}
const double PI=acos(-1);
const double EPS=1e-7;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
struct edge{int to,cap,rev;};//ikisaki youryou gyakuhen
class MF{//max flow
	public:
	int n;
	vector<vector<edge> >G;//[MAX];
	vi level,iter;//[MAX];
	MF(int size){
		n=size;
		G=vector<vector<edge> >(n);
	}
	void add_edge(int from, int to, int cap){
		edge q={to,cap,int(G[to].size())};
		G[from].push_back(q);
		q={from,0,int(G[from].size()-1)};
		G[to].push_back(q);
	}
	void bfs(int s){
		level=vi(n,-1);
		queue<int>q;
		level[s]=0;
		q.push(s);
		while(!q.empty()){
			int v=q.front();q.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;
					q.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(level[v]>=level[e.to]||e.cap<=0) continue;
			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 mf(int s,int t) {//from s to t,ford_fulkerson
		int flow=0;
		while(1){
			bfs(s);
			if(level[t]<0)return flow;
			iter=vi(n);
			int f;
			while((f=dfs(s,t,inf))>0)flow+=f;
		}
	}
};
int main(){
	int n;
	cin>>n;
	MF mf(n*2+2);
	int s=n*2,t=s+1;
	rep(i,n){
		mf.add_edge(s,i,1);
		mf.add_edge(n+i,t,1);
	}
	vp a(n),b(n);
	rep(i,n)cin>>a[i].first>>a[i].second;
	rep(i,n)cin>>b[i].first>>b[i].second;
	rep(i,n)rep(j,n)if(a[i].first<b[j].first&&a[i].second<b[j].second)
		mf.add_edge(i,n+j,1);
	cout<<mf.mf(s,t)<<endl;
}






Measured memory_bytes: 384
# frozen_string_literal: true

n, m = gets.split.map(&:to_i)
array = readlines.map { |e| e.split.map(&:to_i) }

ans = ''

(1..n).to_a.each do |key|
  value = array.select { |e| e[0] == key }.uniq
  if value.size > 1
    puts -1
    exit
  end

  if key == 1 && value.any? && value.first[1] == 0 && n != 1
    puts -1
    exit
  end

  value = if value.empty? && n != 1
            key == 1 ? 1 : 0
          elsif value.empty? && n == 1
            0
          else
            value.first[1]
          end
  ans += value.to_s
end

puts ans


Measured memory_bytes: 1788
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define f first
#define s second
#define pb push_back
#define fix  cout<<std::fixed;
#define mk make_pair
#define mod 1000000007
#define time  cerr<< '\n' << "Time elapsed :" << clock() * 1000.0 / CLOCKS_PER_SEC << " ms\n" ;
#define IOS             ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
int main()
{ 
     ll n,m;cin>>n>>m;
     ll dp[n+1][m+1];
     memset(dp, 0, sizeof(dp));dp[1][1]=1;
     for(int i=1;i<=n;i++)
     {
        for(int j=1;j<=m;j++)
        { char c;cin>>c;
            if(c=='.')
            {   if(i!=1 || j!=1)
                  dp[i][j]=(dp[i-1][j]%mod+dp[i][j-1]%mod)%mod;
            }
            if(c=='#')
                dp[i][j]=0;
        }
     }
     cout<<dp[n][m]%mod;
}

Measured memory_bytes: 8064
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using Graph = vector<vector<pii>>;
const int INF = 1e9 + 1;
const ll LLINF = 1e18;
const int MOD = 1e9 + 7;

int main() {
    int X;
    cin >> X;
    int ans = 1, sum = 0;
    while (sum + ans < X)
        sum += ans, ans++;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define REP(i,n) for (ll i = 0; i < (n); ++i)
#define RREP(i, n) for (ll i = (n) - 1; i >= 0; --i)
#define ALL(v) (v).begin(), (v).end()
template<class T>
using reverse_priority_queue = priority_queue<T, vector<T>, greater<T>>;


int main(){
    ll n;
    cin >> n;

    set<ll> a;
    ll total = 0;

    if(n == 3){
        a = {2, 5, 63};
    }else if(n == 4){
        a = {2, 5, 20, 63};
    }else if(n == 5){
        a = {2, 5, 20, 30, 63};
    }else{
        ll i;
        for(i = 2; a.size() < n && i <= 30000; ++i){
            if(i % 2 == 0 || i % 3 == 0){
                a.insert(i);
                total += i;
            }
        }
        if(total % 6 != 0){
            ll toadd_mod = 0;
            if(total % 6 == 2){
                a.erase(8);
                total -= 8;
            }else if(total % 6 == 3){
                a.erase(9);
                total -= 9;
            }else if(total % 6 == 5){
                a.erase(9);
                total -= 9;
                toadd_mod = 4;
            }
            for(; ; ++i){
                if(i % 6 == toadd_mod){
                    a.insert(i);
                    total += i;
                    break;
                }
            }
        }
        assert(total % 6 == 0);
    }

    assert(a.size() == n);
    
    for(ll ai : a){
        cout << ai << endl;
    }
    return 0;
}


Measured memory_bytes: 4556
import sys
input = sys.stdin.readline

n, x, y = map(int, input().split())
x -= 1
y -= 1
d = [0] * n
for i in range(n - 1):
    for j in range(i + 1, n):
        k = min(j - i, abs(i - x) + abs(j - y) + 1)
        d[k] += 1
for i in range(1, n):
    print(d[i])

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

int n,a;
deque<int> b;

int main()
{
	cin>>n;
	for(int i=0;i<n;i++)
	{
		cin>>a;
		if(i%2==0) b.push_back(a); else b.push_front(a);
	}
	
	if(n%2==0) while(!b.empty()) {cout<<b.front()<<' ';b.pop_front();}
	else while(!b.empty()) {cout<<b.back()<<' ';b.pop_back();}
	
	return 0;
}

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

using namespace std;

void disp(vector<int> a, int n){
    for(int i = 0;i < n;i++){
        if(i == n-1) cout << a[i];
        else cout << a[i] << " ";
    }
    cout << endl;
}

int select(vector<int> a, int n){
    int count = 0;
    for(int i = 0;i < n;i++){
        int minj = i;
        for(int j = i;j < n;j++){
            if(a[j] < a[minj]) minj = j;
        }
        if(i != minj){
            swap(a[i], a[minj]);
            count++;
        }
    }
    disp(a, n);
    return count;
}

int main(void){

    int n;
    cin >> n;
    vector<int> a(n);
    for(int i = 0;i < n;i++) cin >> a[i];

    cout << select(a, n) << endl;

    return 0;
}


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

int main(){
  int n;
  cin >> n;
  int t[n],x[n],y[n];
  for(int i=0;i<n;i++){
    cin >> t[i] >> x[i] >> y[i];
  }
  int check=0;
  for(int i=0;i<n;i++){
    if(t[i]%2!=(x[i]+y[i])%2){
      check++;
    }
  }
  for(int i=0;i<n-1;i++){
    if(t[i+1]-t[i]<abs(x[i+1]-x[i])+abs(y[i+1]-y[i])){
      check++;
    }
  }
  if(t[0]<abs(x[0])+abs(y[0])){
    check++;
  }
  if(check==0){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}


Measured memory_bytes: 1408
import sys
sys.setrecursionlimit(200010)
def input():
    return sys.stdin.readline()[:-1]
def main():
    N, Q = map(int,input().split())
    G = [[] for _ in range(N)]
    for _ in range(N-1):
        a, b = map(int,input().split())
        G[a-1].append(b-1)
        G[b-1].append(a-1)
    V = [0]*N
    for _ in range(Q):
        p, x = map(int,input().split())
        V[p-1] += x

    def dfs(mae,ima):
        for tsugi in G[ima]:
            if tsugi != mae:
                V[tsugi] += V[ima]
                dfs(ima,tsugi)
    dfs(-1,0)
    print(*V)

if __name__ == '__main__':
    main()


Measured memory_bytes: 268428
void main()
{
    long n, a, b;
    rdVals(n, a, b);
    long[] h = n.rdCol;

    bool check(long x)
    {
        long cnt;
        foreach (y; h)
        {
            long rem = max(0, y-x*b);
            cnt += (rem + a - b - 1) / (a - b);
        }
        return cnt <= x;
    }

    long ok = 10 ^^ 10, ng = -1;
    while (abs(ok - ng) > 1)
    {
        long m = (ok + ng) / 2;
        if (check(m)) ok = m;
        else ng = m;
    }

    ok.writeln;
}

enum long mod = 10^^9 + 7;
enum long inf = 1L << 60;

T rdElem(T = long)()
if (!is(T == struct))
{
    return readln.chomp.to!T;
}

alias rdStr = rdElem!string;
alias rdDchar = rdElem!(dchar[]);

T rdElem(T)()
if (is(T == struct))
{
    T result;
    string[] input = rdRow!string;
    assert(T.tupleof.length == input.length);
    foreach (i, ref x; result.tupleof)
    {
        x = input[i].to!(typeof(x));
    }
    return result;
}

T[] rdRow(T = long)()
{
    return readln.split.to!(T[]);
}

T[] rdCol(T = long)(long col)
{
    return iota(col).map!(x => rdElem!T).array;
}

T[][] rdMat(T = long)(long col)
{
    return iota(col).map!(x => rdRow!T).array;
}

void rdVals(T...)(ref T data)
{
    string[] input = rdRow!string;
    assert(data.length == input.length);
    foreach (i, ref x; data)
    {
        x = input[i].to!(typeof(x));
    }
}

void wrMat(T = long)(T[][] mat)
{
    foreach (row; mat)
    {
        foreach (j, compo; row)
        {
            compo.write;
            if (j == row.length - 1) writeln;
            else " ".write;
        }
    }
}

import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.numeric;
import std.mathspecial;
import std.traits;
import std.container;
import std.functional;
import std.typecons;
import std.ascii;
import std.uni;
import core.bitop;

Measured memory_bytes: 3964
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;

int main(){
  int N, L;
  cin >> N >> L;
  vector<string>s(N);
  for(int i = 0; i < N; ++i)cin >> s[i];
  sort(s.begin(), s.end());
  string answer;
  for(int i =0; i<N; ++i){
    answer = answer + s[i];}
  cout << answer << endl;
}

Measured memory_bytes: 256
N,K = map(int,input().split())
cnt = [0]*(N-K+2)

cnt_all = 0
mod = 1000000007

for i in range(K,N+2):
    cnt[i-K] = i*N - i*(i-1) + 1

for i in range(N-K+2):
    cnt_all += cnt[i]

print(cnt_all % mod)

Measured memory_bytes: 19820
#include <bits/stdc++.h>
using namespace std;
long long int gcd(long long int a, long long int b) {
  if(b == 0) return a;
  return gcd(b, a % b);
}

long long int lcm(long long int a, long long int b) {
  return (a / gcd(a, b)) * b;
}

long long int combination(long long int n, long long int r) {
  if ( r * 2 > n ) r = n - r;
  long long int dividend = 1;
  long long int divisor  = 1;
  for ( unsigned int i = 1; i <= r; ++i ) {
    dividend *= (n-i+1);
    divisor  *= i;
  }
  return dividend / divisor;
}
long long int tmp(long long int n, long long int r) {
  return combination(n+r-1, r);
}


int main() {
  long long int N, r;
  vector<long long int> a_v, x_v;
  cin >> r;
  cout << 3*r*r << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
typedef long long int uli;

int x[4],y[4];
uli f[16][16][16][16];
int bat(int n,int idx){
   if(n&(1<<idx))return 1;
   return 0;
}
uli solve(int p[4]){
   uli &ans=f[p[0]][p[1]][p[2]][p[3]];
   if(ans!=-1)return ans;
   ans=0;
   bool fnd=false;
   for(int i=0;i<4 && !fnd;i++){
      for(int j=0;j<4 && !fnd;j++){
         if(bat(p[i],3-j)==1)continue;
         int r=i,c=j;
         fnd=true;
         for(int k=0;k<4;k++){
            int sgn=-1;
            for(int l=0;l<2;l++){
               sgn*=-1;
               int nr=r+sgn*x[k];
               int nc=c+sgn*y[k];
               if(0<=nr && nr<4 && 0<=nc && nc<4){
                  if(bat(p[nr],3-nc)==1)continue;
                  int q[4]={p[0],p[1],p[2],p[3]};
                  q[r]^=(1<<(3-c));
                  q[nr]^=(1<<(3-nc));
                  ans+=solve(q);
               }
            }
         }
      }
   }
   return ans;
}
int main(){
   while(scanf("%d",x)==1){
      if(x[0]>4)break;
      scanf("%d",y);
      for(int i=1;i<4;i++)
         scanf("%d %d",x+i,y+i);
      memset(f,-1,sizeof f);
      f[15][15][15][15]=1;
      int p[4]={0,0,0,0};
      uli ans=solve(p);
      printf("%lld\n",ans);
   }
   return 0;
}

Measured memory_bytes: 1708
#include<iostream>
#include<string>
#include<iostream>
#include<vector>
#include<string.h>
#include<stdio.h>
#include<map>
#include<math.h>
#include<algorithm>
using namespace std;
int main()
{int a,b;
 cin>>a>>b;
 int c=a*b;
 if(c%2==0)
 cout<<"Even"<<endl;
 else
 cout<<"Odd"<<endl; 
 system("pause");
 return 0;
}

Measured memory_bytes: 504
#include <bits/stdc++.h>
#include <iostream>
#include <ctime>
using namespace std;
#define _LL long long
#define rep(i, n) for (_LL i = 0; i < (_LL)(n); i++)
#define vecrep(itr, v) for (auto itr = (v).begin(); itr != (v).end(); itr++)

int main()
{
    int n, x, t; cin >> n >> x >> t;
    cout << ( (( n - 1 ) / x + 1) * t );
    return 0;   
}

Measured memory_bytes: 3620
fun main(args : Array<String>) {
    val n = readLine()!!.toInt()
    val aa = readLine()!!.split(" ").map{it.toInt()}

    var prev = -1
    var cnt = 0
    aa.forEach {
        if (it == prev) {
            prev = -1
            cnt++
        } else {
            prev = it
        }
    }

    println(cnt)
}

Measured memory_bytes: 37864
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int N = 1e6 + 10;
const int INF = 0x3f3f3f3f;
int n;
int a[N], tw = 1, fac[N], cnt[3];
void init(int n) {
	for (int i = 1; i <= n; i++) {
		int t = i;
		fac[i] = fac[i - 1];
		while (t && (t & 1 ^ 1)) {
			fac[i] ++;
			t >>= 1;
		}
	}
}
int fc(int n, int k) {
	return fac[n] - fac[k] - fac[n - k];
}
int main() {
	scanf("%d", &n);
	init(n);
	for (int i = 1; i <= n; i++) {
		char c;
		scanf(" %c", &c);
		a[i] = c - '1';
		if (a[i] == 1)tw = 0;
		int tmp = fc(n - 1, i - 1);
		if (tmp <= 0)cnt[a[i]] ^= 1;
	}
	if (cnt[1])puts("1");
	else {
		if (!tw)puts("0");
		else {
			if (cnt[2])puts("2");
			else puts("0");
		}
	}
	return 0;
}

Measured memory_bytes: 8064
N = int(input())
*W, = map(int, input().split())
 
s1, s2 = 0, sum(W)
ans = sum(W)
 
for i in range(N):
  s1 += W[i]
  s2 -= W[i]
  ans = min(ans, abs(s1 - s2))
print(ans)

Measured memory_bytes: 9144
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define yesno(flg) if(flg){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define MAX_N 1002
#define i197 1000000007

using namespace std;

typedef long long ll;
typedef pair<ll,ll> P1;
typedef pair<int,int> Pi;
typedef pair<double,Pi> Pdi;
typedef pair<ll,int>Pli;
typedef pair<P1,ll> P2;
const ll INF=1000000000000000001;
struct edge{int to,cost;};
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
struct Road{double cost;int a,b;};


int main() {

	ll n;
	ll c1=0,c2=0,c3=0;
	ll total=0;
	cin>>n;
	string s;

	rep(i,n){
		cin>>s;
		if(s[0]=='B'&&s[s.size()-1]=='A')c1++;
		else if(s[0]=='B')c2++;
		else if(s[s.size()-1]=='A')c3++;
		rep(j,s.size()-1){
			if(s[j]=='A'&&s[j+1]=='B')total++;
		}
	}
	if(c1==0)cout<<total+min(c2,c3)<<endl;
	if(c1>0&&c2+c3==0)cout<<total+c1-1<<endl;
	if(c1>0&&c2+c3>0)cout<<total+c1+min(c2,c3)<<endl;
	return 0;

}


Measured memory_bytes: 256
a, b = map(int, input().split())
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])
    if temp!=1:
        arr.append([temp, 1])
    return arr
c = factorization(a)
d = factorization(b)
cnt = 1
for i,j in c:
  for k,l in d:
    if i == k:
      cnt += 1
print(cnt)

Measured memory_bytes: 9316
import sys
input = sys.stdin.readline
import numpy as np
 
N,W = map(int, input().split())
 
dp = [10 ** 10] * N * (10 ** 4)
dp[0] = 0
dp = np.array(dp)
 
 
for i in range(N):
    w,v = map(int, input().split())
    dp[v:] = np.minimum(dp[v:] , dp[:-v] + w)
  
for i,count in enumerate(dp):
    if dp[i] <= W:
        ans = i
print(ans)

Measured memory_bytes: 35900
#include <string>
#include <algorithm>
#include <limits.h>
#include <iostream>

using namespace std;

int main()
{
	long long i, j, k, H, W, hl, wl;
	string a[102];

	cin >> H; cin >> W;
	for (i = 1; i <= H; i++) {
		cin >> a[i];
		a[i] = '#' + a[i] + '#';
	}



	for (i = 0; i < W+2; i++) {
		a[0] += "#";
		a[H + 1] += "#";
	}

	for (i = 0; i < H + 2; i++) {
		cout << a[i] << endl;
	}
	return 0;
}

Measured memory_bytes: 256
let inputString = "";
let currentLine = 0;
process.stdin.on("data", (data) => {
  inputString += data;
});
process.stdin.on("end", function () {
  inputString = inputString
    .trim()
    .split("\n")
    .map((str) => str.trim());
  main();
});
function readLine() {
  return inputString[currentLine++];
}
function main() {
  const [d, t, s] = readLine()
    .split(" ")
    .map((n) => parseInt(n));

  if (s * t >= d) console.log("Yes");
  else console.log("No");
}


Measured memory_bytes: 29904