Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
#coding: utf-8
import math
import heapq
import bisect
#from scipy.misc import comb

MOD = 10**9+7

H,W = map(int, input().split())

Map = []
for i in range(H):
    s = input()
    Map.append(s)

L = [[0]*W for _ in range(H)]
for i in range(H):
    cnt = 0
    for j in range(W):
        if Map[i][j]=="#":
           L[i][j] = -1
           cnt = 0
        else:
            L[i][j] = cnt
            cnt += 1

R = [[0]*W for _ in range(H)]
for i in range(H):
    cnt = 0
    for j in reversed(range(W)):
        if Map[i][j]=="#":
           R[i][j] = -1
           cnt = 0
        else:
            R[i][j] = cnt
            cnt += 1

U = [[0]*W for _ in range(H)]
for j in range(W):
    cnt = 0
    for i in range(H):
        if Map[i][j]=="#":
           U[i][j] = -1
           cnt = 0
        else:
            U[i][j] = cnt
            cnt += 1

D = [[0]*W for _ in range(H)]
for j in range(W):
    cnt = 0
    for i in reversed(range(H)):
        if Map[i][j]=="#":
           D[i][j] = -1
           cnt = 0
        else:
            D[i][j] = cnt
            cnt += 1

ans = 0
for i in range(H):
    for j in range(W):
        ans = max(ans, L[i][j]+R[i][j]+U[i][j]+D[i][j]+1)

print(ans)

Fixed submission:
#coding: utf-8
import math
import heapq
import bisect
import numpy as np
#from scipy.misc import comb

MOD = 10**9+7

H,W = map(int, input().split())
M = np.array([list(input().rstrip("\n")) for _ in range(H)]) == "."

D = np.zeros((H,W),dtype=int)
U = np.zeros((H,W),dtype=int)
L = np.zeros((H,W),dtype=int)
R = np.zeros((H,W),dtype=int)

for i in range(H):
    U[i] = (U[i-1] + 1) * M[i]
    D[-i-1] = (D[-i] + 1) * M[-i-1]

for i in range(W):
    L[:,i] = (L[:,i-1] + 1) * M[:,i]
    R[:,-i-1] = (R[:,-i] + 1) * M[:,-i-1]

print(np.max(U+D+L+R)-3)
Buggy python submission (verdict: Runtime Error):
#coding: utf-8
import math
import heapq
import bisect
import numpy as np
#from scipy.misc import comb

N = int(input())
A = list(map(int, input().split()))

ans = A[0]
for i in range(1,N):
    ans = math.gcd(ans, A[i])

print(ans)

Fixed submission:
#coding: utf-8
import math
import heapq
import bisect
import numpy as np
import fractions
#from scipy.misc import comb

N = int(input())
A = list(map(int, input().split()))

ans = A[0]
for i in range(1,N):
    ans = fractions.gcd(ans, A[i])

print(ans)

Buggy python submission (verdict: Runtime Error):
#coding: utf-8
import math
import heapq
import bisect
import numpy as np
#from scipy.misc import comb

N = int(input())
A = list(map(int, input().split()))

ans = math.gcd(A[0],A[1])
for i in range(2,N+1):
    ans = math.gcd(ans, A[i])

print(ans)

Fixed submission:
#coding: utf-8
import math
import heapq
import bisect
import numpy as np
import fractions
#from scipy.misc import comb

N = int(input())
A = list(map(int, input().split()))

ans = A[0]
for i in range(1,N):
    ans = fractions.gcd(ans, A[i])

print(ans)
Buggy python submission (verdict: Runtime Error):
#coding: utf-8
import math
import heapq
import bisect
import numpy as np
#from scipy.misc import comb

N = int(input())
h = list(map(int, input().split()))

ans += h[0]
base = h[0]
for i in range(1,N):
    ans += max(h[i]-base,0)
    base = h[i]

print(ans)

Fixed submission:
#coding: utf-8
import math
import heapq
import bisect
import numpy as np
#from scipy.misc import comb

N = int(input())
h = list(map(int, input().split()))

ans = h[0]
base = h[0]
for i in range(1,N):
    ans += max(h[i]-base,0)
    base = h[i]

print(ans)
Buggy python submission (verdict: Runtime Error):
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

#define NEW(p,n){p=malloc((n)*sizeof(p[0]));if(p==NULL){printf("not enough memory\n");exit(1);};}
//pの型の変数n個の要素分のメモリを確保し、そのアドレスをpに代入するマクロ

#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define SWAP(type, x, y) do { type tmp = x; x = y; y = tmp; } while (0)

#define MOD 1000000007 

int main(void){
    int H,W;
    scanf("%d%d",&H,&W);

    char map[H][W+1];
    for(int i=0;i<H;i++) scanf("%s",map[i]);

    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            int flg=0;
            if(map[i][j]=='#'){
                if(i>0 && map[i-1][j]=='#') flg=1;
                if(i<H-1 && map[i+1][j]=='#') flg=1;
                if(j>0 && map[i][j-1]=='#') flg=1;
                if(j<W-1 && map[i][j+1]=='#') flg=1;
                if(!flg){
                    printf("No\n");
                    return 0;
                }
            }
        }
    }
    
    printf("Yes\n");

    return 0;
}

Fixed submission:
#coding: utf-8
import math
import heapq
import bisect
import numpy as np
from collections import Counter
#from scipy.misc import comb

H,W = map(int, input().split())

s = ['.'*(W+2)]
for i in range(H):
    row = input()
    s.append('.' + row + '.')
s.append('.'*(W+2))

flg = 1
for i in range(1,H+1):
    for j in range(1,W+1):
        if s[i][j] == "#":
            if s[i-1][j] == "." and s[i+1][j] == "." and s[i][j-1] == "." and s[i][j+1] == ".":
                flg = 0

if flg:
    print("Yes")
else:
    print("No")

Buggy python submission (verdict: Runtime Error):
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

#define NEW(p,n){p=malloc((n)*sizeof(p[0]));if(p==NULL){printf("not enough memory\n");exit(1);};}
//pの型の変数n個の要素分のメモリを確保し、そのアドレスをpに代入するマクロ

#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define SWAP(type, x, y) do { type tmp = x; x = y; y = tmp; } while (0)

#define MOD 1000000007 

int main(void){
    int H,W;
    scanf("%d%d",&H,&W);

    char map[H][W+1];
    for(int i=0;i<H;i++) scanf("%s",map[i]);

    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            int flg=0;
            if(map[i][j]=='#'){
                if(i>0 && map[i-1][j]=='#') flg=1;
                if(i<H-1 && map[i+1][j]=='#') flg=1;
                if(j>0 && map[i][j-1]=='#') flg=1;
                if(j<W-1 && map[i][j+1]=='#') flg=1;
            }
            if(!flg){
                printf("No\n");
                return 0;
            }
        }
    }
    
    printf("Yes\n");

    return 0;
}

Fixed submission:
#coding: utf-8
import math
import heapq
import bisect
import numpy as np
from collections import Counter
#from scipy.misc import comb

H,W = map(int, input().split())

s = ['.'*(W+2)]
for i in range(H):
    row = input()
    s.append('.' + row + '.')
s.append('.'*(W+2))

flg = 1
for i in range(1,H+1):
    for j in range(1,W+1):
        if s[i][j] == "#":
            if s[i-1][j] == "." and s[i+1][j] == "." and s[i][j-1] == "." and s[i][j+1] == ".":
                flg = 0

if flg:
    print("Yes")
else:
    print("No")
Buggy python submission (verdict: Runtime Error):
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

#define NEW(p,n){p=malloc((n)*sizeof(p[0]));if(p==NULL){printf("not enough memory\n");exit(1);};}
//pの型の変数n個の要素分のメモリを確保し、そのアドレスをpに代入するマクロ

#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define SWAP(type, x, y) do { type tmp = x; x = y; y = tmp; } while (0)

#define MOD 1000000007 

//昇順
int asc(const void* a, const void* b){
    return *(int*)a-*(int*)b;
}

int main(void){
    int N;
    scanf("%d",&N);

    int* X;
    NEW(X,N);
    for(int i=0;i<N;i++){
        scanf("%d",&X[i]);
    }

    int* Y;
    NEW(Y,N);
    for(int i=0;i<N;i++) Y[i]=X[i];
    qsort(Y,N,sizeof(int),asc);

    for(int i=0;i<N;i++){
        if(X[i]>=Y[N/2]) printf("%d\n",Y[N/2-1]);
        else printf("%d\n",Y[N/2]);
    }

    return 0;
}

Fixed submission:
#coding: utf-8
import math
import heapq
import bisect
import numpy as np
from collections import Counter
#from scipy.misc import comb

N = int(input())
X = list(map(int, input().split()))
Y = sorted(X)

for x in X:
    if x <= Y[N//2-1]:
        print(Y[N//2])
    else:
        print(Y[N//2-1])
Buggy python submission (verdict: Runtime Error):
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

#define NEW(p,n){p=malloc((n)*sizeof(p[0]));if(p==NULL){printf("not enough memory\n");exit(1);};}
//pの型の変数n個の要素分のメモリを確保し、そのアドレスをpに代入するマクロ

#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define SWAP(type, x, y) do { type tmp = x; x = y; y = tmp; } while (0)

#define MOD 1000000007 

//昇順
int asc(const void* a, const void* b){
    return *(int*)a-*(int*)b;
}

int main(void){
    //A[0]~A[N-1]に格納する
    int* A;
    NEW(A,3);
    for(int i=0;i<3;i++){
        scanf("%d",&A[i]);
    }
    qsort(A,3,sizeof(int),asc);

    int ans=(A[2]-A[1])+(A[1]-A[0])/2+((A[1]-A[0])%2)*2;
    printf("%d\n",ans);

    return 0;
}

Fixed submission:
#coding: utf-8
import math
import heapq
import bisect
import numpy as np
from collections import Counter
#from scipy.misc import comb

A = list(map(int, input().split()))
A.sort()

ans = (A[2]-A[1]) + (A[1]-A[0])//2 + ((A[1]-A[0])%2)*2
print(ans)
Buggy python submission (verdict: Runtime Error):
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

#define NEW(p,n){p=malloc((n)*sizeof(p[0]));if(p==NULL){printf("not enough memory\n");exit(1);};}
//pの型の変数n個の要素分のメモリを確保し、そのアドレスをpに代入するマクロ

#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define SWAP(type, x, y) do { type tmp = x; x = y; y = tmp; } while (0)

#define MOD 1000000007 

typedef struct{
    int x;
    int y;
    int flg;
}data;

//x軸の昇順
int xasc(const void* a, const void* b){
    data p = *(data*)a;
    data q = *(data*)b;
    if(p.x!=q.x) return p.x-q.x;
    else return p.y-q.y;
}

//y軸の降順
int ydesc(const void* a, const void* b){
    data p = *(data*)a;
    data q = *(data*)b;
    if(p.y!=q.y) return q.y-p.y;
    else return q.x-p.x;
}

int main(void){
    int N;
    scanf("%d",&N);

    //A[0]~A[N-1]に格納する
    data* red;
    NEW(red,N);
    for(int i=0;i<N;i++){
        scanf("%d%d",&red[i].x,&red[i].y);
        red[i].flg=0;
    }
    qsort(red,N,sizeof(data),ydesc);

    data* blue;
    NEW(blue,N);
    for(int i=0;i<N;i++){
        scanf("%d%d",&blue[i].x,&blue[i].y);
        blue[i].flg=0;
    }
    qsort(blue,N,sizeof(data),xasc);

    int ans=0;
    for(int i=0;i<N;i++){
        for(int j=0;j<N;j++){
            if(red[j].flg) continue;
            if(red[j].x<blue[i].x && red[j].y<blue[i].y){
                ans++;
                red[j].flg=1;
                break;
            }
        }
    }
    printf("%d\n",ans);

    return 0;
}

Fixed submission:
#coding: utf-8
import math
import heapq
import bisect
import numpy as np
from collections import Counter
#from scipy.misc import comb

N = int(input())
red = [list(map(int,input().split())) for i in range(N)]
blue = [list(map(int,input().split())) for i in range(N)]
red.sort()
blue.sort()

ans = 0
for c,d in blue:
    x = []
    for a,b in red:
        if a < c and b < d:
            x.append([a,b])
    if len(x) > 0:
        ans += 1
        x = sorted(x, key=lambda x:x[1])
        red.remove(x[-1])

print(ans)
Buggy python submission (verdict: Runtime Error):
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

#define NEW(p,n){p=malloc((n)*sizeof(p[0]));if(p==NULL){printf("not enough memory\n");exit(1);};}
//pの型の変数n個の要素分のメモリを確保し、そのアドレスをpに代入するマクロ

#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define SWAP(type, x, y) do { type tmp = x; x = y; y = tmp; } while (0)

#define MOD 1000000007 

int main(void){
    int c[3][3];
    for(int i=0;i<3;i++){
        for(int j=0;j<3;j++) scanf("%d",&c[i][j]);
    }

    int a[3]={0,c[1][0]-c[0][0],c[2][0]-c[0][0]};
    int b[3]={c[0][0],c[0][1],c[0][2]};

    if(c[1][1]!=a[1]+b[1]){
        printf("No\n");
        return 0;
    }
    if(c[1][2]!=a[1]+b[2]){
        printf("No\n");
        return 0;
    }
    if(c[2][1]!=a[2]+b[1]){
        printf("No\n");
        return 0;
    }
    if(c[2][2]!=a[2]+b[2]){
        printf("No\n");
        return 0;
    }
    printf("Yes\n");

    return 0;
}

Fixed submission:
#coding: utf-8
import math
import heapq
import bisect
import numpy as np
from collections import Counter
#from scipy.misc import comb

C = [list(map(int, input().split())) for i in range(3)]
A = [0]*3
B = [0]*3

flg = 0
for i in range(C[0][0]+1):
    A[0] = i
    B[0] = C[0][0]-i
    for j in range(1,3):
        A[j] = C[j][0]-B[0]
        B[j] = C[0][j]-A[0]
    
    tmp = abs(C[1][1]-A[1]-B[1])+abs(C[1][2]-A[1]-B[2])+abs(C[2][1]-A[2]-B[1])+abs(C[2][2]-A[2]-B[2])
    if tmp==0:
        flg = 1

if flg:
    print("Yes")
else:
    print("No")
Buggy python submission (verdict: Runtime Error):
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

#define NEW(p,n){p=malloc((n)*sizeof(p[0]));if(p==NULL){printf("not enough memory\n");exit(1);};}
//pの型の変数n個の要素分のメモリを確保し、そのアドレスをpに代入するマクロ

#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define SWAP(type, x, y) do { type tmp = x; x = y; y = tmp; } while (0)

#define MOD 1000000007 

int main(void){
    int N;
    scanf("%d",&N);

    int M[2][N];
    for(int i=0;i<2;i++){
        for(int j=0;j<N;j++) scanf("%d",&M[i][j]);
    }
    
    //累積和をとる
    for(int i=1;i<N;i++) M[0][i]+=M[0][i-1];
    for(int i=N-2;i>=0;i--) M[1][i]+=M[1][i+1];
    
    int ans=0;
    for(int i=0;i<N;i++) ans=MAX(ans, M[0][i]+M[1][i]);
    printf("%d\n",ans);
    
    return 0;
}

Fixed submission:
#coding: utf-8
import math
import heapq
import bisect
import numpy as np
from collections import Counter
#from scipy.misc import comb

MOD = 10**9+7

N = int(input())
A = [list(map(int, input().split())) for i in range(2)]

ans = 0
for i in range(N):
    tmp = 0
    for j in range(i+1):
        tmp += A[0][j]
    for j in range(i,N):
        tmp += A[1][j]
    ans = max(ans,tmp)

print(ans)
Buggy python submission (verdict: Runtime Error):
#coding: utf-8
import math
import heapq
import bisect
import numpy as np
from collections import Counter
#from scipy.misc import comb

N,C = map(int, input().split())
L = [list(map(int, input().split())) for i in range(N)]

T_MAX = 2*(10**5)+1

time = [0]*(T_MAX)
for l in L:
    time[l[0]*2-1] += 1
    time[l[1]*2+1] -= 1

ans = 0
tmp = 0
for t in time:
    tmp += t
    ans = max(ans, tmp)

print(ans)

Fixed submission:
#coding: utf-8
import math
import heapq
import bisect
import numpy as np
from collections import Counter
#from scipy.misc import comb

N,C = map(int, input().split())
L = [list(map(int, input().split())) for i in range(N)]

T_MAX = 10**5
time = [[0]*C for i in range(T_MAX)]

for s,t,c in L:
    time[s-1][c-1] += 1
    time[t-1][c-1] -= 1
 
ans = 0
tmp = 0
for i in range(T_MAX):
    tmp += time[i].count(1)
    ans = max(ans,tmp)
    tmp -= time[i].count(-1)

print(ans)

Buggy python submission (verdict: Runtime Error):
#coding: utf-8
import math
import heapq
import bisect
import numpy as np
from collections import Counter
#from scipy.misc import comb

N,C = map(int, input().split())
L = [list(map(int, input().split())) for i in range(N)]

time = [0]*(2*(10**5))
for l in L:
    time[l[0]*2-1] += 1
    time[l[1]*2] -= 1

ans = 0
tmp = 0
for t in time:
    tmp += t
    ans = max(ans, tmp)

print(ans)

Fixed submission:
#coding: utf-8
import math
import heapq
import bisect
import numpy as np
from collections import Counter
#from scipy.misc import comb

N,C = map(int, input().split())
L = [list(map(int, input().split())) for i in range(N)]

T_MAX = 10**5
time = [[0]*C for i in range(T_MAX)]

for s,t,c in L:
    time[s-1][c-1] += 1
    time[t-1][c-1] -= 1
 
ans = 0
tmp = 0
for i in range(T_MAX):
    tmp += time[i].count(1)
    ans = max(ans,tmp)
    tmp -= time[i].count(-1)

print(ans)
Buggy python submission (verdict: Runtime Error):
#coding: utf-8
import math
import heapq
import bisect
import numpy as np
from collections import Counter
#from scipy.misc import comb

S = input()
T = input()

start = -1
for i in range(len(S)-len(T),-1,-1):
    flg = 1
    for j in range(len(T)):
        if S[i+j] != '?' and S[i+j] != T[j]:
            flg = 0
            break
    if flg:
        start = i
        break

if flg == -1:
    ans = 'UNRESTORABLE'
else:
    S = S.replace('?', 'a')
    ans = S[:start] + T + S[start+len(T)+1:]

print(ans)

Fixed submission:
#coding: utf-8
import math
import heapq
import bisect
import numpy as np
from collections import Counter
#from scipy.misc import comb

S = input()
T = input()
 
for i in reversed(range(len(S)-len(T)+1)):
    flag = 1
    for j in range(len(T)) :
        if S[i+j] != T[j] and S[i+j] != "?":
            flag = 0
    if flag:
        ans = S[:i] + T + S[i+len(T):]
        print(ans.replace("?", "a"))
        exit()
 
print("UNRESTORABLE")
Buggy python submission (verdict: Runtime Error):
#coding: utf-8
import math
import heapq
import bisect
import numpy as np
from collections import Counter
#from scipy.misc import comb

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

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

d = [0] + [-1]*(N-1)

def dfs(n):
    for v in G[n]:
        if d[v] == -1:
            dfs(v)

ans = 0
for a,b in E:
    G[a].remove(b)
    G[b].remove(a)

    dfs(0)

    if -1 in d:
        ans += 1
    
    for i in range(1,N):
        d[i] = -1

print(ans)

Fixed submission:
#coding: utf-8
import math
import heapq
import bisect
import numpy as np
from collections import Counter
#from scipy.misc import comb

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

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

d = [0] + [-1]*(N-1)

def dfs(n):
    d[n] = 0
    for v in G[n]:
        if d[v] == -1:
            dfs(v)

ans = 0
for a,b in E:
    G[a].remove(b)
    G[b].remove(a)

    dfs(0)

    if -1 in d:
        ans += 1
    
    for i in range(1,N):
        d[i] = -1
    G[a].append(b)
    G[b].append(a)

print(ans)
Buggy python submission (verdict: Runtime Error):
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

#define NEW(p,n){p=malloc((n)*sizeof(p[0]));if(p==NULL){printf("not enough memory\n");exit(1);};}
//pの型の変数n個の要素分のメモリを確保し、そのアドレスをpに代入するマクロ

#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define SWAP(type, x, y) do { type tmp = x; x = y; y = tmp; } while (0)

#define MOD 1000000007 

typedef char* String;

String string_input(void){
    int i,len;
    char buf[100];
    String str;
    scanf("%s",buf);//buf=入力した文字列が入るchar型の配列
    
    len=strlen(buf);//len=文字列の長さを表すint型変数
    NEW(str,len+1);//strはただのポインタだから、ここでNEWを使ってメモリを確保しなくちゃいけない
    for(i=0;i<len;i++){
        str[i]=buf[i];
    }
    str[len]=0;
    
    return str;
}

int main(void){
    int N;
    scanf("%d",&N);

    //A[0]~A[N-1]に格納する
    String* S;
    NEW(S,N);
    for(int i=0;i<N;i++){
        S[i]=string_input();
    }

    int* ans;
    NEW(ans,26);
    for(int i=0;i<26;i++) ans[i]=50;

    int* tmp;
    NEW(tmp,26);
    for(int i=0;i<N;i++){
        for(int j=0;j<26;j++) tmp[j]=0;

        for(int j=0;j<strlen(S[i]);j++){
            tmp[S[i][j]-'a']++;
        }

        for(int j=0;j<26;j++) ans[j]=MIN(ans[j],tmp[j]);
    }

    for(int i=0;i<26;i++){
        char c='a'+i;
        for(int j=1;j<=ans[i];j++) printf("%c",c);
    }
    printf("\n");

    return 0;
}

Fixed submission:
#coding: utf-8
import math
import heapq
import bisect
import numpy as np
from collections import Counter, deque
#from scipy.misc import comb

N = int(input())
S = []
for _ in range(N):
    s = input()
    S.append(s)

cnt = [10000]*26
for s in S:
    for i in range(26):
        cnt[i] = min(cnt[i], s.count(chr(97+i)))

ans = ""
for i in range(26):
    if cnt[i] < 10000: ans += chr(97+i)*cnt[i]

print(ans)
Buggy python submission (verdict: Runtime Error):
#######################################
prime = 10**9+7

def sowa(num):
  return int((1+num)*num/2)
#######################################
n,k = map(int, input().split())
a = list(map(int, input().split()))

tento1 = [sum([1 if a[i]>a[j] else 0 for j in range(i+1,n)]) for i in range(n-1)]
tento2 = [sum([1 if a[i]>a[j] else 0 for j in range(n)]) for i in range(n)]


ret = (sum(tento1) *k %prime) + (sum(tento2) *(sowa(k-1) %prime) %prime)
print(int(ret%prime)))


Fixed submission:
#######################################
prime = 10**9+7

def sowa(num):
  return int((1+num)*num//2)
#######################################
n,k = map(int, input().split())
a = list(map(int, input().split()))

tento1 = [sum([1 if a[i]>a[j] else 0 for j in range(i+1,n)]) for i in range(n-1)]
tento2 = [sum([1 if a[i]>a[j] else 0 for j in range(n)]) for i in range(n)]


ret = (sum(tento1) *k %prime) + (sum(tento2) *(sowa(k-1) %prime) %prime)
print(int(ret%prime))
Buggy python submission (verdict: Time Limit Exceeded):
import sys
big=10**9+7

def modsum(a,b):
  return a%big +b%big

n,m = map(int, input().split())

a = [0]*m
for i in range(m):
  a[i] = int(input())
  
#連続こわれ
for i in range(m-1):
  if a[i]+1 == a[i+1]:
    print(0)
    sys.exit(0)

cho = [0]*(n+1)
if 0 not in a:
  cho[0] = 1
if 1 not in a:
  cho[1] = 1

for i in range(2,n+1):
  if i not in a:
    cho[i] = modsum(cho[i-1], cho[i-2])


print(cho[-1]%big)

Fixed submission:

big=10**9+7

n,m = map(int, input().split())

a = set([int(input()) for _ in range(m)])
  

cho = [0]*(n+1)
if 0 not in a:
  cho[0] = 1
if 1 not in a:
  cho[1] = 1

for i in range(2,n+1):
  if i not in a:
    cho[i] = (cho[i-1]+cho[i-2])%big


print(cho[-1])

Buggy python submission (verdict: Time Limit Exceeded):
import sys
big=10**9+7

def modsum(a,b):
  return a%big + b%big

n,m = map(int, input().split())
n+=1

a = [0]*m
for i in range(m):
  a[i] = int(input())
  
#連続こわれ
for i in range(m-1):
  if a[i]+1 == a[i+1]:
    print(0)
    sys.exit(0)

#選択肢計算
cho = [1]*n
if 1 in a:
  cho[1]=0

for i in range(2,n):
  if i in a:
    cho[i] = 0
  elif i-1 in a:
    cho[i] = cho[i-2]
  else:
    cho[i] = modsum(cho[i-1], cho[i-2])


print(cho[-1]%big)


Fixed submission:

big=10**9+7

n,m = map(int, input().split())

a = set([int(input()) for _ in range(m)])
  

cho = [0]*(n+1)
if 0 not in a:
  cho[0] = 1
if 1 not in a:
  cho[1] = 1

for i in range(2,n+1):
  if i not in a:
    cho[i] = (cho[i-1]+cho[i-2])%big


print(cho[-1])
Buggy python submission (verdict: Time Limit Exceeded):

#math
def gcd(a, b): #最大公約数
  while b:
    a, b = b, a % b
  return int(a)

def gcd3(lis): #最大公約数(3over)
  ans = lis[0]
  for li in lis:
    ans = gcd(ans,li)
  return ans
    
n = int(input())

a = list(map(int, input().split()))

maxgcd = 0
for i in range(n):
  nums = [a[j] for j in range(n) if j!=i]
  #print(nums)
  tmp = gcd3(nums)
  if maxgcd<tmp:
    maxgcd=tmp
    
print(maxgcd)




Fixed submission:

import sys

def gcd(a, b): #最大公約数
  while b:
    a, b = b, a % b
  return int(a)
    
n = int(input())
a = list(map(int, input().split()))


if n==2:
  print(max(a))
  sys.exit(0)
elif n==3:
  lis = [gcd(a[0], a[1]), gcd(a[1], a[2]), gcd(a[2], a[0])]
  print(max(lis))
  sys.exit(0)


tmp_unused = gcd(a[0], a[1])
tmp_used = max(a[0], a[1])
#print("used=", tmp_used, "unused=", tmp_unused)

for i in range(2,n):
  #print(a[i])
  tmp_used = max(tmp_unused, gcd(tmp_used, a[i]))
  tmp_unused = gcd(tmp_unused, a[i])
  
  #print("used=", tmp_used, "unused=", tmp_unused)
print(tmp_used)
Buggy python submission (verdict: Time Limit Exceeded):
import re

s = input()
n = len(s)

pattern = "(01)+|(10)+"
old_n = len(s)+1
while len(s)<old_n:
  old_n=len(s)
  s = re.sub(pattern,"", s)

print(n-len(s))

Fixed submission:
import re

s = input()
n = len(s)

one = [1 if si=="1" else 0 for si in s]
tmp=sum(one)
ret = min(tmp, n-tmp)*2

print(ret)
Buggy python submission (verdict: Time Limit Exceeded):
# coding: utf-8
# Your code here!

N = int(input())
A = list(map(int, input().split()))

ans = []
for i in range(1, N+1):
    ans.append(str(A.index(i)+1))
print(" ".join(ans))

Fixed submission:
N = int(input())
A = list(map(int, input().split()))

ans = [0 for i in range(N)]
for i in range(N):
    idx = A[i]-1
    ans[idx] = str(i+1)
print(" ".join(ans))