akhauriyash/Code-Regression huggingface dataset:
#include <iostream>

using namespace std;

int main()
{
    int X,Y,Z;
    cin >> X >> Y >> Z;
    /*cout << X % (Y + Z) << '\n';
    cout << X % (Y + Z) % Z << '\n';*/
    if((X % (Y+Z)) % Z == 0 && (X % (Y+Z)))
        cout << (X / (Y + Z));
    else
        cout << (X / (Y + Z)) - 1;
    return 0;
}


Measured memory_bytes: 256
import java.util.*;
import java.io.*;
import java.text.*;
public class Main
{
    public static void main(String []args) throws IOException {
    	FastScanner in  = new FastScanner(System.in);
    	PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)), false);
    	solve(in, out);
    	in.close();
    	out.close();
    }
    static long gcd(long a, long b){ return (b==0) ? a : gcd(b, a%b); }
    static int gcd(int a, int b){ return (b==0) ? a : gcd(b, a%b); }
    static class FastScanner{
	BufferedReader reader;
	StringTokenizer st;
	FastScanner(InputStream stream){reader=new BufferedReader(new InputStreamReader(stream));st=null;}
	String next(){while(st == null || !st.hasMoreTokens()){try{String line = reader.readLine();if(line == null){return null;}
	     st = new StringTokenizer(line);}catch (Exception e){throw new RuntimeException();}}return st.nextToken();}
	String nextLine()  {String s=null;try{s=reader.readLine();}catch(IOException e){e.printStackTrace();}return s;}
	int    nextInt()   {return Integer.parseInt(next());}
	long   nextLong()  {return Long.parseLong(next());}
	double nextDouble(){return Double.parseDouble(next());}
	char   nextChar()  {return next().charAt(0);}
	int[]  nextIntArray(int n)         {int[] arr= new int[n];   int i=0;while(i<n){arr[i++]=nextInt();}  return arr;}
	long[] nextLongArray(int n)        {long[]arr= new long[n];  int i=0;while(i<n){arr[i++]=nextLong();} return arr;}
	int[]  nextIntArrayOneBased(int n) {int[] arr= new int[n+1]; int i=1;while(i<=n){arr[i++]=nextInt();} return arr;}
	long[] nextLongArrayOneBased(int n){long[]arr= new long[n+1];int i=1;while(i<=n){arr[i++]=nextLong();}return arr;}
	void   close(){try{reader.close();}catch(IOException e){e.printStackTrace();}}
    }
    
    /********* SOLUTION STARTS HERE ************/
    
    private static void solve(FastScanner in, PrintWriter out){
        String s = in.next().trim();
        if(s.equals("Sunny")) {out.println("Cloudy");return;}
        if(s.equals("Cloudy")) {out.println("Rainy");return;}
        out.println("Sunny");
    }
    
    /************* SOLUTION ENDS HERE **********/
}

Measured memory_bytes: 19668
#include <cstdio>
#include <string>

using namespace std;

int ans;
int n;
char _query_char[26];
char _target_char[101];

int check(string target, string query) {
    int target_len = target.length();
    int qlen = query.length();
    int maxpos = target_len - qlen;

    for (int pos=0; pos<=maxpos; pos++) {
        int len = target_len-pos;
        int maxspan = (len-1)/(qlen-1);

        for (int span=1; span<=maxspan; span++) {
            int new_pos = pos;
            int n = 0;

            while (n < qlen) {
                if (target[new_pos] != query[n]) break;
                n++;
                new_pos += span;
            }

            if (n == qlen) return 1;
        }
    }

    return 0;
}

int main() {
    string query;
    string target;

    scanf("%d", &n);
    scanf("%s", _query_char);

    query = _query_char;
    for (int i=0; i<n; i++) {
        scanf("%s", _target_char);
        target = _target_char;
        ans += check(target, query);
    }

    printf("%d\n", ans);
}

Measured memory_bytes: 1068
function myin(){return require("fs").readFileSync("/dev/stdin", "utf8").trim();}
function myout(t){console.log(t);}//standard output
function myerr(t){console.log(t);}//standard error
//[no]param
//0:何もしない  1:数値へ変換  2:半角SPで分割  3:改行で分割  4:半角SPで分割し、数値配列へ
//5:改行で分割し、数値配列へ  6:1文字に分割  7:1文字に分割し、数値配列へ
function myconv(i,no){switch(no){case 0:return i;case 1:return parseInt(i);case 2:return i.split(" ");case 3:return i.split("\n");case 4:return i.split(" ").map((a)=>Number(a));case 5:return i.split("\n").map((a)=>Number(a));case 6:return i.split("");case 7:return i.split("").map((a)=>Number(a));}}

function Main(input) {
  input = myconv(input,3);
  //次の地点に対して時間内にユークリッド距離で到達できること,かつ、t差と距離の偶奇が一致すること
  var N = myconv(input[0],1);
  var maeT = 0;
  var maeX = 0;
  var maeY = 0;
  for(var i = 1; i <= N; i++){
    var t = myconv(input[i],4)[0];
    var x = myconv(input[i],4)[1];
    var y = myconv(input[i],4)[2];
    var dt = Math.abs(t - maeT);
    var dx = Math.abs(x - maeX);
    var dy = Math.abs(y - maeY);
    if(dx + dy <= dt && (dx+dy) % 2 == dt % 2){
       maeT = t;
      maeX = x;
      maeY = y;
    }else{
      myout("No");
      return;
    }
  }
  myout("Yes");
}

Main(myin());


Measured memory_bytes: 30284
#!/usr/bin/env python3

def main():
    *I, = map(int, open(0).read().split())
    N = I[0]
    M = I[1]
    A = I[2:]

    if (N - sum(A) >= 0):
        print(N - sum(A))
    else:
        print('-1')


main()

Measured memory_bytes: 10056
N = int(input())
li = []

for i in range(N):
    A = int(input())
    li.append(A)

li2 = sorted(li,reverse=True)
ans = max(li)

for i in range(N):
    if(ans == li[i]):
        print(li2[1])
    else:
        print(ans)
    
        

Measured memory_bytes: 14108
#include <iostream>
#include <climits>

using namespace std;

inline int max (int a, int b) {
    return a > b ? a : b;
}

int main (void) {
    int n, i, j;
    while (1) {
        cin >> n;
        if (n == 0) break;
        int a[n];
        for (i = 0; i < n; i++) {
            cin >> a[i];
        }
        int sum = INT_MIN, s;
        for (i = 0; i < n; i++) {
            s = 0;
            for (j = i; j < n; j++) {
                s += a[j];
                sum = max(sum, s);
            }
        }
        cout << sum << endl;
    }
    return 0;
}

Measured memory_bytes: 1168
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author KharYusuf
 */
public class Main {
    public static void main(String[] args) throws Exception {
        Thread thread = new Thread(null, new TaskAdapter(), "KharYusuf", 1 << 27);
        thread.start();
        thread.join();
    }

    static class TaskAdapter implements Runnable {
        @Override
        public void run() {
            InputStream inputStream = System.in;
            OutputStream outputStream = System.out;
            FastReader in = new FastReader(inputStream);
            PrintWriter out = new PrintWriter(outputStream);
            ALphabet solver = new ALphabet();
            solver.solve(1, in, out);
            out.close();
        }
    }

    static class ALphabet {
        public void solve(int testNumber, FastReader s, PrintWriter w) {
            w.println(s.nextChar() > 'Z' ? 'a' : 'A');
        }

    }

    static class FastReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private FastReader.SpaceCharFilter filter;

        public FastReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {

            if (numChars == -1)
                throw new InputMismatchException();

            if (curChar >= numChars) {

                curChar = 0;

                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }

                if (numChars <= 0)
                    return -1;
            }

            return buf[curChar++];
        }

        public char nextChar() {

            int c = read();

            while (isSpaceChar(c))
                c = read();

            return (char) c;
        }

        public boolean isSpaceChar(int c) {

            if (filter != null)
                return filter.isSpaceChar(c);

            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);

        }

    }
}



Measured memory_bytes: 25628
import math

n,d = [int(_) for _ in input().split()]
x = [0]*n
y = [0]*n
result = 0
for i in range(n):
  x[i],y[i] = [int(_) for _ in input().split()]
  if math.sqrt(x[i]*x[i] + y[i]*y[i]) <= d:
    result += 1


print(result)


Measured memory_bytes: 24552
import sys
import math
from fractions import gcd

input = sys.stdin.readline

def prime(n):
    primes = {}
    bound = int(math.sqrt(n)) + 1
    for i in range(2, bound):
        while n % i == 0:
            n //= i
            if not i in primes.keys():
                primes[i] = 1
            else:
                primes[i] += 1
    if n != 1:
        if n not in primes.keys():
            primes[n] = 1
        else:
            primes[n] += 1
    return primes

A, B = map(int, input().split())
g = gcd(A, B)
cur = prime(g)
print(len(cur) + 1)

Measured memory_bytes: 5052
N = int(input())
answers = []

def cal(already_used, answer):
    if len(answer) == N:
        answers.append(answer)
        return

    if len(already_used) == 0:
        plus_1 = 0
    else:
        plus_1 = max(already_used) + 1

    cur_target = already_used + [plus_1]
    for c in cur_target:
        _answer = answer + str(c)
        if c != plus_1:
            _answer = cal(already_used, _answer)
        else:
            _answer = cal(cur_target, _answer)


cal([], "")
for answer in answers:
    for (num, alp) in zip([0, 1, 2, 3, 4, 5, 6, 7, 8, 9], ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j"]):
        answer = answer.replace(str(num), alp)
    print(answer)

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

int main() {
	int n;
	cin >> n;
	int out = 0;
	for(int a = 1; a <= n; a++){
		out += (n - 1) / a;
	}
	cout << out << endl;
}


Measured memory_bytes: 3620
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
 


a, b, x = MAP()

S = x/a        #水の断面積

if a*b/2 >= S:  #水の断面：三角形
	c = 2*S/b
	ans = degrees(atan(b/c))

else:           #水の断面：台形
	c = 2*S/a - b
	ans = degrees(atan((b-c)/a))

print(ans)


Measured memory_bytes: 5588
#include <bits/stdc++.h>
using namespace std;
const int maxn = 555;
int g[maxn][maxn];
int main(){
  int n, m, q; cin >> n >> m >> q;
  for(int i = 0; i < m; i++){
    int x, y; cin >> x >> y;
    g[x][y]++;
  }
  for(int i = 1; i <= n; i++){
  	for(int j = 0; j <= n; j++){
    	g[j][j+i] += g[j][j+i-1];
      	g[j][j+i] += g[j+1][j+i];
      	g[j][j+i] -= g[j+1][j+i-1];
    }
  }
  for(int i = 0; i < q; i++){
    int x, y; cin >> x >> y;
    cout << g[x][y] << endl;
  }
  return 0;
}

Measured memory_bytes: 2048
# ABC159
# String Palindrome
S = input()
n = len(S)
n
m = int(((n - 1)/2)-1)
l = int(((n + 3)/2)-1)

if S[::1] == S[::-1]:
        if S[:m+1:] == S[m::-1]:
            if S[l::] == S[:l-1:-1]:
                print('Yes')
                exit()
print('No')

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

int main(){
  int N;
  cin >> N;
  map<string,int> M;
  for(int i = 0; i < N; ++i){
    string s;
    cin >> s;
    sort(s.begin(), s.end());
    ++M[s];
  }
  long long ans = 0;
  for(auto e : M){
    long long t = e.second;
    ans += t*(t-1)/2;
  }
  cout << ans << endl;
}


Measured memory_bytes: 11136
import sys
import itertools
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)


def kyori(p1, p2):
    return ((p1[0]-p2[0])**2 + (p1[1]-p2[1])**2) ** 0.5


def main():
    N = int(input())

    seq = [list(map(int, input().split())) for _ in range(N)]
    arr = list(itertools.permutations(seq))
    l = len(arr)

    k = 0
    for x in arr:
        for i in range(N-1):
            k += kyori(x[i], x[i+1])

    print(k / l)


if __name__ == '__main__':
    main()


Measured memory_bytes: 8180
#include<bits/stdc++.h>
using namespace std;
int main(){
	int a[100],b,c=0;
	for(int i=1;i<=100;i++){
		a[i] = 0;
	}
	for(int i=1;i<=3;i++){
		scanf("%d",&b);
		a[b]++;
	}
	for(int i=1;i<=100;i++){
		if(a[i] > 0){
			c++;
		}
	}
	printf("%d",c);
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ls ch[x][0]
#define rs ch[x][1]
#define ll long long
using namespace std;

inline ll read(){
	ll num=0,neg=1;char c=getchar();
	while(!isdigit(c)){if(c=='-')neg=-1;c=getchar();}
	while(isdigit(c)){num=(num<<3)+(num<<1)+c-'0';c=getchar();}
	return num*neg;
}

const ll mod=1e9+7;
ll n,f[1000010][2][2];


int main(){
	n=read();f[0][0][0]=1;
	for(int i=1;i<=n;i++){
		f[i][0][0]=f[i-1][0][0]*8%mod;
		f[i][0][1]=(f[i-1][0][0]+f[i-1][0][1]*9%mod)%mod;
		f[i][1][0]=(f[i-1][0][0]+f[i-1][1][0]*9%mod)%mod;
		f[i][1][1]=(f[i-1][0][1]+f[i-1][1][0]+f[i-1][1][1]*10%mod)%mod;
	}cout<<f[n][1][1];
	return 0;
}


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

typedef long long int ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pii> vii;
typedef unordered_map<int,int> umii;
typedef unordered_map<ll,ll> umll;

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define bs(v,val) binary_search(v.begin(),v.end(),val)
// #define mod (int)1e9+7
#define ff first
#define ss second
#define fi(n) for(int i=0;i<n;i++)
#define fj(n) for(int j=0;j<n;j++)
#define all(v) v.begin(),v.end()
#define pb push_back
#define m_p make_pair
#define endl '\n'

struct custom_hash {    // anti-hack for unordered_map. To declare: unordered_map<long long, int, custom_hash> safe_map;
    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        x ^= FIXED_RANDOM;
        return x ^ (x >> 16);
    }
};

ll power(ll x, ll y, ll p)
{  
    ll res = 1;
    x = x % p;  
    if (x == 0) return 0;
    while (y > 0){  
        if (y & 1)  res = (res*x) % p;  
        y = y>>1;
        x = (x*x) % p;  
    }  
    return res;  
}
ll modInverse(ll n, ll p)
{
    return power(n, p-2, p); 
}
// ********** CODE STARTS HERE ****************//

void solve()
{
    int n;
    cin>>n;
    vii v(n);
    fi(n)cin>>v[i].ff>>v[i].ss;
    int mx1 = INT32_MIN, mn1 = INT32_MAX;
    int mx2=mx1,mn2=mn1;
    for(int i=0;i<n;i++)
    {
        mx1 = max(mx1,v[i].ff+v[i].ss);
        mn1 = min(mn1,v[i].ff+v[i].ss);
        mx2 = max(mx2,v[i].ff-v[i].ss);
        mn2 = min(mn2,v[i].ff-v[i].ss);
        
    }
    cout << max(abs(mx1-mn1),abs(mx2-mn2));

}


int main()
{
	fastio;
    int T;
    // cin>>T;
    // while(T--)
        solve();
	return 0;
}

Measured memory_bytes: 4720
#include <bits/stdc++.h>
using namespace std;
#define forn(i, n) for(int i = 0 ; (i) < (n) ; ++i)
#define forx(i, n) for(int i = 1 ; (i) <= (n) ; ++i)
#define ll long long
#define all(x) (x).begin(),(x).end()
#define sqr(x) (x) * (x)
#define debug(x) cout << #x <<" = " << x << endl
#define printvpair(v) for(auto x : v) cout << x.first  <<" " << x.second << endl;
#define printv(v) for(auto x : v) cout << x << " "; cout << endl;

const int N = 1e5 + 7;
int n,x;
vector<int> v;
int main() {
    cin >> n >> x;

    forn(i,n){
        int y;
        cin >> y;
        v.push_back(abs(y - x));
    }
    
    int ans = v[0];

    for (int i = 1; i < n; ++i) {

        ans = __gcd(ans,v[i]);
    }

    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 892
#include <algorithm>
#include <cassert>
#include <chrono>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
using LL = long long;
#define eps 1e-8
#define fi first
#define se second
#define eb emplace_back
#define close \
    std::ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr)
#define FOR(i, x, y) for (LL i = (x), _##i = (y); i < _##i; ++i)
#define FORD(i, x, y) for (LL i = (x), _##i = (y); i > _##i; --i)
#define SORT_UNIQUE(c)         \
    (sort(c.begin(), c.end()), \
     c.resize(distance(c.begin(), unique(c.begin(), c.end()))))
#define int long long
#define CASET    \
    int ___T;    \
    cin >> ___T; \
    for (int __CS = 1; __CS <= ___T; __CS++)
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
mt19937 dlsrand(random_device{}());
mt19937 mrand(std::chrono::system_clock::now().time_since_epoch().count());
int rnd(int x) { return mrand() % x; }
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
LL bin(LL x, LL n, LL MOD) {
    LL ret = MOD != 1;
    for (x %= MOD; n; n >>= 1, x = x * x % MOD)
        if (n & 1) ret = ret * x % MOD;
    return ret;
}
inline LL get_inv(LL x, LL p) { return bin(x, p - 2, p); }
const double PI = acos(-1.0);
constexpr int maxn = 1e6 + 10, N= 1e6+100;
constexpr int INF = 0x3f3f3f3f;
constexpr ll linf = 0x3f3f3f3f3f3f3f3f;
constexpr int mod = 1e9 + 7;
void add(int &a, int b) {
    a += b;
    if (a >= mod) a -= mod;
}
void dec(int &a, int b) {
    a -= b;
    if (a < 0) a += mod;
}
const LL p_max = 1E5 + 100;
LL phi[p_max];
void get_phi() {
    phi[1] = 1;
    static bool vis[p_max];
    static LL prime[p_max], p_sz, d;
    FOR (i, 2, p_max) {
        if (!vis[i]) {
            prime[p_sz++] = i;
            phi[i] = i - 1;
        }
        for (LL j = 0; j < p_sz && (d = i * prime[j]) < p_max; ++j) {
            vis[d] = 1;
            if (i % prime[j] == 0) {
                phi[d] = phi[i] * prime[j];
                break;
            }
            else phi[d] = phi[i] * (prime[j] - 1);
        }
    }
}
int32_t main() {
    get_phi();
    int n, k;
    cin >> n >> k;
    ll ans = 0;
    for (int i = 1; i <= k; i++) {
        ans += 1ll * phi[i] * bin(k / i, n, mod) % mod;
        ans %= mod;
    }
    cout << ans << endl;
}

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

int main(){
    int a,b,c,d;
    int start,goal;
    cin>>a>>b>>c>>d;
    
    if (a<=c)
        start=c;
    else if(c<a)
        start=a;

    if (d<=b)
        goal=d;
    else if (b<d)
        goal = b;
    
    printf("%d\n",goal-start>=0 ? goal-start:0);
        return 0;
    

}

Measured memory_bytes: 256
using System;

namespace AizuOnLine
{
    class Program
    {
        static void Main(string[] args)
        {

            Console.ReadLine();
            var data = Console.ReadLine().Split(' ');

            int min = 1000000;
            int max = -1000000;
            long sum = 0;

            for (int i = 0; i < data.Length; i++)
            {
                int num = Convert.ToInt32(data[i]);
                sum += num;
                min = Math.Min(min, num);
                max = Math.Max(max, num);
            }

            Console.WriteLine(min + " " + max + " " + sum);

        }
    }
}

Measured memory_bytes: 10052
#include<cstdio>
const int MAXN=2000005,MOD=1000000007;

int PowMod(int a,int b)
{
	int res=1;
	while(b)
	{
		if(b&1)
			res=1LL*res*a%MOD;
		b>>=1;
		a=1LL*a*a%MOD;
	}
	return res;
}

int fac[MAXN],ifac[MAXN];
int X[6],Y[6];

int calc(int x,int y)
{
	return 1LL*fac[x+y]*ifac[x]%MOD*ifac[y]%MOD;
}

int calc1(int x,int y)
{
	int res=0;
	res=(res+calc(x-X[0]+1,y-Y[0]+1))%MOD;
	res=(res+calc(x-X[1],y-Y[1]))%MOD;
	res=(res-calc(x-X[0]+1,y-Y[1])+MOD)%MOD;
	res=(res-calc(x-X[1],y-Y[0]+1)+MOD)%MOD;
	return res;
}
int calc2(int x,int y)
{
	int res=0;
	res=(res+calc(X[5]-x+1,Y[5]-y+1))%MOD;
	res=(res+calc(X[4]-x,Y[4]-y))%MOD;
	res=(res-calc(X[5]-x+1,Y[4]-y)+MOD)%MOD;
	res=(res-calc(X[4]-x,Y[5]-y+1)+MOD)%MOD;
	return res;
}

int main()
{
	fac[0]=1;
	for(int i=1;i<MAXN;i++)
		fac[i]=1LL*fac[i-1]*i%MOD;
	ifac[MAXN-1]=PowMod(fac[MAXN-1],MOD-2);
	for(int i=MAXN-2;i>=0;i--)
		ifac[i]=1LL*ifac[i+1]*(i+1)%MOD;
	
	for(int i=0;i<6;i++)
		scanf("%d",&X[i]);
	for(int i=0;i<6;i++)
		scanf("%d",&Y[i]);
	
	int ans=0;
	for(int i=X[2];i<=X[3];i++)
	{
		ans=(ans+(MOD-1LL*(i+Y[2])*calc1(i,Y[2]-1)%MOD*calc2(i,Y[2])%MOD)%MOD)%MOD;
		ans=(ans+1LL*(i+Y[3]+1)*calc1(i,Y[3])%MOD*calc2(i,Y[3]+1)%MOD)%MOD;
	}
	for(int i=Y[2];i<=Y[3];i++)
	{
		ans=(ans+(MOD-1LL*(i+X[2])*calc1(X[2]-1,i)%MOD*calc2(X[2],i)%MOD)%MOD)%MOD;
		ans=(ans+1LL*(i+X[3]+1)*calc1(X[3],i)%MOD*calc2(X[3]+1,i)%MOD)%MOD;
	}
	printf("%d\n",ans);
	
	return 0;
}


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

int main() {
  string weather;
  cin >> weather;
  
  if(weather == "Sunny"){
     cout << "Cloudy" << endl;
  }else if(weather == "Cloudy"){
    cout << "Rainy" << endl;
  }else if(weather == "Rainy"){
    cout << "Sunny" << endl;
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <chrono>
#include <random>
#define ll long long int
#define ull unsigned long long int
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define rep(i,n) for(ll i=0;i<n;i++)
#define loop(i,a,b) for(ll i=a;i<=b;i++)
#define inputv(arr,n) for(ll i=0;i<n;i++){ll value;cin>>value;arr.pb(value);}
#define sz(a) ((ll)(a).size())
#define len(a) ((ll)(a).length())
#define precise cout<<fixed<<setprecision(0); 
#define F first
#define S second
#define vi vector <int> 
#define pll pair<ll,ll>
#define vpll vector<pll>
#define vs vector <string>
#define vc vector <char>
#define vl vector <ll>
#define YES cout<<"Yes\n"
#define NO cout<<"No\n"
#define all(c) (c).begin(),(c).end()
#define max3(a,b,c) max(max(a,b),c)
#define min3(a,b,c) min(min(a,b),c)
#define IOS { ios :: sync_with_stdio(false); cin.tie(0); cout.tie(0); }
inline ll max(ll a,ll b)
{return ((a>b)?a:b);}
inline ll min(ll a,ll b)
{return ((a>b)?b:a);}
inline ll gcd(ll a ,ll b)
{if(b==0) return a;a%=b;return gcd(b,a);}
#define nl cout<<"\n"
using namespace std;
ll power(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll modInverse(ll a){return power(a,mod-2);}
const int N=500023;
// hashing for pairs
struct HASH{
  size_t operator()(const pair<int,int>&x)const{
    return hash<long long>()(((long long)x.first)^(((long long)x.second)<<32));
  }
};
//sort in reverse order
bool compare(ll x, ll y){
    return x>y;
}
bool poss(ll mid,vl arr,ll k)
{
  ll val=0;
  rep(i,sz(arr))
  {
    val+=((arr[i]-1)/mid);
  }
 // cout<<" for ans : "<<mid<<" we have "<<val<<" cuts";nl;
  if(val<=k)
  {
    return 1;
  }
  else
  {
    return 0;
  }
  
}
void solve()
{
  ll n,k;
  cin>>n>>k;
  vl arr;
  inputv(arr,n);
  ll l=1,r=(ll)1e9+100;
  while (l!=r)
  {
    ll  mid = (l+r)/2;
   // cout<<"check for "<<l<<" "<<r;
    if(poss(mid,arr,k))
    {
      r=mid;
    }
    else
    {
      l=mid+1;
    }
    
  }
  cout<<l;nl;
  return;
}
int main()
{
    IOS;
    int T=1;
  //  cin>>T;
    int t=0;
    while(t++<T)
    {
        //cout<<"Case #"<<t<<":"<<' ';
        solve();
        //cout<<'\n';
    }
    cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
}

Measured memory_bytes: 6324
#include<stdio.h>

#define N 101


int MAX = (1<<21), fir = 0, time = 1, thi = 2, n, A[N][N], num[N], d[N], f[N], count;



void deps(int x){

  int i;

  num[x] = time;

  count++;

  d[x] = count;

  for ( i = 0; i < n; i++ )
    {

      if ( A[x][i] == 0 )
	{
	  continue;
	}
      
      if ( num[i] == fir )
	{

	  deps(i);

	}
    }

  num[x] = thi;

  f[x] = ++count;

}

void dfs(){

  int i, x;

  for ( i = 0; i < n; i++ )
    {
      num[i] = fir;
    }
  
  count = 0;

  for ( x = 0; x < n; x++ ){

    if ( num[x] == fir ) deps(x);

  }

  for ( i = 0; i < n; i++ ){

    printf("%d %d %d\n", i+1, d[i], f[i]);

  }

}

int main(){
  
  int x, y, z, i, j;

  scanf("%d", &n);

  for ( i = 0; i <n; i++ )
    {
      for ( j = 0; j <n; j++ )
	{
	  A[i][j] = 0;
	}
    }
  
  for ( i = 0; i < n; i++ )
    {
      scanf("%d %d", &x, &y);
     
      for ( j = 0; j < y; j++ )
	{
	  scanf("%d", &z);

	  A[x-1][z-1] = 1;
	}
    }
  
  dfs();

  return 0;
}

Measured memory_bytes: 636
import os
import sys

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

S = sys.stdin.readline().rstrip()
K = int(sys.stdin.readline())

s = set()
for k in range(1, K + 1):
    for i in range(len(S)):
        s.add(S[i:i + k])

s = list(sorted(list(s)))
print(s[K - 1])


Measured memory_bytes: 39280
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <math.h>
#include <numeric>
#include <complex>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <bitset>
#include <functional>
#include <assert.h>
using ll=long long;
#define int ll
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define eb emplace_back
#define all(x) x.begin(),x.end()
#define SZ(x) ((int)x.size())
#define fi first
#define se second
const int INF = 1e15;
using namespace std;

template<class T> using vc=vector<T>;
template<class T> using vvc=vc<vc<T>>;

using pi=pair<int,int>;
using vi=vc<int>;

template<class T>
inline bool chmax(T &a,T b){if(a<b){a=b;return true;}return false;}
template<class T>
inline bool chmin(T &a,T b){if(a>b){a=b;return true;}return false;}

vi ans;
void dfs(vvc<int> &G,vi &dp,vi &A,int pre,int v){
    auto pos=lower_bound(all(dp),A[v]);
    int save=*pos;
    *pos=A[v];
    ans[v]=lower_bound(all(dp),INF)-dp.begin();
    for(auto a:G[v]){
        if(a==pre) continue;
        dfs(G,dp,A,v,a);
    }
    *pos=save;
}
signed main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout<<fixed<<setprecision(20);

    int N; cin >> N;
    ans.resize(N+10);
    vi A(N+10);
    rep(i,N) cin >> A[i];
    vvc<int> G(N);
    rep(i,N-1){
        int a,b; cin >> a >> b;
        a--; b--;
        G[a].eb(b);
        G[b].eb(a);
    }
    vi dp(N,INF);
    dfs(G,dp,A,-1,0);
    rep(i,N) cout << ans[i] << "\n";
}

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

const int inf = 1e9;
const ll linf = 1e18;

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

    string a, b; cin >> a >> b;
    int x = stoi(a + b);
    for (int i = 1; i < 500; i++) {
        if (i * i == x) {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, K;
  cin >> N >> K;
  int x,sum;
  
  for(int i = 0;i < N;i++){
  cin >> x;
    if(K-x >= x)
    sum += 2 * x;
    else
      sum += 2 * (K - x);  
  }
  cout << sum << endl;
 
  // ここにプログラムを追記
  
}

Measured memory_bytes: 256
def rgb(s):
    if s=="R":return 0
    if s=="G":return 1
    if s=="B":return 2
def rgb2(s,t):
    if (s=="R" and t =="G" ) or (t=="R" and s =="G" ):
        return 2
    elif (s=="R" and t =="B" ) or (s=="B" and t =="R" ):
        return 1
    else:return 0


n = int(input())
s = input()
co = [[0]*3 for i in range(n+1)]
for i in range(1,n+1):
    for j in range(3):
        co[i][j] = co[i-1][j]
    co[i][rgb(s[i-1])] = co[i-1][rgb(s[i-1])] + 1
ans = 0
for i in range(n):
    w1 = s[i]
    for j in range(i+1,n):
        w2 = s[j]
        d = j-i
        if w1!=w2:
            ans += co[-1][rgb2(w1,w2)] - co[j][rgb2(w1,w2)]
            if j+d <= n-1:
                if rgb(s[j+d]) == rgb2(w1,w2):
                    ans-=1
print(ans)


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

#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++)
#define DEBUGP(val) cerr << #val << "=" << val << "\n"

using namespace std;
typedef long long int ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int, int> PI;
const ll mod = 1e9 + 7;



int main(void) {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  while (cin >> n && n) {
    n /= 4;
    int tot = 0;
    REP(i, 0, n) {
      int x;
      cin >> x;
      tot += x;
    }
    cout << tot << endl;
  }
}



Measured memory_bytes: 3112
#include<cstdio>
using namespace std;
int N,K,ans;
int main()
{
	scanf("%d %d",&N,&K);
	for(int i=1,a;i<=N;i++)
	scanf("%d",&a);
	if((N-1)%(K-1)==0)
	ans=(N-1)/(K-1);
	else
	ans=(N-1)/(K-1)+1;
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 128
//be name khoda

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

#define pii pair<int, int>
#define mp make_pair
#define REP(i, n) for(int i = 0; i < (int)(n); i++)

typedef long long ll;

const int N = 1;

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	string s;
	cin >> s;
	int cnt = 0;
	for(int i = 0; i < 6; i++)
		cnt += s[i] == '1';
	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define inf 2333333333333333
#define N 1000010
#define p(a) putchar(a)
#define For(i,a,b) for(long long i=a;i<=b;++i)

using namespace std;
long long n;
long long ans[N],a[N];
void in(long long &x){
    long long y=1;char c=getchar();x=0;
    while(c<'0'||c>'9'){if(c=='-')y=-1;c=getchar();}
    while(c<='9'&&c>='0'){ x=(x<<1)+(x<<3)+c-'0';c=getchar();}
    x*=y;
}
void o(long long x){
    if(x<0){p('-');x=-x;}
    if(x>9)o(x/10);
    p(x%10+'0');
}

signed main(){
    in(n);
    For(i,1,n) in(a[i]);
    For(i,1,n){
    	ans[a[i]]=i;
    }
    For(i,1,n) o(ans[i]),p(' ');

    return 0;
}

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

using namespace std;

int N;

long long int A[200005], B[200005];

vector<pair<long long int, long long int> > V;

int main(void) {

	cin >> N;

	for (int i = 1; i <= N; i++) {
		cin >> A[i] >> B[i];
		V.push_back(make_pair(B[i], A[i]));
	}

	sort(V.begin(), V.end());

	
	int sign = 1;

	long long int tm = 0;

	for (int i = 0; i <= N-1; i++) {
		long long int sub = V[i].first - V[i].second;
		if (tm <= sub) { tm += V[i].second; }
		else { sign = -1; }
	}

	if (sign == -1) { cout << "No" << endl; }
	else { cout << "Yes" << endl; }


	return 0;
}

Measured memory_bytes: 8560
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;

class TEST{
	static void Main(){
		Sol mySol =new Sol();
		mySol.Solve();
	}
}

class Sol{
	public void Solve(){
		
		while(true){
			int N=ri();
			if(N==0)return;
			
			bool[][] B=new bool[100][];
			for(int i=0;i<100;i++){
				B[i]=new bool[100];
			}
			int ofs=50;
			
			for(int i=0;i<N;i++){
				var d=ria();
				B[d[1]+ofs][d[0]+ofs]=true;
			}
			
			int M=ri();
			int r=10+ofs;
			int c=10+ofs;
			int cnt=0;
			for(int i=0;i<M;i++){
				var ss=rsa();
				int dx=0;
				int dy=0;
				switch(ss[0][0]){
					case 'N':dx=0;dy=1;break;
					case 'E':dx=1;dy=0;break;
					case 'W':dx=-1;dy=0;break;
					case 'S':dx=0;dy=-1;break;
				}
				int rep=int.Parse(ss[1]);
				for(int j=0;j<rep;j++){
					r+=dy;c+=dx;
					if(B[r][c]){
						cnt++;
						B[r][c]=false;
					}
				}
			}
			Console.WriteLine(cnt==N?"Yes":"No");
		}
	}

	public Sol(){
	}

	static String rs(){return Console.ReadLine();}
	static int ri(){return int.Parse(Console.ReadLine());}
	static long rl(){return long.Parse(Console.ReadLine());}
	static double rd(){return double.Parse(Console.ReadLine());}
	static String[] rsa(){return Console.ReadLine().Split(' ');}
	static int[] ria(){return Array.ConvertAll(Console.ReadLine().Split(' '),e=>int.Parse(e));}
	static long[] rla(){return Array.ConvertAll(Console.ReadLine().Split(' '),e=>long.Parse(e));}
	static double[] rda(){return Array.ConvertAll(Console.ReadLine().Split(' '),e=>double.Parse(e));}
}

Measured memory_bytes: 9168
package main

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

func main() {
	sc.Split(bufio.ScanWords)
	N := nextInt()
	M := nextInt()
	ballCounts := make([]int, N)
	for i := 0; i < N; i++ {
		ballCounts[i] = 1
	}
	redCance := make([]bool, N)
	redCance[0] = true
	for i := 0; i < M; i++ {
		x := nextInt()
		y := nextInt()
		x -= 1
		y -= 1
		ballCounts[x]--
		ballCounts[y]++
		redCance[y] = redCance[x] || redCance[y]
		if ballCounts[x] == 0 {
			redCance[x] = false
		}
	}

	ans := 0
	for i := 0; i < N; i++ {
		if redCance[i] {
			ans++
		}
	}
	fmt.Println(ans)
}

var sc = bufio.NewScanner(os.Stdin)

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

func nextInt() int {
	i, _ := strconv.Atoi(nextLine())
	return i
}


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

int main(){
    int H;
    cin >> H;
    vector<int> heap(H + 1);

    for (int i = 1; i < H + 1; i++) {
        cin >> heap[i];
    }

    for (int i = 1; i < H + 1; i++) {
        cout << "node " << i << ": key = " << heap[i] << ", ";
        if (i / 2) {
            cout << "parent key = " << heap[i/2] << ", ";
        }
        if (i * 2 <= H) {
            cout << "left key = " << heap[i*2] << ", ";
        }
        if (i * 2 + 1 <= H) {
            cout << "right key = " << heap[i*2+1] << ", ";
        }
        cout << endl;
    }


    return 0;
}

Measured memory_bytes: 3096
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 2e5 + 5, mod = 1e9 + 7;


int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int n;
    cin >> n;
    cout << (n + 1) / 2;



    return 0;
}


Measured memory_bytes: 3628
N = int(input())
T = [int(input()) for i in range(N)]

def gcd(x, y):
    if y == 0:
        return x
    else:
        return gcd(y, x % y)

def lcm(x, y):
    return (x * y) // gcd(x, y)

x = T[0]
for i in range(N-1):
    x = lcm(x, T[i+1])

print(x)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define MOD 1000000007
#define INF 1061109567
#define pb push_back
#define in(s) freopen(s,"r",stdin);
#define out(s) freopen(s,"w",stdout);
#define fi first
#define se second
#define bw(i,r,l) for (int i=r-1;i>=l;i--)
#define fw(i,l,r) for (int i=l;i<r;i++)
#define fa(i,x) for (auto i:x)
using namespace std;
string s;
int cnt=0,win=0;
signed main() {
	//in("aome.inp");
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	cin>>s;
	fa (i,s) {
		if (i=='g') {
			if (!cnt) cnt++;
			else win++,cnt--;
		} else {
			if (!cnt) win--,cnt++;
			else cnt--;
		}
	}
	cout<<win;
	return 0;
}

Measured memory_bytes: 512
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		long x[] = new long[n], y[] = new long[n];
		
		for(int i=0;i<n;i++){
			x[i] = sc.nextLong();
			y[i] = sc.nextLong();
		}
		
		long parity = Math.abs((x[0] + y[0]) % 2);
		
		boolean f = true;
		for(int i=1;i<n;i++){
			if(Math.abs((x[i]+y[i])%2) != parity)
				f = false;
		}
		
		if(f){
			long a[] = new long[31];
			
			a[0] = 1;
			for(int i=1;i<31;i++){
				a[i] = a[i-1]*2;
			}
			
			
			if(parity==0){
				System.out.println(32);
				System.out.print(1+" ");
			}
			else{
				System.out.println(31);
			}
			
			for(int i=30;i>=0;i--){
				System.out.print(i==30 ? a[i]:" "+a[i]);
			}
			System.out.println();
			
			
			for(int i=0;i<n;i++){
				if(parity==0){
					if(Math.abs(x[i]-1) + Math.abs(y[i]) <= (1L<<31) -1){
						x[i] -= 1;
						System.out.print("R");
					}
					else if(Math.abs(x[i]+1) + Math.abs(y[i]) <= (1L<<31) -1){
						x[i] += 1;
						System.out.print("L");
					}
					else if(Math.abs(x[i]) + Math.abs(y[i]-1) <= (1L<<31) -1){
						y[i] -=1;
						System.out.print("U");
					}
					else{
						y[i]+=1;
						System.out.print("D");
					}
				}
				
				
				for(int j=30;j>=0;j--){
					
					if(Math.abs(x[i]-a[j]) + Math.abs(y[i]) <= (1L<<j) -1){
						x[i] -= a[j];
						System.out.print("R");
					}
					else if(Math.abs(x[i]+a[j]) + Math.abs(y[i]) <= (1L<<j) -1){
						x[i] += a[j];
						System.out.print("L");
					}
					else if(Math.abs(x[i]) + Math.abs(y[i]-a[j]) <= (1L<<j) -1){
						y[i] -= a[j];
						System.out.print("U");
					}
					else{
						y[i] += a[j];
						System.out.print("D");
					}
				}
				System.out.println();
			}
			
		}
		else{
			System.out.println(-1);
		}
	}

}


Measured memory_bytes: 29428
use std::cmp::*;
use std::io::*;

fn main() {
    let mut s: String = String::new();
    std::io::stdin().read_to_string(&mut s).ok();
    let mut itr = s.trim().split_whitespace();
    let n: usize = itr.next().unwrap().parse().unwrap();
    let mut m: usize = itr.next().unwrap().parse().unwrap();
    let mut a: Vec<(usize, usize)> = (0..n)
        .map(|_| {
            (
                itr.next().unwrap().parse().unwrap(),
                itr.next().unwrap().parse().unwrap(),
            )
        })
        .collect();
    a.sort();

    let mut ans = 0;
    for i in 0..n {
        let num = min(a[i].1, m);
        ans += num * a[i].0;
        m -= num;
        if m == 0 {
            break;
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 5792
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <iomanip>
#include <map>
#include <set>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <iterator>
#include <string>
#include <limits>

using namespace std;

using i64 = int64_t;
using P = pair<i64, i64>;
//i64 mod = 1000000007;
i64 mod = 998244353;
int int_max = 2147483647;
i64 INF = 1e16;
int max_n = 1e5;

int main(int argc, char **argv) {
    i64 t;
    cin >> t;

    for (int ti=0; ti<t; ++ti) {
        i64 n;
        cin >> n;
        std::vector<i64> a(n);
        std::vector<i64> xo = {0};
        for (int i=0; i<n; ++i) {
            cin >> a[i];
        }
        string s;
        cin >> s;

        bool res{true};

        for (int i=n-1; i >= 0; --i) {
            i64 num = a[i];
            for (i64 v : xo) num = min(num, num ^ v);
            if (num) {
                if (s[i] == '0') {
                    xo.push_back(num);
                } else {
                    res = false;
                    break;
                }
            }
        }
        cout << (res ? '0' : '1') << endl;
    }

    return 0;
}

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

int main(){
  int a,b,c;
  cin >> a;
  cin >> b;
  cin >> c;
  
  bool is575 = (a+b+c == 5+7+5) && (a*b+b*c+c*a == 5*7 + 7*5 + 5*5) && (a*b*c == 5*7*5);
  if (is575){
    cout << "YES";
  }else{
    cout << "NO";
  }
  
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define INF (1<<30)
#define MOD 1000000007
#define l_ength size
using ll = long long;
using namespace std;
typedef pair<int, int> pii;

int main(){
	int h, w;
	cin >> h >> w;
	char feld[h][w];
	for( int i = 0; i < h; ++i ){
		string temp;
		cin >> temp;
		for( int j = 0; j < w; ++j){
			feld[i][j] = temp[j];
		}
	}
	
	vector<pii> bw = {pii(-1, 0), pii(1, 0), pii(0, -1), pii(0, 1), pii(1, 1), pii(1, -1), pii(-1, 1), pii(-1, -1)};
	for( int i = 0; i < h; ++i ){
		for( int j = 0; j < w; ++j){
			if( feld[i][j] == '.' ){
				int cnt = 0;
				for( auto d : bw ){
					int crx = i + d.first;
					int cry = j + d.second;
					if( 0 <= crx && crx < h && 0 <= cry && cry < w && feld[crx][cry] == '#' ){
						++cnt;
					}
				}
				feld[i][j] = '0' + cnt;
			}
		}
	}
	
	for( int i = 0; i < h; ++i ){
		for( int j = 0; j < w; ++j){
			cout << feld[i][j]; 
		}
		cout << endl;
	}
	
	return 0;
}

Measured memory_bytes: 256
import sys

n, k = map(int, input().split())
A = list(map(int, input().split()))

route = [1]
appearance = set()
index = 1
cnt = 0
flg = False
for _ in range(k):
    if index in appearance:
        flg = True
        break
    appearance.add(index)
    cnt += 1
    next_city = A[index - 1]
    route.append(next_city)
    index = next_city

if flg is False:
    print(route[k])
    sys.exit()

# 繰り返し個数
duplicate = route[route.index(index):len(route) - 1]
print(duplicate[(k - cnt) % (len(duplicate))])
# print(duplicate)
# print(route)


Measured memory_bytes: 32376
from fractions import gcd
from datetime import date, timedelta
from heapq import*
import math
from collections import defaultdict, Counter, deque
import sys
from bisect import *
import itertools
import copy
sys.setrecursionlimit(10 ** 7)
MOD = 10 ** 9 + 7


def main():
    n = int(input())
    a = list(map(int, input().split()))
    ans = float("inf")
    su = sum(a)
    s = 0
    for i in range(n):
        s += a[i]
        su -= a[i]
        ans = min(ans, abs(s - su))
    print(ans)
    
                    


if __name__ == '__main__':
    main()


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

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

	int n, a[100005], dp[100005];
	cin >> n;
	memset(a, 0, sizeof(a));
	memset(dp, 0, sizeof(dp));
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
	}
	dp[2] = abs(a[2] - a[1]);
	for (int i = 3; i <= n; i++) {
		dp[i] = min(dp[i-1] + abs(a[i] - a[i-1]), dp[i-2] + abs(a[i] - a[i-2]));
	}
	cout << dp[n];
}

Measured memory_bytes: 1024
import java.util.*;
 
class Main{
  public static void main (String[] args){
    Scanner sc = new Scanner(System.in);
    long N = sc.nextLong();
    String ans = "YES";
    Set<Integer> A = new HashSet<>();
    for(int i = 0; i < N; i++){
      A.add(sc.nextInt());
    }
    if(A.size() != N){
      ans = "NO";
    }    
    System.out.println(ans);
    }
}
    
    

Measured memory_bytes: 69352
#include <stdio.h>

int main(){
    char str[1500];
    for (int i = 0; i < 1500; i++){
        str[i] = '\0';
    }
    fgets(str, sizeof(str), stdin);
    for (int i = 0; str[i] != '\0'; i++){
        if (str[i] >= 'A' && str[i] <= 'Z'){
            str[i] += 'a' - 'A';
        }
        else if (str[i] >= 'a' && str[i] <= 'z'){
            str[i] -= 'a' - 'A';
        }
    }
    printf("%s", str);
    return 0;
}


Measured memory_bytes: 2044
#include<iostream>
#include<vector>
#include<set>
#include<algorithm>
#include<string>
#include<iomanip>
#include <queue>

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define MOD 1000000007
#define MAXS(x,y) (x = max(x,y))
#define MINS(x,y) (x = min(x,y))

using namespace std;

typedef long long int ll;

const ll INF=(ll)1e18;

ll f[100001];
int N, K;

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

  priority_queue<int, vector<int>, greater<int> > pq;

  vector<pair<int, int> > td;
  set<int> s;

  REP(i,N){
    ll t,d;
    cin >> t >> d;
    td.push_back(make_pair(d,t));
  }
  sort(td.begin(), td.end(), greater<pair<int, int> >());

  ll ans = 0;
  REP(i,K){
    ans += td[i].first;
    if(s.find(td[i].second) == s.end()){
      s.insert(td[i].second);
    }else{
      pq.push(td[i].first);
    }
  }

  ll f = ans;
  ans = ans + s.size() * s.size();

  FOR(i,K,N){
    if(pq.empty())break;
    if(s.count(td[i].second))continue;
    s.insert(td[i].second);
    f -= pq.top(); pq.pop();
    f += td[i].first;
    ans = max(ans, (ll)(f + s.size() * s.size()));
  }
  cout << ans << endl;


}

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

int main(){
    int k, m, i, s;
    int a[3];
    cin >> a[0] >> a[1] >> a[2] >> k;
    sort(a, a+3);
    s = a[2];
    for(i=0; i<k; i++){
        s *= 2;
    }
    s += a[0] + a[1];
    cout << s;
    return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
k = int(input())
if k % 2 < 1 or k % 5 < 1:
    print(-1)
else:
    c = 1
    mod = 7 % k
    mop = 7 % k
    while mod > 0:
        mop = mop*10%k
        mod += mop
        mod %= k
        c += 1
    print(c)


Measured memory_bytes: 63232
/* BISMILLAHIR RAHMANIR RAHIM */
#include<bits/stdc++.h>
#define fast ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define s(v)       sort(v.begin(),v.end())
#define r(v)       reverse(v.begin(),v.end())
#define pf         printf
#define sf         scanf
#define GCD(x,y)   __gcd(x, y)
#define pb         push_back
#define ll         long long
#define vs         v.size()
#define ss         s.size()

using namespace std;
int main()
{
    string s;
    cin>>s;
    int sum=0;
    for(int i=0;i<s.size();i++)
    {
        sum+=s[i]-'0';
    }
    if(sum%9==0 || sum==0) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}


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

using namespace std;

/*

        Bismillahir Rahmanir Rahim
        Problem :
        Problem Link :
        Topics :
        Solver : Masud Parves
        I Love Code More than Sharks Love Blood <3
*/


#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define SZ(a)           (int)a.size()
#define all(a)  a.begin(), a.end()
#define allr(a)  a.rbegin(), a.rend()


#define sf(a)           scanf("%d",&a)
#define sff(a,b)        scanf("d",&a,&b)
#define sfff(a,b,c)     scanf("d%d",&a,&b,&c)

#define f0(i,b) for(int i=0;i<(b);i++)
#define f1(i,b) for(int i=1;i<=(b);i++)
#define f2(i,a,b) for(int i=(a);i<=(b);i++)
#define fr(i,b,a) for(int i=(b);i>=(a);i--)

#define CIN ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
#define TEST_CASE(t) for(int z=1 ; z<=t ; z++)
#define PRINT_CASE printf("Case %d: ",z)
#define Debug(x)            cout<<#x " = "<<(x)<<endl
#define NOT_VISITED 0
#define IS_VISITED 1
#define WHITE 0
#define GRAY 1
#define BLACK 2



int fx[4]= {1,-1,0,0};
int fy[4]= {0,0,1,-1};

/*-----------------------Bitmask------------------*/
//int Set(int N,int pos){return N=N  (1<<pos);}
//int Reset(int N,int pos){return N= N & ~(1<<pos);}
//bool Check(int N,int pos){return (bool)(N & (1<<pos));}
/*------------------------------------------------*/


const double PI = acos(-1.0);
const double EPS = 1e-6;
const int MOD = (int)1e9+7;
const int maxn = (int)1000+5;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef pair<ll, int> plli;
typedef pair<int, ll> pill;
char box[maxn][maxn];
ll DP[maxn][maxn];
int h,w;

ll cal(int i,int j){

    if(i==h && j==w) return 1;
    if(i>h || j>w) return 0;
    if(i>h && j>w) return 0;
    if(box[i][j]=='#') return 0;

    ll &res=DP[i][j];

    if(res!=-1) return res;

    ll res0=0,res1=0;

    res0=cal(i+1,j)%MOD;
    res1=cal(i,j+1)%MOD;
    res=(res0+res1)%MOD;
    return res;

}


int main() {
    CIN
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);


    cin>>h>>w;


    for(int i=1 ; i<=h ; i++){
        for(int j=1 ; j<=w ; j++){
            cin>>box[i][j];
        }
    }

    memset(DP , -1, sizeof(DP));

    cout<<cal(1,1)<<endl;




//    for(int i=1 ; i<=h ; i++){
//        for(int j=1 ; j<=w ; j++){
//            cout<<box[i][j];
//        }
//        cout<<endl;
//    }

    return 0;
}



Measured memory_bytes: 9216