akhauriyash/Code-Regression huggingface dataset:
using namespace std;
#include <bits/stdc++.h>
#define fdto(i, r, l) for(int i = r; i >= l; --i)
#define fto(i, l, r) for(int i = l; i <= r; ++i)
#define forit(it, type, var) for(type::iterator it = var.begin(); it != var.end(); it++)
#define ii pair<int, int>
#define iii pair<int, ii>
#define MEMS(a,b) memset(a,b,sizeof(a))
#define fi first
#define se second
#define m_p make_pair
#define pb push_back
#define ll long long
#define ld long double
#define maxN 1000000000000000000
ll power(ll a,ll b){ll res=1;while(b>0){res*=a;b--;}return res;}
int main()
{
    
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll l,i,cnt=0;
    string s,t;
    cin>>s;
    cin>>t;

    l=s.length();
    for(i=0;i<l;i++)
    {
        if(s[i]!=t[i])
        cnt++;
    }
    cout<<cnt<<endl;
    return 0;
}

Measured memory_bytes: 3780
#!/usr/bin/python3
# -*- coding: utf-8 -*-



N = int(input())
Pn = list(map(int, input().split()))
ret = 0
for i,p in enumerate(Pn):
  if i+1 != p:
    ret += 1
if ret <= 2:
  print("YES")
else:
  print("NO")

Measured memory_bytes: 39820
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double lf;
typedef pair<ll,ll> ii;
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(ll i=1;i<=n;i++)
#define RST(i,n) memset(i,n,sizeof i)
#define SZ(a) (int)a.size()
#define ALL(a) a.begin(),a.end()
#define X first
#define Y second
#define mkp make_pair
#define pb push_back
#define eb emplace_back
#define pob pop_back
#ifdef cold66
#define debug(...) do{\
    fprintf(stderr,"%s - %d (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);\
    _do(__VA_ARGS__);\
}while(0)
template<typename T>void _do(T &&_x){cerr<<_x<<endl;}
template<typename T,typename ...S> void _do(T &&_x,S &&..._t){cerr<<_x<<", ";_do(_t...);}
template<typename _a,typename _b> ostream& operator << (ostream &_s,const pair<_a,_b> &_p){return _s<<"("<<_p.X<<","<<_p.Y<<")";}
template<typename It> ostream& _OUTC(ostream &_s,It _ita,It _itb)
{
    _s<<"{";
    for(It _it=_ita;_it!=_itb;_it++)
    {
        _s<<(_it==_ita?"":",")<<*_it;
    }
    _s<<"}";
    return _s;
}
template<typename _a> ostream &operator << (ostream &_s,vector<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a> ostream &operator << (ostream &_s,set<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a,typename _b> ostream &operator << (ostream &_s,map<_a,_b> &_c){return _OUTC(_s,ALL(_c));}
template<typename _t> void pary(_t _a,_t _b){_OUTC(cerr,_a,_b);cerr<<endl;}
#define IOS()
#else
#define debug(...)
#define pary(...)
#define endl '\n'
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0);
#endif // cold66
//}
template<class T> inline bool chkmax(T &a, const T &b) { return b > a ? a = b, true : false; }
template<class T> inline bool chkmin(T &a, const T &b) { return b < a ? a = b, true : false; }
template<class T> using MaxHeap = priority_queue<T>;
template<class T> using MinHeap = priority_queue<T, vector<T>, greater<T>>;

const ll MAXn=3e2+5,MAXlg=__lg(MAXn)+2;
const ll MOD=1000000007;
const ll INF=0x3f3f3f3f;

ll n;
char d[MAXn][MAXn];
ll gogo(ll x){
  char tmp[MAXn][MAXn];
  REP (i,n) REP (j,n) tmp[i][j] = d[i][(j+x)%n];
  REP (i,n) REP (j,n) if (tmp[i][j] != tmp[j][i]) return 0;
  return 1;
}
int main(){
  IOS();
  cin >> n;
  REP (i,n) REP (j,n) cin >> d[i][j];

  ll ans = 0;
  REP (T,n) ans += gogo(T);
  cout << ans * n << endl;
}


Measured memory_bytes: 384
package main

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

)


func max(a,b int) int{
	if a < b {
		return b
	}
	return a
}

func min(a,b int) int{
	if a < b {
		return a
	}
	return b
}


func search(nums []int) int{

	var ans  = -20000000000
	var m  = nums[0]

	for i:= 1; i<len(nums);i++{
		
		t := nums[i] - m
		ans = max(t,ans)
		m = min(m,nums[i])
	}

	return ans

}


func main() {
	var N int
	var nums []int

	fmt.Scan(&N)

	var sc = bufio.NewScanner(os.Stdin)

	for i:= 0; i < N; i++{
		sc.Scan()
		n,_:= strconv.Atoi(sc.Text())
		nums = append(nums,n)

	}
	
	fmt.Println(search(nums))

}



Measured memory_bytes: 9548
a = gets.chomp
num_ary = gets.split.map(&:to_i)
times = 0
is_odd = false
loop{
  num_ary.map!{|num|
    if num.odd?
      is_odd = true
      break
    end
    num / 2
  }
  break if is_odd
  times += 1
}
puts times

Measured memory_bytes: 1788
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cstdlib>
using namespace std;
void YES(){cout << "YES" << endl;}
void NO(){cout << "NO" << endl;}
void Yes(){cout << "Yes" << endl;}
void No(){cout << "No" << endl;}
int main() {
  int N;
  cin >> N;
  vector<string>S;
  string t;
  for(int i=0;i<N;i++){
    cin >> t;
    S.push_back(t);
  }
  sort(S.begin(),S.end());
  int count=1;
  for(int i=1;i<N;i++){
    if(S[i]!=S[i-1]){
      count++;
    }
  }
  cout << count;
  cout << endl;
  return 0;
}


Measured memory_bytes: 11604
N = int(input())  
 
data = ([int(input()) for i in range(N)])

data.insert(0, 0)

cnt = 0
i = 1
v = 0

while v != 2:
  v = data[i]
  i = v
  if cnt >= N: 
    cnt = -1
    break
  cnt += 1
  
print(cnt)

Measured memory_bytes: 7212
#include<iostream>
#include<string>
#include<vector>
#include<math.h>
#include<algorithm>
#include<cstdio>
#include<stdio.h>
#include<stack>
#include<sstream>
#include<iomanip>
#include<map>
#include<unordered_map>
#include<list>
#include<numeric>
typedef long long ll;

#define pi 3.14159265358979323846
#define VI vector<int>
#define VLL vector<long long>
#define MAX max_element
#define MIN min_element
#define all(v) v.begin(), v.end()
const ll MOD = 1e9 + 7;
using namespace std;
template<typename T>
T gcd(T a, T b) {
	if (b == 0) return a;
	return gcd(b, a % b);
	//return b ? gcd(b, a % b) : a;
}
template<typename T>
T lcm(T a, T b) {
	ll g = gcd(a, b);
	return a / g * b; // Be careful not to overflow
	//return a * b / gcd(a, b);
}

template<typename T>
T binarysearch(vector<T> A, T key) {
	ll left = 0;ll right = 4;ll mid;
	while (left < right) {
		mid = (left + right) / 2;
		if (key == A[mid]) return 1;
		if (key > A[mid]) left = mid + 1;
		else if (key < A[mid]) right = mid;
	}
	return 0;
}

template<typename T>
T finder(vector<T> vec, T number) {
	auto itr = find(vec.begin(), vec.end(), number);
	size_t index = distance(vec.begin(), itr);
	if (index != vec.size()) { // 発見できたとき
		return 1;
	}
	else { // 発見できなかったとき
		return 0;
	}
}
ll frac(ll n)//階乗
{
	if (n == 0) {
		return 1;
	}
	return (n * frac(n - 1)) % MOD;
}

template<typename T>
T keta(T a) {
	ll kazu = 1;
	while (1) {
		if (a / 10 != 0) { a /= 10;kazu++; }
		else break;
	}
	return kazu;
}//桁数

//素数判定
template<typename T>
bool IsPrime(T num)
{
	if (num < 2) return false;
	else if (num == 2) return true;
	else if (num % 2 == 0) return false; // 偶数はあらかじめ除く

	double sqrtNum = sqrt(num);
	for (int i = 3; i <= sqrtNum; i += 2)
	{
		if (num % i == 0)
		{
			// 素数ではない
			return false;
		}
	}

	// 素数である
	return true;
}

template<typename T>
T nCr(ll n, T r) {
	ll ans = 1;
	for (int i = n; i > n - r; --i) {
		ans = ans * i;
	}
	for (int i = 1; i < r + 1; ++i) {
		ans = ans / i;
	}
	return ans;
}
/*char r[4];
int yaju[4];
char op[3];
int sum = 0;
scanf("%s", r);
for (int i = 0;i < 4;i++) {
	yaju[i] = r[i] - '0';
}
*/
//vector<vector<int>> data(3, vector<int>(4));
//vector<vector<Type>> vv(n);

int main() {
	ll N, ans = 0;cin >> N;
	ll mina = 0;
	vector<ll>sum;
	vector<ll> A(N),B(N);
	for (ll i = 0;i < N;i++) {
		cin >> A[i];
		if (A[i] < 0)mina++;
		B[i] = abs(A[i]);
	}
	if(mina==0){
		for (ll i = 0;i < N;i++) {
			ans += A[i];
		}
	}
	else if (N % 2 != 0) {
		if (mina % 2 == 0) {
			for (ll i = 0;i < N;i++) {
				ans += B[i];
			}
		}
		else {
			sort(all(B));
			ans -= B[0];
			for (ll i = 1;i < N;i++) {
				ans += abs(B[i]);
			}
		}
	}
	else {
		if (mina % 2 == 0) {
			for (ll i = 0;i < N;i++) {
				ans += B[i];
			}
		}
		else {
			sort(all(B));
			ans -= B[0];
			for (ll i = 1;i < N;i++) {
				ans += abs(B[i]);
			}
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(int i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(int i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(int i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define uniq(x) (x).erase(unique((x).begin(), (x).end()), (x).end())

int n, k;
int v[55];

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    cin >> n >> k;
    rep(i, n) cin >> v[i];
    ll ans = INT_MIN;
    
    rep(a, k + 1) {
        rep(b, k - a + 1) {
            ll tmp = 0;
            int cnt = 0;
            priority_queue<int, vector<int>, greater<int>> pq;
            
            rep(i, min(a, n)) {
                if (cnt < n) {
                    tmp += v[i];
                    pq.push(v[i]);
                    cnt++;
                }
            }
            
            rreps(i, max(n - b, 0), n) {
                if (cnt < n) {
                    tmp += v[i];
                    pq.push(v[i]);
                    cnt++;
                }
            }
            
            rep(i, k - a - b) {
                if ((!pq.empty()) && (pq.top() < 0)) {
                    tmp -= pq.top();
                    pq.pop();
                }
            }
            
            ans = max(ans, tmp);
        }
    }
    
    cout << ans << endl;
    return 0;
}


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

int N[20];




int main(){
	int n;
	int count = 0;
	int M = 0;
	cin >> n;
	for (int i = 0; i < n; i++) cin >> N[i];

	for (int i = 0; i < n; i++){
		if (M <= N[i]){
			M = N[i];
			count++;
		}
	}
	cout << count << endl;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int weeks = sc.nextInt();
        debtHell(100000, weeks);
    }
    
    public static void debtHell(int total, int weeks){
        int sum = total;
        for(int i = 0; i < weeks; i++){
            double yield = sum * 0.05;
            if(yield % 1000 == 0){
                sum += yield;
            }else{
                sum += (int)(yield /1000 + 1) *1000;
            }
        }
        System.out.println(sum);
    }
}


Measured memory_bytes: 25976
fn main(){
    let raw = input();
    let x: i32 = raw.parse::<i32>().unwrap();
    if 30 <= x {
        println!("Yes");
    }else {
        println!("No");
    }
}

fn input() -> String{
    let mut buf = String::new();
    std::io::stdin().read_line(&mut buf).unwrap();
    buf.trim_end().to_string()
}

Measured memory_bytes: 2116
#include <iostream>
#include <algorithm>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <functional>
#include <string>
#include <cstdlib>
#include <numeric>
#include <cstdbool>
#include <map> 
typedef long long ll;
using namespace std;

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

const long long INF = 1LL << 60;
int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };
ll ma = 1000000000 + 7;


int main() {
	int a, b, c;
	cin >> a >> b >> c;
	string res="No";
	if (a == b && a == c) {
		res = "Yes";
	}
	cout << res << endl;

}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cassert>
#include <climits>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <fstream>

using namespace std;
#define SZ(x) (int)(x).size()
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REPR(i,n) for(int i=(n)-1;i>=0;i--)
#define ALL(s) (s).begin(), (s).end()
#define so(V) sort(ALL(V))
#define rev(V) reverse(ALL(V))
#define uni(v) v.erase( unique(ALL(v)) , v.end());

typedef long long unsigned int llu;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
const double EPS = 1e-9;
const int MOD = 1e9 + 7;
const int INF = (1 << 29);
const ll LINF = 1e18;
const double PI = acos(-1);

template<typename T>vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T, typename... Ts>auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...)); }
template<typename T, typename U, typename... V>
typename enable_if<is_same<T, U>::value != 0>::type
fill_v(U& u, const V... v) { u = U(v...); }
template<typename T, typename U, typename... V>
typename enable_if<is_same<T, U>::value == 0>::type
fill_v(U& u, const V... v) { for (auto& e : u) fill_v<T>(e, v...); }
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 (a > b) { a = b; return 1; } return 0; }

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int A, B, T;
	cin >> A >> B >> T;
	cout << (T / A) * B << endl;
	return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _20191021
{
    class Program
    {
        static void Main(string[] args)
        {
            int a = int.Parse(Console.ReadLine());
            string s = Console.ReadLine();

            if (a >= 3200)
                Console.WriteLine(s);

            else
                Console.WriteLine("red");
            
        }
    }
}


Measured memory_bytes: 13140
/*
このコード、と～おれ!
Be accepted!
∧＿∧　
（｡･ω･｡)つ━☆・*。
⊂　　 ノ 　　　・゜+.
　しーＪ　　　°。+ *´¨)
 　　　　　　　　　.· ´¸.·*´¨) ¸.·*¨)
		  　　　　　　　　　　(¸.·´ (¸.·'* ☆
*/

#include <cstdio>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstring>
#include <vector>
#include <numeric>
#include <iostream>
#include <random>
#include <map>
#include <unordered_map>
#include <queue>
#include <regex>
#include <functional>
#include <complex>
#include <list>
#include <cassert>
#include <iomanip>
#include <set>
#include <stack>
#include <bitset>

////多倍長整数, cpp_intで宣言
//#include <boost/multiprecision/cpp_int.hpp>
//using namespace boost::multiprecision;

//#pragma gcc target ("avx2")
//#pragma gcc optimization ("Ofast")
//#pragma gcc optimization ("unroll-loops")
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define rep1(i, n) for(int i = 1; i <= (n); ++i)
#define rep2(i, n) for(int i = 2; i < (n); ++i)
#define repr(i, n) for(int i = n; i >= 0; --i)
#define reprm(i, n) for(int i = n - 1; i >= 0; --i)
#define printynl(a) printf(a ? "yes\n" : "no\n")
#define printyn(a) printf(a ? "Yes\n" : "No\n")
#define printYN(a) printf(a ? "YES\n" : "NO\n")
#define printim(a) printf(a ? "possible\n" : "imposible\n")
#define printdb(a) printf("%.50lf\n", a) //少数出力
#define printLdb(a) printf("%.50Lf\n", a) //少数出力
#define printdbd(a) printf("%.16lf\n", a) //少数出力(桁少なめ)
#define prints(s) printf("%s\n", s.c_str()) //string出力
#define all(x) (x).begin(), (x).end()
#define allsum(a, b, c) ((a + b) * c / 2LL) //等差数列の和、初項,末項,項数
#define pb push_back
#define rpriq priq<int, vector<int>, greater<int>>
#define deg_to_rad(deg) (((deg)/360.0L)*2.0L*PI)
#define rad_to_deg(rad) (((rad)/2.0L/PI)*360.0L)
#define Please return
#define AC 0
#define manhattan_dist(a, b, c, d) (abs(a - c) + abs(b - d)) /*(a, b) から (c, d) のマンハッタン距離 */
#define inf numeric_limits<double>::infinity();
#define linf numeric_limits<long double>::infinity()

using ll = long long;

constexpr int INF = 1073741823;
constexpr int MINF = -1073741823;
constexpr ll LINF = ll(4661686018427387903);
constexpr ll MOD = 1e9 + 7;
constexpr long double eps = 1e-6;
const long double PI = acosl(-1.0L);

using namespace std;

void scans(string& str) {
	char c;
	str = "";
	scanf("%c", &c);
	if (c == '\n')scanf("%c", &c);
	while (c != '\n' && c != -1 && c != ' ') {
		str += c;
		scanf("%c", &c);
	}
}

void scanc(char& str) {
	char c;
	scanf("%c", &c);
	if (c == -1)return;
	while (c == '\n') {
		scanf("%c", &c);
	}
	str = c;
}

double acot(double x) {
	return PI / 2 - atan(x);
}

ll LSB(ll n) { return (n & (-n)); }

/*-----------------------------------------ここからコード-----------------------------------------*/



int main() {

	int r, b, w, g;
	scanf("%d%d%d%d", &r, &b, &g, &w);
	printf("%d\n", w + b + g + r);

	Please AC;
}


Measured memory_bytes: 3172
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define ins insert
#define pqueue(x) priority_queue<x,vector<x>,greater<x>>
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
#define vtpl(x,y,z) vector<tuple<x,y,z>>
//#define at(x,i) get<i>(x);//
#define rev(x) reverse(x);
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
using vpl=vector<pl>;
using vvpl=vector<vpl>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[8]={1,0,-1,0,1,1,-1,-1};
const ll dx[8]={0,-1,0,1,1,-1,1,-1};
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
int main(){
    ll n,c;cin >> n >>c;
    vvl d(c,vl(c));
    rep(i,c)rep(j,c)cin >> d[i][j];
    vl x(c,0),y(c,0),z(c,0);
    rep(i,n){
        rep(j,n){
            ll h;cin >> h;h--;
            if((i+j)%3==0)x[h]++;
            if((i+j)%3==1)y[h]++;
            if((i+j)%3==2)z[h]++;
        }
    }
    ll ans=INF;
    rep(i,c){
        rep(j,c){
            rep(k,c){
                if(i==j||j==k||k==i)continue;
                ll tmp=0;
                rep(ii,c){
                    tmp+=x[ii]*d[ii][i];
                }
                rep(jj,c){
                    tmp+=y[jj]*d[jj][j];
                }
                rep(kk,c){
                    tmp+=z[kk]*d[kk][k];
                }
                chmin(ans,tmp);
            }
        }
    }
    cout << ans <<endl;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        long x = in.nextLong();
        long t = in.nextLong();
        long res = (x-t < 0) ? 0: x-t;
        System.out.println(res);
    }
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
#include <iostream>
#include <math.h>
using namespace std;
int main() {
    int64_t N;
    cin >> N;;
    int64_t sum = 0;
    int64_t sum2 = 0;
    int64_t avg = INT64_MAX;
    vector<int64_t>vec(N);
    for (int i=0; i<N; i++) {
        cin >> vec.at(i);
        sum += vec[i];
    }

    for (int i=N-1; i>0; i--){
        sum -= vec[i];
        sum2 += vec[i];
        int64_t s = abs(sum - sum2);
        if (s < avg) {
            avg = s;
        }
    }

    cout << avg << endl;
    return 0;
}

Measured memory_bytes: 1792
def integer_cards(cards, params)
  card_keys = cards.uniq.sort
  card_count = cards.each_with_object(Hash.new { |h, k| h[k] = 0 }) { |i, h| h[i] += 1 }

  param_keys = []
  param_count = Hash.new { |h, k| h[k] = 0 }
  params.each { |c, k| param_keys << k; param_count[k] += c }
  param_keys.sort_by! { |n| n * -1 }

  card_key_idx = 0
  param_keys.each do |param_key|
    while ((card_key = card_keys[card_key_idx]) < param_key) && param_count[param_key] > 0 && card_key_idx < cards.size
      replace_count = [card_count[card_key], param_count[param_key]].min
      card_count[card_key] -= replace_count
      param_count[param_key] -= replace_count

      card_keys << param_key unless card_count.key?(param_key)
      card_count[param_key] += replace_count

      if card_count[card_key].zero?
        card_key_idx += 1
      end
    end
  end

  sum = 0
  card_key_idx.upto(card_keys.size - 1) do |i|
    card_count[card_keys[i]]
    sum += card_keys[i] * card_count[card_keys[i]]
  end
  sum
end

n, m = gets.split.map(&:to_i)
cards = gets.split.map(&:to_i)
params = []
m.times do 
  params << gets.split.map(&:to_i)
end

puts integer_cards(cards, params)

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

typedef vector<int> vi;
typedef pair<int, int> pii;
#define endl "\n"
#define sd(val) scanf("%d", &val)
#define ss(val) scanf("%s", &val)
#define sl(val) scanf("%lld", &val)
#define debug(val) printf("check%d\n", val)
#define all(v) v.begin(), v.end()
#define PB push_back
#define MP make_pair
#define FF first
#define SS second
#define ll long long
#define MOD 1000000007
#define clr(val) memset(val, 0, sizeof(val))
#define what_is(x) cerr << #x << " is " << x << endl;
#define OJ                            \
    freopen("input.txt", "r", stdin); \
    freopen("output.txt", "w", stdout);
#define FIO                           \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);

int main()
{
    int t;
    cin >> t;

    string s;

    cin >> s;
    int R = 0;
    int r = 0;

    for (int i = 0; i < t; i++)
    {
        if (s[i] == 'R')
            R++;
    }

    for (int i = 0; i < R; i++)
    {
        if (s[i] == 'R')
            r++;
    }

    cout << R - r << endl;

    return 0;
}

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

const int MOD = 1e9 + 7;
const int MAX = 3e6 + 5;

int fact[MAX];
int inv[MAX];

int Power(int n, int x) {
  if (x == 0) {
    return 1;
  } else if (x & 1) {
    return 1ll * n * Power(n, x - 1) % MOD;
  } else {
    int res = Power(n, x / 2);
    return 1ll * res * res % MOD;
  }
}

int C(int n, int r) {
  if (r > n || r < 0) {
    return 0;
  }
  return 1ll * fact[n] * inv[r] % MOD * inv[n - r] % MOD;
}

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

  fact[0] = inv[0] = 1;
  for (int i = 1; i < MAX; i++) {
    fact[i] = 1ll * i * fact[i - 1] % MOD;
    inv[i] = Power(fact[i], MOD - 2);
  }

  int K;
  cin >> K;
  string S;
  cin >> S;
  int ans = 0;
  for (int i = 0; i <= K; i++) {
    ans += 1ll * Power(26, i) * Power(25, K - i) % MOD * C(K - i + int(S.size()) - 1, int(S.size()) - 1) % MOD;
    if (ans >= MOD) {
      ans -= MOD;
    }
  }
  cout << ans << "\n";
  return 0;
}


Measured memory_bytes: 27672
#include<iostream>
#include<vector>
#include<algorithm>
#include<cctype>
#include<utility>
#include<string>
#include<cmath>
#include<cstring>
#include<queue>
#include<map>
#include<queue>

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 1000000007
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;
typedef long long int ll;
ll dx[4] = {1,0,0,-1};
ll dy[4] = {0,1,-1,0};

#define ARRAY_MAX 2005
ll n,h,w;
ll X1[ARRAY_MAX],X2[ARRAY_MAX],Y1[ARRAY_MAX],Y2[ARRAY_MAX];
ll field[ARRAY_MAX*2][ARRAY_MAX*2];
vector<ll> xs,ys,xunzip,yunzip;
map<ll,ll> xzip,yzip;

void compress(vector<ll>& x,map<ll,ll>& zip,vector<ll>& unzip){

    VSORT(x);
    x.erase(unique(x.begin(),x.end()),x.end());
    unzip.resize(x.size());
    REP(i,x.size()){
        zip[x[i]] = i;
        unzip[i] = x[i];
    }
}


int main(){

    cin >> n;
   
    REP(i,n){
        cin >> X1[i] >> Y1[i] >> X2[i] >> Y2[i];
        xs.push_back(X1[i]);
        xs.push_back(X2[i]);
        ys.push_back(Y1[i]);
        ys.push_back(Y2[i]);
    }

    compress(xs,xzip,xunzip);
    compress(ys,yzip,yunzip);

    w = xzip.size();
    h = yzip.size();

    REP(i,h){
        fill(field[i],field[i]+w,0);
    }
    REP(i,n){
        field[yzip[Y1[i]]][xzip[X1[i]]]++;
        field[yzip[Y1[i]]][xzip[X2[i]]]--;
        field[yzip[Y2[i]]][xzip[X1[i]]]--;
        field[yzip[Y2[i]]][xzip[X2[i]]]++;
    }
    
    REP(i,h+1){
        REP(j,w){
            field[i][j+1] += field[i][j];
        }
    }
    REP(i,w+1){
        REP(j,h){
            field[j+1][i] += field[j][i];
        }
    }

    ll ans = 0;
    REP(y,h){
        REP(x,w){
            if(field[y][x] > 0){
                ans += (yunzip[y+1] - yunzip[y])*(xunzip[x+1] - xunzip[x]);
            }

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


Measured memory_bytes: 129116
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define vi vector<int>
#define pb push_back
#define pii pair<int , int>
#define fast ios_base::sync_with_stdio(0)
#define mod 1000000007
int dim;
struct Matrix
{
    ll val[52][52];
};
Matrix identity()
{
    Matrix ob;
    for(int i=0; i<dim; i++){
        for(int j=0; j<dim; j++){
            ob.val[i][j] = (i==j);
        }
    }
    return ob;
}
Matrix multiply(Matrix& x, Matrix& y)
{
    Matrix ret;
    for(int i=0; i<dim; i++){
        for(int j=0; j<dim; j++){
            ret.val[i][j] = 0;
            for(int k=0; k<dim; k++){
                ret.val[i][j] = (ret.val[i][j] + (x.val[i][k] * y.val[k][j])%mod)%mod;
            }
        }
    }
    return ret;
}
Matrix bigMod(Matrix base, ll p)
{
    if(p==0) return identity();
    Matrix x = bigMod(base, p/2);
    x = multiply(x,x);
    if(p%2) x = multiply(x,base);
    return x;
}
int main()
{
    fast;
    ll n,k;
    cin>>n>>k;
    dim = n;
    Matrix mat;
    for(int i=0; i<n; i++){
        for(int j=0; j<n; j++){
            cin>>mat.val[i][j];
        }
    }
    mat = bigMod(mat,k);
    ll ans = 0;
    for(int i=0; i<n; i++){
        for(int j=0; j<n; j++){
            ans+=mat.val[i][j];
            ans%=mod;
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 5376
from collections import deque
from collections import defaultdict
N, M = list(map(int, input().split()))

AB = []
for _ in range(M):
    a, b = list(map(int, input().split()))
    a -= 1
    b -= 1
    AB.append((a, b))

ans = 0

for m in range(M):
    count = 0
    T = defaultdict(list)
    for a, b in AB:
        if count == m:
            bridge = (a, b)
            count += 1
            continue
        T[a].append(b)
        T[b].append(a)
        count += 1

    q = deque()
    q.append(bridge[0])

    visited = [False] * N

    flg = True
    while q:
        c = q.popleft()
        visited[c] = True
        if c == bridge[1]:
            flg = False
            break
        for t in T[c]:
            if not visited[t]:
                q.append(t)
    if flg:
        ans += 1
print(ans)


Measured memory_bytes: 3316
// By Mohit Gupta
#include <bits/stdc++.h>
using namespace std;
//DEBUG 
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
#define printint(v) copy(begin(v), end(v), ostream_iterator<int>(cout," "))
#define printintv(s,e) copy(s,e, ostream_iterator<int>(cout," "))
#define forstl(i,v) for(auto &i: v)
#define all(v) (v).begin(), (v).end()
#define forn(i,e) for(int i = 0; i < e; i++)
#define forsn(i,s,e) for(int i = s; i < e; i++)
#define rforn(i,s) for(int i = s; i >= 0; i--)
#define rforsn(i,s,e) for(int i = s; i >= e; i--)
#define clz(a) __builtin_clz(a) // count leading zeroes
#define ctz(a) __builtin_ctz(a) // count trailing zeroes
#define popc(a) __builtin_popcount(a) // count set bits (for ints only diff for ll)
//https://gcc.gnu.org/onlinedocs/gcc/Other-Builtins.html for other in built
#define ln "\n"
#define dbg(x) cout<<#x<<" = "<<x<<ln
#define pb push_back
#define fi first
#define se second
#define IOS ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
typedef long long ll;
typedef pair<int,int> p32; 
typedef pair<ll,ll> p64;
typedef pair<double,double> pdd;
typedef vector<ll> v64;
typedef vector<int> v32;
typedef vector<vector<int> > vv32;
typedef vector<p64> vp64;
typedef vector<p32> vp32;
typedef map<int,int> m32;
#pragma GCC optimize ("-O2")
const int LIM = 1e5+5, MOD = 998244353;
int t,n,m,k,x,y;

int h[LIM];
v32 good(LIM,1);

int32_t main()
{
    IOS;
    cin>>n>>m;
    forsn(i,1,n+1) cin>>h[i];
    forn(i,m){
      cin>>x>>y;
      if(h[x]>=h[y]) good[y]=0;
      if(h[x]<=h[y]) good[x]=0;
    }
    int ans=0;
    forsn(i,1,n+1) ans+=good[i];
    cout<<ans<<ln;
}


Measured memory_bytes: 3992
import java.util.Scanner;

class Main{
  public static void main(String[] args){
    Scanner scan=new Scanner(System.in);
    int a=scan.nextInt();
    int b=scan.nextInt();
    if(a>=1 && a<=9 && b>=1 && b<=9){
      System.out.println(a*b);
    }else{
      System.out.println("-1");
    }
  }
}

Measured memory_bytes: 21588
import java.util.*;

public class Main{
    public static void main(String[] args) {
	Scanner sc = new Scanner(System.in);
	int H = sc.nextInt();
	int W = sc.nextInt();
	for ( int i = 0; i < H; i++ ) {
	    for ( int j = 0; j < W; j++ ) {
		String S = sc.next();
		if ( S.equals("snuke") ) {
		    System.out.printf("%c%d\n",'A'+j,i+1);
		}
	    }	    
	}

    }
}


Measured memory_bytes: 22228
n = int(input())
a = list(map(int, input().split()))
dic = {}
for i in range(n):
  if a[i] in dic:
    dic[a[i]] += 1
  else:
    dic[a[i]] = 1
q = int(input())
total = sum(a)
for _ in range(q):
  b, c = map(int, input().split())
  if b not in dic:
    print(total)
  else:
    total += (c - b) * dic[b]
    if c in dic:
      dic[c] += dic[b]
    else:
      dic[c] = dic[b]
    dic[b] = 0
    print(total)

Measured memory_bytes: 20800
n, k = map(int, input().split())
a = list(map(int, input().split()))

#idx = a.index(min(a))
#print(n // k + 1 )
ans = None
if n == k:
    ans = 1
else:
    if (n - 1) % (k - 1) != 0:
        ans = (n - 1) // (k - 1) + 1
    else:
        ans = (n - 1) // (k - 1)

print(ans)

Measured memory_bytes: 52652
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
using namespace std;

int main()
{
    int x;
    cin >> x;
    int a = x / 500;
    int b = (x - 500*a) / 5;
    cout << 1000 * a + 5 * b << endl;

    return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize("O3")
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;

using ll = long long;
using P = pair<int, int>;
using T = tuple<int, int, int>;

template <class T> inline T chmax(T &a, const T b) {return a = (a < b) ? b : a;}
template <class T> inline T chmin(T &a, const T b) {return a = (a > b) ? b : a;}

constexpr int MOD = 1e9 + 7;
constexpr int inf = 1e9;
constexpr long long INF = 1e18;
constexpr double pi = acos(-1);
constexpr double EPS = 1e-10;

int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};

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

    int n; cin>>n;
    string s; cin>>s;

    int ans = 0;
    for(int i=0; i<n; i++){
        char cur = s[i];
        while(i + 1 < n && cur == s[i+1]){
            cur = s[++i];
        }
        ans++;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 512
from collections import Counter
import math
n=int(input())
s=[['']*10]*n

def com(n, r):
    if n>=r:
        return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
    else:
        return 0
for i in range(n):
    s[i]=list(input())
    s[i].sort()
s=map(tuple,s)
c=dict(Counter(s))
x=0
for i in c.values():
    x+=com(i,2)
print(x)

Measured memory_bytes: 45064
import           Control.Monad
import           Data.List
import           Data.Maybe
import qualified Data.ByteString.Char8 as B

type Coord = (Double, Double)

main :: IO ()
main = solve <$> getParams >>= print

getParams :: IO [Coord]
getParams = readLn >>= flip replicateM getCoord

getCoord :: IO Coord
getCoord = do
  [x, y] <- map readInt . B.words <$> B.getLine
  return (fromIntegral x, fromIntegral y)

readInt :: B.ByteString -> Int
readInt = fst . fromJust . B.readInt

solve :: [Coord] -> Double
solve = average . map pathLength . permutations

pathLength :: [Coord] -> Double
pathLength xs = sum . zipWith distance xs $ tail xs

distance :: Coord -> Coord -> Double
distance (xi, yi) (xj, yj) = sqrt $ (xi - xj)^2 + (yi - yj)^2

average :: Fractional a => [a] -> a
average xs = sum xs / genericLength xs


Measured memory_bytes: 5116
#include <bits/stdc++.h>
#define le 300
using namespace std;
int n[le];
int main(){
  memset(n, 0, sizeof(n));
  string s;
  cin >> s;
  for(int i = 0; i < s.size(); i++) n[s[i]]++;
  for(int i = 'a'; i < 'z' + 1; i++){
    if(n[i] % 2 != 0){
      printf("No\n");
      return 0;
    }
  }
  printf("Yes\n");
  return 0;
}


Measured memory_bytes: 384
import heapq
N, M = map(int, input().split())
X = sorted([list(map(int, input().split())) for _ in range(N)], key=lambda x: x[0])
heap = []
ans = 0
j = 0
 
for i in range(1, M+1): # M - i 日後にするバイトを考える
    while (j < N) and (X[j][0] <= i): # 支払いがi日以内
        heapq.heappush(heap, -X[j][1]) # 候補の追加。最大の値が欲しいためマイナスに
        j += 1
    if len(heap):
        ans += - heapq.heappop(heap) # 候補があるとき、候補から最大値を取り出す
print(ans)

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

Measured memory_bytes: 588
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#define MAXN 1010
#define MAXM 2010
#define MOD 1000000007
#define $ long long
inline $ fuck($ x, $ p) {
    $ y = 1;
    while (p) {
        if (p & 1) y = y * x % MOD;
        x = x * x % MOD;
        p >>= 1;
    }
    return y;
}
$ n, m, x, t, ans, head[MAXN], to[MAXN << 1], val[MAXN << 1], next[MAXN << 1], tot = 0;
inline void _($ u, $ v, $ w) {
    next[tot] = head[u], to[tot] = v, val[tot] = w, head[u] = tot++;
    next[tot] = head[v], to[tot] = u, val[tot] = w, head[v] = tot++;
}
struct edge {
    $ u, v, w;
    inline friend bool operator<(const edge &a, const edge &b) {
        return a.w < b.w;
    }
} e[MAXM];
$ p[MAXN], deep[MAXN], qd[MAXM], fa[MAXN][20], max[MAXN][20];
inline $ find($ x) { return x == p[x] ? x : p[x] = find(p[x]); }
$ dis[MAXN][MAXN], eq, up;
$ dfs($ *dis, $ x, $ fa, $ nowans) {
    dis[x] = nowans;
    for ($ tmp, i = head[x]; ~i; i = next[i]) {
        if (to[i] == fa) continue;
        if (~(tmp = dfs(dis, to[i], x, std::max(nowans, val[i])))) return tmp;
    }
    return -1;
}
int main() {
    scanf("%lld%lld%lld", &n, &m, &x);
    for ($ i = 1; i <= m; i++) scanf("%lld%lld%lld", &e[i].u, &e[i].v, &e[i].w);
    memset(head, -1, sizeof(head));
    std::sort(e + 1, e + m + 1);
    for ($ i = 1; i <= n; i++) p[i] = i;
    for ($ i = 1; i <= m; i++) {
        $ U = find(e[i].u), V = find(e[i].v);
        if (U == V) continue;
        p[U] = V, t += e[i].w, qd[i] = 1;
        _(e[i].u, e[i].v, e[i].w);
    }
    if ((t = x - t) < 0) return puts("0"), 0;
    for (int i = 1; i <= n; i++)
        dfs(dis[i], i, 0, 0);
    for ($ i = 1; i <= m; i++) {
        if (qd[i]) continue;
        $ delta = e[i].w - dis[e[i].u][e[i].v] - t;
        if (delta > 0)
            up++;
        else if (delta == 0)
            eq++;
    }
    ans = 2LL * (fuck(2, eq) - 1) % MOD * fuck(2, up) % MOD;
    if (!t) ans = (ans + (fuck(2, n - 1) - 2) * fuck(2, m - n + 1) % MOD) % MOD;
    printf("%lld\n", ans);
    return 0;
}

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

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());

            int[,] dp = new int[n, n + 1];

            for (int i = 0; i < n; i++)
            {
                int[] input = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);

                for (int j = 0; j < n; j++)
                {
                    dp[i, j + 1] = dp[i, j] + input[j];
                }
            }

            int max = int.MinValue;

            for (int ws = 0; ws < n; ws++)
            {
                for (int wt = ws + 1; wt <= n; wt++)
                {
                    for (int hs = 0; hs < n; hs++)
                    {
                        int sum = 0;

                        for (int ht = hs; ht < n; ht++)
                        {
                            sum += dp[ht, wt] - dp[ht, ws];

                            max = Math.Max(max, sum);
                        }
                    }
                }
            }
            Console.WriteLine(max);
        }
    }
}

Measured memory_bytes: 9408
function main()
  
  S = collect(chomp(readline()))
  T = collect(chomp(readline()))
  
  reverse!(S)
  reverse!(T)
  
  len_S = length(S)
  len_T = length(T)
  
  check = 0
  check2 = 0
  ans = false
  
  for i in 1:len_S - len_T + 1
    for j in 1:len_T
      if S[i + j - 1] == T[j] || S[i + j - 1] == '?'
        check += 1
      else
        check = 0
        break
      end
    end
    if check != 0
      check2 = i
      ans = true
      break
    end
  end

  String_ans = []
  num = 1
  
  if ans
    for i in 1:len_S
      if i < check2 || check2 + len_T - 1 < i
        if S[i] == '?'
          push!(String_ans, 'a')
        else
          push!(String_ans, S[i])
        end
      else
        push!(String_ans, T[num])
        num += 1
      end
    end
  else
    push!(String_ans, "UNRESTORABLE")
  end
  
  reverse!(String_ans)
  
  println(join(String_ans))
  
end

main()

Measured memory_bytes: 179896
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;

int main(){
  ll n;
  cin >> n;
  ll a[n];
  for(ll i=0;i<n;i++) cin >> a[i];
  ll ans[n]={};
  for(int i=0;i<n;i+=2){
    ans[0]+=a[i];
  }
  for(int i=1;i<n;i+=2){
    ans[0]-=a[i];
  }
  for(int i=1;i<n;i++){
    ans[i]=2*a[i-1]-ans[i-1];
  }
  for(int i=0;i<n;i++) cout << ans[i] << " ";
  cout << endl;
}

Measured memory_bytes: 2816
import java.util.*;
public class Main {
	public static void main(String[] args)
	{
		Scanner sc=new Scanner(System.in);
		int arr[]=new int[5];
		for(int i=0;i<5;i++)
		{
			arr[i]=sc.nextInt();
		}
		for(int i=0;i<5;i++)
		{
			if(arr[i]==0)
			{
				System.out.println(i+1);
				break;
			}
		}
	}

}


Measured memory_bytes: 35740
using System;
using System.Linq;
using System.Collections.Generic;
class Program
{
    static void Main()
    {
        var input = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToList();
        var num = input[0] * input[1];
        if (num >= 2 && num % 2 == 0)
        {
            Console.WriteLine("Even");
        }
        else
        {
            Console.WriteLine("Odd");
        }
    }
}

Measured memory_bytes: 13268
#include <iostream>
#include <vector>

int main(int argc, char *argv[]) {
  std::vector<int> a = {1, 1, 1, 2, 1, 2, 1, 5,  2, 2, 1, 5, 1, 2, 1, 14,
                        1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
  int n;
  std::cin >> n;
  std::cout << a.at(n - 1) << std::endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <queue>
#include <vector>
#include <algorithm>
#include <set>
#include <cmath>
#include <tuple>
#include <cstring>
#include <map>
#include <iomanip>
#include <ctime>
#include <complex>
#include <cassert>
#include <climits>
using namespace std;
typedef long long ll;
#define _ << " " <<
#define all(X) (X).begin(), (X).end()
#define len(X) (X).size()
#define Pii pair<int, int>
#define Pll pair<ll, ll>
#define Tiii tuple<int, int, int>
#define Tlll tuple<ll, ll, ll>

int INF = 1e9;
struct Edge { int from, to, cost; };

Edge edge[10050];
vector<int> fow[10050], rev[10050];
vector<bool> fow_reach(10050, false), rev_reach(10050, false);
int dist[5050];
int V, E;
bool neg = false;

void bellman_ford(int s) {
    for (int i = 0; i < V; i++) dist[i] = INF;
    dist[s] = 0;
    for (int i = 0; i < V; i++) {
        bool update = false;
        for (int j = 0; j < E; j++) {
            Edge e = edge[j];
            if (dist[e.to] > dist[e.from] + e.cost) {
                dist[e.to] = dist[e.from] + e.cost;
                update = true;
                if (i == V - 1 && fow_reach[e.from] && rev_reach[e.to]) {
                    neg = true;
                }
            }
        }
        if (!update) return;
    }
}

void fow_search(int k) {
    fow_reach[k] = 1;
    for (auto & i : fow[k]) {
        if (!fow_reach[i]) fow_search(i);
    }
}

void rev_search(int k) {
    rev_reach[k] = 1;
    for (auto & i : rev[k]) {
        if (!rev_reach[i]) rev_search(i);
    }
}

int main() {
    int p, ans;
    cin >> V >> E >> p;
    for (int i = 0; i < E; i++) {
        cin >> edge[i].from >> edge[i].to >> edge[i].cost;
        edge[i].from--;
        edge[i].to--;
        edge[i].cost = -edge[i].cost + p;
        fow[edge[i].from].push_back(edge[i].to);
        rev[edge[i].to].push_back(edge[i].from);
    }
    fow_search(0);
    rev_search(V - 1);
    bellman_ford(0);
    ans = max(0, -dist[V - 1]);
    if (neg || dist[0] != 0) cout << -1 << endl;
    else cout << ans << endl;

}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
struct job{
	long long a;
	long long b;
}c[200005];
int cmp(job x,job y)
{
	if(x.b==y.b) return x.a>y.a;
	else return x.b<y.b;
}
long long n,ans;
int main(){
	cin>>n;
	for(int i=1;i<=n;i++) cin>>c[i].a>>c[i].b;
	sort(c+1,c+1+n,cmp);
	for(int i=1;i<=n;i++)
	{
		ans+=c[i].a;
		if(ans>c[i].b) {cout<<"No";return 0;}
	}
	cout<<"Yes";
	return 0;
}

Measured memory_bytes: 3328
import itertools


def resolve():
    N, M, Q = map(int, input().split())
    a = [0 for i in range(Q)]
    b = [0 for i in range(Q)]
    c = [0 for i in range(Q)]
    d = [0 for i in range(Q)]

    for i in range(Q):
        a[i], b[i], c[i], d[i] = map(int, input().split())
        b[i] -= 1
        a[i] -= 1
    ans = 0

    for seq in itertools.combinations_with_replacement(range(M), N):
        tmp = 0
        for i in range(Q):
            if seq[b[i]] - seq[a[i]] == c[i]:
                tmp += d[i]
        ans = max(ans, tmp)

    print(ans)


resolve()

Measured memory_bytes: 68320
/*
このコード、と～おれ!
Be accepted!
∧＿∧　
（｡･ω･｡)つ━☆・*。
⊂　　 ノ 　　　・゜+.
　しーＪ　　　°。+ *´¨)
 　　　　　　　　　.· ´¸.·*´¨) ¸.·*¨)
		  　　　　　　　　　　(¸.·´ (¸.·'* ☆
					*/

#include <stdio.h>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstring>
#include <vector>
#include <numeric>
#include <iostream>
#include <random>
#include <map>
#include <unordered_map>
#include <queue>
#include <regex>

#pragma GCC optimize("Ofast")
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define rep1(i, n) for(int i = 1; i <= (n); ++i)
#define rep2(i, n) for(int i = 2; i < (n); ++i)
#define repr(i, n) for(int i = n; i >= 0; --i)
#define reprm(i, n) for(int i = n - 1; i >= 0; --i)
#define printynl(a) printf(a ? "yes\n" : "no\n")
#define printyn(a) printf(a ? "Yes\n" : "No\n")
#define printYN(a) printf(a ? "YES\n" : "NO\n")
#define printin(a) printf(a ? "possible\n" : "inposible\n")
#define printdb(a) printf("%.50lf\n", a)//少数出力
#define printdbd(a) printf("%.16lf\n", a)//少数出力(桁少なめ)
#define prints(s) printf("%s\n", s.c_str())//string出力
#define all(x) (x).begin(), (x).end()
#define allsum(a, b, c) ((a + b) * c / 2)//等差数列の和、初項,末項,項数
#define pb push_back
#define priq priority_queue
#define rpriq priq<int, vector<int>, greater<int>>
#define deg_to_rad(deg) (((deg)/360.0)*2.0*PI)
#define rad_to_deg(rad) (((rad)/2.0/PI)*360.0)
#define Please return
#define AC 0

using ll = long long;

constexpr int INF = 1073741823;
constexpr int MINF = -1073741823;
constexpr ll LINF = ll(4661686018427387903);
constexpr ll MOD = 1000000007;
const double PI = acos(-1);

using namespace std;

void scans(string& str) {
	char c;
	str = "";
	scanf("%c", &c);
	if (c == '\n')scanf("%c", &c);//最初の改行対策
	while (c != '\n' && c != -1) {
		str += c;
		scanf("%c", &c);
	}
}

void scanc(char& str) {
	char c;
	scanf("%c", &c);
	if (c == -1)return;
	while (c == '\n') {
		scanf("%c", &c);
	}	str = c;
}

double acot(double x) {
	return PI / 2 - atan(x);
}

/*-----------------------------------------ここからコード-----------------------------------------*/
ll gcd(ll a, ll b) {
    if (b==0) return a;
    else return gcd(b, a%b);
}

ll lcm(ll number1,ll number2){
	return number1 * number2 / gcd(number1,number2);	
}

int main() {
	
	int n;
	scanf("%d", &n);
	vector<int> a(n);
	rep(i, n)scanf("%d", &a[i]);
	ll ans = 0;
	rep(i, n)ans += a[i] - 1;
	printf("%lld\n", ans);
	
	Please AC;
}


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

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(x) (x).begin(), (x).end()

using namespace std;

template <typename T> T &chmin(T &a, const T &b) {return a = min(a, b);}
template <typename T> T &chmax(T &a, const T &b) {return a = max(a, b);}

using ll = long long;
using ld = long double;

const int INF = 1e9;
const ld eps = 1e-9, pi = acos(-1.0);

ll gcd(ll a, ll b){
  return b ? gcd(b, a%b) : a;
}

bool isPrime(ll x){
  for(ll i=2; i<sqrt(x); i++){
    if(x%i==0) return false;
  }
  return true;
}

void solve(long long A, long long B){
  if(A<B) swap(A, B);
  ll g = gcd(A,B);
  set<ll> res;
  res.insert(1);
  for(ll i=2; i<=sqrt(A); i++){
    if(g%i==0) res.insert(i);
    while(g%i==0) g/=i;
  }
  if(isPrime(g)) res.insert(g);
  cout << res.size() << endl;
}

int main(){
  long long A;
  scanf("%lld",&A);
  long long B;
  scanf("%lld",&B);
  solve(A, B);
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
int main(void)
{
	int n,len,i;
	char s[10001];
	scanf("%d",&n);
	scanf("%s",s);
	len=strlen(s);
	for (i=0;i<len;i++)
	{
		n=n%26;
		s[i]=s[i]+n;
		if (s[i]>90)
		s[i]=s[i]-26;
	}
	printf("%s",s);
 } 

Measured memory_bytes: 888
A, B, C, X = [int(input()) for i in range(4)]
count = 0
for a in range(A+1):
    for b in range(B+1):
        for c in range(C+1):
            if(X == 500 * a + 100 * b + 50 * c):
                count += 1
print(count)


Measured memory_bytes: 2940
#include<iostream>

using namespace std;

string s[10] = {"\n",".,!? ","abc","def","ghi","jkl","mno","pqrs","tuv","wxyz"};

char now,before;
string in;


void solve(){
  now = '\n';
  before = 'N';
  int c=0,r=0;
  int index = 0;
  while(in[index++] == '0');
  
  for(int i = index-1; i < in.length(); i++){
    if(in[i] == '0'){
      if(c+r){
	now = s[c][r%s[c].length()];
	cout << now;
	c = r =0;
      }
    }else if(before == in[i]){
      r++;
    }else{
      c = in[i]-'0';
      r = 0;
    }
    before = in[i];
  }
  cout << endl;
}

int main(){
  int N;
  cin >> N;
  while(N--){
    cin.ignore();
    while(getline(cin,in)) solve();
  }
  return 0;
}

Measured memory_bytes: 1212
import itertools
S = list(input())

SUM = 0
for pattern in itertools.product('+ ', repeat=len(S)-1):
    form = ''
    for i in range(len(S)-1):
        form += S[i] + pattern[i]
    form += S[-1]
    SUM += eval(form.replace(' ', ''))
print(SUM)


Measured memory_bytes: 3060
#include <iostream>
#include <cmath>
#include <bits/stdc++.h>
#define _USE_MATH_DEFINES

using namespace std;

int main()
{
    int a, b, h, m;
    const double PI = 3.141592653589793238462643383279502884;

    cin >> a >> b >> h >> m;

    double hRad = - (PI * 2) / 12 * h - (PI * 2) / (12 * 60) * m + PI / 2;
    double mRad = - (PI * 2) / 60 * m + PI / 2;

    // cout << "hRad:" << hRad << endl;
    // cout << "mRad:" << mRad << endl;

    double ax = 1.0 * a * cos(hRad);
    double ay = 1.0 * a * sin(hRad);

    double bx = 1.0 * b * cos(mRad);
    double by = 1.0 * b * sin(mRad);

    double ans = sqrt((ax - bx) * (ax - bx) + (ay - by) * (ay - by));

    cout.precision(17);
    cout << fixed << ans << endl;
    return 0;
}

Measured memory_bytes: 4096