akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <iostream>
#define rs register short
#define ri register int
using namespace std;

typedef long long LL;
const int N = 2001;
const int K = N << 2;
const int M = 2e5 + 5;
const LL mod = 1e9 + 7;

template <typename T> inline void read(T &x) {
  char ch; x = 0;
  while (!isdigit(ch = getchar()));
  do {x = (x << 1) + (x << 3) + ch - '0';} while (isdigit(ch = getchar()));
}

namespace MathCal {
  LL fac[K], inv[K];
  inline LL Co(int x, int y) {
    if (x < y) return 0;
    return fac[x] * inv[y] % mod * inv[x - y] % mod;
  }
  inline LL pow(LL x, LL exp) {
    LL ret = 1;
    for (; exp; exp >>= 1, x = x * x % mod)
      if (exp & 1) ret = ret * x % mod;
    return ret;
  }
  inline void pre() {
    for (int i = fac[0] = 1; i < K; i ++) fac[i] = fac[i - 1] * i % mod;
    inv[K - 1] = pow(fac[K - 1], mod - 2);
    for (int i = K - 1; i >= 1; i --) inv[i - 1] = inv[i] * i % mod;
  }
}
using namespace MathCal;

int dp[N << 1][N << 1];
int a[M], b[M], n;

inline void adj(int &x) {
  if (x >= mod) x -= mod;
}

int main() {
  int Maxx = 0, Maxy = 0;
  pre();
  read(n);
  for (ri i = 1; i <= n; i ++) {
    read(a[i]); read(b[i]);
    Maxx = max(Maxx, a[i]);
    Maxy = max(Maxy, b[i]);
    dp[N - a[i]][N - b[i]] ++;
  }
  int A = N - Maxx, B = N + Maxx, C = N - Maxy, D = N + Maxy;
  for (rs i = A; i <= B; i ++)
    for (rs j = C; j <= D; j ++) {
      dp[i][j] += dp[i - 1][j];
      adj(dp[i][j]);
      dp[i][j] += dp[i][j - 1];
      adj(dp[i][j]);
    }
  LL ans = 0;
  for (ri i = 1; i <= n; i ++) {
    ans += dp[a[i] + N][b[i] + N] - Co(a[i] + a[i] + b[i] + b[i], a[i] + a[i]);
    if (ans < 0) ans += mod;
    if (ans >= mod) ans -= mod;
  }
  printf("%lld\n", ans * pow(2LL, mod - 2) % mod);
  return 0;
}


Measured memory_bytes: 64512
#include <bits/stdc++.h>
using namespace std;
int K,N,a[200001],dist=0,prev_v=0,tmp_maxi,maxi=0;

int main(){
    cin >> K >> N;
    for (int i=0;i<N;i++) cin >> a[i];
    
    a[N] = K + a[0];
    int prev_v = a[0];
    for(int i=0;i<N+1;i++){
        tmp_maxi = a[i] - prev_v;
        prev_v = a[i];

        if(tmp_maxi >= maxi) {
            maxi = tmp_maxi;
        }
    }
    cout << K - maxi << endl;
}

Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {

  public static void main(String[] args){

    Scanner sc = new Scanner(System.in);

    int a = sc.nextInt();
    int b = sc.nextInt();
    int c = sc.nextInt();

    if(a + b >= c)
      System.out.println("Yes");
    else
      System.out.println("No");
  }

}


Measured memory_bytes: 23764
package main

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

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 500001), 500000)
	return scanner
}

func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}

func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}

func getNextUint64(scanner *bufio.Scanner) uint64 {
	i, _ := strconv.ParseUint(getNextString(scanner), 10, 64)
	return i
}

func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}

func main() {
	fp := os.Stdin
	wfp := os.Stdout

	if len(os.Args) > 1 {
		fp, _ = os.Open(os.Args[1])
		if len(os.Args) > 2 {
			wfp, _ = os.Create(os.Args[2])
		}
	}

	scanner := getScanner(fp)
	writer := bufio.NewWriter(wfp)

	v := getNextInt(scanner)
	e := getNextInt(scanner)

	grl := GRL{}

	grl.prenum = make([]int, v)
	grl.parent = make([]int, v)
	grl.lowest = make([]int, v)
	grl.visited = make([]int, v)
	grl.g = make([][]int, v)
	grl.timer = 1
	for i := 0; i < v; i++ {
		grl.g[i] = make([]int, 0)
	}

	for i := 0; i < e; i++ {
		s := getNextInt(scanner)
		t := getNextInt(scanner)
		grl.g[s] = append(grl.g[s], t)
		grl.g[t] = append(grl.g[t], s)
	}

	grl.dfs(0, -1)

	np := 0
	ans := make([]int, 0)
	for i := 1; i < v; i++ {
		if grl.parent[i] == 0 {
			np++
			continue
		}
		if grl.prenum[grl.parent[i]] <= grl.lowest[i] {
			ans = append(ans, grl.parent[i])
		}
	}

	if np > 1 {
		ans = append(ans, 0)
	}

	sort.Ints(ans)
	for i := 0; i < len(ans); i++ {
		if i > 0 && ans[i] == ans[i-1] {
			continue
		}
		fmt.Fprintln(writer, ans[i])
	}

	writer.Flush()
}

type GRL struct {
	timer                           int
	prenum, parent, lowest, visited []int
	g                               [][]int
}

func (grl *GRL) dfs(current, prev int) {
	grl.prenum[current] = grl.timer
	grl.lowest[current] = grl.timer
	grl.timer++
	grl.visited[current] = 1
	for _, to := range grl.g[current] {
		if grl.visited[to] == 0 {
			grl.parent[to] = current
			grl.dfs(to, current)
			if grl.lowest[current] > grl.lowest[to] {
				grl.lowest[current] = grl.lowest[to]
			}
			continue
		}
		if prev == to {
			continue
		}
		if grl.lowest[current] > grl.prenum[to] {
			grl.lowest[current] = grl.prenum[to]
		}
	}
}



Measured memory_bytes: 6228
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll mod=1e9+7;

int main(){
    string str;
    cin >> str;
    int a, b, c, d;
    a=str[0]-'0', b=str[1]-'0', c=str[2]-'0', d=str[3]-'0';
    if(a+b+c+d==7){
        cout << a << '+' << b << '+' << c << '+' << d << '=' << 7;
    }else if(a+b+c-d==7){
        cout << a << '+' << b << '+' << c << '-' << d << '=' << 7;
    }else if(a-b+c+d==7){
        cout << a << '-' << b << '+' << c << '+' << d << '=' << 7;
    }else if(a+b-c+d==7){
        cout << a << '+' << b << '-' << c << '+' << d << '=' << 7;
    }else if(a-b-c+d==7){
        cout << a << '-' << b << '-' << c << '+' << d << '=' << 7;
    }else if(a+b-c-d==7){
        cout << a << '+' << b << '-' << c << '-' << d << '=' << 7;
    }else if(a-b+c-d==7){
        cout << a << '-' << b << '+' << c << '-' << d << '=' << 7;
    }else if(a-b-c-d==7){
        cout << a << '-' << b << '-' << c << '-' << d << '=' << 7;
    }
}

Measured memory_bytes: 256
import collections

#文字列を一文字ずつ取得したいとき
def inputStrOnebyOne():
    s = list(input())
    return s

#整数を一つずつリストに入れる
def inputOnebyOne_Int():
    a = list(int(x) for x in input().split())
    return a

def main():
    m = input()
    print(str(48-int(m)))

if __name__=='__main__':
    main()

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

static const int N=101;
static const int INF=(1<<21);

int n,M[N][N];
int d[N];

void bfs(int s){
  queue<int> q;
  q.push(s);

  for(int i=0;i<n;i++) d[i]=INF;
  d[s]=0;
  
  int u;
 
  while(!q.empty()){
    u=q.front();
    q.pop();
    for(int v=0;v<n;v++){
      if(M[u][v]==0) continue;
      if(d[v]!=INF) continue;
      d[v]=d[u]+1;
      q.push(v);
    }
  }
 
  for(int i=0;i<n;i++){
    if(d[i]==INF)d[i]=-1;
  }
  
  for(int i=0;i<n;i++){
    cout<<i+1<<" "<<d[i]<<endl;
  }
  
}

int main(){
  int u,k,v;

  cin>>n;
  for(int i=0;i<n;i++){
    for(int j=0;j<n;j++) M[i][j]=0; 
  }
 
  for(int i=0;i<n;i++){
    cin>>u;
    cin>>k;
    for(int j=0;j<k;j++){
      cin>>v;
      M[u-1][v-1]=1;
    }
  }
 
  bfs(0);

  return 0;
}

Measured memory_bytes: 1240
N, K = map(int, input().split())

A = [[0 for _ in range(N+1)] for _ in range(100)]
A[0] = [0] + list(map(int, input().split()))

for l in range(1,100):
  #print(A[0])
  for j in range(1, N+1):
    #print(l,j)
    #print(l-1,A[l-1][j])
    A[l][j] = A[l-1][A[l-1][j]] #2^(l-1)1回テレポート後、さらに^(l-1)1回テレポート
  if 2 ** l > K:
    break

k = K
ans = 1
keta = 0
while k > 0:
  if k & 1:
    ans = A[keta][ans]
  k = k >> 1
  keta += 1

print(ans)
        
        
        



Measured memory_bytes: 292736
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <map>
#include <set>

#define MIN_INT -2147483648
#define MAX_INT 2147483647
#define MIN_LONG -9223372036854775808L
#define MAX_LONG 9223372036854775807L
#define PI 3.141592653589793238462643383279502884L

#define long long long int

using std::vector;
using std::map;
using std::set;
using std::string;
using std::pair;
using std::cin;
using std::cout;
using std::cerr;

// @author: pashka

int main() {
    std::ios::sync_with_stdio(false);

    int n;
    cin >> n;
    vector<string> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    int res = 0;
    for (int t = 0; t < n; t++) {
        bool ok = true;
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                if (a[(i + t) % n][j] != a[(j + t) % n][i]) {
                    ok = false;
                }
            }
        }
        if (ok) {
            res += n;
        }
    }
    cout << res << "\n";

    return 0;
}	 

Measured memory_bytes: 384
#include <iostream>
#include <algorithm>

using namespace std;

typedef long long ll;

ll n;
ll a[5];
ll ans = 1e7;

long long check()
{
    long long res = 0;
    for (int i = 0; i < n; i++)
    {
        while (res % 10 != 0) res++;
        res = res + a[i];
    }
    ans = min(ans, res);
}

int main()
{
    n = 5;
    for (int i = 0; i < 5; i++)
    {
        cin >> a[i];
    }
    for (int i = 0; i < 120; i++)
    {
        check();
        next_permutation(a, a + n);
    }
    cout << ans;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define Hello ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long
#define endl '\n'
int main()
{
    Hello
    int n;
    cin >> n;
    int b[n + 5], a[n + 5], sum = 0;
    for(int i = 0; i < n - 1; i++)
        cin >> b[i];
    for(int i = n - 2; i >= 0; i--){
        if(i == n - 2)
            a[i] = a[i + 1] = b[i];
        else{
            a[i] = b[i];
            a[i + 1] = min(b[i], a[i + 1]);
        }
    }
    for(int i = 0; i < n; i++)
        sum += a[i];
    cout << sum;
    return 0;
}


Measured memory_bytes: 256
/******************************************************************************

                            Online Java Compiler.
                Code, Compile, Run and Debug java program online.
Write your code in this editor and press "Run" button to execute it.

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

import java.util.*;
public class Main
{
	public static void main(String args[]) throws Exception
	{
	    try
	    {
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		String str[]=new String[2*100000];
		for(int i=0;i<n;i++)
		{
		          str[i]=sc.next();
		}
		Set<String> set=new HashSet<>(Arrays.asList(str));
		set.remove(null);
		System.out.println(set.size());
	    }
	    catch(Exception e)
	    {}
	    


	}
}



Measured memory_bytes: 75040
#include <iostream>
#include <cmath>
#include <iomanip>
#include <cstdio>
#include <stack>
#include <queue>
#include <bits/stdc++.h>
typedef long long int ll;
typedef long double ld;
using namespace std;

int main(){
    ll n,k;
    cin>>n>>k;
    ll flag;
    if(n%2==0){
        flag=n/2;
    }else{
        flag=n/2+1;
    }
    if(flag>=k){
        cout<<"YES"<<endl;
    }else{
        cout<<"NO"<<endl;
    }
}

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

using namespace std;

#define range(i, m, n) for(int i = m; i < n; i++)
#define husk(i, m, n) for(int i = m; i > n; i--)

int n;

int main() {
  cin >> n;
  map<long long, int> cnt;
  long long p = 0;
  cnt[0] = 1;
  range(i, 0, n) {
    int a;
    cin >> a;
    p += a;
    cnt[p]++;
  }
  long long res = 0;
  for(auto it : cnt) {
    long long s = it.second;
    res += s * (s - 1) / 2;
  }
  cout << res;
  return 0;
}


Measured memory_bytes: 12800
import java.util.Scanner;
public class Main {
	public static void main(String args[]) {
		Scanner scanner = new Scanner(System.in);
		int a = scanner.nextInt();
		int b = scanner.nextInt();
		if(a*b%2==0){
			System.out.println("Even");
		}
		else{
			System.out.println("Odd");
		}
	}
}

Measured memory_bytes: 21716
from collections import deque


def main():
    string = deque(input())
    answer = 0
    while string:
        if string[0] == string[-1]:
            string.pop()
            if string:
                string.popleft()
            answer += 0
        else:
            if string[0] == "x":
                string.append("x")
                answer += 1
            elif string[-1] == "x":
                string.appendleft("x")
                answer += 1
            else:
                answer = -1
                break
    print(answer)


if __name__ == '__main__':
    main()



Measured memory_bytes: 4204
#include<cstdio>
using namespace std;
long long n,m,s;

int main(){
    scanf("%lld",&n);
    m=n;
    while(m){
        s+=m%10;
        m/=10;
    }
    if(n%s==0) printf("Yes\n");
    else printf("No\n");
    return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main(){
int n;string s;int x=0,p=0;
cin >> n;cin >>s;
for(int i=0;i<n;i++){
  if(s[i]=='I') x++;
  if(s[i]=='D') x--;
  p=max(x,p);
}
cout << p<<endl;
}


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

int main(){
  int i,seconds,total=0;
  
  for(i = 0; i < 4; i++){
    cin >> seconds;
    total+=seconds;
  }
  
  int result_minutes=total/60;
  int result_seconds=total%60;

  cout << result_minutes << endl;
  cout << result_seconds << endl;
  return 0;
}

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

int main(){
    string s;
    
    cin >> s;
    int N = atoi(s.c_str());
    
    int num[4];
    for(int i=0; i < 4; i++){
        num[i] = N%10;
        N = N / 10;
    }
    
    int opt[4];
    for(int X=0; X<16; X++){
        int sum=num[3];
        ostringstream ss;
        ss << num[3];
        string ans=ss.str();
        for(int i=0; i<3; i++){
            opt[i] = (X>>i)&1;
        }
        
        for(int j=2; j>-1; j--){
            ostringstream ss;
            ss << num[j];
            
            switch(opt[j]){
                case 1:
                    sum += num[j];
                    ans += "+"+ss.str();
                    break;
                case 0:
                    sum -= num[j];
                    ans += "-"+ss.str();
                    break;
                default:
                    break;
            }
        }
        
        if(sum == 7){
            ans += "=7";
            cout << ans << endl;
            return 0;
        }
    }
    
    
    return 0;
}


Measured memory_bytes: 256
import numpy as np

A = np.arange(int(input()) + 1)
B = np.arange(int(input()) + 1)
C = np.arange(int(input()) + 1)
total = int(input())
choice = 0
def abc(a, b, c):
    return 500*a + 100*b +50*c

for a in A:
    for b in B:
        for c in C:
            if abc(a, b, c) == total:
                choice += 1
print(choice)

Measured memory_bytes: 27152
#include<stdio.h>

int main(void)
{
	int a[100],i,n;
	scanf("%d", &n);
	for(i=0;i<n;i++)
	{
		scanf("%d", &a[i]);
	}
	for(i=n-1;i>0;i--)
	{
		printf("%d ",a[i]);
	}
	printf("%d\n", a[0]);
	return 0;
}



Measured memory_bytes: 2104
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Map;
import java.util.Scanner;
import java.util.HashMap;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Kenji
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        ABC091B solver = new ABC091B();
        solver.solve(1, in, out);
        out.close();
    }

    static class ABC091B {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            Map<String, Integer> map = new HashMap<>();
            int N = in.nextInt();
            for (int i = 0; i < N; i++) {
                String s = in.next();
                Integer integer = map.get(s);
                if (integer == null) {
                    integer = 0;
                }
                integer = integer + 1;
                map.put(s, integer);
            }

            int M = in.nextInt();
            for (int i = 0; i < M; i++) {
                String s = in.next();
                Integer integer = map.get(s);
                if (integer == null) {
                    integer = 0;
                }
                integer = integer - 1;
                map.put(s, integer);
            }

            int max = 0;
            for (Integer i : map.values()) {
                max = Math.max(i, max);
            }

            if (max < 0) {
                max = 0;
            }
            out.println(max);
        }

    }
}



Measured memory_bytes: 23764
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <vector>

#define rep(i, x, n) for(int i = x; i < n; i++)
using namespace std;
const long long INF = 1LL << 60;

long long GCD(long long a, long long b) {
    if(b == 0)
        return a;
    else
        return GCD(b, a % b);
}
long long LCM(long long a, long long b) {
    long long g = GCD(a, b);
    return a / g * b;
}
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() {
    int A, B, C;
    cin >> A >> B >> C;
    int m = max({A, B, C});
    if(m % 2 == (A + B + C) % 2) {
        cout << ((3 * m - (A + B + C)) / 2) << endl;
    } else {
        cout << ((3 * (m + 1) - (A + B + C)) / 2) << endl;
    }
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <numeric>
#include <iterator>

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int,int> PII;
typedef vector<PII> VPII;
typedef istringstream ISS;
typedef ostringstream OSS;

#define REP( i, m, n ) for ( int i = (int)( m ); i < (int)( n ); ++i )
#define FOR( v, c ) for ( auto &v : c )
#define EACH( it, c ) for ( auto it = c.begin(); it != c.end(); ++it )
#define ALL( c ) (c).begin(), (c).end()
#define DRANGE( c, p ) (c).begin(), (c).begin() + p, (c).end()

#define PB( n ) push_back( n )
#define MP( a, b ) make_pair( ( a ), ( b ) )
#define EXIST( c, e ) ( (c).find( e ) != (c).end() )

#define fst first
#define snd second

#define DUMP( x ) cerr << #x << " = " << ( x ) << endl
#define DEBUG( x ) cerr << __FILE__ << ":" << __LINE__ << ": " << #x << " = " << ( x ) << endl

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

	int n, m;
	cin >> n >> m;

	vector<double> ls( n ), as( n ), bs( n );
	REP( i, 0, n )
	{
		cin >> ls[i] >> as[i] >> bs[i];
	}

	double res = 0;
	REP( i, 0, 1ULL << n )
	{
		int bits = 0;
		{
			REP( j, 0, n )
			{
				bits += !!( i & 1ULL << j );
			}
		}
		if ( bits != m )
		{
			continue;
		}

		double tmp = 0;
		REP( j, 0, n )
		{
			REP( k, j + 1, n )
			{
				if ( ( i & 1ULL << j ) && ( i & 1ULL << k ) )
				{
					tmp += pow( ls[j] - ls[k], 2. ) + pow( as[j] - as[k], 2. ) + pow( bs[j] - bs[k], 2. );
				}
			}
		}
		res = max( res, tmp );
	}
	cout << setprecision( 8 ) << fixed << res << endl;

	return 0;
}

Measured memory_bytes: 1304
inf = float('inf')
# ベルマンフォード法 計算量(VE)
# [引数]: 隣接リスト, 始点, 終点
class Bellmanford:
    def __init__(self, to:list, start:int, goal:int = -1):
        self.N = len(to)
        self.to = [s[:] for s in to]
        self.start = start
        self.goal = goal
        self.dist = [inf] * self.N
        self.dist[start] = 0
        self.exists_negative_cycle = False
        self.exists_negative_cycle_stog = False
        self.is_updated = [False] * self.N

    # distを更新
    def update(self) -> None:
        for _ in range(self.N - 1):
            for v, s in enumerate(self.to):
                if not s: continue
                for nv, w in s:
                    if self.dist[nv] > self.dist[v] + w:
                        self.dist[nv] = self.dist[v] + w

    # グラフの負閉路検出
    def detection(self) -> bool:
        for v, s in enumerate(self.to):
            if not s: continue
            for nv, w in s:
                if self.dist[nv] > self.dist[v] + w:
                    self.dist[nv] = self.dist[v] + w
                    self.exists_negative_cycle = True
        return self.exists_negative_cycle

    # スタートからゴールまでのパスの負閉路検出
    def detection_stog(self) -> bool:
        for _ in range(self.N):
            for v, s in enumerate(self.to):
                if not s: continue
                for nv, w in s:
                    if self.dist[nv] > self.dist[v] + w:
                        self.dist[nv] = self.dist[v] + w
                        self.is_updated[nv] = True
                    if self.is_updated[v] is True:
                        self.is_updated[nv] = True
        self.exists_negative_cycle_stog = self.is_updated[self.goal]
        return self.exists_negative_cycle_stog

inf = float('inf')
# ワーシャルフロイド法 計算量O(N^3)
# [引数]: 隣接行列
class Warshallfloyd:
    def __init__(self, admat:list):
        self.N = len(admat)
        self.dist = [c[:] for c in admat]

    def update(self) -> None:
        for k in range(self.N):
            for i in range(self.N):
                for j in range(self.N):
                    if i == j:
                        self.dist[i][j] = 0
                    elif self.dist[i][j] > self.dist[i][k] + self.dist[k][j]:
                        self.dist[i][j] = self.dist[i][k] + self.dist[k][j]

N, M = map(int,input().split())
to = [[] for _ in range(N)]
admat = [[inf] * N for _ in range(N)]
for _ in range(M):
    s, t, d = map(int,input().split())
    to[s].append((t, d))
    admat[s][t] = d

BF = Bellmanford(to, 0)
BF.update()
if BF.detection():
    print("NEGATIVE CYCLE")
    exit()
WF = Warshallfloyd(admat)
WF.update()
ans_list = [[-1] * N for _ in range(N)]
for i in range(N):
    for j in range(N):
        ans_list[i][j] = WF.dist[i][j] if WF.dist[i][j] != inf else "INF"

for ans in ans_list:
    print(*ans)


Measured memory_bytes: 7376
#include <iostream>
#include <string>
#include <algorithm>
#include <math.h>
#include <vector>
#include <iomanip>
#include <map>
#include <queue>

using namespace std;

#define fori(x) for (int i = 0; i < x; ++i)
#define forj(x) for (int j = 0; j < x; ++j)

typedef long long ll;

const int INF = 2e9 + 5;
const int alength=100100;

int main() {
	int h,w,k;
	cin>>h>>w>>k;
	//# true
	bool c[10][10]={};
	fori(h){
		forj(w){
			char hoge;
			cin>>hoge;
			if(hoge=='#'){
				c[i][j]=true;
			}
		}
	}

	int ans=0;
	for(int x=0;x<(1<<h);++x){
		for(int y=0;y<(1<<w);++y){
			int count=0;
			fori(h){
				forj(w){
					if(c[i][j]&&!((x>>i)&1)&&!((y>>j)&1)){
						++count;
					}
				}
			}
			if(count==k){
				++ans;
			}
		}
	}
	cout<<ans;
}

Measured memory_bytes: 3632
#include <iostream>
#include <cstdio>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;
int main(){
    string s; cin >> s;
    int cnt=0;
    for(int i=1; i<s.size(); i++){
        if(s[i-1]==s[i]){ 
            cnt++;
            if(s[i]=='1'){
                s[i]-=1;
            }else{
                s[i]+=1;
            }
        }
    }
    cout << cnt << endl;
}

Measured memory_bytes: 512
from collections import deque
n = int(input())
route = [[] for i in range(n)]
for i in range(n):
    s = input()
    for j in range(n):
        if s[j] == "1":
            route[i].append(j)
            route[j].append(i)
ans = -1
for p in range(n):
    visit = [-1 for i in range(n)]
    visit[p] = 1
    d = deque()
    d.append(p)
    while d:
        now = d.popleft()
        for i in route[now]:
            if visit[i] == -1:
                visit[i] = visit[now] + 1
                d.append(i)
            elif abs(visit[i] - visit[now]) != 1:
                print(-1)
                exit()
    ans = max(ans,max(visit))
print(ans)

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

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

  int n;
  cin >> n;

  if (n % 2) {
    cout << (n * 2) << '\n';
  } else {
    cout << n << '\n';
  }

  return 0;
}

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


int main(){
    string s,t;cin>>s>>t;
    int ok=1;
    rep(i,0,s.size()){
        if(s[i]!=t[i])ok=0;
    }
    if(ok)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;

    
}

    









Measured memory_bytes: 3624
#pragma GCC optimize("Ofast")
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"

using namespace std;

using u8 = uint8_t;
using u16 = uint16_t;
using u32 = uint32_t;
using u64 = uint64_t;
using i8 = int8_t;
using i32 = int32_t;
using i64 = int64_t;

constexpr char newl = '\n';
constexpr double eps = 1e-10;

#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define F0R(i,b) FOR(i,0,b)
#define RFO(i,a,b) for (int i = ((b)-1); i >=(a); i--)
#define RF0(i,b) RFO(i,0,b)
//#define fi first
//#define se second
#define debug(x) cout << #x << ": " << x << '\n';
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()

template<typename T1, typename T2> inline void chmin(T1& a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1& a, T2 b) { if (a < b) a = b; }
template<class T> void Print(vector<T> v) {
  F0R(i, v.size()) {
    cout << v[i] << ' ';
  }
  cout << newl;
}

#if 1


// INSERT ABOVE HERE
signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);

  int N, M;
  cin >> N >> M;

  vector<int> nac(N), nwa(N);

  F0R(i, M) {
    int p; string s;
    cin >> p >> s; p--;

    if (s == "AC") {
      nac[p]++;
    }
    else {
      if (nac[p] == 0) nwa[p]++;
    }
  }

  int rac = 0, rwa = 0;

  F0R(i, N) {
    if (nac[i]) {
      rac++;
      rwa += nwa[i];
    }
  }

  cout << rac << ' ' << rwa;
}
#endif


Measured memory_bytes: 1024
using System;
using System.Linq;
using System.Collections.Generic;
class Program
{
	static void Main(string[] args)
	{
		List<int> input = IO.GetIntList();
		int h = input[0];
		int a = input[1];
		int count = 0;
		while(h > 0){
		    h -= a;
		    count++;
		}

		Console.WriteLine(count);
	}

}

static class IO
{
    static public string GetString() { return Console.ReadLine(); }
    static public int GetInt() { return int.Parse(Console.ReadLine()); }
    static public long GetLong() { return long.Parse(Console.ReadLine()); }
    static public List<string> GetStringList() { return Console.ReadLine().Split(' ').ToList(); }
    static public List<int> GetIntList() { return Console.ReadLine().Split(' ').Select(int.Parse).ToList(); }
    static public List<long> GetLongList() { return Console.ReadLine().Split(' ').Select(long.Parse).ToList(); }
    static public List<double> GetDoubleList() { return Console.ReadLine().Split(' ').Select(double.Parse).ToList(); }
    static public void WriteStrings<T>(IEnumerable<T> values) { foreach (var o in values) { Console.Write(o + " "); } }
}

Measured memory_bytes: 13268
#include<cstdlib>
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
using namespace std;
typedef long long lng;
#define UP(i,a,b) for(int i=(a); i<=(b); ++i)
#define DOWN(i,b,a) for(int i=(b); i>=(a); --i)
#define REP(i,n) UP(i,0,n-1)
#define ALL(a) (a).begin(), (a).end()
#define UNIQUE(a) a.erase(unique(ALL(a)), a.end()) //NOTE: <a> must be sorted in advance

lng power(lng b, int n) {lng sol=1; while(n>0) {if(n&1) {sol=sol*b;} n>>=1; b*= b;} return sol;} //calculate b^n in O(log(n)) time

const int MOD = 1000000007; //10^9+7
const double PI = 3.1415926535897932384626;

/*********** variables ************/
int N;
vector<int> seq;
/**********************************/


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

    UP(i, 2, N) seq.push_back(i);
    lng ans = 1;
    UP(d, 2, N) {
        int cnt = 0;
        bool flg = true;
        while(flg) {
            flg = false;
            REP(i, (int)seq.size()) {
                if(seq[i]%d == 0) {
                    flg = true;
                    cnt++;
                    seq[i] /= d;
                }
            }
        }
        ans *= cnt+1;
        ans %= MOD;
    }
    cout << ans << endl;
}


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

int main() {
  string S;
  cin >> S;
  
  int count = 0;
  
  if (S.at(0) == 'A') {
    for (int i = 1; i < S.size(); i++) {
      if (S.at(i) == 'C' && i != 1 && i != S.size()-1) {
        count++;
      } else if (S.at(i) >= 'A' && S.at(i) <= 'Z') {
        count += 2;
      }
    }
  }
  
  if (count == 1) {
    cout << "AC" << endl;
  } else {
    cout << "WA" << endl;
  }
}

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

int main()
{
  int count;
  int n,x;

  while(1){
    count = 0;
    
    cin >> n >> x;
    if(n == 0 && x == 0){break;}
    
    else{
      for(int i=1; i<=n; i++){
	for(int j=1; j<=n; j++){
	  for(int k=1; k<=n; k++){

	    int tot = i + j + k;
	    //	    cout << i <<"+"<< j << "+" << k << "="<< tot << endl; // debug
	    
	    if(i != j && j != k && k != i &&tot == x)
	      {count = count + 1;}
	  }}}
    } //end else
    cout << count / 6 << endl;}   // end while.
  //  "/6" means divide by 3! (permutation).

  return 0;
}


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

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> ii;
typedef tuple<ll, ll, ll> iii;
typedef vector<ll> vi;
typedef vector<ii> vii;
typedef vector<iii> viii;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
#define REP(i,n) for (ll i = 0; i < n; ++i)
#define REPR(i,n) for (ll i = n-1; i >= 0; --i)
#define FOR(i,m,n) for (ll i = m; i < n; ++i)
#define FORR(i,m,n) for (ll i = n-1; i >= m; --i)
#define FORE(x,xs) for (const auto& x : xs)
#define ALL(v) v.begin(), v.end()
#define CHMIN(x,y) x = min(x, y)
#define CHMAX(x,y) x = max(x, y)

template<int mod> struct ModInt {
    int64_t x;
    ModInt() : x(0) {}
    ModInt(int64_t y) : x(y >= 0 ? y % mod : (y % mod + mod) % mod) {}

    ModInt &operator+=(const ModInt &a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }

    ModInt &operator-=(const ModInt &a) {
        if ((x += mod - a.x) >= mod) x -= mod;
        return *this;
    }

    ModInt &operator*=(const ModInt &a) {
        x = 1LL * x * a.x % mod;
        return *this;
    }

    ModInt &operator/=(const ModInt &a) {
        *this *= a.inverse();
        return *this;
    }

    ModInt operator-() const {
        return ModInt(-x);
    }

    ModInt operator+(const ModInt a) const {
        return ModInt(*this) += a;
    }

    ModInt operator-(const ModInt a) const {
        return ModInt(*this) -= a;
    }

    ModInt operator*(const ModInt a) const {
        return ModInt(*this) *= a;
    }

    ModInt operator/(const ModInt a) const {
        return ModInt(*this) /= a;
    }

    bool operator==(const ModInt a) const {
        return x == a.x;
    }

    bool operator!=(const ModInt a) const {
        return x != a.x;
    }

    ModInt pow(int64_t k) const {
        ModInt ret(1), mul(x);
        while (k > 0) {
            if (k & 1) ret *= mul;
            mul *= mul;
            k >>= 1;
        }
        return ret;
    }

    ModInt inverse() const {
        return pow(mod - 2);
    }

    friend ostream &operator<<(ostream &os, const ModInt &p) {
        return os << p.x;
    }

    friend istream &operator>>(istream &is, ModInt &a) {
        int64_t t;
        is >> t;
        a = ModInt<mod>(t);
        return (is);
    }
};

const int MOD = 998244353;
using modint = ModInt<MOD>;

const int MAX = 3e3+10;

int N, S, A[MAX];

modint dp[MAX][MAX];

modint solve() {
    dp[0][0] = modint(1);

    REP (i, N) {
        dp[i+1][0] += 1;
        REP (k, S+1) {
            dp[i+1][k] += dp[i][k];
            if (k >= A[i]) dp[i+1][k] += dp[i][k-A[i]];
        }
    }

    modint ans(0);
    FOR (i, 1, N+1) ans += dp[i][S];
    return ans;
}

int main() {
    cin >> N >> S;
    REP (i, N) cin >> A[i];
    cout << solve() << endl;
}

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

using namespace std;
#define int long long
const int INF = 1000000007;


int a[500001];
signed main(){
    int  r,d,x;
    cin>>r>>d>>x;
    for(int i=1;i<=10;i++){
        x=r*x-d;
        cout<<x<<endl;
    }
    
    
   
    return 0;
}

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

int compute(int n){
  int ret = 0;
  while(n > 0){
    ret += n%10;
    n /= 10;
  }
  return ret;
}

main(){
  int n;
  cin >> n;
  int ans = n;
  for(int i = 1;i < n;i++){
    ans = min(ans, compute(i) + compute(n-i));
  }
  cout << ans << endl;
  return 0;
}


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



int main(){
    while(true){
        string a,b;
        ll flaga=0,flagb=0,flagc=0;
        cin >> a;
        if(a == "."){
            return 0;
        }
        cin >> b;
        long unsigned int i=0,j=0;
        while(i != a.length() && j != b.length()){
            if(a[i]!=b[j]){
                if(flaga==0){
                    flagc=1;
                    break;
                }
                else if(flagb==1){
                    flagc=1;
                    break;
                }
                else{
                    flagb=1;
                    flagc=2;
                    while(a[i]!='"'){
                        i++;
                    }
                    while(b[j]!='"'){
                        j++;
                    }
                }
            }
            if(a[i]=='"'){
                if(flaga==0)flaga=1;
                else flaga=0;
            }
            i++;j++;
        }
        if(i != a.length() || j != b.length()){
            flagc=1;
        }
        if(flagc==1){
            cout << "DIFFERENT" << endl;
        }else if(flagc==2){
            cout << "CLOSE" << endl;
        }else{
            cout << "IDENTICAL" << endl;
        }
    } 
}





Measured memory_bytes: 3200
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<map>
#include<stack>
#include<cmath>
#include<iomanip>
#include<set>
#include<numeric>
#include<sstream>
#include<random>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rrep(i, st, n) for (int i = st; i < n; ++i)
using pii = pair<int, int>;
const int inf = 1e9 + 7;
int dy[] = {0, 0, -1, 1, -1, 1, -1, 1};
int dx[] = {1, -1, 0, 0, -1, 1, 1, -1};


void posi(vector<ll> v, int m) {
    sort(v.begin(), v.end(), greater<ll>());
    ll sum = 0;
    rep(i, m) sum += v[i];
    cout << sum << endl;
}
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, m; cin >> n >> m;
    if (m == 0) {
        cout << 0 << endl;
        return 0;
    }
    vector<ll> v[8];
    int flg = 0;
    rep(i, n) {
        ll x, y, z; cin >> x >> y >> z;
        if (x < 0 || y < 0 || z < 0) flg = 1;
        v[0].push_back(x + y + z);
        v[1].push_back(x + y - z);
        v[2].push_back(x - y + z);
        v[3].push_back(x - y - z);
        v[4].push_back(-x + y + z);
        v[5].push_back(-x + y - z);
        v[6].push_back(-x - y + z);
        v[7].push_back(-x - y - z);
    }
    if (flg == 0) {posi(v[0], m); return 0;}
    rep(i, 8) sort(v[i].begin(), v[i].end(), greater<ll>());
    ll ans = 0;
    rep(i, 8) {
        ll tmp = 0;
        rep(j, m) {
            tmp += v[i][j];
        }
        ans = max(ans, tmp);
    }
    cout << ans << endl;
}


Measured memory_bytes: 384
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Linq;
using static MyIO;


public class D
{
	public static void Main()
	{
		int N = GetInt();
		int[] A = new int[N];
		for(int i = 0; i < N; i++)
			A[i] = GetInt();

		int[] x = new int[N];
		for(int i = 0; i < N; i++)
			x[0] += (i % 2 == 0) ? A[i] : -A[i];

		for(int i = 1; i < N; i++)
			x[i] = 2 * A[i - 1] - x[i - 1];

		var sb = new StringBuilder();
		for(int i = 0; i < N; i++)
			sb.AppendFormat($"{x[i]} ");
		Console.WriteLine(sb);
	}
}


public static class MyIO
{
	private static string[] args = null;
	private static int num = -1;
	private static int used = -1;

	private static string getArg()
	{
		if(used == num)
		{
			args = Console.ReadLine().Split(' ');
			num = args.Length;
			used = 0;
		}
		return args[used++];
	}

	public static int GetInt(){ return int.Parse(getArg()); }
	public static long GetLong(){ return long.Parse(getArg()); }
	public static double GetDouble(){ return double.Parse(getArg()); }
	public static string GetString(){ return getArg(); }
}





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

int main(void){
    int n, x;
    cin >> n >> x;
    int now = 0, ans = 1;
    vector<int> l(n);
    for (int i = 0; i < n; i++)
    {
        cin >> l[i];

    }
    for (int i = 0; i < n; i++)
    {
        now += l[i];
        if(now > x) break;
        ans++;
    }
    cout << ans << endl;
    
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define all(vec) vec.begin(), vec.end()
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
constexpr ll INF = (1LL << 30) - 1LL;
constexpr ll LINF = (1LL << 60) - 1LL;
constexpr ll MOD = 1e9 + 7;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }
ll n;
vector<ll> a;
ll check(ll x) {
    ll res = 0;
    for (int i = 0; i < n; i++) {
        ll to = lower_bound(all(a), x - a[i]) - a.begin();
        res += n - to;
    }
    return res;
}
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll m;
    cin >> n >> m;
    a.resize(n);
    vector<ll> sum(n + 1);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    sort(all(a));
    for (int i = 0; i < n; i++) {
        sum[i + 1] = sum[i] + a[i];
    }
    ll ok = INF, ng = 0;
    while (ok - ng > 1LL) {
        ll mid = (ok + ng) / 2LL;
        if (check(mid) <= m) {
            ok = mid;
        } else {
            ng = mid;
        }
    }
    ll t = m - check(ok);
    ll res = t * (ok - 1LL);
    for (int i = 0; i < n; i++) {
        ll to = lower_bound(all(a), ok - a[i]) - a.begin();
        res += sum[n] - sum[to] + a[i] * (n - to);
    }
    cout << res << endl;
}


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

using namespace std;

struct UnionFind
{
  vector< int > data;

  UnionFind(int sz)
  {
    data.assign(sz, -1);
  }

  bool unite(int x, int y)
  {
    x = find(x), y = find(y);
    if(x == y) return (false);
    if(data[x] > data[y]) swap(x, y);
    data[x] += data[y];
    data[y] = x;
    return (true);
  }

  int find(int k)
  {
    if(data[k] < 0) return (k);
    return (data[k] = find(data[k]));
  }

  int size(int k)
  {
    return (-data[find(k)]);
  }
};

int main()
{
  int H, W;
  int beet[26] = {};

  cin >> H >> W;
  for(int i = 0; i < H; i++) {
    string s;
    cin >> s;
    for(auto &j : s) beet[j - 'a']++;
  }

  UnionFind uf(H * W);
  for(int i = 0; i < H; i++) {
    for(int j = 0; j < W; j++) {
      uf.unite(i * W + j, i * W + (W - j - 1));
    }
  }
  for(int i = 0; i < H; i++) {
    for(int j = 0; j < W; j++) {
      uf.unite(i * W + j, (H - 1 - i) * W + j);
    }
  }

  vector< pair< int, int > > vs[10000];
  for(int i = 0; i < H; i++) {
    for(int j = 0; j < W; j++) {
      vs[uf.find(i * W + j)].emplace_back(i, j);
    }
  }
  vector< pair< int, int > > vq;
  for(int i = 0; i < 10000; i++) {
    if(vs[i].empty()) continue;
    vq.emplace_back(vs[i].size(), i);
  }

  sort(vq.rbegin(), vq.rend());

  for(auto &p : vq) {
    sort(beet, beet + 26);
    if(beet[25] < p.first) {
      cout << "No" << endl;
      return (0);
    }
    beet[25] -= p.first;
  }

  cout << "Yes" << endl;
}

Measured memory_bytes: 768
A = int(input())
B = int(input())
C = int(input())
X = int(input())
a = range(A+1)
b = range(B+1)
c = range(C+1)
ans = 0
for i in a:
  for j in b:
    for k in c:
      if 10*i + 2*j + k == X/50:
      	ans = ans+1
print(ans)

Measured memory_bytes: 3064
//============================================================================
// Name        : JOI.cpp
// Author      :
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;

// 1. dp?????????
//???J?????????O ?????????I
//???????????????????????????????????????
//??????????????????????????????????????
//??????????????????????????????????????
//??????????????????????????????????????
//?????????????????????????????????????
//?????????????????????????????????????
//?????????????????????????????????????
//????????????????????????????????????

int dp[9][1001];
// 2. n?????????
int N;
char D[1001];

// 7. calc?????????
int calc(int k,int m){
	// 8. dp???????????°??????
	if(dp[k][m]>=0)return dp[k][m];
	// 9. dp????¨????

	if(k==1)dp[k][m]=calc(1,m-1)+calc(2,m-1)+calc(3,m-1)+calc(4,m-1)+calc(5,m-1)+calc(6,m-1)+calc(7,m-1);
	if(k==2)dp[k][m]=calc(1,m-1)+calc(2,m-1)+calc(3,m-1)+calc(4,m-1)+calc(6,m-1)+calc(7,m-1);
	if(k==3)dp[k][m]=calc(1,m-1)+calc(2,m-1)+calc(3,m-1)+calc(4,m-1)+calc(5,m-1)+calc(6,m-1);
	if(k==4)dp[k][m]=calc(1,m-1)+calc(2,m-1)+calc(3,m-1)+calc(4,m-1)+calc(5,m-1)+calc(7,m-1);
	if(k==5)dp[k][m]=calc(1,m-1)+calc(3,m-1)+calc(4,m-1)+calc(5,m-1);
	if(k==6)dp[k][m]=calc(1,m-1)+calc(2,m-1)+calc(3,m-1)+calc(6,m-1);
	if(k==7)dp[k][m]=calc(1,m-1)+calc(2,m-1)+calc(4,m-1)+calc(7,m-1);
	dp[k][m]=dp[k][m]%10007;
	return dp[k][m];
}
int main() {
	cin>>N;

	//3.?????????
	for(int i=0;i<8;i++){
		for(int j=0;j<1001;j++){
			dp[i][j]=-1;
		}
	}
	//4.??\???
	for(int i=1;i<N+1;i++){
		cin>>D[i];
		if(D[i]=='J'){
			dp[4][i]=0;
			dp[5][i]=0;
			dp[7][i]=0;
		}
		if(D[i]=='O'){
			dp[3][i]=0;
			dp[5][i]=0;
			dp[6][i]=0;

		}
		if(D[i]=='I'){
			dp[2][i]=0;
			dp[6][i]=0;
			dp[7][i]=0;
		}

	}



	//5.???????????¨???
		dp[1][1]=1;
		dp[2][1]=1;
		dp[3][1]=1;
		dp[6][1]=1;
		dp[4][1]=0;
		dp[5][1]=0;
		dp[7][1]=0;

	if(D[1]=='O'){
		dp[3][1]=0;
		dp[6][1]=0;
	}
	if(D[1]=='I'){
		dp[2][1]=0;
		dp[6][1]=0;
	}

	//6.??????
	int total=0;
	for(int i=1;i<8;i++){
		total+=calc(i,N);
		total=total%10007;
	}
	cout<<total<<endl;



	return 0;
}

Measured memory_bytes: 3140
#include<stdio.h>
#include<stdlib.h>

int main()
{
  int n,m;
  int a[51],b[51],c[51],d[51];

  scanf("%d %d",&n,&m);

  int i,j;
  
  for (i=1;i<=n;i++) {
    scanf("%d %d",&a[i],&b[i]);
  }

  for (i=1;i<=m;i++) {
    scanf("%d %d",&c[i],&d[i]);
  }

  int ans;
  int min;
  int dist;

  for (i=1;i<=n;i++) {
    ans=1;
    min=abs(a[i]-c[1])+abs(b[i]-d[1]);
    for (j=2;j<=m;j++) {
      dist=abs(a[i]-c[j])+abs(b[i]-d[j]);
      if (dist<min) {
	ans=j;
	min=dist;
      }
    }
    printf("%d\n",ans);
  }
 
  return 0;
}


Measured memory_bytes: 128
import heapq
from collections import deque
N,K = map(int,input().split())
V = list(map(int,input().split()))

ans = 0
for i in range(0,K+1):
    for j in range(0,K+1-i):
        D = deque(V)
        num = 0 #宝石の価値合計
        a = []  #取り出した宝石格納、heapq

        cnt = 0
        while cnt < i and len(D):   #B,右から取り出す
            x = D.pop()
            heapq.heappush(a,x)
            num += x
            cnt += 1
        cnt = 0
        while cnt < j and len(D):   #A,左から取り出す
            x = D.popleft()
            heapq.heappush(a,x)
            num += x
            cnt += 1
        sub = K-i-j
        while sub and len(a):       #CとD,送り返す
            y = heapq.heappop(a)
            if y <= 0:              #宝石がマイナスの時だけ価値＋
                num -= y
            sub -= 1
        ans = max(ans,num)
print(ans)


Measured memory_bytes: 3444
#include "bits/stdc++.h"
using namespace std;
//#b?£?f??????r???????????¨?±????v??????????????§??\?±????????????¨??????????????????v?????????????????´??????v????????????????????¨??????????????????
int main() {
int n,b,f,r,v;
	cin>>n;
	int e[5][4][11]={};
	for (int i = 0; i < n; ++i) {
		cin>>b>>f>>r>>v;
		e[b][f][r]+=v;
	}
	for (int i = 1; i < 5; ++i) {
		for (int j = 1; j < 4; ++j) {
			for (int k = 1; k < 11; ++k) {
				cout<<" "<<e[i][j][k];
			}
			cout<<endl;
		}
		if(i==4){return 0;}
		cout<<"####################"<<endl;
	}
}

Measured memory_bytes: 3088
#include <iostream>
#include <string>

int main() {
    using namespace std;
    int n, total;
    total = 0;
    cin >> n;
    for (int i=1; i<=n; i++) {
        // comp = i;
        // cnt = 0;
        // while (comp != 0) {
        //     // comp /= 10;
        //     // cnt++;
        //     // cout << cnt << endl;
        // }
        string x = to_string(i);
        if (x.size() % 2 == 1) total++;
    }
    cout << total;
}

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

using ll = long long int;

const int MAX_N = 2005;
const ll INF = (ll)1e10;

ll a[MAX_N];
ll answer, memo[MAX_N][2];
ll N, W, Z;

ll ans(int il, int f, ll cx, ll cy) {
  if (memo[il][f] != (-1)) {return memo[il][f];}
  ll tmp;
  if (il == N) {
    return abs(cx - cy);
  }

  if (f == 1) {
    tmp = INF;
    for (int i = il; i < N; ++ i) {
      tmp = min(tmp, ans(i + 1, 0, cx, a[i]));
    }
  }
  else {
    tmp = -1;
    for (int i = il; i < N; ++ i) {
      tmp = max(tmp, ans(i + 1, 1, a[i], cy));
    }
  }
  return memo[il][f] = tmp;
}

int main(void){
    // Here your code !
    scanf("%d %lld %lld", &N, &W, &Z);
    for (int i = 0; i < N; ++i) {
      scanf("%lld", &a[i]);
    }
    memset(memo, -1, sizeof(memo));
    answer = ans(0, 0, W, Z);
    printf("%lld\n", answer);
    return 0;
}

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

int main()
{
	//int a = 0, b = 0, c = 0, d = 0, e = 0, f = 0, g = 0, h = 0, ans = 0;
	long a = 0, b = 0, c = 0, d = 0, e = 0, f = 0, g = 0, h = 0, i = 0, j = 0, k = 0, l = 0, ans = 0;
	//cout << LONG_MAX << endl;
	string p;
	int n;
	int w = 0;
	cin >> n;
	cin >> p;
	for ( a = 0; a < n; a++)
	{
		if (p[a]=='E')
		{
			e++;
		}
		/*else if(p[a] == 'W')
		{
			w++;
		}*/
	}
	ans = 10000000;
	for ( a = 0; a < n; a++)
	{
		if (p[a]=='E')
		{
			e--;
		}
		b = e+w;
		ans=min(b, ans);
		/*if (p[a] == 'E')
		{
			e--;
		}*/
		if (p[a] == 'W')
		{
			w++;
		}
	}

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

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

public class Main {

	public static void main(String[] args) {

		Scanner stdin = new Scanner(System.in);
		BufferedReader input = new BufferedReader(new InputStreamReader(System.in));

		int D = stdin.nextInt();
		int L = stdin.nextInt();
		
		int syou = D / L;
		int amari = D % L;
		
		System.out.println(syou + amari);
		
	}

}

Measured memory_bytes: 26340
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#include <algorithm>
#define rep(i,n) for(int i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
using namespace std;
using Graph = vector<vector<int>>;
typedef long long ll;
const int mod= 1e+9+7;

int main(){
    int h,w;cin>>h>>w;
    vector<vector<char>>a(h,vector<char>(w));
    rep(i,h){
        rep(j,w)cin>>a[i][j];
    }
    int cnt=0;
    rep(i,h){
        for(int j=cnt;j<w;j++){
            while(a[i][j]=='#'){
                a[i][j]='.';
                j++;
            }
            cnt=j-1;
            break;
        }
    }
      rep(i,h){
        rep(j,w){
            if(a[i][j]=='#'){
                cout<<"Impossible"<<endl;
                return 0;
            }
        }
    }
    cout<<"Possible"<<endl;
}





Measured memory_bytes: 256
import java.io.*;

public class Main {
  
  static long n;

  public static void main(String[] args) throws IOException {

    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

    String[] in;
    in = br.readLine().split(" ");
    n = Long.parseLong(in[0]);

    br.close();

    long ans = 0;
    ans += (n / 500) * 1000;
    n -= n / 500 * 500;

    ans += n / 5 * 5;
    
    System.out.println(ans);
  }
}

Measured memory_bytes: 23124