akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;

#ifdef DBG
void debug_(){ cout << endl; }
template<typename T, typename... Args>
void debug_(T&& x, Args&&... xs){
	cout << x << " "; debug_(forward<Args>(xs)...);
}
#define dbg(...) debug_(__VA_ARGS__);
#else
#define dbg(...) 
#endif

int main() {
	ios_base::sync_with_stdio(false);
	int N, K;
	cin >> N >> K;
	vector<bool> have(N);
	for(int i=0; i<K; i++){
		int d;
		cin >> d;
		for(int j=0; j<d; j++){
			int a;
			cin >> a;
			have[a-1] = true;
		}
	}

	int ans = 0;
	for(int i=0; i<N; i++){
		if(!have[i]) ans++;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3620
n = int(input())
answer = 0

def gcd(i, j):
    while j:
        i, j = j, i % j
    return i

for a in range(1,n+1):
    for b in range(1,n+1):
        d = gcd(a,b)
        for c in range(1, n+1):
            answer += gcd(c, d)
print(answer)

Measured memory_bytes: 9140
N = int(input())
Nums = input().split()

AA = set(Nums)

if '0' in AA:
  print(0)
else:
  A = 1
  for i in range(N):
    A*=int(Nums[i])
    if A > 10**18:
      A = -1
      break
  print(A)

Measured memory_bytes: 24112
#include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctype.h>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>

using namespace std;

#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i, n) REP(i, 0, n)
#define lengthof(x) (sizeof(x) / sizeof(*(x)))
#define FILL(ptr, value) FILL_((ptr), sizeof(ptr)/sizeof(value), (value))
template <typename T>
void FILL_(void * ptr, size_t size, T value){
  std::fill((T*)ptr, (T*)ptr+size, value);
}
//4方向ベクトル→↑←↓
int dx[] ={1,0,-1,0};
int dy[] ={0,-1,0,1};
int dp[10010];
int main()
{
  int n;
  dp[0] = 1;
  for(int i = 1;i < 10010;i++){
    dp[i] =dp[i-1]+i;
  }
  while(cin>>n){
    cout <<dp[n]<<endl;
  }
  return 0;
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<pair<int,int>> vpii;

#define F first
#define S second
#define PU push
#define PUF push_front
#define PUB push_back
#define PO pop
#define POF pop_front
#define POB pop_back

#define REP(i,a,b) for(int i=a; i<=b; i++)

void solve(int test_case) {
	int n;
	cin>>n;
	ll sol = n;
	while(--n){
		sol = (sol*n)%(ll)(1e9+7);
	}
	cout<<sol;
}

int main() {
	
	////// FILE BASED IO////
	//freopen("in", "r", stdin);
	//freopen("out", "w", stdout);
	///////////////
	
	ios::sync_with_stdio(0);
	cin.tie(0);
	int t=1;
	//cin>>t;
	REP(i,1,t) {
		solve(i);
	}
}	


Measured memory_bytes: 3572
n,m,l = map(int,input().split())
A = list()
B = list()
for i in range(n):
    A.append(list(map(int,input().split())))
for i in range(m):
    B.append(list(map(int,input().split())))
for i in range(n):
    C = list()
    for j in range(l):
        sum = 0
        for k in range(m):
            sum += A[i][k] * B[k][j]
        C.append(sum)
    print(" ".join(list(map(str,C))))



Measured memory_bytes: 6248
#include<bits/stdc++.h>
using namespace std;
void print(int arr[],int n)
{
    int i;
    for(i=0;i<n-1;i++)
        printf("%d ",arr[i]);
    printf("%d\n",arr[i]);
}
int main()
{
    int n,cnt=0;
    scanf("%d",&n);
    int arr[n+1];
    for(int i=0;i<n;i++)
        scanf("%d",&arr[i]);
    for(int i = 0; i < n; ++i)
        for(int j = 0, m = n - i - 1; j < m; ++j)
            if(arr[j] > arr[j + 1])
            {
                swap(arr[j], arr[j + 1]);
                cnt++;
            }
    print(arr,n);
    printf("%d\n",cnt);
    return 0;
}



Measured memory_bytes: 3196
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;

const int MAXN=1e5+5;

int n,m;
bool vis[MAXN];
int head[MAXN],ecnt;
struct edge{
    int v,nxt;
}E[MAXN*2];
int deq[MAXN*2],l,r;

void addedge(int u,int v){
    E[++ecnt]=(edge){v,head[u]};
    head[u]=ecnt;
}

int check(int u){
    for(int i=head[u];i;i=E[i].nxt){
        int v=E[i].v;
        if(!vis[v]) return v;
    }
    return -1;
}

int main(){

    scanf("%d%d",&n,&m);
    l=n,r=n+1;
    for(int i=1;i<=m;i++){
        int u,v;
        scanf("%d%d",&u,&v);
        addedge(u,v);
        addedge(v,u);
        if(i==1){
            deq[l]=u;
            deq[r]=v;
            vis[u]=vis[v]=1;
        }
    }
    while(1){
        int u=check(deq[l]);
        if(u==-1) break;
        else deq[--l]=u,vis[u]=1;
    }
    while(1){
        int u=check(deq[r]);
        if(u==-1) break;
        else deq[++r]=u,vis[u]=1;
    }
    printf("%d\n",r-l+1);
    for(int i=l;i<=r;i++)
        printf("%d ",deq[i]);


    fclose(stdin);
    fclose(stdout);
}


Measured memory_bytes: 3072
from collections import deque

N,M = map(int,input().split())
AB = [list(map(int,input().split())) for _ in range(M)]

line = [[] for _ in range(N+1)]
flag = True
ans = [0] * (N+1)

for A,B in AB:
    line[A].append(B)
    line[B].append(A)

def bfs(now):
    que = deque()
    que.append(now)
    while que.__len__() != 0:
        now = que.popleft()
        for ne in line[now]:
            if ans[ne] != 0:
                continue
            ans[ne] = now
            que.append(ne)

bfs(1)
if 0 in ans[2:]:
    print('No')
else:
    print('Yes')
    print("\n".join(str(i) for i in ans[2:]))

Measured memory_bytes: 65656
#include<iostream>
#include<cmath>
using namespace std;
int main()
{
    long long N,K,a,b;
    cin>>N>>K;
    if(N%K==0)
    {
        cout<<0<<endl;
    }
    else
    {
         a=N%K;
         b=abs(K-a);
         if(a<b)
         {
             cout<<a<<endl;
         }
         else
         {
             cout<<b<<endl;
         }
    }
    return 0;
}


Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }
typedef long long ll;
typedef vector<int> vint;
typedef pair<int, int> pint;
typedef vector<long long> vlong;
typedef vector<string> vstring;
#define _GLIBCXX_DEBUG
#define vpush(a,x) a.push_back(x);
#define rep(i, n) REP(i, 0, n)
#define all(v) v.begin(), v.end()
#define REP(i, x, n) for(int i = x; i < n; i++)
const int INF = 1 << 30;
const int dx[] = {1,0,-1,0,1,1,-1,-1};
const int dy[] = {0,-1,0,1,1,-1,-1,1};
#define stp(x)  setprecision(x)
int main(){
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int N;
  string s,t;
  cin>>N>>s>>t;
  rep(i,N+1){
    if(s.substr(i)==t.substr(0,N-i)){
      cout<<N+i<<endl;
      return 0; 
    }
  }
  return(0);
}


Measured memory_bytes: 256
#include <stdio.h>
typedef long long ll;

int main(void) {
  ll i, j, k, n, a[3][3], b;
  bool t[3][3], c, ans = false;
  for(i = 0; i < 3; ++i) for(j = 0; j < 3; ++j) t[i][j] = false;
  for(i = 0; i < 3; ++i) for(j = 0; j < 3; ++j) scanf("%lld", &a[i][j]);
  scanf("%lld", &n);
  for(k = 0; k < n; ++k) {
    scanf("%lld", &b);
    for(i = 0; i < 3; ++i) for(j = 0; j < 3; ++j) if(a[i][j] == b) t[i][j] = true;
  }
  for(i = 0; i < 3; ++i) {
    c = true;
    for(j = 0; j < 3; ++j) c = c & t[i][j];
    ans = c | ans;
  }
  for(i = 0; i < 3; ++i) {
    c = true;
    for(j = 0; j < 3; ++j) c = c & t[j][i];
    ans = c | ans;
  }
  c = t[0][0] & t[1][1] & t[2][2];
  ans = c | ans;
  c = t[0][2] & t[1][1] & t[0][2];
  ans = c | ans;
  printf("%s", ans ? "Yes" : "No");
  return 0;
}

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

const int N = 2e5 + 10, mod = 1e9 + 7;

bool check(long long x) {
    int pre = -1;
    while(x) {
        int d = x % 10;
        if(pre >= 0 && abs(pre - d) > 1) return 0;
        pre = d;
        x /= 10;
    }
    return 1;
}

long long nex(long long x) {
    long long ret = 0;
    vector<int> v;
    while(x) {
        int d = x % 10;
        v.push_back(d);
        x /= 10;
    }
    reverse(v.begin(), v.end());
    bool ok = 1;
    for(int i = 1; i < v.size(); i++) {
        if(abs(v[i] - v[i - 1]) > 1) {
            if(v[i] > v[i - 1]) v[i] += 10 - v[i] + max(0, v[i - 1] - 1);
            else v[i] += v[i - 1] - 1 - v[i]; 
            int carry = (v[i] >= 10);
            v[i] %= 10;
            for(int j = i - 1; j >= 0; j--) {
                v[j] += carry;
                carry = (v[j] > 9);
                v[j] %= 10;
                ok &= (abs(v[j] - v[j + 1]) <= 1);
            }
            for(int j = i + 1; j < v.size(); j++) v[j] = max(0, v[j - 1] - 1);
            if(carry) v.insert(v.begin(), 1);
            break;
        }
    }
    for(int a : v) ret = ret * 10 + a;
    return (ok ? ret : nex(ret));
}

int main() {
    // ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int k; cin >> k;
    long long i;
    for(i = 1; ; i++) {
        if(check(i)) {
            k--;
            if(!k) break;
        }
        else i = nex(i) - 1;
    }
    printf("%lld\n", i);
    return 0;
}

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

using namespace std;
using ll = long long;
using pii = pair<int, int>;

#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define sz size()

const int N = 4e3 + 5;
const int MOD = 1e9 + 7;

int pR[N], pG[N], pB[N];

int main(){

  int n;
  string s;
  cin >> n >> s;
  int tot1 = 0, tot2 = 0, tot3 = 0;
  for(int i = 0; i < n; i++){
    pR[i] += s[i] == 'R'; pG[i] += s[i] == 'G', pB[i] += s[i] == 'B';
    if(i){
      pR[i] += pR[i - 1], pG[i] += pG[i - 1], pB[i] += pB[i - 1];
    }
  }
  ll ans = 0LL;
  for(int i = 1; i < n - 1; i++){
    int sR = pR[n - 1] - pR[i];
    int sG = pG[n - 1] - pG[i];
    int sB = pB[n - 1] - pB[i];

    if(s[i] == 'R')ans += pG[i - 1] * sB + pB[i - 1] * sG;
    else if(s[i] == 'G')ans += pR[i - 1] * sB + pB[i - 1] * sR;
    else ans += pG[i - 1] * sR + pR[i - 1] * sG;
  }

  for(int len = 1; len < n - 1; len++){
    for(int i = len; i < n - len; i++){
      if(s[i] != s[i - len] and s[i] != s[i + len] and s[i - len] != s[i + len])ans--;
    }
  }
  cout << ans << endl;
  return 0;
}

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

#define EACH(i, a) for (auto &&i : a)
#define FOR(i, a, b) for (int i = (int)a; i < (int)b; ++i)
#define RFOR(i, a, b) for (int i = (int)b - 1; i >= (int)a; --i)
#define REP(i, n) FOR(i, 0, n)
#define REPS(i, n) FOR(i, 1, int(n) + 1)
#define RREP(i, n) RFOR(i, 0, n)
#define RREPS(i, n) RFOR(i, 1, int(n) + 1)
#define ALL(x) (x).begin(), (x).end()
#define MEMSET(v, h) memset((v), h, sizeof(v))
#define debug(x) cout << #x << ": " << x << endl

#define pb push_back
#define mp make_pair
#define F first
#define S second

#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
#define next asdnext
#define prev asdprev
#define INF (1L << 30)
#define MOD (1000000007)
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

template <class T>
void pv(T a, T b)
{
  for (T i = a; i != b; ++i)
    cout << *i << " ";
  cout << endl;
}
template <class T>
void pvp(T a, T b)
{
  for (T i = a; i != b; ++i)
    cout << "(" << i->first << ", " << i->second << ") ";
  cout << endl;
}
template <class T>
bool chmax(T &a, const T &b)
{
  if (a < b)
  {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
bool chmin(T &a, const T &b)
{
  if (b < a)
  {
    a = b;
    return 1;
  }
  return 0;
}
int in()
{
  int x;
  scanf("%d", &x);
  return x;
}

using ll = long long;
#define int ll

//**********

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

  int n, st, end, min, max;
  cin >> n >> st >> end >> min >> max;

  int diff = end - st;
  bool ans = false;
  REP(i, n)
  { // i: プラス方向の数
    int ans_min = st + min * i - max * (n - i - 1);
    int ans_max = st + max * i - min * (n - i - 1);
    if (end >= ans_min && end <= ans_max)
    {
      ans = true;
    }
  }

  if (ans)
  {
    cout
        << "YES" << endl;
  }
  else
  {
    cout
        << "NO" << endl;
  }
  return 0;
};


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

using namespace std;

int main(){
    int a, b;
    cin >> a >> b;
    string s;
    cin >> s;
    int c = 0;
    int j;
    bool ok = true;
    for (int i = 0; i < s.size(); ++i) {
        if (s[i] == '-') {
            ++c;
            j = i;
        }
    }
    if (c == 1 && j == a) {
        cout << "Yes\n";
    } else {
        cout << "No\n";
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
void ABC70(void);
void ABC71(void);
void ABC72(void);
void ABC73(void);
void ABC74(void);
void ABC75(void);
void ABC76(void);
void ABC77(void);
void ABC78(void);
void ABC79(void);

int main(void){
    ABC77();
}

void ABC77(){
    int n;
    cin>>n;
    n=sqrt(n);
    cout<<n*n<<endl;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using static Input;

public class Prog
{
    private const int INF = 1000000007;
    private const long INFINITY = 9223372036854775807;
    private struct Pair { public int x, y; }
    private static int[] dx = { 0, 1, 0, -1 };
    private static int[] dy = { 1, 0, -1, 0 };
    public static void Main()
    {
        string S = NextString();
        int[] A = new int[S.Length];
        for (int i = 0; i < S.Length; i++) A[i] = int.Parse(S[i].ToString());
        int ans0 = 0;
        for (int i = 1; i < S.Length; i++)
        {
            if (A[i] == A[i - 1])
            {
                A[i] = (A[i] == 0 ? 1 : 0);
                ans0++;
            }
            //Console.WriteLine(S);
        }
        Console.WriteLine(ans0);
    }
}

public class Input
{
    private static Queue<string> q = new Queue<string>();
    private static void Confirm() { if (q.Count == 0) foreach (var s in Console.ReadLine().Split(' ')) q.Enqueue(s); }
    public static int NextInt() { Confirm(); return int.Parse(q.Dequeue()); }
    public static long NextLong() { Confirm(); return long.Parse(q.Dequeue()); }
    public static char NextChar() { Confirm(); return char.Parse(q.Dequeue()); }
    public static string NextString() { Confirm(); return q.Dequeue(); }
    public static double NextDouble() { Confirm(); return double.Parse(q.Dequeue()); }
    public static int[] LineInt() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); }
    public static long[] LineLong() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); }
    public static string[] LineString() { return Console.ReadLine().Split(' ').ToArray(); }
    public static double[] LineDouble() { return Console.ReadLine().Split(' ').Select(double.Parse).ToArray(); }
}


Measured memory_bytes: 15396
#include <bits/stdc++.h>
using namespace std;
template<class T> ostream& operator<<(ostream &os, vector<T> V) {
os << "[ "; for(auto v : V) os << v << " "; return os << "]";}
template<class L, class R> ostream& operator<<(ostream &os, pair<L,R> P) {
    return os << "(" << P.first << "," << P.second << ")";}

// #define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cout << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...) 1
#endif
typedef long long ll;
typedef double ld;
#define pll pair<ll,ll>
#define pii pair<int, int>
#define pb push_back
#define mp(x, y) make_pair((x), (y))
#define F first
#define S second
#define I insert
#define vi vector<int>
#define vll vector<ll>
#define vpll vector<pll>
#define all(x) (x).begin(), (x).end()
#define sz(x) (ll)(x).size()
   
const ll Mod = 1e9 + 7;
int main(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); 
    ll n , W ; cin >> n >> W;
    int A[2][n+1];
    for(int i = 1;i <= n; i++)
        cin >> A[0][i] >> A[1][i];

    ll dp[2][W+1];
    memset(dp , 0 , sizeof(dp));

    ll ans = 0;
    for(int i = 1;i <= n ;i++){
        for(int w = W-A[0][i]; w >= 0 ; w--){
            dp[1][w+A[0][i]] = max(dp[0][w+A[0][i]] , dp[0][w] + A[1][i]);
        }
        for(int w = 0 ; w <= W ; w++)
            dp[0][w] = dp[1][w];
    }
    for(int w = 0 ; w <= W ; w++)
        ans = max(ans , dp[0][w]);
    cout << ans << endl;

    
    
    return 0;
}

Measured memory_bytes: 1792
//AUTHOR:BlackBox Inc.//
#include<bits/stdc++.h>
#include<unordered_map>
#include<tr1/unordered_map>
#define ll long long
#define ull unsigned long long
#define vi vector<int>
#define vlli vector<long long int>
#define vvi vector<vector<int>>
#define endl "\n"
#define vpii vector<pair<int,int>>
#define vs vector<string>
#define lin1(x) ll int x; x = scan();
#define lin2(x,y) ll int x, y; x = scan(), y = scan();
#define lin3(x,y,z) ll int x, y, z; x = scan(), y = scan(), z = scan();
#define pb(x) push_back(x)
#define makep(x,y) make_pair(x,y)
#define mx(a,b) (a)>(b)?(a):(b)
#define mn(a,b) (a)<(b)?(a):(b)
#define fori(s,e) for(i=s;i<=e;i++)
#define forj(s,e) for(j=s;j<=e;j++)
#define fork(s,e) for(k=s;k<=e;k++)
#define rep(i,s,e) for(int i=s;i<=e;i++)
#define brep(i,s,e) for(int i=s;i>=e;i--)
#define all(x) x.begin(),x.end()
#define mem(x,y) memset(x,y,sizeof(x));
#define bits1(x) __builtin_popcount(x)
#define pi 3.14159265358979323846264338327950
#define MOD7 1000000007
#define MOD9 1000000009
#define fast std::ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
using namespace std;
using namespace std::tr1;

int main()
{
#ifdef RAHUL
    freopen("input.txt","r",stdin);
#endif


string s;
cin>>s;
int temp=0,max1=0;
for(auto c:s ){

	if(c=='A' or c=='C' or c=='G' or c=='T'){
		temp+=1;
	}
	else{
		temp=0;
	}
	max1=max(temp,max1);
}
cout<<max1<<endl;


return 0;
}

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {
 
	public static void main(String[] args) {
 
		// 読み込み
		Scanner sc = new Scanner(System.in);
		int K = sc.nextInt();
        int N = sc.nextInt();
      
        List<Integer> A = new ArrayList<>();
        for(int i =0; i < N; i++)
          A.add(sc.nextInt());
       
        int maxD = 0;
        
        for(int i =0; i < N; i++) {
        	int dist = 0;
        	if (i == N-1)
        		dist = K - A.get(i) + A.get(0);
        	else {
        		dist = Math.abs(A.get(i) - A.get(i + 1));
        	}
        	
        	if(dist > maxD) {
        		maxD = dist;
        	}
        	        		
        }
        
         System.out.println(K - maxD);
	}
}

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

int main() {
  int A, B, H, M;
  cin >> A >> B >> H >> M;
  long double  a = A; 
  long double b = B;
  long double h = H; 
  long double m = M;
//  long double ans = sqrt(A*A + B*B - 2 * A * B * cos(abs(5*H-M)*M_PI/30));
  long double rad = abs(30*h - 5.5*m)*M_PI/180;
  long double ans = sqrt(a*a + b*b - 2 * a * b * cos(rad));

  cout << fixed << setprecision(10);
  cout << ans << endl;
}

Measured memory_bytes: 4188
#include <bits/stdc++.h>
#include <cstdlib>
#include <cmath>
#include <algorithm>
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Graph= vector<vector<int>>; 
#define rep(i,n) for(ll i=0;i<n;i++) 
#define rep2(i,n,m) for(ll i=n;i<=m;i++)
#define rep3(i,n,m) for(ll i=n;i>=m;i--)
#define pb push_back
#define eb emplace_back
#define ppb pop_back
const ll INF=1e18 ;
inline void chmax(ll& a,ll b){a=max(a,b);}
inline void chmin(ll& a,ll b){a=min(a,b);}
int main(){
  int a,b,m ;
  cin >> a>>b>>m ;
  vector<int> A(a) ;rep(i,a) cin>> A[i] ;
  vector<int> B(b) ;rep(i,b) cin>> B[i] ;
  vector<int> x(m) ;vector<int> y(m) ;vector<int> c(m) ;
  rep(i,m) cin>> x[i]>>y[i]>>c[i] ;
  ll ans=INF ; ll sum= 0;
  rep(i,m){
    sum= A[x[i]-1]+B[y[i]-1] -c[i] ;
    chmin(ans,sum) ;
  }
  sort(A.begin(),A.end()) ;sort(B.begin(),B.end()) ;
  ll poi=A[0]+B[0] ;
  chmin(ans,poi) ;
  cout<< ans <<endl ;
  return 0;
  }

Measured memory_bytes: 2176
#include <queue>
#include <iostream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <stack>
#include <string>
#include <vector>
#include <map>
#include <functional>
#include <set>

#define rep(i, n) for(int i = 0; i < (n); i++)
#define MAX(a, b) (((a) < (b)) ? (b) : (a))
#define MIN(a, b) (((a) < (b)) ? (a) : (b))

using namespace std;
typedef long long int ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pint;
const ll inf = (1LL << 60);
const ll mod = 1000000007;
ll max(ll a, ll b) {
	if (a < b)
		return b;
	else
		return a;

}
ll min(ll a, ll b) {
	if (a < b)
		return a;
	else
		return b;

}
int main() {

	ll N, A, B;
	cin >> N >> A >> B;

	cout << min(N*A, B) << endl;

	
	return 0;
}

Measured memory_bytes: 256
def main(): 
    import sys
    input = lambda: sys.stdin.readline().rstrip()

    n, m, s = map(int, input().split())
    s = min(s, 2500)
    from collections import defaultdict
    # O(ElogV)
    import heapq
    def dijkstra(s, x):
        # 始点sから各頂点への最短距離
        d = defaultdict(lambda: float("inf"))
        d[(s, x)] = 0
        # 各頂点が訪問済みかどうか
        used = defaultdict(lambda: False)
        used[(s, x)] = True
        # 仮の距離を記録するヒープ
        que = []
        for e in edge[(s, x)]:
            heapq.heappush(que, e)
        while que:
            minedge = heapq.heappop(que)
            if used[minedge[1]]:
                continue
            v = minedge[1]
            d[v] = minedge[0]
            used[v] = True
            for e in edge[v]:
                if not used[e[1]]:
                    heapq.heappush(que, (e[0] + d[v], e[1]))
        return d

    max_money = 2500
    edge = defaultdict(list)
    for _ in range(m):
        u, v, a, b = map(int, input().split())
        u -= 1
        v -= 1
        for i in range(a, max_money + 1):
            edge[(u, i)].append((b, (v, i - a)))
            edge[(v, i)].append((b, (u, i - a)))
    for j in range(n):
        c, d = map(int, input().split())
        for i in range(max_money):
            if i + c <= max_money:
                edge[(j, i)].append((d, (j, i + c)))

    ans = [10**18]*n

    d = dijkstra(0, s)
    for i in d:
        x, y = i
        cost = d[i]
        ans[x] = min(ans[x], cost)
    for i in ans[1:]:
        print(i)
main()

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

int main() {
  ll x;
  cin >> x;
  //   2
  // 3 1 4
  //   5
  //   6
  if (x <= 6) {
    cout << 1 << endl;
  } else if (x <= 11) {
    cout << 2 << endl;
  } else {
    ll z = x / 11;
    z *= 2;
    ll y = x % 11;
    if (y == 0) {
      cout << z << endl;
    } else {
      cout << (y <= 6 ? z + 1 : z + 2) << endl;
    }
  }
}

Measured memory_bytes: 256
import queue
n,q = map(int,input().split())
qu = queue.Queue()
current = 0
for i in range(n):
    name,time = input().split()
    qu.put([name,int(time)])
    
while not qu.empty():
    process = qu.get()
    if process[1] <= q:
        print(process[0],str(current+process[1]))
        current += process[1]
    else:
        current += q
        process[1] -= q
        qu.put(process)


Measured memory_bytes: 14400
def hersCode(L, n):
  ok = len(L)
  ng = -1
  while abs(ok - ng) > 1:
    mid = abs(ok + ng) // 2
    if L[mid] < n:
      ok = mid
    else:
      ng = mid
  return ok


N = int(input())
A = [int(input()) for _ in range(N)]

L = [-1]
for i in range(N):
  t = hersCode(L, A[i])
  if t == len(L) - 1:
    L[-1] = A[i]
    L.append(-1)
  else:
    L[t] = A[i]

print(len(L) - 1)

Measured memory_bytes: 7808
/// Code By t_bone_289 (Tushar Singh)
/// An Immature Programmer.... I'm still developing !!
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/trie_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define pll pair<ll,ll>
#define fi first
#define se second
#define mp make_pair
#define pb emplace_back
#define endl '\n'
#define M 1000000007
#define error(x) cout << #x << " = " << x << endl;
#define pi 3.14159265358979323846
typedef long long ll;
typedef long double ld;
template <typename T>
void ContainerError(T &v){cout<<"{";for(auto &x:v){cout<<x<<',';}cout<<"}"<<endl;return;}
typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
ll powmod(ll base,ll exp,ll MOD){ll res=1;while(exp>0){if(exp%2==1) res=(res*base)%MOD;base=(base*base)%MOD;exp/=2;}return (res%MOD);}
ll mpow(ll base,ll exp){ll res=1;while(exp>0){if(exp%2==1) res=(res*base);base=(base*base);exp/=2;}return (res);}
ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    ll n;
    cin>>n;
    vector<ll> v1;
    vector<ll> v2;
    vector<ll> v(n);
    for(auto &x:v)
    {
        cin>>x;
        if(x<0)
        {
            v1.pb(x);
        }
        else
        {
            v2.pb(x);
        }
    }
    sort(v1.begin(),v1.end());
    reverse(v1.begin(),v1.end());
    sort(v2.begin(),v2.end());
    ll sz1 = v1.size();
    ll sz2 = v2.size();
    if(sz1%2==0)
    {
        ll ans=0;
        for(auto x:v)
        {
            ans += abs(x);
        }
        cout<<ans;
        return 0;
    }
    if((sz1&1))
    {
        ll ans=0;
        for(auto x:v)
        {
            ans += abs(x);
        }
        if(sz2!=0){ans -= 2*min(abs(v1[0]),abs(v2[0]));}
        else
        {
            ans -= 2*abs(v1[0]);
        }
        cout<<ans;
        return 0;
    }
    return 0;
}



Measured memory_bytes: 2424
h,w=map(int,input().split())
A=[list(map(int,input().split())) for _ in range(h)]

B=[]
for i in range(h):
    flag=1 if i%2==0 else -1
    for j in range(w)[::flag]:
        if A[i][j]%2==1:
            if 0<=j+flag<w:
                B.append([i,j,i,j+flag])
                A[i][j+flag] +=1
            elif i+1<h:
                B.append([i,j,i+1,j])
                A[i+1][j] +=1

print(len(B))
for i in B:
    print(*list(map(lambda x:x+1,i)))

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

int main(){
  int N;
  cin >> N;
  vector<int> dp(3,0);
  for(int i = 0; i < N; ++i){
    vector<int> dp_(3,0);
    int abc[3];
    for(int j = 0; j < 3; ++j) cin >> abc[j];
    for(int j = 0; j < 3; ++j){
      for(int k = 0; k < 3; ++k){
        if(j == k) continue;
        dp_[k] = max(dp_[k],dp[j] + abc[k]);
      }
    }
    dp = dp_;
  }
  cout << *max_element(dp.begin(), dp.end()) << endl;
}


Measured memory_bytes: 256
import Control.Applicative

num n =
  case n of
  1 -> 13
  _ -> n - 1

main = do
  [a, b] <- words <$> getLine
  solve (num $ toInt a) (num $ toInt b)
  where
    toInt :: String -> Int
    toInt = read
    solve a b
      | a < b = putStrLn "Bob"
      | a > b = putStrLn "Alice"
      | otherwise = putStrLn "Draw"


Measured memory_bytes: 508
#include <bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
#define int long long
using namespace std;
typedef pair<int,int>P;
typedef pair<P,int>P2;
#define F first
#define S second

struct RLQ{
  int n=(1<<17),data[(1<<18)];
  RLQ(){
    fill(data,data+(1<<18),1e17);
  }
  void update(int k,int x){
    k+=n-1;
    data[k]=x;
    while(k>0){
      k=(k-1)/2;
      data[k]=min(data[k*2+1],data[k*2+2]);
    }
  }
  int find(int a,int b,int k=0,int l=0,int r=(1<<17)){
    if(r<=a || b<=l)return 1e17;
    if(a<=l && r<=b)return data[k];
    int v1=find(a,b,k*2+1,l,(l+r)/2);
    int v2=find(a,b,k*2+2,(l+r)/2,r);
    return min(v1,v2);
  }
};

int n,m;

signed main(){
	RLQ R;
	vector<P2>v;
	cin>>n>>m;
	r(i,m){
		int a,b,c;
		cin>>a>>b>>c; a--; b--;
		v.push_back(P2(P(b,a),c));
	}
	sort(v.begin(),v.end());
	R.update(0,0);
	r(i,m){
		int l=v[i].F.S;
		int r=v[i].F.F;
		int c=v[i].S;
		int MIN = R.find(l,r)+c;
		int X=R.find(r,r+1);
		if(X>MIN){
			R.update(r,MIN);
		}
	}
	int A=R.find(n-1,n);
	if(A>1e16)cout<<-1<<endl;
	else cout<<A<<endl;
}


Measured memory_bytes: 8052
N = int(input())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]

pm = 0
for i in range(N) :
    if a[i] >= b[i] :
        pm += 2 * (a[i] - b[i])
    else :
        if a[i] % 2 != b[i] % 2 :
            pm += 1
        pm -= b[i] - a[i]
        
if pm > 0 :
    print('No')
else :
    print('Yes')

Measured memory_bytes: 41632
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream>
#include <random>
#include <map>
#include <fstream>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <assert.h>
#include <complex>
#include <omp.h>
using namespace std;
#define eps 0.000001
#define LONG_INF 10000000000000
#define GOLD 1.61803398874989484820458
#define seg_size 65536*4
#define REP(i,n) for(long long i = 0;i < n;++i)
unsigned long xor128() {
	static unsigned long x = time(NULL), y = 362436069, z = 521288629, w = 88675123;
	unsigned long t = (x ^ (x << 11));
	x = y; y = z; z = w;
	return (w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)));
}

long long a(long long b){
    long long geko = 0;
    for(long long i = b / 4 * 4;i <= b;++i){
        geko ^= i;
    }
    return geko;
}

void solve(long long A, long long B){
    cout << (a(A-1) ^ a(B)) << endl;
}

// Generated by 1.1.3 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long A;
    scanf("%lld",&A);
    long long B;
    scanf("%lld",&B);
    solve(A, B);
    return 0;
}


Measured memory_bytes: 256
#include <unistd.h>
#include <stdlib.h>

char ibuf[3000000];
char *ibufe = ibuf-1;

extern inline void readall(){
  int k, t = 0;
  while((k=read(STDIN_FILENO, ibuf+t, sizeof(ibuf)-t))>0) t += k;
}


int read_uint(){
  int x=0;
  while(*(++ibufe) <'0');
  do {
    x *= 10;
    x += *ibufe-'0';
  } while(*(++ibufe) >='0');

  return x;
}

char buf[40];
char *bufe = buf;

void write_uintln(long long int x){
  int i;
  static char tmp[23];
  if(x==0){
    *bufe++ = '0';
    *bufe++ = '\n';
    return;
  }

  for(i=0; x; i++){
    tmp[i] = '0' + x % 10;
    x /= 10;
  }
  for(i--; i >= 0; i--){
    *bufe++ = tmp[i];
  }
  *bufe++ = '\n';
}

extern inline void writeall(){
  int k, t = 0;
  while((k=write(STDOUT_FILENO, buf+t, bufe-buf-t))>0) t += k;
}


int n;
int A[200000];

inline void swap(int *a, int *b){
  int z;
  z = *a;
  *a = *b;
  *b = z;
}

int kth(int *A, int n, int k){
  int ll, rr;
  ll = 0;
  rr = n;
  while(1){
    int i, l, r, pivot;
    swap(A+ll, A+(ll+rr)/2);
    pivot = A[ll];
    l = ll;
    r = rr;
    i = ll+1;
    while(i < r){
      if(A[i] < pivot) swap(A+l++, A+i++);
      else if(A[i] > pivot) swap(A+--r, A+i);
      else i++;
    } 
    if(k < l) rr = l;
    else if(k >= r) ll = r;
    else return pivot;
  }
}

int main(){
  int i, m;
  long long int r;
  readall();
  n = read_uint();
  for(i=0;i<n;i++){
    A[i] = read_uint()-(i+1);
  }
  m = kth(A, n, n/2);
  r = 0;
  for(i=0;i<n;i++) r += abs(A[i] - m);
  write_uintln(r);
  writeall();
  return 0;
}


Measured memory_bytes: 2944
//Priyanshu Kumar : IIIT Allahabad
#include<bits/stdc++.h>
using namespace std;

#define ll long long int
#define MAX 100005
#define M 1000000007
#define sz size()
#define ln length()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define si(n) scanf("%d",&n)
#define sl(n) scanf("%lld",&n)
#define pi(n) printf("%d",n)
#define pin(n) printf("%d\n",n);
#define pl(n) printf("%lld",n)
#define pln(n) printf("%lld\n",n);
inline ll gcd(ll x,ll y){return x%y==0?y:gcd(y,x%y);}
inline ll lcm(ll x,ll y){return x*(y/gcd(x,y));}
inline ll powmod(ll a,ll b,ll mod) 
{
	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;
}
inline ll mulmod(ll a, ll b, ll c)
{
	if(!b)return 0;
	ll x = mulmod(a, b/2, c);
	if (b & 1)return (x+x+a)%c;
	return (x+x)%c;
}

/*ll C(int n,int r,int MOD)
{
    //cout<<"Enter : "<<n<<" "<<r<<endl;
    if(n < r || n < 0 || r < 0)
        return 0;
    ll ret = 1;
    ll f = max(n-r,r);
    ll s = min(n-r,r);
    for(int i=f+1;i<=n;i++)
        ret = ret*i;
    for(int i=2;i<=s;i++)
        ret = ret/i;
    cout<<n<<" "<<r<<" "<<ret%M<<endl;
    return ret%M;
}*/
ll fac[200005];

ll modularExponentiation(ll x,ll n,ll MOD)
{
    ll result=1;
    while(n>0)
    {
        if(n % 2 ==1)
            result=(result * x)%MOD;
        x=(x*x)%MOD;
        n=n/2;
    }
    return result;
}

ll modInverse(ll A,ll MOD)
{
    return modularExponentiation(A,M-2,M);
}


ll C(ll n,ll r,ll MOD)
{
    //cout<<n<<" "<<r<<" ";
    if(n < r || n < 0 || r < 0)
        return 0;//cout<<endl,0;
    ll ret = ((fac[n]%M)*(modInverse(fac[r],MOD)%M))%M;
    ret = ((ret%M)*(modInverse(fac[n-r],MOD)%M))%M;
    //cout<<ret<<endl;
    return ret;
}

map <int,int> m;
int main()
{
    int n;
    cin>>n;
    n++;
    fac[0] = 1;
    for(int i=1;i<=200000;i++)
    {
        fac[i] = ((fac[i-1]%M)*(i%M))%M;
    }
    int a[n+1],ind,num;
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        if(m[a[i]] == 1)
        {
            ind = i;
            num = a[i];
        }
        m[a[i]] = 1;
    }
    int focc;
    for(int i=0;i<n;i++)
    {
        if(a[i] == num)
        {
            focc = i;
            break;
        }
    }
    int maxlen = n - ind;
    for(int i=1;i<=n;i++)
    {
        ll val = C(n,i,M)%M;
        val = (val%M - C(maxlen - 1 + focc,i-1,M)%M)%M;
        if(val < 0)
            val = (val + M)%M;
        cout<<val<<endl;
    }
	return 0;
}


Measured memory_bytes: 7808
#include<bits/stdc++.h>
#define LL long long
using namespace std;
const int maxn=500000;
LL x[maxn];
LL a,b,c,d;
LL n;

int main()
{
    scanf("%lld%lld%lld%lld%lld",&n,&a,&b,&c,&d);
    for(int i=0;i<=n-1;i++){
        if(c*(n-1-i)-d*i<=b-a&&d*(n-1-i)-c*i>=b-a){
            printf("YES");
            return 0;
        }
    }
    printf("NO");
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<math.h>
#include<iomanip>
#include<stdio.h>
#include<cstring>
using namespace std;
 
int main(){

  int a, b, c, d;
  cin >> a >> b >> c >> d;

  if(a+b<c+d){
    cout << "Right" << endl;
  } else if(a+b==c+d){
    cout << "Balanced" << endl;
  } else {
    cout << "Left" << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define is(a) (a == '1')
#define il(a, b, c) (c > 0 && a == '1' && b == '1')
using namespace std;

int presum[2005][2005];
int leftsum[2005][2005];
int topsum[2005][2005];
char Get[2005][2005];

int Getans(int r1, int c1, int r2, int c2){
	int ans = presum[r2][c2] - presum[r2][c1 - 1] - presum[r1 - 1][c2] + presum[r1 - 1][c1 -1];
	ans -= leftsum[r2][c2] - leftsum[r2][c1] - leftsum[r1 - 1][c2] + leftsum[r1 - 1][c1];
	ans -= topsum[r2][c2] - topsum[r1][c2] - topsum[r2][c1 - 1] + topsum[r1][c1 - 1];
	return ans;
}

int main() {
	int N, M, Q;
	cin >> N >> M >> Q;
	for(int i = 1; i <= N; i++){
		for(int j = 1; j <= M; j++){
			cin >> Get[i][j];
			presum[i][j] = is(Get[i][j]) + presum[i-1][j] + presum[i][j-1] - presum[i-1][j-1];
			leftsum[i][j] = il(Get[i][j], Get[i][j-1], j) + leftsum[i][j-1] + leftsum[i-1][j] - leftsum[i-1][j-1];
			topsum[i][j] = il(Get[i][j], Get[i-1][j], i) + topsum[i][j-1] + topsum[i-1][j] - topsum[i-1][j-1];
	
			
		}
	}
	
	while(Q--){
		int r1, c1, r2, c2;
		cin >> r1 >> c1 >> r2 >> c2;
		cout << Getans(r1, c1, r2, c2) << "\n";
	}
	
	return 0;
}

Measured memory_bytes: 52864
#include <iostream>
#include <cstdlib>
using namespace std;
int main()
{
    long h[100002],a[100002],i,n;
    //cout<<"P:";
    cin>>n;
    for(i=1;i<=n;i++)
        cin>>h[i];
    i=1;
    a[0]=0;
    a[1]=0;
    a[2]=abs(h[1]-h[2]);
    for(i=3;i<=n;i++)
    {
       
        a[i]=min(a[i-2]+abs(h[i]-h[i-2]),a[i-1]+abs(h[i]-h[i-1]));
       
    }
    cout<<a[n];
    return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <cassert>
#include <algorithm>
#include <functional>
#include <set>
#include <cmath>
#include <limits>
#include <iostream>
using namespace std;
using ll=long long;
int main(){
   ll l,r;
   cin >> l >>r;
   ll reg=1e9;
   if(r-l<2019){
    for(ll i=l;i<r;i++){
        for(ll j=i+1;j<=r;j++){
            ll I=i%2019;
            ll J=j%2019;
            reg=min(reg,(I*J)%2019);
            }
        }
   }else{
        for(ll i=l;i<l+2020;i++){
            for(ll j=i+1;j<=l+2021;j++){
                ll I=i%2019;
                ll J=j%2019;
         //  cout<< I<< " "<<J<<endl;
         reg=min(reg,(I*J)%2019);
            }
        }
   }
   cout<<reg<<endl;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-

import sys
import os
import math


def cross(v1, v2):
    return v1[0] * v2[1] - v1[1] * v2[0]

def sign(v):
    if v >= 0:
        return 1
    else:
        return -1

for s in sys.stdin:
    ax, ay, bx, by, cx, cy, dx, dy = map(float, s.split(','))

    AB = (bx - ax, by - ay)
    BC = (cx - bx, cy - by)
    CD = (dx - cx, dy - cy)
    DA = (ax - dx, ay - dy)

    c0 = cross(AB, BC)
    c1 = cross(BC, CD)
    c2 = cross(CD, DA)
    c3 = cross(DA, AB)

    if sign(c0) == sign(c1) == sign(c2) == sign(c3):
        print('YES')
    else:
        print('NO')

Measured memory_bytes: 7472
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
 
int main(){
  int i,j,cnt=0;
  int n,m;
  cin>>n;
  int d[n];
  for(i=0;i<n;i++)cin>>d[i];
  cin>>m;
  int t[m];
  for(i=0;i<m;i++)cin>>t[i];
  sort(d,d+n);
  sort(t,t+m);
  for(i=0;i<n;i++){
    if(d[i]==t[cnt])cnt++;
  }
  if(cnt==m)cout<<"YES";
  else cout<<"NO";
}

Measured memory_bytes: 1920
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<string>
#include<vector>

typedef unsigned long long ULL;
typedef long long LL;

using namespace std;

typedef struct{
    int num;
    int year;
    int prefecture;
    int city_num;

}CITY;
bool sort_state(CITY a, CITY b){
    if( a.year < b.year  || ( a.year == b.year && a.prefecture < b.prefecture) ){
        return true;
    }else{
        return false;
    }
}
bool sort_yaer( CITY a, CITY b){
    if( a.year < b.year ){
        return true;
    }else{
        return false;
    }
}
bool sort_prefectre( CITY a, CITY b){
    if( a.prefecture < b.prefecture){
        return true;
    }else{
        return false;
    }
}
bool sort_num(CITY a, CITY b){
    if( a.num < b.num){
        return true;
    }else{
        return false;
    }
}
int main(){
    int i;
    int N,M;
    int p,y;

    int id_pre, id_num;
    CITY *city;

    cin >> N >> M;

    city = new CITY[M];

    for(i=0;i<M;i++){
        cin >> p >> y;
        city[i].num = i;
        city[i].prefecture = p;
        city[i].year = y;
    }
    sort(city,city+M,sort_yaer);
    stable_sort(city,city+M,sort_prefectre);
    id_pre = -1;
    id_num = -1;
    for(i=0;i<M;i++){
        if( id_pre !=  city[i].prefecture ){
            id_pre = city[i].prefecture;
            id_num = 0;
        }
        id_num++;
        city[i].city_num = id_num;
    }
    sort(city,city+M,sort_num);
    for(i=0;i<M;i++){
        printf("%06d%06d\n",city[i].prefecture,city[i].city_num);
    }
    
    return 0;
}


Measured memory_bytes: 3064
#input of int(split by space)
def get_i()
  return gets.chomp.split(" ").map(&:to_i)
end
#input of float(split by space)
def get_f()
  return gets.chomp.split(" ").map(&:to_f)
end
#input of string(split by space)
def get()
  return gets.chomp.split(" ")
end
#input of string(split per one character)
def get_nsp()
  return gets.chomp.split("")
end
#yes or no decision
def yn_judge(bool,y="Yes",n="No")
  return bool ? y : n 
end
#create of array
def array(size1,init=nil,size2=-1)
  if size2==-1
      return Array.new(size1){init}
  else
      return Array.new(size2){Array.new(size1){init}}
  end
end

def max(a,b)
    return a>b ? a : b
end

def min(a,b)
    return a>b ? b : a
end

INF=Float::INFINITY

N=gets.to_i
A=get_i
def cal(sum,res)
  1.upto(N-1) do|i|
      if sum<0
          if sum+A[i]<=0
            res-=sum+A[i]-1
            sum=1
          else
            sum+=A[i]
          end
      else
          if sum+A[i]>=0
              res+=sum+A[i]+1
              sum=-1
          else
              sum+=A[i]
          end
      end
  end
  return res
end
ans=[]
ans<<cal(A[0],0) unless A[0].zero?
ans<<cal(1,(A[0]-1).abs)
ans<<cal(-1,(A[0]+1).abs)
puts ans.min

Measured memory_bytes: 21812
using System;
using System.Collections.Generic;
using System.Linq;
class Program{
	const int mod=1000000007;
	const long o=1;
	static void Main(){
		Sc sc=new Sc();
		long[] a=sc.La;
		long b=a[1],c=a[1];
		c+=(a[0]&-2)+(a[3]&-2)+(a[4]&-2);
		if(a[0]%2==1&&a[3]%2==1&&a[4]%2==1){c++;}
		if(a[0]>0&&a[3]>0&&a[4]>0){
			a[3]--;
			a[4]--;
			a[0]--;
			b+=3;
		}
		b+=(a[0]&-2)+(a[3]&-2)+(a[4]&-2);
		Console.WriteLine("{0}",Math.Max(c,b));
	}
}

class Sc{
	public int I{get{return int.Parse(Console.ReadLine());}}
	public long L{get{return long.Parse(Console.ReadLine());}}
	public double D{get{return double.Parse(Console.ReadLine());}}
	public string S{get{return Console.ReadLine();}}
	public int[] Ia{get{return Array.ConvertAll(Console.ReadLine().Split(),int.Parse);}}
	public long[] La{get{return Array.ConvertAll(Console.ReadLine().Split(),long.Parse);}}
	public double[] Da{get{return Array.ConvertAll(Console.ReadLine().Split(),double.Parse);}}
	public string[] Sa{get{return Console.ReadLine().Split();}}
}

Measured memory_bytes: 13268
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <set>
#include <map>
#include <queue>
using namespace std;
#define rep(i,n) for(int i = 0;i<n;i++)
const long long MOD = 1000000007LL;
const string alpha = "abcdefghijklmnopqrstuvwxyz";
long long gcd(long long a,long long b){
    if(b > a){
        swap(a,b);
    }
    bool flag = true;
    long long gcdl;
    while(flag){
        if(a%b == 0){
            flag = false;
            gcdl = b;
        }
        else{
            swap(a,b);
            b = b % a;
        }
    }
    return gcdl;
}
int main(){
    long n,m;
    cin >> n >> m;
    string sn,sm;
    cin >> sn >> sm;
    long gcdnm = gcd(n,m);
    long a = n/gcdnm;
    long b = m/gcdnm;
    bool fl = true;
    rep(i,gcdnm){
        if(sn[i*a] != sm[i*b]){
            cout << -1 << endl;
            fl = false;
            break;
        }
    }
    long ans = a*b*gcdnm;
    if(fl){
        cout << ans << endl;
    }
}

Measured memory_bytes: 512
#include<bits/stdc++.h>                                                                                               
using namespace std;
 
#define rep(i,n) for(int i=0;i<(n);++i)
#define reps(i,n) for(int i=1;i<=(n);++i)
#define all(x) (x).begin(),(x).end()
#define int long long
#define mk_p(a,b)   make_pair((a),(b))
using pii = pair<int,int>;
constexpr int INF  = 0x3f3f3f3f;
constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;

int gcd(int a,int b){return b ? gcd(b,a%b) : a;} 
int lcm(int a,int b){return a/gcd(a,b)*b;}

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    int n = s.size();
    rep(i,n-1){
        if(s[i] == 'A' && s[i+1] == 'C'){
            cout << "Yes\n";
            return 0;
        }
    }   
    cout << "No\n";
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
#include <functional>
#include <cctype>
 
using namespace std;
 
#define REP(i,n) for(int i = 0; i < (int)n; ++i)
 
int main()
{
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
 
    int n;
    cin >> n;
    vector<int> A(n);
 
    REP(i, n) cin >> A[i];
 
    int max = *max_element(A.begin(), A.end());
    vector<int> B(max + 1);
 
    REP(i, n) {
        ++B[A[i]];
    }
 
    REP(i, max + 1)
        REP(j, B[i]) {
            cout << i;
            if(i == max && j == B[i] - 1) cout << endl;
            else cout << ' ';
        }
    return 0;
}

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

int two(int n){
  int ans=0;
  while(n%2==0){
    ans++;
    n/=2;
  }
  return ans;
}

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

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
def input(): return sys.stdin.readline().rstrip()

def main():
    A,B=map(int,input().split())
    print(A*B-A-+B+1)

if __name__ == '__main__':
    main()


Measured memory_bytes: 38256
#include <iostream>
#include <iomanip>
#include <string>
#include <array>
#include <vector>
#include <list>
#include <deque>
#include <set>
#include <map>
#include <math.h>
#include <algorithm>
#include <queue>
#include <stack>

using namespace std;

const string n = "0123456789";

int main() {

	int n;
	cin >> n;

	vector<int> color;
	color.assign(n, 1);
	color[0] = 0;

	map<int, vector<pair<int, bool>>> l;
	stack<pair<int, bool>> st;
	st.push(make_pair(0, false));

	int x, y, z;
	for (int i = 0; i < n - 1; i++) {
		cin >> x >> y >> z;
		l[x - 1].push_back(make_pair(y - 1, z & 1));
		l[y - 1].push_back(make_pair(x - 1, z & 1));
	}
	while (!st.empty()) {
		if (l.count(st.top().first)) {
			pair<int, bool> stbuf = st.top();
			pair<int, bool> buf = l[st.top().first].back();
			l[st.top().first].pop_back();
			if (l[st.top().first].empty()) l.erase(st.top().first);
			if (color[buf.first] != 1) continue;

			color[buf.first] = (buf.second ? ~color[stbuf.first] : color[stbuf.first]);
			st.push(buf);
		}
		else {
			st.pop();
		}
	}

	for (int i = 0; i < n; i++) {
		cout << (color[i] ? 1 : 0) << endl;
	}

	return 0;
}

Measured memory_bytes: 12288
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations, accumulate, groupby, product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    from math import floor, ceil
    #from operator import itemgetter

    #inf = 10**17
    #mod = 10**9 + 7

    s = input().rstrip()
    res = []
    for i in s:
        if i=='0' or i=='1':
            res.append(i)
        else:
            res = res[:-1]
    print(*res, sep='')

if __name__ == '__main__':
    main()

Measured memory_bytes: 3316
#include<stdio.h>
int main(void){
    int  m,f,r,i,j,k,t;
    while(1){
        scanf("%d%d%d",&m,&f,&r);
        if(m==-1&&f==-1&&r==-1)break;
        t=m+f;
        if(m==-1||f==-1){
            printf("F\n");
        }else if(t>=80){
        printf("A\n");
        }else if(t>=65&&t<=80){
        printf("B\n");
        }else if(t<=65&&t>=50){
        printf("C\n");
        }else if(r>=50){
        printf("C\n");
        }else if(t<=50&&t>=30){
        printf("D\n");
        }else printf("F\n");
    }
    return 0;
}

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

int clock (int a, int b){
    return a + b;
}

int main (){
    int a, b, c;
    cin >> a >> b;
    c = clock(a,b);
    if (clock(a,b)>=24){
        c = c- 24;
    }
    cout << c << endl;
}

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

int main(){
    int N,K;
    cin >> N >> K;
    int x[100001];
    for(int i = 0;i < N; i++){
        cin >> x[i];
    }
    ll ans = 1e9;

    for(int i = 0; i < N-K+1; i++){
        ll t = 1e9;
        if(x[i] < 0 && x[i+K-1] > 0){
            t = min(  ( abs(x[i])+ abs(x[i+K-1]-x[i]) ),
            ( abs(x[i+K-1])+abs(x[i+K-1]-x[i]) )  );
        }else{
            t = max(abs(x[i]),abs(x[i+K-1]));
        }
        ans = min(ans,t);
    }
    cout << ans << endl;
    return 0;
    
}

Measured memory_bytes: 640