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

typedef long long ll;
ll n[105], w[105];
ll dp[100005][100];
ll max(ll a, ll b)
{
    return a > b ? a : b;
}
ll knap(ll index, ll W, ll N)
{

    if (index >= N || W <= 0)
    {
        return 0;
    }
    // else if (W - w[index] < 0)
    // {
    //     return 0;
    // }

    if (dp[W][index] != -1)
    {
        return dp[W][index];
    }

    ll a = (knap(index + 1, W - w[index], N));
    a += n[index];
    ll b = knap(index + 1, W, N);
    if (W - w[index] < 0)
    {
        return dp[W][index] = b;
    }
    return dp[W][index] = max(a, b);
}

int main()
{
    ll N, W;
    cin >> N >> W;
    ll i = 0;
    for (int x = 0; x < 100005; x++)
    {
        for (int y = 0; y < 105; y++)
            dp[x][y] = -1;
    }
    while (i < N)
    {
        cin >> w[i] >> n[i];
        i++;
    }
    ll ans = knap(0, W, N);
    cout << ans << endl;
}

Measured memory_bytes: 78336
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<iostream>
#include<queue>
#include<stack>
#include<utility>
#include<vector>
using namespace std;

typedef long long lint;

int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    for(int i = 0 ; i < n ; i++){
        cin >> a[i];
    }
    sort(a.begin(), a.end());
    int minv = a[0], maxv = a[n-1], ans = 0, tmp = 0, j;
    for(int i = minv ; i <= maxv ; i++){
        int cnt = 0;
        j = tmp;
        while(a[j] == i){
            cnt++;
            j++;
            if(j == n){
                break;
            }
        }
        tmp = j;
        if(j < n){
            while(a[j] <= i + 2){
                cnt++;
                j++;
                if(j == n){
                    break;
                }
            }
        }
        ans = max(ans, cnt);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 640
import java.io.*;
import java.util.*;

class Main{
    public static void main(String args[])throws IOException{
      try(BufferedReader br = new BufferedReader(new InputStreamReader(System.in))){
        int N = Integer.parseInt(br.readLine());
        String[] str = new String[N];
        
        for(int i = 0; i < N; i++){
          str[i] = br.readLine();
        }

        Map<String, Integer> map = new HashMap<>();
        int value = 0;  
        int max = 1;     
        
        for(int i = 0; i < N; i++){
          if(map.size() == 0){
            map.put(str[i], 1);
          }else{
            if(map.containsKey(str[i])){
              value = map.get(str[i]);
              value += 1;
           
              if(max < value){
                max = value;
              }

              map.put(str[i], value);
            }else{
              map.put(str[i], 1);
            }
          }
        }

        List<String> list = new ArrayList<>();

        for(Map.Entry<String, Integer> entry : map.entrySet()){
          if(max == entry.getValue()){
            list.add(entry.getKey());
          }
        }

        Collections.sort(list);

        for (String string : list) {
          System.out.println(string);
        }

      }
    }
}

Measured memory_bytes: 63816
#include "bits/stdc++.h"

using namespace std;

const int INF = numeric_limits<int>::max() / 2;

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

    int h,w;//w>h
    while(cin>>h>>w,h||w){
        int cr=INF,hei=INF,wid;
        for(int haba=1;haba<=150;haba++){
            for(int taka=1;taka<haba;taka++){
                if(h*h+w*w<taka*taka+haba*haba || 
                h*h+w*w==taka*taka+haba*haba && h<taka){
                    if(taka*taka+haba*haba<cr ||
                    taka*taka+haba*haba==cr && taka<hei){
                        cr=taka*taka+haba*haba;
                        hei=taka;
                        wid=haba;
                    }
                }
            }
        }
        cout<<hei<<" "<<wid<<endl;
    }
}

Measured memory_bytes: 3160
#include <iostream>

using namespace std;

const int N=5;

int main(void){
  int cnt[3];
  int h[N];
  
  while (cin >> h[0], h[0]){
    for (int i=1; i<N; i++) cin >> h[i];
    for (int i=0; i<3; i++) cnt[i]=0;
    for (int i=0; i<N; i++) cnt[h[i]-1]++;
    //cout << cnt[0] << " " << cnt[1] << " " << cnt[2] << endl;
    if (cnt[0]+cnt[1]==0 ||
      cnt[1]+cnt[2]==0 ||
      cnt[2]+cnt[0]==0 ||
      cnt[0]*cnt[1]*cnt[2]){
      for (int i=0; i<N; i++){
        cout << 3 << endl;
      }
    } else {
      for (int i=0; i<N; i++){
        cout << (cnt[(h[i]+1)%3]?2:1) << endl;
      }
    }
  }
  return 0;
}



Measured memory_bytes: 3136
package main

import (
	"fmt"
)

func abs(n int) int {
	if n < 0 {
		return -n
	}
	return n
}

func main() {
	var n, k int
	fmt.Scan(&n, &k)

	x := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&x[i])
	}

	ans := 0
	for _, v := range x {
		if v < abs(k-v) {
			ans += 2 * v
		} else {
			ans += 2 * abs(k-v)
		}
	}
	fmt.Println(ans)
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
const int N=1e6;
int a[N];
int did(int x,int y){
    return min(x,y-x);
}
int main(){
    ios::sync_with_stdio(false);
    int n;
    cin>>n;
    int mx=0;
    for (int i=1;i<=n;i++)
        cin>>a[i],mx=max(mx,a[i]);
    int s=a[1];
    for (int i=1;i<=n;i++)
        if (a[i]!=mx){
            s=a[i];
            break;
        }
    for (int i=1;i<=n;i++){
        if (did(s,mx)<did(a[i],mx))s=a[i];
    }
    cout<<mx<<' '<<s;
    return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
 
#define ll long long
#define ld long double
#define pb push_back
// #define mp make_pair
#define nt _int128 
#define fir first
#define sec second
#define fast_as_levi ios_base::sync_with_stdio(false) , cin.tie(NULL);
#define debug(x) cout<<x<<"\n";
#define debug cout<<"debugged\n";
#define inf 0x3f3f3f3f
 
const ll mod = 1e9 + 7;
const ll mx = 2e6 + 5;
const ll mxi = 2e3 + 5;

int main()
{
    fast_as_levi;
    ll i,n;
    cin>>n;
    ll ar[n];
    for(i=0;i<n;i++)
    {
        cin>>ar[i];
    }
    ll dp[n+1]={0};
    dp[1] = abs(ar[1]-ar[0]);
    for(i=2;i<n;i++)
    {
        dp[i] = min(dp[i-1] + abs(ar[i]-ar[i-1]) , dp[i-2] + abs(ar[i]-ar[i-2]));
    }
    cout<<dp[n-1];
}

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

int main(){

  int n, q, i, j, l, r, m=0, count=0;
  int s[100000], t[50000];

  cin >> n;
  for (i=0; i<n; i++){
    cin >> s[i];
  }

  cin >> q;
  for (i=0; i<q; i++){
    cin >> t[i];
  }

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

    l=0; r=n;
  
    while (l < r){
      m=(l+r)/2;

      // cout << i << " " << l << " " << r << " " << m << " " << count << endl;

      if (s[m]==t[i]){
	count++;
	break;
      }
      if (s[m] < t[i]) {
	l = m + 1;
	
      }

      if (s[m] > t[i]) {
	r = m;
      }
    }

  }

  cout << count << endl;
  
  return 0;

}

Measured memory_bytes: 3560
PROGRAM-ID.                      AGC_026_B.
*> 入荷すると (個数 mod B) は (mod B の世界で) D mod B 個増える

*> 0 から B - 1 までの 円
*> a = A mod B
*> d = D mod B
*> スタート地点に戻る lcm(B, d) / d
*> スタート地点に戻る まで 他の地点 を 2 度 訪れることはない

*> lcm(B, d) = B * d / gcd(B, d)

*> d 移動 lcm(B, d)を1回ループ B / gcd(B, d) 回
*> gcm(B, d) 移動 Bを1回ループ 最大 B - g

*> 個数 mod B の最大は g = gcd(B, D) としてB - g + (A mod g)
DATA                             DIVISION.
WORKING-STORAGE                  SECTION.
    01 T       PIC 9(3).

    01 INP     PIC X(79).
    01 A       PIC 9(19).
    01 B       PIC 9(19).
    01 C       PIC 9(19).
    01 D       PIC 9(19).

    01 g       PIC 9(19).
    01 ad      PIC 9(19).
    01 ar      PIC 9(19).

    01 x       PIC 9(19).

    01 str     PIC X(3).

PROCEDURE                        DIVISION.
    ACCEPT T.

    PERFORM T TIMES
        ACCEPT INP

        UNSTRING INP
        DELIMITED BY SPACE
        INTO A B C D

        MOVE "No" TO str

        IF B <= A AND B <=D
            IF B <= C
                MOVE "Yes" TO str
            ELSE
*> 個数 mod B の最大は g = gcd(B, D) としてB - g + (A mod g)
                CALL "GCD"      USING BY CONTENT B
                                      BY CONTENT D
                                      BY REFERENCE g

                DIVIDE g INTO A GIVING ad REMAINDER ar

                SUBTRACT g FROM B GIVING x

                ADD ar TO x

                IF x <= C
                    MOVE "Yes" TO str
                END-IF
            END-IF
        END-IF

        DISPLAY str(1:FUNCTION STORED-CHAR-LENGTH(str))
    END-PERFORM.

    STOP RUN.
END PROGRAM AGC_026_B.

PROGRAM-ID.                      GCD.
*> すべての整数 は 0 の約数
*> 0 と 7 の 最大公約数 は 7
*> X と Y の 最大公約数 は X と (X MOD Y) の 最大公約数 と同じ
*> gcd 1 ならば 互いに素
DATA                             DIVISION.
WORKING-STORAGE                  SECTION.
    01 N       EXTERNAL PIC 9(10).

    01 d       PIC 9(19).
    01 r       PIC 9(19).

    01 x       PIC 9(19).

LINKAGE                          SECTION.
*> (IN)  d_a
*>       d_b
*> (OUT) d_ret
    01 d_a     PIC 9(19).
    01 d_b     PIC 9(19).
    01 d_ret   PIC 9(19).

PROCEDURE                        DIVISION USING d_a d_b d_ret.
    MOVE d_a TO d_ret
    MOVE ZERO TO r
    MOVE d_b TO x

*> do while
    PERFORM WITH TEST AFTER UNTIL ZERO = r
        DIVIDE x INTO d_ret GIVING d REMAINDER r
        MOVE x TO d_ret
        MOVE r TO x
    END-PERFORM.
END PROGRAM GCD.

PROGRAM-ID.                      LCM.
DATA                             DIVISION.
WORKING-STORAGE                  SECTION.
    01 N       EXTERNAL PIC 9(10).

    01 g       PIC 9(19).
    01 t       PIC 9(10).

LINKAGE                          SECTION.
*> (IN)  d_a
*>       d_b
*> (OUT) d_ret
    01 d_a     PIC 9(19).
    01 d_b     PIC 9(19).
    01 d_ret   PIC 9(19).

PROCEDURE                        DIVISION USING d_a d_b d_ret.
    CALL "GCD"          USING BY CONTENT   d_a
                              BY CONTENT   d_b
                              BY REFERENCE g

*> a * (b / g)
    DIVIDE g INTO d_b GIVING t
    MULTIPLY d_a BY t

    MOVE t TO d_ret.
END PROGRAM LCM.


Measured memory_bytes: 636
N = int(input())
S = []
for i in range (N):
	title,time=input().split()
	S.append((title,time,i))
X = input()
ans = 0

for i in S:
	if i[0] == X:
		tmp = i[2]
		break
for i in S:
	if i[2]>tmp:
		ans =ans+int(i[1])

print(ans)

Measured memory_bytes: 3064
n,m = map(int,input().split())
ab = [list(map(int,input().split())) for _ in range(n)]
cd = [list(map(int,input().split())) for _ in range(m)]

li = [[0] * m for _ in range(n)]

for i in range(n):
    for j in range(m):
        li[i][j] = abs(ab[i][0] - cd[j][0]) + abs(ab[i][1] - cd[j][1])

for i in range(n):
    print(li[i].index(min(li[i]))+1)


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

using namespace std;

char a[5005][5005];
long long n, m, ans[5005][5005];

int main() {
    scanf("%d%d\n", &n, &m);
    int MOD = 1e9 + 7;
    for (int i = 1; i <= n; i++){
        for (int j = 1; j < m; j++)
            scanf("%c", &a[i][j]);
        scanf("%c\n", &a[i][m]);
    }
    ans[1][1] = 1;
    for (int i = 1; i <= n; i++){
        for (int j = 1; j <= m; j++)
            if (a[i][j] == '.'){
                if (a[i - 1][j] == '.'){
                    ans[i][j] = (ans[i][j] + ans[i - 1][j]) % MOD;
                }
                if (a[i][j - 1] == '.'){
                    ans[i][j] = (ans[i][j] + ans[i][j - 1]) % MOD;
                }
            }
    }
    cout << ans[n][m];
}

Measured memory_bytes: 45952
fun main(args: Array<String>) {
  var split = readLine()!!.split(" ")
  val n = Integer.parseInt(split[0])!!
  val d = Integer.parseInt(split[1])!!
  var points = mutableListOf<List<Int>>()
  var count = 0
  for (i in 0..n - 1) {
    points.add(readLine()!!.split(" ").map { Integer.parseInt(it)!! })
  }
  for (i in 0..n - 1) {
    for (j in i + 1..n - 1) {
      var distance = 0
      for (id in 0..d - 1) {
        distance += (points[i][id] - points[j][id]) * (points[i][id] - points[j][id])
      }
      var dd = Math.sqrt(distance.toDouble())
      var isInt = dd % 1.0 == 0.0
      if (isInt) {
        count += 1
      }
  	}
  }
  println(count)
}

Measured memory_bytes: 37784
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
//大小比較(大)
long long int big(long long int a, long long int b) {
	if (a >= b) {
		return a;
	}
	else {
		return b;
	}
}

//大小比較(小)
long long int small(long long int a, long long int b) {
	if (a >= b) {
		return b;
	}
	else {
		return a;
	}
}

main() {
	long long int c,d,a,b,n, m,k;
	char str[5];
	scanf("%lld%lld%lld%lld",&a,&b,&c,&d);
	if (((a - b >= -d&&a - b <= d) && (c - b >= -d&&c - b <= d)) || (a - c >= -d&&a - c <= d)) { printf("Yes"); }else{ printf("No"); }
	
}


Measured memory_bytes: 128
import std.conv;
import std.stdio;
import std.string;

void main()
{
	auto s = readln.strip;
	writeln( solve( s ) );
}

auto solve( in string s )
{
	auto n = s.to!int;
	auto sn = 0;
	
	foreach( c; s )
	{
		sn += [ c ].to!int;
	}
	
	return ( n % sn == 0 ) ? "Yes" : "No";
}

unittest
{
	assert( solve( "12" ) == "Yes" );
	assert( solve( "101" ) == "No" );
	assert( solve( "999999999" ) == "Yes" );
}


Measured memory_bytes: 256
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    sc.next();
    String str = sc.next();
    int x = 0, max = 0;
    for(int i = 0; i < str.length(); i++){
      x += (str.charAt(i) == 'I') ? 1 : -1;
      max = Math.max(max, x);
    }
    System.out.println(max);
  }
}

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

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

    string S;
    cin >> S;
    int cnt1 = 0, cnt2 = 0;
    for (int i = 0; i < S.size(); ++i) {
        if (S.at(i) != '0' + i % 2) {
            cnt1++;
        }
        if (S.at(i) != '0' + (i + 1) % 2) {
            cnt2++;
        }
    }
    cout << min(cnt1, cnt2) << endl;

    return 0;
}

Measured memory_bytes: 512
import sys
from bisect import *
from heapq import *
from collections import *
from itertools import *
from functools import *
from math import *
from fractions import *

sys.setrecursionlimit(100000000)
input = lambda: sys.stdin.readline().rstrip()


def main():
    N, T = map(int, input().split())
    roads = [tuple(map(int, input().split())) for _ in range(N)]
    roads = [(c, t) for c, t in roads if t <= T]
    print('TLE' if len(roads) == 0 else min(c for c, _ in roads))

main()


Measured memory_bytes: 63980
#include <stdio.h>

int main( void ) {

	int n, i, debt = 100000;

	scanf( "%d", &n );

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

		debt *= 1.05;
		if ( debt % 1000 != 0 ) { debt = ( debt / 1000 + 1 ) * 1000; }

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

	return 0;

}

Measured memory_bytes: 592
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
use std::io::{Write, BufWriter};
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, [ $t:tt ]) => {{
        let len = read_value!($next, usize);
        (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    }};

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused)]
macro_rules! debug {
    ($($format:tt)*) => (write!(std::io::stderr(), $($format)*).unwrap());
}
#[allow(unused)]
macro_rules! debugln {
    ($($format:tt)*) => (writeln!(std::io::stderr(), $($format)*).unwrap());
}

// editorial
fn solve() {
    let out = std::io::stdout();
    let mut out = BufWriter::new(out.lock());
    macro_rules! puts {
        ($($format:tt)*) => (write!(out,$($format)*).unwrap());
    }
    input! {
        n: usize,
        a: [usize1; n],
    }
    let mut f = vec![0; n];
    for &a in &a {
        f[a] += 1;
    }
    let mut d = vec![0; n + 1];
    for i in 0..n {
        d[f[i]] += 1;
    }
    let mut acc = vec![0; n + 1];
    let mut acc_w = vec![0; n + 1];
    acc[0] = d[0];
    for i in 1..n + 1 {
        acc[i] = acc[i - 1] + d[i];
        acc_w[i] = acc_w[i - 1] + i * d[i];
    }
    let mut tbl = vec![0; n + 1];
    for x in 1..n + 1 {
        let net = acc_w[x] + (n - acc[x]) * x;
        tbl[x] = net / x;
    }
    tbl[0] = 1 << 50; // sentinel
    let mut pos = n;
    for i in 1..n + 1 {
        while tbl[pos] < i {
            pos -= 1;
        }
        puts!("{}\n", pos);
    }
}

fn main() {
    // In order to avoid potential stack overflow, spawn a new thread.
    let stack_size = 104_857_600; // 100 MB
    let thd = std::thread::Builder::new().stack_size(stack_size);
    thd.spawn(|| solve()).unwrap().join().unwrap();
}


Measured memory_bytes: 33660
#include <iostream>
#include <algorithm>
#include <cmath>
#include <limits>
#include <iomanip>
#include <vector>
#include <cstring>
#include <queue>
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
#define mod 1000000007;
#define my_mod 2019;
ll MAX(ll a,ll b,ll c){return max(a,max(b,c));}
ll MIN(ll a,ll b,ll c){return min(a,min(b,c));}
const int dx[4] = {0,1,0,-1};
const int dy[4] = {1,0,-1,0};
template<class T> inline bool chmax(T &a,T& b){if(a < b){a = b; return true;} else return false;}
template<class T> inline bool chmin(T &a,T& b){if(a > b){a = b; return true;} else return false;}
int main(){
    ll h,n;
    cin >> h >> n;
    ll sum = 0;
    rep(i,n){
        int x;
        cin >> x;
        sum += x;
    }
    sum < h ? cout << "No" << endl : cout << "Yes" << endl;
}

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

using namespace std;
int main()
{
    vector<int> v;int a;
    for(int i=0;i<5;i+=1){
        cin>>a;v.push_back(a);
        if(v[i]==0){
            cout<<i+1<<endl;break;
        }
    }




    return 0;
}


Measured memory_bytes: 3564
#AtCorder Beginner Context 110 C String Transformation

import collections

#入力を1文字ずつリストにして変数に格納
s = list(input())
t = list(input())

cs = collections.Counter(s)
ct = collections.Counter(t)

slist = list(cs.values())
tlist = list(ct.values())

slist.sort()
tlist.sort()

if slist == tlist:
    print("Yes")
else:
    print("No")



Measured memory_bytes: 7344
#include <bits/stdc++.h>
#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 INF 2e9
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;

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

int main()
{
	int h, w;
	cin >> h >> w;

	string s[h];

	REP(i, h) cin >> s[i];

	REP(i, h){
		REP(j, w){
			if (s[i][j] == '#') continue;

			int num = 0;
			REP(d, 8){
				const int ni = i + dx[d];
				const int nj = j + dy[d];

				if (ni < 0 or h <= ni) continue;
				if (nj < 0 or w <= nj) continue;
				if (s[ni][nj] == '#') num++;
			}

			s[i][j] = '0' + num;
		}
	}

	REP(i, h) cout << s[i] << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <list>
#include <chrono>
#include <random>

using namespace std;
typedef long long ll;

int DAYS;
const int TYPES = 26;

vector<int> c;
vector<vector<ll>> s;

ll point;
vector<ll> penalty;

chrono::system_clock::time_point startTime, endTime;
mt19937 engine(random_device{}());

void simulate(vector<int> &t) {
    vector<int> last(TYPES, -1);
    point = 0, penalty.assign(TYPES, 0);
    for (int i = 0; i < DAYS; i++) {
        point += s[i][t[i]], last[t[i]] = i;
        for (int j = 0; j < TYPES; j++) {
            penalty[j] += c[j] * (i - last[j]);
        }
    }
}

void update(vector<int> &t, int x, int y) {
    int lastx = -1, lasty = -1;
    penalty[x] = 0, penalty[y] = 0;
    for (int i = 0; i < DAYS; i++) {
        if (t[i] == x)lastx = i;
        if (t[i] == y)lasty = i;

        penalty[x] += c[x] * (i - lastx), penalty[y] += c[y] * (i - lasty);
    }
}

ll scoring() {
    ll ret = point;
    for (auto &x:penalty)ret -= x;
    return ret;
}


ll mod_rnd(ll mod) { return engine() % mod; }

int main() {
    startTime = chrono::system_clock::now();

    cin >> DAYS;
    c.resize(TYPES);
    for (int i = 0; i < TYPES; i++)cin >> c[i];
    s.assign(DAYS, vector<ll>(TYPES));
    for (int i = 0; i < DAYS; i++) {
        for (int j = 0; j < TYPES; j++) {
            cin >> s[i][j];
        }
    }

    vector<int> t(DAYS);
    for (int i = 0; i < DAYS; i++) t[i] = i % TYPES;

    simulate(t);
    ll currentScore = scoring();

    while (chrono::duration_cast<chrono::milliseconds>(endTime - startTime).count() < 1950) {
        int ope = mod_rnd(15);
        if (ope == 0) {
            int d = -1, q = -1;
            do {
                d = mod_rnd(DAYS), q = mod_rnd(TYPES);
            } while (t[d] == q);

            int old = t[d];
            t[d] = q;
            point -= s[d][old], point += s[d][q];
            update(t, old, q);
            ll changedScore = scoring();

            if (currentScore < changedScore)currentScore = changedScore;
            else {
                t[d] = old;
                point += s[d][old], point -= s[d][q];
                update(t, old, q);
            }
        } else {
            int x = -1, y = -1;
            do {
                x = mod_rnd(DAYS), y = mod_rnd(DAYS);
            } while (x == y);

            point -= s[x][t[x]], point -= s[y][t[y]];
            swap(t[x], t[y]);
            point += s[x][t[x]], point += s[y][t[y]];
            update(t, t[x], t[y]);
            ll changedScore = scoring();

            if (currentScore < changedScore)currentScore = changedScore;
            else {
                point -= s[x][t[x]], point -= s[y][t[y]];
                swap(t[x], t[y]);
                point += s[x][t[x]], point += s[y][t[y]];
                update(t, t[x], t[y]);
            }
        }
        endTime = chrono::system_clock::now();
    }

    for (auto &x:t)cout << x + 1 << endl;
    return 0;
}

Measured memory_bytes: 3732
#include <iostream>
#include <string>
#include <string.h>
#include <map>
#include <set> 
#include <algorithm>
#include <vector>
#include <queue>
#include <stdio.h> 
#include <cstdio>
#include <math.h>
#include <cmath>
#include <sstream>
#include <cassert>
#include <functional>
#include <cfloat>
#include <climits>
#include <cstring>
#include <stack>
#include <time.h>
#include <complex>
using namespace std;
int main()
{
    int X,A,B,cnt,ans;
    cin>>X>>A>>B;
    cnt=X-A;
    ans=cnt%B;
    cout<<ans;
return 0;
}


Measured memory_bytes: 256
from queue import *

class Vertex:
	def __init__(self, u, k):
		self.u = u
		self.vertices = [0] * k
		self.d = -1
	def __str__(self):
		return str(self.u) + ' ' + str(self.d)

class Inf:
	def __init__(self,u,d):
		self.u = u
		self.d = d

def BFS(n, vertices):
	q = Queue()
	q.put(Inf(1,0))
	while q.empty() == False:
		inf = q.get()
		vertex = vertices[inf.u-1]
		if vertex.d == -1:
			vertex.d = inf.d
		else:
			vertex.d = min(vertex.d, inf.d)
		dist = inf.d + 1
		for i in range(len(vertex.vertices)):
			u = vertex.vertices[i]
			if vertices[u-1].d == -1:
				q.put(Inf(u, dist))
	
n = int(input())
vertices = []
for i in range(n):
	v = list(map(int, input().split()))
	u = v[0]
	k = v[1]
	vertex = Vertex(u, k)
	for j in range(k):
		vertex.vertices[j] = v[j+2]
	vertices.append(vertex)

BFS(n, vertices)
for i in range(n):
	print(str(vertices[i]))


Measured memory_bytes: 15292
import sys

file_input = sys.stdin

H, W, N = map(int, file_input.readline().split())

town_map = file_input.read()

start_index = town_map.index('S')

mouse = [start_index, 0]
# position, elapsed time

from collections import deque

for goal in range(1, N + 1):
    q = deque()
    unvisited = [True] * len(town_map)
    unvisited[mouse[0]] = False
    goal = str(goal)
    while True:
        cur_pos = mouse[0]
        
        ew_pos = cur_pos % (W + 1)
        if ew_pos < (W - 1):
            next_pos = cur_pos + 1
            lot = town_map[next_pos]
            if lot != 'X' and unvisited[next_pos]:
                if lot == goal:
                    mouse = [next_pos, mouse[1] + 1]
                    break
                else:
                    m = [next_pos, mouse[1] + 1]
                    unvisited[next_pos] = False
                    q.append(m)
        if ew_pos > 0:
            next_pos = cur_pos - 1
            lot = town_map[next_pos]
            if lot != 'X' and unvisited[next_pos]:
                if lot == goal:
                    mouse = [next_pos, mouse[1] + 1]
                    break
                else:
                    m = [next_pos, mouse[1] + 1]
                    unvisited[next_pos] = False
                    q.append(m)
        
        ns_pos = cur_pos // (W + 1)
        if ns_pos < (H - 1):
            next_pos = cur_pos + W + 1
            lot = town_map[next_pos]
            if lot != 'X' and unvisited[next_pos]:
                if lot == goal:
                    mouse = [next_pos, mouse[1] + 1]
                    break
                else:
                    m = [next_pos, mouse[1] + 1]
                    unvisited[next_pos] = False
                    q.append(m)
        if ns_pos > 0:
            next_pos = cur_pos - W - 1
            lot = town_map[next_pos]
            if lot != 'X' and unvisited[next_pos]:
                if lot == goal:
                    mouse = [next_pos, mouse[1] + 1]
                    break
                else:
                    m = [next_pos, mouse[1] + 1]
                    unvisited[next_pos] = False
                    q.append(m)
        mouse = q.popleft()

print(mouse[1])


Measured memory_bytes: 22604
N, X, M = list(map(int, input().split()))

L = [0] * M
S = [0] * (M + 1)
cnt = 1

L[X] = 1
S[1] = X

t = X
cnt = 1
for i in range(N):
  t = t * t % M
  if L[t] != 0:
    r = L[t]
    break
  L[t] = i + 2
  S[cnt + 1] = S[cnt] + t
  cnt += 1

if N <= cnt:
  print(S[N])
  exit()

roop = cnt - r + 1
d, m = divmod(N - r + 1, roop)

ans = (S[cnt] - S[r - 1]) * d
ans += S[r + m - 1]
print(ans)


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

#define IOS ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define I insert
#define endl '\n'
#define all(x) x.begin(), x.end()

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<class T> using oset=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
 
using vvll = vector< vector<ll> >;
using vll = vector<ll> ;
using vb = vector<bool> ;
using pll = pair<ll, ll> ;

const ll maxs = 1e6+5;
const ll lmaxs = 20;
ll mod = 1e9+7;
ll oo = 1e15;


void pre(){



}


void solve(){

    set<ll> s;
    for(ll i=0;i<3;i++){
        ll v;
        cin >> v;
        s.I(v);
    }
    if(s.size()==2){
        cout << "Yes";
    }else cout << "No";

}

int main(){
    // #ifndef ONLINE_JUDGE
    // freopen("input00.txt","r",stdin);
    // #endif
    IOS;
    pre();
    ll T = 1;
    //cin>>T;
    while(T--){
        solve();   
    }
    return 0;
}

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

typedef struct{
  int parent;
  int left;
  int right;
} node;

int main(){
  node *ro,*A;
  int i,j,n,r,c,k,a,depth;

  scanf("%d",&n);
  ro=(node *)malloc(sizeof(node)*n);
  A=ro;
  for(i=0;i<n;i++){
    A[i].parent=-1;
    A[i].left=-1;
    A[i].right=-1;
  }
  for(i=0;i<n;i++){
    scanf("%d %d",&r,&k);    
    for(j=0;j<k;j++){
      scanf("%d",&c);
      A[c].parent=r;
      if(j==0)A[r].left=c;
      else A[a].right=c;
      a=c;
    }
  }
  for(i=0;i<n;i++){
    a=A[i].parent;
    depth=0;
    while(a!=-1){
      depth++;
      a=A[a].parent;
    }
    printf("node %d: parent = %d, depth = %d, ",i,A[i].parent,depth);
    if(A[i].parent==-1)printf("root, [");
    else if(A[i].left==-1)printf("leaf, [");
    else printf("internal node, [");
    a=A[i].left;
    if(a!=-1){
      printf("%d",A[i].left);
      while(A[a].right!=-1){
	printf(", %d",A[a].right);
	a=A[a].right;
      }
    }
    printf("]\n");
  }
  return 0;
}


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

void solve()
{
	ll n,k;
	scanf("%lld %lld", &n, &k);
	ll a[n];
	for (int i = 0; i < n; ++i)
	{
		scanf("%lld", &a[i]);
	}
	ll i;
	for ( i = 0; i < k; ++i)
	{
		ll b[n] = {};
		for (ll j = 0; j < n; ++j)
		{
			b[max(0ll,j-a[j])]++;
			if(j+a[j]+1<n)
				b[j+a[j]+1]--;
		}
		bool flag = true;
		for(ll j = 0; j < n; j++)
		{
			if(j!=0)
				b[j] += b[j-1];
			a[j] = b[j];
			if(a[j]!=n)
				flag = false;
		}
		if(flag)
			break;
	}
	for (int i = 0; i < n; ++i)
	{
		printf("%lld ", a[i]);
	}
}

int main()
{
	ll t = 1;
	// cin>>t;
	while(t--)
	{
		solve();
	}
}

Measured memory_bytes: 6836
#include<bits/stdc++.h>
using namespace std;
string s="RYBG";
int n,m,d;

int cal(int x,int y){
	if (d&1) return x%2<<1|y%2;
	return ((x+y)%(d*2)/d)*2 + ((x+d-(x+y)%d/2)%d < d/2);
}

int main(){
	cin>>n>>m>>d;
	for (int i=0;i<n;i++){
		for (int j=0;j<m;j++)
			printf("%c",s[cal(i,j)]);
		puts("");
	}
}

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

using ll = long long;
using Pii = std::pair<int, int>;
using Pll = std::pair<ll, ll>;

const ll INF = (ll)1e11;

using namespace std;

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

    int A, P;
    cin >> A >> P;
    
    cout << (3 * A + P) / 2 << endl;

    return 0;
}


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

using namespace std;

typedef long long ll;

#define sz(x) ((int)(x).size())
#define in(x) int x;cin>>x
#define inn(x, y) int x,y;cin>>x>>y
#define innn(x, y, z) int x,y,z;cin>>x>>y>>z
#define bit(n) (1<<(n))

#define out(x) cout<<(x)<<endl;
#define outt(x,y) cout<<(x)<<" "<<(y)<<endl;
#define err(x) cerr<<(x)<<endl;
#define errr(x,y) cerr<<(x)<<" "<<(y)<<endl;
#define errrr(x,y,z) cerr<<(x)<<" "<<(y)<<" "<<(z)<<endl;

#define rep(i,n) for (int i=0;i<(n);i++)
#define repp(i,n) for (int i=1;i<=(n);i++)
#define reppp(j, i, n) for (int j=i+1; j<n; j++)

#define lim5 100010
#define lim9 1000000010

#define deg(rad) (((rad)/2/M_PI)*360)
#define mid(min, max) ((min + max) / 2)

int main() {
    ll n;
    cin >> n;
    in(m);
    ll a = 0;
    rep(i, m) {
        ll t;
        cin >> t;
        a += t;
    }
    out(n - a < -1 ? -1 : n - a)
    return 0;
}


Measured memory_bytes: 3624
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<string>
#include<vector>
#include<stack>
#include<bitset>
#include<cstdlib>
#include<cmath>
#include<set>
#include<list>
#include<deque>
#include<map>
#include<queue>
#define INF 0x3f3f3f3f
using namespace std;
typedef long long ll;
int a[2000020];
int main(void)
{
    int n,m,s,k,t,T,x,y;
    scanf("%d %d",&x,&y);
    if(x%y==0)
        printf("%d\n",x/y);
    else
        printf("%d\n",x/y+1);
    return 0;
}




Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
	// 30 20 10 0
	int w, sum = 0;
	cin >> w;
	while (w >= 0){
		if (w >= 30) sum += 1150 + 1250 + 1400 + ((w - 30) * 160);
		else if (w < 30 && w >= 20) sum += 1150 + 1250 + ((w - 20) * 140);
		else if (w < 20 && w >= 10)sum += 1150 + ((w - 10) * 125);
		else sum += 1150;
		cout << 4280-sum << endl;
		sum = 0;

		cin >> w;
	}
	return 0;
}

Measured memory_bytes: 1160
using System;
using System.Linq;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using System.Text;
 
public class Program
{
    public void Proc() {
        Reader.IsDebug = false;
        string[] inpt = Reader.ReadLine().Split(' ');
        long ans = 0;
        if(inpt[1].Equals("+")) {
            ans = long.Parse(inpt[0]) + long.Parse(inpt[2]);
        } else {
            ans = long.Parse(inpt[0]) - long.Parse(inpt[2]);
        }
        Console.WriteLine(ans);

    }




    public class Reader {
        public static bool IsDebug = true;
        private static System.IO.StringReader SReader;
        private static string InitText = @"




";
        public static string ReadLine() {
            if(IsDebug) {
                if(SReader == null) {
                    SReader = new System.IO.StringReader(InitText.Trim());
                }
                return SReader.ReadLine();
            } else {
                return Console.ReadLine();
            }
        }
    }
    public static void Main(string[] args)
    {
        Program prg = new Program();
        prg.Proc();
    }
}


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

#define REP(i,n) for(int i=0;i<(int)(n);i++)

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

int main(){
    long long K;
    scanf("%lld",&K);

    ll ans = 0;

    for (int a=1; a<=K; a++)
        for (int b=1; b<=K; b++)
            for (int c=1; c<=K; c++)
                ans += gcd(gcd(a,b), c);

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



Measured memory_bytes: 3760
#include<stdio.h>
#define NUM 13
   
int main(){
 int num[NUM*4-1],ncmp,n,i,j;
 char pcmp;
 for(i=0; i<NUM; i++){
  num[NUM*0+i] = i+1;
  num[NUM*1+i] = i+1;
  num[NUM*2+i] = i+1;
  num[NUM*3+i] = i+1;
 }
 scanf("%d", &n);
 for(i=0; i<n; i++){
  scanf(" %c",&pcmp);
  scanf(" %d", &ncmp);
  for(j=0; j<NUM; j++){
   switch(pcmp){
    case 'S': if(ncmp==num[NUM*0+j]){num[NUM*0+j] = -1;} break;     
    case 'H': if(ncmp==num[NUM*1+j]){num[NUM*1+j] = -1;} break;
    case 'C': if(ncmp==num[NUM*2+j]){num[NUM*2+j] = -1;} break;
    case 'D': if(ncmp==num[NUM*3+j]){num[NUM*3+j] = -1;} break;
    default:break;
   }
  }
 }
 for(i=0; i<NUM*4; i++){
  if(num[i]!=-1){
   if(i<NUM){printf("S %d\n", num[i]);}
   else if(NUM*1<=i&&i<NUM*2){printf("H %d\n", num[i]);}
   else if(NUM*2<=i&&i<NUM*3){printf("C %d\n", num[i]);}
   else if(NUM*3<=i&&i<NUM*4){printf("D %d\n", num[i]);}
  }
 }
 return 0;
}

Measured memory_bytes: 596
// JavaProgram.cpp
// Author : Priydarshi Singh (@dryairship)
// One cat just leads to another. One bug leads to two others.

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

// I like my types defined.
typedef long long           ll;
typedef pair<int, int>      pii;
typedef pair<ll, ll>        pll;
typedef vector<int>         vi;
typedef vector<ll>          vl;
typedef vector<pii>         vii;
typedef vector<pll>         vll;
typedef set<int>            si;
typedef map<string, int>    msi;
typedef map<int, int>       mii;

// Traditional science is all about finding "hashtag define"s.
#define fr(i, n)            for(int i=0; i<(n); ++i)
#define frC(i, n, c)        for(int i=0; (i<(n)) && (c); ++i)
#define frA(i, a, n)        for(int i=a; i<=(n); ++i)
#define frD(i, a, n)        for(int i=a; i>=(n); --i)
#define fill(a)             memset(a, 0, sizeof(a))
#define fill1(a)            memset(a, -1, sizeof(a))
#define revsort(a, b)       sort(a, b, greater<int>())
#define ff                  first
#define ss                  second
#define pb                  push_back 
#define dout                if(DEBUGGING) cout
#define dbg                 if(DEBUGGING) 
#define endl                "\n"

// When you realize MOD > INF...
int DEBUGGING    =          0;
const int INF    =          1000000000;
const int MOD    =          1000000007;
const ll LINF    =          1e18;
const double PI  =          3.1415926535897932;
const double EPS =          1e-7;

// I'D SPAM. Hehe.
ll gcdEx                    (ll a, ll b, ll *x, ll *y){if(!a){*x=0;*y=1;return b;} 
ll x1,y1,gcd=gcdEx          (b%a,a,&x1,&y1); *x=y1-(b/a)*x1;*y=x1; return gcd;}
ll modI(ll b, ll m)         {ll x,y;gcdEx(b,m,&x,&y);return (x%m+m)%m;}
ll modD(ll a, ll b)         {return (modI(b,MOD)*(a%MOD))%MOD;}
ll modS(ll a, ll b)         {return ((a%MOD)-(b%MOD)+MOD)%MOD;}
ll modP(ll x, ll y)         {ll r=1; x%=MOD; while(y>0){if(y&1){r=(r*x)%MOD;} y=y>>1; x=(x*x)%MOD;} return r;}
ll modA(ll a, ll b)         {return ((a%MOD)+(b%MOD))%MOD;}
ll modM(ll a, ll b)         {return ((a%MOD)*(b%MOD))%MOD;}

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int dp[100005][3];

void solve(int TEST_CASE){
    int n;
    cin >> n;
    int a,b,c;
    cin >> a >> b >> c;
    dp[0][0] = a;
    dp[0][1] = b;
    dp[0][2] = c;
    frA(i, 1, n-1){
        cin >> a >> b >> c;
        dp[i][0] = a + max(dp[i-1][1], dp[i-1][2]);
        dp[i][1] = b + max(dp[i-1][0], dp[i-1][2]);
        dp[i][2] = c + max(dp[i-1][1], dp[i-1][0]);
    }
    cout << max(dp[n-1][0], max(dp[n-1][1], dp[n-1][2]));
}

int main(int argc, char* argv[]){
    if(argc==2 && argv[1][1]=='v') DEBUGGING = 1;
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    cin.exceptions(cin.failbit);
    int nTestCases=1;
    //cin >> nTestCases;
    frA(i,1,nTestCases) solve(i);
    return 0;
}

Measured memory_bytes: 4788
from collections import defaultdict

def main():
    N, K = map(int, input().split())
    d = defaultdict(int)
    for _ in range(N):
        a, b = map(int, input().split())
        d[a] += b
    total = 0
    for v, freq in sorted(d.items()):
        total += freq
        if total >= K:
            print(v)
            exit()


if __name__ == '__main__':
    main()


Measured memory_bytes: 85796
#include<bits/stdc++.h>
#define endl '\n';
#define rep(i,n) for(int i=0; i<(n); i++)
using namespace std;
using ll = long long;
using P = pair<int,int>;
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("Ofast")
constexpr ll INF = 1e18;
constexpr int inf = 1e9;
constexpr double INFD = 1e100;
constexpr ll mod = 1000000007;
constexpr ll mod2 = 998244353;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
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; }
// ios::sync_with_stdio(false);
// cin.tie(nullptr);
// ---------------------------------------------------------------------------

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int N;
    cin >> N;
    vector<string> str(N);
    for(int i=0; i<N; i++){
        cin >> str[i];
    }
    int now = 0;
    for(int i=0; i<N; i++){
        if(str[i] == "A"){
            now++;
        }else{
            now--;
        }
        if(now < 0){
            cout << "NO" << endl;
            return 0;
        }
    }
    if(now != 0){
        cout << "NO" << endl;
    }else{
        cout << "YES" << endl;
    }
    return 0;
}


Measured memory_bytes: 3260
# Your code hered


h,w=gets.split
h=h.to_i
w=w.to_i

array=[]
10.times{
    array<<gets.split.map(&:to_i)
    
    
}
array2=Array.new(10).map{Array.new(10,100000000)}


10.times{
i=0
10.times{
    j=0
    10.times{
    k=0
        10.times{
            array[i][j]=[array[i][j],array[i][k]+array[k][j]].min
            
             k+=1      
            
        }
     j+=1   
        
    }
 i+=1   
    
}

}


array3=[]
h.times{
    array3<<gets.split.map(&:to_i)
    
    
    
}
array4=[]
hhh=0
10.times{
    
    array4<<array3.flatten.count(hhh)
    hhh+=1
}



answer=0
kk=0
10.times{
    answer+=array[kk][1]*array4[kk]
    
   kk+=1 
    
}

puts    answer









Measured memory_bytes: 5552
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int N = in.nextInt();
		int x = in.nextInt();
		int count = 0;
		int a[] = new int[N];
		for (int i = 0; i < N; i++) {
			a[i] = in.nextInt();
		}
		Arrays.sort(a);
		long sum=x;
		for (int i = 0; i < N; i++) {
			sum = sum - a[i];
			if (sum >= 0) {
				count++;
			}
		}
		if (sum > 0) {
			count--;
		}
		System.out.println(count);

	}
}


Measured memory_bytes: 21460
#include <iostream>

using namespace std;

int main(int argc, const char *argv[]) {
  int A[3][3];
  int N, b;
  cin >> A[0][0] >> A[0][1] >> A[0][2];
  cin >> A[1][0] >> A[1][1] >> A[1][2];
  cin >> A[2][0] >> A[2][1] >> A[2][2];
  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> b;
    for (int j = 0; j < 3; j++) {
      for (int k = 0; k < 3; k++) {
        if(b == A[j][k]){
          A[j][k] = 0;
        }
      }
    }
  }

  for (int i = 0; i < 3; i++) {
    if(A[i][0] == 0 && A[i][1] == 0 && A[i][2] == 0){
      cout << "Yes" << endl;
      return 0;
    }
    if(A[0][i] == 0 && A[1][i] == 0 && A[2][i] == 0){
      cout << "Yes" << endl;
      return 0;
    }
  }
  if (A[0][0] == 0 && A[1][1] == 0 && A[2][2] == 0) {
      cout << "Yes" << endl;
      return 0;
  }
  if (A[0][2] == 0 && A[1][1] == 0 && A[2][0] == 0) {
      cout << "Yes" << endl;
      return 0;
  }
  cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 888
#include<stdio.h>
#define WHITE 0
#define GRAY  1
#define BLACK 2

int n,M[100][100];
int color[100];
int time;
int d[100],f[100];

void visit(int u){
  int v;
  
  color[u] = GRAY;
  d[u] = ++time;
  for(v=0;v<n;v++){
    if(M[u][v] == 0) continue;
    if(color[v] == WHITE) visit(v);
  }
  color[u] = BLACK;
  f[u] = ++time;
}

void dfs(){
  int u;

  for(u=0;u<n;u++) color[u] = WHITE;
  time = 0;
  
  for(u=0;u<n;u++){
    if(color[u]==WHITE) visit(u);
  }
}

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

  scanf("%d",&n);
  for(i=0;i<n;i++)
   for(j=0;j<n;j++)
      M[i][j]=0;
	
  for(i=0;i<n;i++){
    scanf("%d%d",&u,&k);
    for(j=0;j<k;j++){
      scanf("%d",&v);
      M[u-1][v-1] = 1;
    }
  }
  
  dfs();
  for(i=0;i<n;i++) printf("%d %d %d\n",i+1,d[i],f[i]);
  
  return 0;
}


Measured memory_bytes: 2068
#include <iostream>
#include <string>
#include <map>
#include <algorithm>
#include <vector>

#define ll long long

int main()
{
    ll D, T, S;
    std::cin >> D >> T >> S;

    ll sum = T * S;
    if(sum >= D) {
        std::cout << "Yes" << std::endl;
    }
    else {
        std::cout << "No" << std::endl;
    }
}

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

int main(){
    int sx, sy, tx, ty;
    cin >> sx >> sy >> tx >> ty;
    for(int i=0; i<tx-sx; i++){
        cout << "R";
    }
    for(int i=0; i<ty-sy; i++){
        cout << "U";
    }
    for(int i=0; i<tx-sx; i++){
        cout << "L";
    }
    for(int i=0; i<ty-sy; i++){
        cout << "D";
    }
    cout << "D";
    for(int i=0; i<tx-sx+1; i++){
        cout << "R";
    }
    for(int i=0; i<ty-sy+1; i++){
        cout << "U";
    }
    cout << "L";

    cout << "U";
    for(int i=0; i<tx-sx+1; i++){
        cout << "L";
    }
    for(int i=0; i<ty-sy+1; i++){
        cout << "D";
    }
    cout << "R" << endl;
}

Measured memory_bytes: 256
N,M,K = map(int,(input().split()))
MOD = 998244353
kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]
 
gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]
 
def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret

ans = 0
for i in range(K+1):
    ans = (ans + (nCr(N-1,i) * M * pow(M-1,N-i-1,MOD))) %MOD
print(ans)

Measured memory_bytes: 86160
use std::io::Read;
use std::io::Write;

fn run() {
    let out = std::io::stdout();
    let mut out = std::io::BufWriter::new(out.lock());
    let mut s = String::new();
    std::io::stdin().read_to_string(&mut s).unwrap();
    let mut it = s.trim().split_whitespace();
    it.next();
    let s: Vec<char> = it.next().unwrap().chars().collect();
    it.next();
    for k in it {
        let k: usize = k.parse().unwrap();
        let mut d = 0u64;
        let mut m = 0;
        let mut dm = 0;
        let mut dmc = 0;
        for &c in s[..k].iter() {
            if c == 'D' {
                d += 1;
            } else if c == 'M' {
                m += 1;
                dm += d;
            } else if c == 'C' {
                dmc += dm;
            }
        }
        for (&f, &t) in s.iter().zip(s[k..].iter()) {
            if f == 'D' {
                dm -= m;
                d -= 1;
            } else if f == 'M' {
                m -= 1;
            }
            if t == 'D' {
                d += 1;
            } else if t == 'M' {
                m += 1;
                dm += d;
            } else if t == 'C' {
                dmc += dm;
            }
        }
        writeln!(out, "{}", dmc).ok();
    }
}

fn main() {
    run();
}


Measured memory_bytes: 11512
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n=sc.nextInt();
    int[] a = new int[n];
    int max=0;
    int nex=0;
    int pos=0;
    for(int i=0;i<n;i++){
        a[i]=sc.nextInt();
        if(a[i]>nex){
            nex=a[i];
            if(nex>max){
                nex=max;
                max=a[i];
                pos=i;
            }
        }
    }
    for(int i=0;i<n;i++){
        if(i==pos){
            System.out.println(nex);
        }else{
            System.out.println(max);
        }
    }
  }
}


Measured memory_bytes: 92788
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); ++i)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
using namespace std;
const int MAX = 1000000;
const int MOD = 998244353;
 
long long fac[MAX], finv[MAX], inv[MAX];
 
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
 
// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
int main(){
  long n,m,k;
  cin>>n>>m>>k;
  COMinit();
  long ans=0;
  long l=m;
  int p=n-k-1;
  while(p--){
    l=l*(m-1)%MOD;
  }
  for(int i=k;i>=0;i--){
    long now=COM(n-1,i);
    now=now*l%MOD;
    l=l*(m-1)%MOD;
    ans=(ans+now)%MOD;
  }
  cout<<ans<<endl;
}

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

using namespace std;
void primeFactors(long long n)
{
    while (n % 2 == 0)
    {
        cout << 2 << " ";
        n = n/2;
    }
    for (int i = 3; i <= sqrt(n); i = i + 2)
    {
        while (n % i == 0)
        {
            cout << i << " ";
            n = n/i;
        }
    }
    if (n > 2)
        cout << n << " ";
}
int main()
{
    long long a , b ;
    cin >> a >> b;
    vector<long long>v1 , v2;
    while (a % 2 == 0)
    {
        v1.push_back(2);
        a/=2;
    }
    for (int i = 3; i <= sqrt(a); i+=2)
    {
        while (a % i == 0)
        {
            v1.push_back(i);
            a/=i;
        }
    }
    if (a > 2)
        v1.push_back(a);

    while (b % 2 == 0)
    {
        v2.push_back(2);
        b/=2;
    }
    for (int i = 3; i <= sqrt(b); i+=2)
    {
        while (b % i == 0)
        {
            v2.push_back(i);
            b/=i;
        }
    }
    if (b > 2)
        v2.push_back(b);
    sort(v2.begin(), v2.end());
    sort(v1.begin(), v1.end());
    v1.resize( unique(v1.begin() , v1.end()) -v1.begin());
    v2.resize( unique(v2.begin() , v2.end()) -v2.begin());
    for(int i = 0 ; i < v1.size() ; i++)
    {
        if(!binary_search(v2.begin(),v2.end(),v1[i]))
        {
            v1.erase(v1.begin()+i);
            i--;
        }
    }

    cout << v1.size()+1 << " ";

    return 0;
}


Measured memory_bytes: 256